use std::sync::Arc;
use super::fixture::{World, world};
use super::painted;
use crate::app::WoundGrace;
use crate::cli_outbound::Cli;
use crate::keymap::InspectorTab;
use crate::steps_view::ORPHANED_MAIL;
use crate::test_support::FakeClock;
const DRIVER_WORDS: &str = "lernie: branch tip is an assistant entry with tool_use unmatched \
by committed tool results — declined (ARCH 6)";
const NEEDLE: &str = "tool_use unmatched";
fn orphaned_mail(world: &World, driver_log: Option<&[u8]>) {
let messages = world.ws.join("agents/c-1/messages");
std::fs::write(messages.join("003-user.md"), "hello?").unwrap();
if let Some(bytes) = driver_log {
let steps = world.ws.join("steps/c-1");
std::fs::create_dir_all(&steps).unwrap();
std::fs::write(steps.join("driver.log"), bytes).unwrap();
}
}
fn orphaned_world(driver_log: Option<&[u8]>) -> (World, FakeClock) {
let mut world = world();
let ws = world.ws.clone();
orphaned_mail(&world, driver_log);
world.model.focus_agent(&ws, "c-1");
world.model.select_tab(InspectorTab::Transcript);
let clock = FakeClock::new();
world.state.orphan_grace = WoundGrace::new(Arc::new(clock.handle()));
world.converge();
(world, clock)
}
#[test]
fn the_window_states_why_the_chat_stopped_answering() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let (mut world, clock) = orphaned_world(Some(DRIVER_WORDS.as_bytes()));
let early = painted(&mut world, &lernie, &bl);
assert!(
!early.contains(ORPHANED_MAIL),
"the orphan is graced before it is believed:\n{early}"
);
clock.advance(world.model.cadence().wound_grace());
let text = painted(&mut world, &lernie, &bl);
assert!(text.contains(ORPHANED_MAIL), "the class, in words:\n{text}");
assert!(
text.contains(NEEDLE),
"THE BALL: the dead driver's own words, on screen:\n{text}"
);
assert!(
text.contains("driver.log"),
"and where the whole of it lives:\n{text}"
);
}
#[test]
fn an_orphan_with_nothing_to_quote_still_banners_and_says_so() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let (mut world, clock) = orphaned_world(None);
let _ = painted(&mut world, &lernie, &bl);
clock.advance(world.model.cadence().wound_grace());
let text = painted(&mut world, &lernie, &bl);
assert!(text.contains(ORPHANED_MAIL), "still the class:\n{text}");
assert!(
text.contains("nothing on disk says why"),
"the honest end of the trail:\n{text}"
);
}