#![allow(clippy::unwrap_used)]
use std::path::Path;
use tempfile::tempdir;
use yog::transcript::{self, EntryKind};
const AGENT: &str = "20260719T120000Z-reply";
fn write_msg(ws: &Path, name: &str, bytes: &[u8]) {
let dir = ws.join("agents").join(AGENT).join("messages");
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join(name), bytes).unwrap();
}
fn write_response(ws: &Path, seq: u32, body: &[u8]) {
let dir = ws.join("steps").join(AGENT).join(format!("{seq:03}"));
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("response.json"), body).unwrap();
}
#[test]
fn open_response_surfaces_a_visually_distinct_live_tail() {
let dir = tempdir().unwrap();
let ws = dir.path();
write_msg(ws, "001-operator.md", b"summarize the design");
write_response(
ws,
1,
b"{\"type\":\"content_delta\",\"index\":0,\"delta\":{\"text_delta\":\"The design \"}}\n\
{\"type\":\"content_delta\",\"index\":0,\"delta\":{\"text_delta\":\"streams.\"}}\n",
);
let settled = transcript::build(ws, AGENT, false);
assert_eq!(settled.entries.len(), 1, "no live tail when not in flight");
assert!(matches!(
settled.entries[0].kind,
EntryKind::Delivered { .. }
));
let live = transcript::build(ws, AGENT, true);
assert_eq!(live.entries.len(), 2, "committed message + live tail");
assert!(matches!(live.entries[0].kind, EntryKind::Delivered { .. }));
let tail = live.entries.last().unwrap();
assert!(
matches!(&tail.kind, EntryKind::Streaming { text } if text == "The design streams."),
"expected a Streaming live tail folding the growing response, got {:?}",
tail.kind
);
assert_eq!(tail.raw, b"The design streams.");
let streaming = live
.entries
.iter()
.filter(|e| matches!(e.kind, EntryKind::Streaming { .. }))
.count();
assert_eq!(streaming, 1);
}