use serde_json::{Value, json};
use crate::render::rendered;
#[track_caller]
fn says(frame: &Value, needles: &[&str]) {
let said = rendered(frame);
for needle in needles {
assert!(said.contains(needle), "{frame}\n-> {said}");
}
}
#[test]
fn every_class_of_a_bounded_preview_says_what_it_is() {
for (preview, needle) in [
(json!({"kind": "text", "text": "hello"}), "hello"),
(
json!({"kind": "truncated", "text": "hel", "size": 9_000}),
"head of 9000 bytes",
),
(json!({"kind": "binary", "size": 12}), "12 bytes, binary"),
(json!({"kind": "a-class-from-2027"}), "no reading"),
] {
says(
&json!({"ok": true, "kind": "files", "worktree": true, "rows": [],
"truncated": false, "preview": preview}),
&[needle],
);
}
}
#[test]
fn a_worktree_that_answered_nothing_says_so() {
says(
&json!({"ok": true, "kind": "files", "worktree": false}),
&["no worktree listing"],
);
says(
&json!({"ok": true, "kind": "files", "worktree": true, "truncated": true,
"working_dir": "/w", "rows": [
{"path": "src", "size": 0, "dir": true},
{"path": "src/lib.rs", "size": 40, "dir": false}]}),
&["in /w", "(truncated)", "src/", "40 bytes"],
);
}
#[test]
fn every_class_of_a_captured_document_is_printed_as_what_it_is() {
let absent = json!({"kind": "absent"});
says(
&json!({"ok": true, "kind": "step", "seq": "004",
"meta": {"kind": "json", "raw": "{\"a\":1}"},
"request": absent,
"staging": {"kind": "unparsed", "note": "not JSON", "raw": "oops"},
"response": [{"kind": "a-class-from-2027"}],
"tools": [{"tool_id": "t1", "is_error": true,
"input": absent, "output": absent}],
"stderr": {"kind": "text", "text": "warned"},
"driver": {"kind": "text", "text": "drove"}}),
&[
"step 004",
"{\"a\":1}",
"request: not written",
"not JSON",
"no reading",
"t1",
"ERROR",
"warned",
"drove",
],
);
}
#[test]
fn every_transcript_entry_and_every_block_has_a_reading() {
says(
&json!({"ok": true, "kind": "transcript", "rows": [
{"name": "002-model.md", "raw": "", "kind": "model",
"model_id": "a-model", "usage": {"input": 5},
"blocks": [{"kind": "text", "text": "said"},
{"kind": "thinking", "text": "thought"},
{"kind": "tool-use", "id": "t1", "name": "Bash", "input": "ls"},
{"kind": "a-block-from-2027"}]},
{"name": "003-tool.md", "raw": "", "kind": "tool-result",
"tool_use_id": "t1", "content": "ok", "is_error": true},
{"name": "004-live.md", "raw": "", "kind": "streaming",
"thinking": "still", "text": "going"},
{"name": "005-fold.md", "raw": "", "kind": "compacted",
"first": 1, "last": 9, "summary": "the gist"},
{"name": "006-raw.md", "raw": "", "kind": "raw"},
{"name": "007-new.md", "raw": "", "kind": "an-entry-from-2027"}
]}),
&[
"a-model",
"input 5",
"said",
"thinking",
"thought",
"Bash (t1)",
"[a-block-from-2027]",
"result of t1",
"ERROR",
"still",
"going",
"compacted 1–9",
"the gist",
"raw",
"an-entry-from-2027",
],
);
}
#[test]
fn every_boolean_receipt_says_both_of_its_answers() {
for (frame, needle) in [
(
json!({"ok": true, "kind": "retired", "discarded": true}),
"went with it",
),
(
json!({"ok": true, "kind": "retired", "discarded": false}),
"is kept",
),
(
json!({"ok": true, "kind": "floored", "standing": true}),
"a floor stands",
),
(
json!({"ok": true, "kind": "floored", "standing": false}),
"no floor stands",
),
(
json!({"ok": true, "kind": "armed", "armed": true}),
"it is armed",
),
(
json!({"ok": true, "kind": "armed", "armed": false}),
"not armed",
),
(
json!({"ok": true, "kind": "answered", "tool": "Bash", "tool_use": "t1",
"verdict": "allow", "scope": "workspace", "advanced": true}),
"advanced",
),
(
json!({"ok": true, "kind": "answered", "tool": "Bash", "tool_use": "t1",
"verdict": "hold", "scope": "call", "advanced": false}),
"still parked",
),
(
json!({"ok": true, "kind": "delivered", "base": "b", "target": "main",
"source": "work/x", "commit": "abc"}),
"as abc",
),
(
json!({"ok": true, "kind": "delivered", "base": "b", "target": "main",
"source": null, "commit": null}),
"landed nothing",
),
] {
says(&frame, &[needle]);
}
}
#[test]
fn a_governing_commit_carries_the_engines_own_sentence_either_way() {
says(
&json!({"ok": true, "kind": "governing", "oid": "abc123", "short_oid": "abc123",
"follows": "main", "files": ["souls/worker.md"]}),
&["policy follows config/main", "souls/worker.md"],
);
says(
&json!({"ok": true, "kind": "governing", "oid": "abc123", "short_oid": "abc123",
"follows": null, "diverged_lineages": 2, "files": []}),
&["policy held at abc123", "no file governs it"],
);
}
#[test]
fn the_start_family_renders_and_an_enrollment_prints_no_secret() {
let body = json!({"workspace": "proj", "goal": "write the changelog"});
says(
&json!({"ok": true, "kind": "prepared", "prepared": body}),
&["staged in proj", "write the changelog"],
);
says(
&json!({"ok": true, "kind": "fanned", "rows": []}),
&["no candidate"],
);
let said = rendered(&json!({"ok": true, "kind": "enrolled", "grade": "operator",
"name": "phone", "address": "h:1", "ca": "CA-PEM",
"cert": "CERT-PEM", "key": "KEY-PEM"}));
assert!(said.contains("enrolled phone"), "{said}");
assert!(
!said.contains("KEY-PEM"),
"the key reached the terminal: {said}"
);
}
#[test]
fn every_gate_the_engine_can_offer_has_a_word() {
let path = crate::test_support::corpus::root()
.join("answers")
.join("agent.json");
let mut frame = crate::test_support::corpus::fixture(&path)
.frames
.first()
.cloned()
.expect("the agent fixture carries a frame");
for gate in ["nudgeable", "stoppable", "stop_children"] {
frame[gate] = Value::Bool(true);
}
says(&frame, &["offers: nudge, stop, stop children"]);
}
#[test]
fn a_trail_row_says_who_made_the_act() {
says(
&json!({"ok": true, "kind": "ops", "rows": [
{"ts": "1700", "client": "phone-1", "origin": "balls", "standing": "clean",
"failed": false, "exit_label": "exit 0", "exit": 0, "argv": "bl list",
"cwd": "/p", "stdout": "", "stderr": ""}]}),
&["phone-1", "balls", "bl list"],
);
}
#[test]
fn a_client_that_has_never_dialled_is_the_row_that_says_it() {
says(
&json!({"ok": true, "kind": "clients", "rows": [
{"client": "minted", "present": false, "tools": []}]}),
&["minted", "never dialled"],
);
let dialled = rendered(&json!({"ok": true, "kind": "clients", "rows": [
{"client": "real", "present": false, "tools": [], "last_seen": 1_757_000_000_i64}]}));
assert!(!dialled.contains("never dialled"), "{dialled}");
}