use super::*;
mod exec;
pub(super) const ROOT: &str = "r-aa";
pub(super) const CHILD: &str = "r-aa-c-bb";
fn agent(id: &str, state: AgentState, ts: i64) -> Agent {
Agent {
branch_name: format!("agents/{id}"),
agent_id: id.to_string(),
name: None,
tip_oid: "a".repeat(40),
tip_short_oid: "aaaaaaaa".into(),
tip_timestamp_unix: ts,
last_action_unix: ts,
messages: 0,
steps: vec![],
preview: None,
stream: crate::git_tree::Stream::default(),
tool_calls: vec![],
state,
state_uncertain: false,
truncated: false,
failure: None,
flagged: None,
pending: vec![],
conflicted_oid: None,
budget_oid: None,
abandoned_oid: None,
notify_oid: None,
held: None,
goal_ball: None,
goal_name: None,
call_start_unix: None,
}
}
#[test]
fn the_gate_counts_every_running_or_uncertain_member_and_only_members() {
let kid = agent(CHILD, AgentState::InFlight, 2);
let ghost = agent("z-zz", AgentState::Live, 3);
let mut root = agent(ROOT, AgentState::Stopped, 1);
root.state_uncertain = true; let confirm = confirmation(ROOT, &[root, kid, ghost]);
assert_eq!(
confirm.live,
[ROOT, CHILD],
"the other conversation is not ours"
);
assert!(confirm.refused());
assert!(!confirm.subtree_armed(ROOT), "never armed while refused");
}
#[test]
fn a_settled_conversation_passes_and_the_typed_name_arms_the_subtree() {
let mut root = agent(ROOT, AgentState::Stopped, 1);
root.goal_name = Some("fix the parser".into());
let confirm = confirmation(ROOT, &[root, agent(CHILD, AgentState::Quiescent, 2)]);
assert!(!confirm.refused());
assert_eq!(
confirm.name, "fix the parser",
"the §3.3 ladder names the dialog"
);
assert!(
confirm.subtree_armed(" fix the parser "),
"whitespace forgiven"
);
assert!(!confirm.subtree_armed("fix"), "nothing else is");
}
#[test]
fn an_absent_root_is_the_general_path_with_empty_inputs() {
let confirm = confirmation("gone-id", &[]);
assert_eq!(confirm.name, "gone-id", "rung three: its own id");
assert!(!confirm.refused());
}
#[test]
fn the_seat_reads_the_same_gate_off_an_answered_forest() {
let kid = agent(CHILD, AgentState::InFlight, 2);
let ghost = agent("z-zz", AgentState::Live, 3);
let mut root = agent(ROOT, AgentState::Stopped, 1);
root.state_uncertain = true;
root.goal_name = Some("fix the parser".into());
let agents = [root, kid, ghost];
let rows = crate::nav::convs::forest_rows(
&agents,
"/ws",
&|_, _: &str, _: &str, _: &str| false,
100,
&|id: &str| crate::nav::convs::ConvBall {
id: id.to_owned(),
state: None,
title: None,
badge: None,
},
&[],
);
let seat = confirmation_of_rows(&rows, ROOT);
assert_eq!(
seat,
confirmation(ROOT, &agents),
"one gate, two projections"
);
assert!(seat.refused(), "the §10 uncertainty still counts as live");
let absent = confirmation_of_rows(&rows, "gone-id");
assert_eq!(absent, confirmation("gone-id", &[]));
}
#[test]
fn the_refusal_names_the_live_members() {
assert_eq!(
live_refusal(&["r-aa".into(), "r-aa-c-bb".into()]),
"refused \u{2014} live: r-aa, r-aa-c-bb \u{2014} stop them first"
);
}
#[test]
fn the_report_parse_reads_both_moods_and_refuses_garbage() {
let subtree = parse_report(
"would delete r-aa; descendants: 2 (r-aa-c-bb, r-aa-d-ee); pending deposits: 3",
)
.unwrap();
assert_eq!(subtree.descendants, [CHILD, "r-aa-d-ee"]);
assert_eq!(subtree.pending_deposits, 3);
let leaf = parse_report("deleted r-aa; descendants: 0; pending deposits: 0").unwrap();
assert_eq!(
leaf,
Census {
descendants: vec![],
pending_deposits: 0
}
);
for garbage in [
"",
"agent \"r-aa\" is being driven",
"would delete r-aa; descendants: 1 (x; pending deposits: y",
] {
assert!(parse_report(garbage).is_none(), "{garbage:?}");
}
}