use super::*;
use crate::git_tree::{Delta, ToolCallState};
use crate::nav::convs::{Doing, doing, seats};
fn streaming(id: &str, delta: Option<Delta>) -> Agent {
let mut a = agent(id, AgentState::InFlight, 1);
a.stream.last_delta = delta;
a
}
#[test]
fn an_open_call_splits_three_ways_on_its_last_delta() {
assert_eq!(doing(&streaming("a", None)), Doing::Waiting);
assert_eq!(
doing(&streaming("a", Some(Delta::Thinking))),
Doing::Thinking
);
assert_eq!(doing(&streaming("a", Some(Delta::Text))), Doing::Inference);
for delta in [None, Some(Delta::Thinking), Some(Delta::Text)] {
assert!(doing(&streaming("a", delta)).is_model_call());
}
}
#[test]
fn a_tool_counts_only_under_a_driver_that_could_have_started_it() {
let live = named_tool("a", AgentState::Live, ToolCallState::InFlight, None, None);
assert_eq!(doing(&live), Doing::Tools);
let dead = named_tool(
"a",
AgentState::Stopped,
ToolCallState::InFlight,
None,
None,
);
assert_eq!(doing(&dead), Doing::Idle);
let done = named_tool("a", AgentState::Live, ToolCallState::Complete, None, None);
assert_eq!(doing(&done), Doing::Idle);
}
#[test]
fn an_open_call_outranks_a_running_tool() {
let mut both = named_tool(
"a",
AgentState::InFlight,
ToolCallState::InFlight,
None,
None,
);
both.stream.last_delta = Some(Delta::Text);
assert_eq!(doing(&both), Doing::Inference);
}
#[test]
fn every_settled_state_is_one_idle() {
for state in [AgentState::Quiescent, AgentState::Stopped] {
assert_eq!(doing(&agent("a", state, 1)), Doing::Idle);
assert!(!doing(&agent("a", state, 1)).is_model_call());
}
assert_eq!(doing(&agent("a", AgentState::Live, 1)), Doing::Idle);
}
#[test]
fn seats_are_the_root_then_its_descent() {
let mut root = agent("20260427T120000Z-aaaa", AgentState::InFlight, 3);
root.name = Some("energize".into());
root.stream.last_delta = Some(Delta::Thinking);
let kid = named_tool(
"20260427T120000Z-aaaa-20260427T120100Z-bbbb",
AgentState::Live,
ToolCallState::InFlight,
None,
None,
);
let agents = vec![root, kid];
let laid = seats(&agents, "20260427T120000Z-aaaa");
assert_eq!(laid.len(), 2);
assert_eq!(laid.first().map(|s| s.doing), Some(Doing::Thinking));
assert_eq!(
laid.first().map(|s| s.name.clone()),
Some("energize".to_owned())
);
assert_eq!(laid.get(1).map(|s| s.doing), Some(Doing::Tools));
}
#[test]
fn an_id_that_roots_nothing_seats_nobody() {
assert!(seats(&[], "no-such-root").is_empty());
}