use super::fixture::World;
use crate::cli_outbound::Cli;
use crate::nav::convs::{id_floor, is_stamp};
const ROOT: &str = "20260803T045643Z-1e5f99d4";
const CHILD: &str = "20260803T045643Z-1e5f99d4-20260804T101112Z-abcdef01";
const GONE: &str = "20260803T045643Z-1e5f99d4-20260805T220100Z-deadbeef";
const PEER: &str = "20260731T101112Z-abcdef01";
const BREAKS: &[char] = &[
' ', '\n', '\t', '·', ':', ',', '(', ')', '[', ']', '"', '\'', '—', '→', '⟩', '⟨',
];
fn id_runs(painted: &str) -> Vec<String> {
painted
.split(BREAKS)
.filter(|token| token.split('-').any(is_stamp))
.map(str::to_owned)
.collect()
}
fn painted_over_ids(tab: crate::keymap::InspectorTab) -> String {
let (lernie, bl) = (Cli::new("yog-absent-lernie"), Cli::new("yog-absent-bl"));
let mut world = super::inbox_composer::quick(super::fixture::world());
let ws = world.ws.clone();
world.add_root(ROOT, "cormorant");
world.add_root(PEER, "peregrine");
world.add_child(ROOT, CHILD);
deposit_from(&world, ROOT, CHILD);
deposit_from(&world, ROOT, GONE);
deposit_from(&world, ROOT, PEER);
world.model.mark_dirty([ws.clone()]);
world.converge();
world.model.focus_agent(&ws, ROOT);
world.model.select_tab(tab);
world.state.expanded.insert(ROOT.to_owned());
super::painted(&mut world, &lernie, &bl)
}
fn deposit_from(world: &World, agent: &str, sender: &str) {
let dir = world.ws.join("inbox").join(agent);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(
dir.join(format!("{sender}-001.md")),
format!("---\nfrom: {sender}\ndeposited_at: t0\n---\nreporting back"),
)
.unwrap();
}
#[test]
fn no_painted_run_spells_more_of_an_agent_id_than_the_ladder_does() {
let lawful = [ROOT, CHILD, GONE].map(|id| id_floor(id).to_owned());
for tab in [
crate::keymap::InspectorTab::Transcript,
crate::keymap::InspectorTab::Inbox,
] {
let painted = painted_over_ids(tab);
let runs = id_runs(&painted);
assert!(
!runs.is_empty(),
"the {tab:?} drive painted no id at all — the fixture no longer \
reaches a seat that spells one, so this scan is asserting nothing:\n{painted}"
);
for run in &runs {
assert!(
lawful.contains(run),
"a seat spells an agent id past the ladder's floor: {run:?} on \
{tab:?}, where §3.3 allows only {lawful:?} — every title rides \
the display ladder, and the id's seats are the ladder's floor \
and the hover:\n{painted}"
);
}
}
}
#[test]
fn the_scan_indicts_the_defect_that_shipped() {
let leaked = format!("✉ {CHILD} · t0");
let runs = id_runs(&leaked);
assert_eq!(
runs,
vec![CHILD.to_owned()],
"the whole chain is read out of the row as one run"
);
assert!(
!runs.contains(&id_floor(CHILD).to_owned()),
"and it is not the floor's spelling, so the invariant above fails on it"
);
assert_eq!(
id_runs(&format!("✉ {} · t0", id_floor(CHILD))),
vec![id_floor(CHILD).to_owned()]
);
assert!(id_runs("✉ user · t0").is_empty());
}
#[test]
fn a_named_senders_deposit_paints_the_name_the_rest_of_the_frame_paints() {
let painted = painted_over_ids(crate::keymap::InspectorTab::Inbox);
assert!(
painted.contains("✉ peregrine · t0"),
"the header names its sender — what this very frame's roster calls \
it:\n{painted}"
);
assert!(
!painted.contains(PEER),
"and the id it used to spell is nowhere: a named agent's id has two \
seats, the ladder's floor and the hover, and this is neither:\n{painted}"
);
}
#[test]
fn a_nameless_chained_child_row_shows_its_terminal_segment_and_hovers_the_full_id() {
let (lernie, bl) = (Cli::new("lernie"), Cli::new("bl"));
let mut world = super::inbox_composer::quick(super::fixture::world());
let ws = world.ws.clone();
world.add_child("c-1", "c-1-20260803T045643Z-1e5f99d4");
world.model.mark_dirty([ws.clone()]);
world.converge();
world.model.focus_agent(&ws, "c-1");
world.state.expanded.insert("c-1".to_owned());
let out = super::painted(&mut world, &lernie, &bl);
assert!(
out.contains("20260803T045643Z-1e5f99d4"),
"the child's row titles it by its terminal generation:\n{out}"
);
assert!(
!out.contains("c-1-20260803T045643Z-1e5f99d4"),
"the row never re-spells the lineage — the indent and its elbow state it:\n{out}"
);
let bz = Cli::new("bz");
let ctx = egui::Context::default();
ctx.memory_mut(|m| m.set_everything_is_visible(true));
let mut frame = || {
let full = ctx.run(super::input(), |ctx| {
super::super::render(ctx, &mut world.model, &mut world.state, &lernie, &bl, &bz);
});
crate::paint_probe::text_of(&full)
};
frame();
let hovered = frame();
assert!(
hovered.contains("c-1-20260803T045643Z-1e5f99d4"),
"the full chained id rides the hover:\n{hovered}"
);
}