rho-coding-agent 3.10.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use agent_client_protocol::v1::schema::{
    PermissionOption, PermissionOptionKind, ToolCallUpdate, ToolCallUpdateFields, ToolKind,
};
use pretty_assertions::assert_eq;

use super::*;

fn permission_request(kind: ToolKind) -> RequestPermissionRequest {
    RequestPermissionRequest::new(
        "session",
        ToolCallUpdate::new("call", ToolCallUpdateFields::new().kind(kind)),
        vec![PermissionOption::new(
            "allow",
            "Allow",
            PermissionOptionKind::AllowOnce,
        )],
    )
}

// Covers: Plan pins agy's `plan` mode and rejects every permission request;
// Bypass pins `default` and approves a declared command; both spawn agy on
// the run's own agent; a pinned model becomes the session option; runs never
// authenticate; nothing is approved or spawned before `prepare`.
// Owner: Antigravity policy wiring; the driver applying these is covered in
// `acp_runtime` session tests, the fence table in `fence` tests.
#[test]
fn prepared_run_pins_agent_mode_permissions_and_model() {
    let run_dir = tempfile::tempdir().unwrap();
    let execute = permission_request(ToolKind::Execute);
    for (mode, expected_mode, expected_decision) in [
        (PermissionMode::Plan, "plan", PermissionDecision::Reject),
        (
            PermissionMode::Bypass,
            "default",
            PermissionDecision::AllowOnce,
        ),
    ] {
        let mut policy = AntigravityAcpPolicy::new(
            Some("gemini-3.8-flash".into()),
            vec![AntigravityTool::ReadFile, AntigravityTool::RunCommand],
            mode,
            PathBuf::from("/work"),
            PromptPolicy::Extend(String::new()),
        );
        assert_eq!(
            policy.decide_permission(&execute),
            PermissionDecision::Reject,
            "{mode}: before prepare"
        );
        assert!(policy.spawn_plan().is_err(), "{mode}: before prepare");
        assert_eq!(policy.prepare(run_dir.path()), Ok(()));
        let agent = policy.prepared.as_ref().unwrap().agent.clone();
        assert_eq!(agent.root, run_dir.path().join("agy"));
        let argv = policy.spawn_plan().unwrap().argv;
        assert_eq!(
            (
                argv,
                policy.session_mode(),
                policy.session_config(),
                policy.auth_method(&[]),
                policy.decide_permission(&execute),
            ),
            (
                vec![
                    "acp".into(),
                    "--cli_dir_name".into(),
                    "rho".into(),
                    "--add-dir".into(),
                    agent.root.into_os_string(),
                    "--agent".into(),
                    agent.name.into(),
                ],
                Some(SessionModeId::new(expected_mode)),
                vec![SessionConfigChoice {
                    id: "model".into(),
                    value: "gemini-3.8-flash".into(),
                }],
                None,
                expected_decision,
            ),
            "{mode}"
        );
    }
}

// Covers: `prepare` gates the run through the fence, so a mode Rho cannot
// answer for fails before spawn (the fence table owns the other cases).
// Owner: Antigravity preflight; message wording is not locked.
#[test]
fn prepare_refuses_modes_that_need_a_human() {
    let run_dir = tempfile::tempdir().unwrap();
    let prepared = AntigravityAcpPolicy::new(
        None,
        vec![AntigravityTool::ReadFile],
        PermissionMode::Auto,
        PathBuf::from("/work"),
        PromptPolicy::Extend(String::new()),
    )
    .prepare(run_dir.path());
    assert!(prepared.is_err());
    assert!(
        !run_dir.path().join("agy").exists(),
        "no agent file is written"
    );
}

// Covers: `prepare` refuses a definition that would replace agy's system
// prompt, which agy only appends to, where the same run extending it
// prepares.
// Owner: Antigravity preflight; message wording is not locked.
#[test]
fn prepare_refuses_replacing_agys_system_prompt() {
    let prepared = [
        PromptPolicy::Extend("be brief".into()),
        PromptPolicy::Replace("be brief".into()),
    ]
    .map(|prompt| {
        let run_dir = tempfile::tempdir().unwrap();
        AntigravityAcpPolicy::new(
            None,
            vec![AntigravityTool::ReadFile],
            PermissionMode::Bypass,
            PathBuf::from("/work"),
            prompt,
        )
        .prepare(run_dir.path())
        .is_ok()
    });
    assert_eq!(prepared, [true, false]);
}

// Covers: agy names a call of one of rho's served tools `mcp_rho_<tool>`,
// kind `other`, and the policy reads the tool from that alone, so the
// driver approves its ask and holds its card for the served call; a call
// of another kind, or of none, names no tool. Kills: the kind check dropped
// (a command the model named `mcp_rho_process` would skip the fence), the
// name not read through agy's naming (`run_command` read as a tool). Which
// names agy's naming reads back is `each_naming_reads_back_only_rhos_tools`'.
// Owner: Antigravity policy (served tool names).
#[test]
fn reads_rhos_served_tools_from_agys_mcp_names() {
    let policy = AntigravityAcpPolicy::new(
        None,
        vec![AntigravityTool::ReadFile],
        PermissionMode::Bypass,
        PathBuf::from("/work"),
        PromptPolicy::Extend(String::new()),
    );
    let cases = [
        (
            "mcp_rho_questionnaire",
            Some(ToolKind::Other),
            Some("questionnaire"),
        ),
        (
            "mcp_rho_list_session_pull_requests",
            Some(ToolKind::Other),
            Some("list_session_pull_requests"),
        ),
        ("mcp_rho_process", Some(ToolKind::Execute), None),
        ("mcp_rho_process", None, None),
        ("run_command", Some(ToolKind::Other), None),
    ];
    for (name, kind, expected) in cases {
        assert_eq!(
            policy.agent_tool(AgentToolCallRef {
                meta: None,
                name: Some(name),
                kind,
            }),
            expected,
            "{name} {kind:?}"
        );
    }
}