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;

// Covers: a ref names the same element across reads of one document, and
// a ref from an earlier document never reaches a node of the new one,
// whose ids can repeat the old ones.
// Owner: browser element refs
#[test]
fn refs_last_as_long_as_their_document() {
    let mut refs = Refs::default();
    refs.follow("first");
    let link = BackendNodeId(14);
    let button = BackendNodeId(30);
    assert_eq!(
        [refs.name(link), refs.name(button), refs.name(link)],
        ["ref_1", "ref_2", "ref_1"]
    );
    assert_eq!(refs.node("ref_2", "first"), Ok(button));

    refs.follow("first");
    assert_eq!(refs.node("ref_1", "first"), Ok(link), "same document");
    refs.follow("second");
    assert_eq!(
        refs.node("ref_1", "second"),
        Err(StaleRef("ref_1".to_owned())),
        "a new document's node 14 is another element"
    );
    assert_eq!(refs.name(button), "ref_1", "numbering starts over");
}

// Covers: a ref that names no element fails as stale rather than reaching
// some other one.
// Owner: browser element refs
#[test]
fn unknown_refs_are_stale() {
    let mut refs = Refs::default();
    refs.follow("page");
    refs.name(BackendNodeId(5));
    for name in ["ref_0", "ref_2", "ref_x", "5", ""] {
        assert_eq!(
            refs.node(name, "page"),
            Err(StaleRef(name.to_owned())),
            "{name:?}"
        );
    }
    assert_eq!(
        refs.node("ref_1", "an older page"),
        Err(StaleRef("ref_1".to_owned())),
        "asked about another document"
    );
}