rho-coding-agent 3.7.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use agent_client_protocol::{v1::schema as v1, v2::schema as v2};
use pretty_assertions::assert_eq;
use serde_json::json;

use super::{request, response};

// Covers: v2 removed a string property's `pattern`, and its strict parse
// fails a request-scoped form that names `sessionId` or `toolCallId`, even
// as null. An MCP server's forwarded schema may carry `pattern`, so the v2
// request must drop it and name only its one scope; the v2 types do both,
// and a schema crate that stopped doing so would break hosts.
// Owner: ACP v2 boundary, elicitation request mapping
#[test]
fn forms_lose_pattern_and_keep_one_scope() {
    let schema = json!({
        "type": "object",
        "properties": {"code": {"type": "string", "title": "Code", "pattern": "^[0-9]+$"}},
        "required": ["code"],
    });
    let cases = [
        (
            "session scope with a tool call",
            json!({"sessionId": "s", "toolCallId": "call-1"}),
        ),
        ("request scope", json!({"requestId": 7})),
    ];
    for (label, scope) in cases {
        let mut wire =
            json!({"mode": "form", "message": "Enter the code", "requestedSchema": schema});
        wire.as_object_mut()
            .unwrap()
            .extend(scope.as_object().unwrap().clone());
        let v1_request: v1::CreateElicitationRequest =
            serde_json::from_value(wire.clone()).unwrap();
        wire["requestedSchema"]["properties"]["code"]
            .as_object_mut()
            .unwrap()
            .remove("pattern");
        assert_eq!(
            serde_json::to_value(request(&v1_request).unwrap()).unwrap(),
            wire,
            "{label}"
        );
    }
}

// Covers: v2 requires an elicitation action the agent doesn't know to be
// handled as `cancel`; v1 Rho reads an unknown action as a decline.
// Owner: ACP v2 boundary, elicitation response mapping
#[test]
fn unknown_actions_cancel() {
    let cases = [
        (
            json!({"action": "_tck_unknown", "extra": 1}),
            json!({"action": "cancel"}),
        ),
        (json!({"action": "decline"}), json!({"action": "decline"})),
        (
            json!({"action": "accept", "content": {"code": "42"}}),
            json!({"action": "accept", "content": {"code": "42"}}),
        ),
    ];
    for (answered, expected) in cases {
        let answered: v2::CreateElicitationResponse = serde_json::from_value(answered).unwrap();
        assert_eq!(
            serde_json::to_value(response(answered).unwrap()).unwrap(),
            expected
        );
    }
}