rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use std::{collections::BTreeMap, sync::Arc};

use pretty_assertions::assert_eq;
use rho_providers::credentials::{CredentialStore, MemoryCredentialStore};

use super::*;

// Covers: testing a server never changes or leaks the daemon's store: a
// draft that logs in elsewhere sees no saved OAuth tokens, and clearing or
// replacing them through the probe, as a token issued by another
// authorization server does, leaves the saved ones in place, while the probe
// itself reads what it wrote; and a draft's secret values win over
// stored ones without being stored, each kept for redaction, which replaces
// a value holding another one whole.
// Owner: MCP probe credential stores.
#[test]
fn a_probe_reads_through_its_stores_and_leaves_the_daemons_unchanged() {
    let daemon = Arc::new(MemoryCredentialStore::default());
    daemon
        .set_secret("mcp-oauth:linear", "saved-tokens")
        .unwrap();
    daemon
        .set_secret(&account_name("linear", "TOKEN"), "stored-token")
        .unwrap();
    daemon
        .set_secret(&account_name("linear", "OTHER"), "stored-other")
        .unwrap();

    let scratch = ScratchTokens::new(daemon.clone());
    let before = scratch.get_secret("mcp-oauth:linear").unwrap();
    let deleted = scratch.delete_secret("mcp-oauth:linear").unwrap();
    let after_delete = scratch.get_secret("mcp-oauth:linear").unwrap();
    scratch
        .set_secret("mcp-oauth:linear", "draft-tokens")
        .unwrap();
    let after_write = scratch.get_secret_fresh("mcp-oauth:linear").unwrap();

    let served = Served::default();
    let secrets = UnsavedFirst::new(
        "linear",
        BTreeMap::from([("TOKEN".to_owned(), "other".to_owned())]),
        Some(daemon.clone()),
        served.clone(),
    );
    let read = [
        secrets
            .get_secret_fresh(&account_name("linear", "TOKEN"))
            .unwrap(),
        secrets
            .get_secret_fresh(&account_name("linear", "OTHER"))
            .unwrap(),
    ];
    let refused = [
        secrets
            .set_secret(&account_name("linear", "TOKEN"), "x")
            .is_err(),
        secrets
            .delete_secret(&account_name("linear", "TOKEN"))
            .is_err(),
    ];

    assert_eq!(
        (
            (before, deleted, after_delete, after_write),
            read,
            refused,
            served.redact("got other and stored-other"),
            [
                daemon.get_secret("mcp-oauth:linear").unwrap(),
                daemon.get_secret(&account_name("linear", "TOKEN")).unwrap(),
            ],
        ),
        (
            (None, false, None, Some("draft-tokens".to_owned())),
            [Some("other".to_owned()), Some("stored-other".to_owned())],
            [true, true],
            "got [redacted] and [redacted]".to_owned(),
            [
                Some("saved-tokens".to_owned()),
                Some("stored-token".to_owned())
            ],
        )
    );
}