use super::*;
use crate::boundary::consume::sweep;
#[test]
fn a_dead_claimants_gesture_is_answered_in_doubt_not_re_run() {
let root = tempdir().unwrap();
deposit::deposit(root.path(), "g-died", &json!({"op": "ack"})).unwrap();
drop(deposit::claim(root.path(), "g-died").unwrap());
assert_eq!(sweep(root.path(), "T1"), 1);
let reply = deposit::read_reply(root.path(), "g-died").unwrap();
assert_eq!(reply["ok"], false);
let error = reply["error"].as_str().unwrap();
assert!(error.contains("in doubt"), "{error}");
assert!(
error.contains("read the world"),
"the refusal carries the recovery contract: {error}"
);
let ops = crate::opslog::tail(root.path(), 8);
assert_eq!(
ops.len(),
1,
"the debris row is durable, and it is the ONLY \
row — an /ack that had re-run would have left its own: {ops:?}"
);
assert_eq!(ops[0].argv, vec!["yog-step", "gesture-debris"]);
assert_eq!(
sweep(root.path(), "T2"),
0,
"answered debris stays answered"
);
}
#[test]
fn a_live_claim_is_never_swept() {
let root = tempdir().unwrap();
deposit::deposit(root.path(), "g-slow", &json!({"op": "ack"})).unwrap();
let held = deposit::claim(root.path(), "g-slow").unwrap();
assert_eq!(sweep(root.path(), "T1"), 0);
assert!(
deposit::read_reply(root.path(), "g-slow").is_none(),
"no reply was forged for work in flight"
);
drop(held);
}
#[test]
fn answered_audit_and_an_empty_world_sweep_to_nothing() {
let root = tempdir().unwrap();
assert_eq!(
sweep(root.path(), "T1"),
0,
"no claimed dir is the empty set"
);
let d = deps(root.path());
deposit::deposit(root.path(), "q-1", &json!({"op": "balls"})).unwrap();
assert_eq!(consume(&d, &mut ui(), "T1", 100), 1);
assert_eq!(
sweep(root.path(), "T2"),
0,
"an answered claim is audit, not debris"
);
}
#[test]
fn an_unwritable_in_doubt_reply_leaves_its_own_step_failure_row() {
let root = tempdir().unwrap();
deposit::deposit(root.path(), "g-died", &json!({"op": "ack"})).unwrap();
drop(deposit::claim(root.path(), "g-died").unwrap());
let replies = deposit::gestures_dir(root.path()).join("replies");
std::fs::write(&replies, b"x").unwrap();
assert_eq!(sweep(root.path(), "T1"), 0);
let ops = crate::opslog::tail(root.path(), 8);
assert!(
ops.iter()
.any(|e| e.argv.get(1).is_some_and(|s| s == "gesture-reply")),
"{ops:?}"
);
}