use super::{AGENT, write_file};
use crate::files_view::Preview;
use crate::steps_view::{StepDetail, detail};
const ADAPTER: &str = "bz: no workspace in this environment — providers, sign-ins and the model \
cache belong to a workspace.";
const DRIVER: &str = "litany: provider refused the turn — unpaired tool_use in the tail";
fn write_driver_log(ws: &std::path::Path, bytes: &[u8]) {
let dir = ws.join("steps").join(AGENT);
std::fs::create_dir_all(&dir).unwrap();
std::fs::write(dir.join("driver.log"), bytes).unwrap();
}
fn wounded() -> (tempfile::TempDir, StepDetail) {
let dir = tempfile::tempdir().unwrap();
let ws = dir.path();
write_file(ws, "001", "request.json", br#"{"model":"opus"}"#);
write_file(ws, "001", "response.json", b"");
write_file(ws, "001", "stderr.log", ADAPTER.as_bytes());
write_driver_log(ws, DRIVER.as_bytes());
let d = detail(ws, AGENT, "001").unwrap();
(dir, d)
}
#[test]
fn a_step_with_captured_words_carries_both_logs_whole() {
let (_dir, d) = wounded();
assert_eq!(d.stderr, Some(Preview::Text(ADAPTER.to_owned())));
assert_eq!(d.driver, Some(Preview::Text(DRIVER.to_owned())));
let said = crate::steps_view::wire::detail(&d);
assert!(
said["stderr"]["text"].as_str().unwrap_or_default() == ADAPTER,
"got:\n{said:#}"
);
assert!(
said["driver"]["text"].as_str().unwrap_or_default() == DRIVER,
"got:\n{said:#}"
);
}
#[test]
fn an_empty_or_absent_log_is_no_reading_at_all() {
let dir = tempfile::tempdir().unwrap();
let ws = dir.path();
write_file(ws, "001", "meta.json", br#"{"commit":"c0ffee"}"#);
write_file(ws, "001", "stderr.log", b"");
let d = detail(ws, AGENT, "001").unwrap();
assert_eq!(d.stderr, None, "an empty log is nothing to read");
assert_eq!(d.driver, None, "an absent log is the same fact");
let said = crate::steps_view::wire::detail(&d);
assert!(said["stderr"].is_null(), "got:\n{said:#}");
assert!(said["driver"].is_null(), "got:\n{said:#}");
}