use std::sync::Arc;
use std::time::Duration;
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::NO_RESPONSE;
use crate::test_support::FakeClock;
const BZ_REFUSAL: &str = "bz: no workspace in this environment — providers, sign-ins and the \
model cache belong to a workspace, and there is nothing shared to fall back to. Run this inside \
a yog workspace, or focus one in yog.";
const NEEDLE: &str = "no workspace in this environment";
fn dead_step(world: &World, stderr: &[u8]) {
let dir = world.ws.join("steps/c-1/002");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("request.json"), br#"{"model":"opus"}"#).unwrap();
std::fs::write(dir.join("response.json"), b"").unwrap();
std::fs::write(dir.join("stderr.log"), stderr).unwrap();
}
fn wounded_world(stderr: &[u8]) -> (World, FakeClock) {
let mut world = world();
let ws = world.ws.clone();
dead_step(&world, stderr);
world.model.focus_agent(&ws, "c-1");
world.model.select_tab(InspectorTab::Transcript);
let clock = FakeClock::new();
world.state.wound_grace = WoundGrace::new(Arc::new(clock.handle()));
world.converge();
(world, clock)
}
fn past_the_window(world: &World) -> Duration {
world.model.cadence().wound_grace()
}
#[test]
fn the_window_states_why_the_reply_never_came() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let (mut world, clock) = wounded_world(BZ_REFUSAL.as_bytes());
let early = painted(&mut world, &lernie, &bl);
assert!(
!early.contains(NEEDLE),
"the wound is graced before it is believed:\n{early}"
);
clock.advance(past_the_window(&world));
let text = painted(&mut world, &lernie, &bl);
assert!(
text.contains(NO_RESPONSE),
"the §7.3 class, in words:\n{text}"
);
assert!(
text.contains(NEEDLE),
"THE BALL: the reason the operator never saw — the step's own \
stderr.log, on screen:\n{text}"
);
assert!(
text.contains("stderr.log"),
"and where the whole of it lives:\n{text}"
);
assert!(
!text.contains("activity trail below"),
"the dead pointer is gone:\n{text}"
);
}
#[test]
fn a_wound_with_nothing_to_quote_still_banners_and_says_so() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let (mut world, clock) = wounded_world(b"");
let _ = painted(&mut world, &lernie, &bl);
clock.advance(past_the_window(&world));
let text = painted(&mut world, &lernie, &bl);
assert!(text.contains(NO_RESPONSE), "still the class:\n{text}");
assert!(
text.contains("nothing on disk says why"),
"the honest end of the trail:\n{text}"
);
}