rho-coding-agent 3.12.0

A fast Rust agent harness with a small footprint and opinionated defaults
Documentation
use super::*;
use pretty_assertions::assert_eq;
use AcpProtocol::{V1, V2};

// Covers: an adapter that answered v1 to v2 starts its next runs on v1
// until it reports another version, answers v2, or fails a v1
// `initialize` (as one upgraded to speak v2 only); one a policy runs on v1
// is not v1-only; and what an adapter's last `initialize` said is known,
// nothing before one answered.
// Owner: ACP adapter cache (pure).
#[test]
fn the_cache_remembers_what_each_adapter_said() {
    let facts = |protocol, images| Some(AdapterFacts { protocol, images });
    // (case, its initializes: (requested, answered on, version), `None`
    // for a v1 one that failed; then the protocol a v2 run starts on and
    // what is known)
    let cases = [
        ("an adapter never run", vec![], (V2, None)),
        (
            "a v2 adapter",
            vec![Some((V2, V2, "0.114.0"))],
            (V2, facts(V2, true)),
        ),
        (
            "one that answered v1 to v2 starts on v1",
            vec![Some((V2, V1, "0.9.0")), Some((V1, V1, "0.9.0"))],
            (V1, facts(V1, true)),
        ),
        (
            "an upgrade tries v2 again",
            vec![Some((V2, V1, "0.9.0")), Some((V1, V1, "1.0.0"))],
            (V2, facts(V1, true)),
        ),
        (
            "an adapter that answers v2 later is not v1-only",
            vec![Some((V2, V1, "0.9.0")), Some((V2, V2, "1.0.0"))],
            (V2, facts(V2, true)),
        ),
        (
            "a failed v1 start asks for v2 again",
            vec![Some((V2, V1, "0.9.0")), None],
            (V2, facts(V1, true)),
        ),
        (
            "an adapter its policy runs on v1 is not v1-only",
            vec![Some((V1, V1, "1.5.23"))],
            (V2, facts(V1, true)),
        ),
    ];
    let path = Path::new("/bin/adapter");
    for (case, answered, expected) in cases {
        let adapters = Adapters::default();
        let adapter = Adapter {
            cache: &adapters,
            path,
        };
        for initialize in answered {
            match initialize {
                Some((requested, protocol, version)) => {
                    adapter.initialized(requested, protocol, Some(version.to_owned()), true);
                }
                None => adapter.v1_failed(),
            }
        }
        assert_eq!(
            (adapter.start_on(V2), adapters.known(path)),
            expected,
            "{case}"
        );
    }
}