use super::{diagnostic_lines, print_merged_pr_pass};
#[test]
fn merged_pr_pass_surfaces_an_agent_owned_skip() {
let body = serde_json::json!({
"removed": [],
"removed_bytes": 0,
"spared_agent_owned": [
"/repo/.claude/worktrees/agent-7f3: owned by dispatched agent agent-7f3 \
— a delegation naming it has not ended",
],
"refused_at_recheck": [],
"removal_failed": [],
});
let lines = diagnostic_lines(&body);
assert_eq!(lines.len(), 1, "{lines:?}");
assert!(lines[0].contains("spared"), "{}", lines[0]);
assert!(lines[0].contains("agent-7f3"), "{}", lines[0]);
print_merged_pr_pass(Some(&body), false);
}
#[test]
fn merged_pr_pass_diagnostics_keep_their_kinds_apart() {
let body = serde_json::json!({
"spared_agent_owned": ["/a: an agent owns it"],
"refused_at_recheck": ["/b: a session claims it now"],
"removal_failed": ["/c: git-locked"],
});
let lines = diagnostic_lines(&body);
assert_eq!(lines.len(), 3, "{lines:?}");
assert!(lines[0].contains("dispatched agent"), "{}", lines[0]);
assert!(lines[1].contains("re-check"), "{}", lines[1]);
assert!(lines[2].contains("removal FAILED"), "{}", lines[2]);
}
#[test]
fn merged_pr_pass_diagnostics_tolerate_absent_and_malformed_keys() {
assert!(diagnostic_lines(&serde_json::json!({})).is_empty());
assert!(
diagnostic_lines(&serde_json::json!({ "spared_agent_owned": "not-an-array" })).is_empty()
);
assert!(diagnostic_lines(&serde_json::json!({ "spared_agent_owned": [7, null] })).is_empty());
}
#[test]
fn merged_pr_pass_prints_nothing_for_a_null_body() {
print_merged_pr_pass(None, true);
print_merged_pr_pass(Some(&serde_json::Value::Null), false);
}
#[test]
fn merged_pr_pass_reports_reclaimed_paths_and_bytes() {
let body = serde_json::json!({
"removed": ["/tmp/a", "/tmp/b"],
"removed_bytes": 4096,
"refused_at_recheck": [],
"removal_failed": [],
"reclaimable": 2,
"reclaimable_bytes": 4096,
});
print_merged_pr_pass(Some(&body), false);
print_merged_pr_pass(Some(&body), true);
}
#[test]
fn merged_pr_pass_surfaces_recheck_refusals() {
let body = serde_json::json!({
"removed": [],
"removed_bytes": 0,
"refused_at_recheck": ["/tmp/c: a session claims it now"],
"removal_failed": ["/tmp/d"],
"reclaimable": 1,
});
print_merged_pr_pass(Some(&body), false);
}
#[test]
fn merged_pr_pass_reports_a_failed_pass_rather_than_a_zero_count() {
let body = serde_json::json!({ "error": "task panicked" });
print_merged_pr_pass(Some(&body), false);
}
#[test]
fn merged_pr_pass_tolerates_missing_fields() {
print_merged_pr_pass(Some(&serde_json::json!({})), true);
print_merged_pr_pass(
Some(&serde_json::json!({ "removed": "not-an-array" })),
false,
);
}