rho-coding-agent 3.5.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use agent_client_protocol::v1::schema::{AuthMethod, AuthMethodAgent, AuthMethodTerminal};
use pretty_assertions::assert_eq;
use rho_protocol::{AuthKind, AuthStatus, AuthSummary};

use super::methods;
use crate::app::acp::host_features::HostFeatures;

fn summary(auth: &str, label: &str, kind: AuthKind) -> AuthSummary {
    AuthSummary {
        auth: auth.into(),
        provider: "p".into(),
        label: label.into(),
        kind,
        status: AuthStatus::SignedOut,
    }
}

fn terminal(auth: &str, label: &str) -> AuthMethod {
    AuthMethod::Terminal(
        AuthMethodTerminal::new(auth.to_owned(), label.to_owned())
            .args(vec!["--login".into(), auth.into()]),
    )
}

// Covers: an interactive login runs in the host only where it opens URLs,
// an API key never does (secrets must not travel in ACP messages), the
// terminal login is offered only to hosts with a terminal, and neither a
// kind this rho does not know nor a sign-in whose approval nothing reports
// (Ollama Cloud's device key) is offered at all
// Owner: ACP auth advertisement
#[test]
fn auth_methods_follow_what_the_host_can_do() {
    let auths = [
        summary("openai-codex", "ChatGPT", AuthKind::Login),
        summary("openai", "OpenAI API key", AuthKind::ApiKey),
        summary("future", "Future", AuthKind::Unknown),
        summary("ollama-cloud-device", "Ollama Cloud", AuthKind::Login),
    ];
    let cases = [
        (
            "urls and terminal",
            /*urls*/ true,
            /*terminal*/ true,
            vec![
                AuthMethod::Agent(AuthMethodAgent::new("openai-codex", "ChatGPT")),
                terminal("openai", "OpenAI API key"),
            ],
        ),
        (
            "terminal only",
            false,
            true,
            vec![
                terminal("openai-codex", "ChatGPT"),
                terminal("openai", "OpenAI API key"),
            ],
        ),
        (
            "urls only",
            true,
            false,
            vec![AuthMethod::Agent(AuthMethodAgent::new(
                "openai-codex",
                "ChatGPT",
            ))],
        ),
        ("neither", false, false, vec![]),
    ];
    for (label, urls, terminal, expected) in cases {
        let features = HostFeatures {
            urls,
            terminal,
            ..HostFeatures::default()
        };
        assert_eq!(methods(&auths, features), expected, "{label}");
    }
}