use agent_client_protocol::v1::schema::{
SessionUpdate, ToolCall, ToolCallStatus, ToolCallUpdate, ToolCallUpdateFields,
};
use pretty_assertions::assert_eq;
use super::OwnCalls;
#[test]
fn the_agents_own_calls_count_from_their_announcement_to_their_end() {
let announced = |id: &'static str, status, served: Option<&'static str>| {
let call = ToolCall::new(id, "Task").status(status);
(SessionUpdate::ToolCall(call), served)
};
let updated = |id: &'static str, status: Option<ToolCallStatus>| {
let fields = match status {
Some(status) => ToolCallUpdateFields::new().status(status),
None => ToolCallUpdateFields::new(),
};
(
SessionUpdate::ToolCallUpdate(ToolCallUpdate::new(id, fields)),
None,
)
};
let heard = [
announced("task", ToolCallStatus::Pending, None),
announced("rho-wait", ToolCallStatus::InProgress, Some("sessions")),
updated("task", Some(ToolCallStatus::InProgress)),
updated("task", None),
announced("read", ToolCallStatus::InProgress, None),
announced("done", ToolCallStatus::Completed, None),
updated("rho-wait", Some(ToolCallStatus::Completed)),
updated("read", Some(ToolCallStatus::Failed)),
updated("task", Some(ToolCallStatus::Completed)),
];
let calls = OwnCalls::default();
let told: Vec<Option<usize>> = heard
.iter()
.map(|(update, served)| calls.hear(update, *served))
.collect();
assert_eq!(
told,
vec![
Some(1),
None,
None,
None,
Some(2),
None,
None,
Some(1),
Some(0)
]
);
}