Kill remaining testable chat_gate mutants with boundary tests

This commit is contained in:
Meta Vens 2026-12-06 12:40:02 +01:00
commit bc98bf088e

View file

@ -1282,6 +1282,15 @@ mod tests {
assert_eq!(late_resend.exit, 1);
assert!(late_resend.stdout.contains("ResendUnknown"), "{}", late_resend.stdout);
// Fresh say at EXACT UNSETTLED_WINDOW_MS boundary succeeds even while pending_send is still stored.
reloaded.chat.send_replies.borrow_mut().push_back(Err(anyhow!("socket timeout")));
let timed_out_exact = reloaded
.handle(
Request::Say { room: "#exp2:gamecult.org".into(), text: Some("lost2".into()), resend: None },
t_expired + 100,
)
.unwrap();
assert_eq!(timed_out_exact.exit, 3);
reloaded.chat.send_replies.borrow_mut().push_back(Ok(ChatSendReceipt {
request_id: "x".into(),
event_id: Some("$ev9".into()),
@ -1290,11 +1299,11 @@ mod tests {
}));
let fresh_after_exp = reloaded
.handle(
Request::Say { room: "#exp:gamecult.org".into(), text: Some("fresh".into()), resend: None },
t_expired + 1,
Request::Say { room: "#exp2:gamecult.org".into(), text: Some("fresh".into()), resend: None },
t_expired + 100 + UNSETTLED_WINDOW_MS,
)
.unwrap();
assert_eq!(fresh_after_exp.exit, 0);
assert_eq!(fresh_after_exp.exit, 0, "{}", fresh_after_exp.stdout);
}
#[test]
@ -1366,6 +1375,26 @@ mod tests {
let batch_bs = eng.handle(Request::Pending { ack: true }, t0 + 381_000).unwrap();
assert!(batch_bs.stdout.contains("MIND_RUN_BACKSTOP"), "{}", batch_bs.stdout);
// 2b. Human break in #hbreak at the exact same (sender, ts) as a prior human line in #other_h
// must NOT be deduped across rooms (kills held.room == room -> !=).
eng.chat.pending_replies.borrow_mut().push_back(Ok(ChatPending {
persona: "nibu".into(),
deliveries: vec![
delivery(11, "#hbreak:gamecult.org", "$hb1", "@nibu:gamecult.org", t0 + 400_000, "m1"),
delivery(12, "#hbreak:gamecult.org", "$hb2", "@eureka:gamecult.org", t0 + 405_000, "m2"),
delivery(13, "#hbreak:gamecult.org", "$hb3", "@nibu:gamecult.org", t0 + 410_000, "m3"),
delivery(14, "#other_h:gamecult.org", "$oh1", "@meta:gamecult.org", t0 + 415_000, "other human"),
delivery(15, "#hbreak:gamecult.org", "$hb_human", "@meta:gamecult.org", t0 + 415_000, "human break"),
delivery(16, "#hbreak:gamecult.org", "$hb4", "@nibu:gamecult.org", t0 + 420_000, "m4"),
delivery(17, "#hbreak:gamecult.org", "$hb5", "@eureka:gamecult.org", t0 + 425_000, "m5"),
delivery(18, "#hbreak:gamecult.org", "$hb6", "@meta:gamecult.org", t0 + 430_000, "final human"),
],
tail: None,
tail_gaps: vec![],
}));
let broken_by_human = eng.handle(Request::Pending { ack: true }, t0 + 431_000).unwrap();
assert!(!broken_by_human.stdout.contains("backstop"), "human break in #hbreak must reset run: {}", broken_by_human.stdout);
// 3. Pushing 35 lines into a room caps stored history at ROOM_LINES_CAP (32), keeping newest.
let many: Vec<ChatDelivery> = (0..35_u64)
.map(|i| delivery(20 + i, "#cap:gamecult.org", &format!("$c{i}"), "@meta:gamecult.org", t0 + 500_000 + i * 1000, "x"))
@ -1455,7 +1484,19 @@ mod tests {
assert_eq!(ans2.exit, 0);
assert!(ans2.stdout.contains("Posted $s2"), "{}", ans2.stdout);
for _ in 0..100 {
if handle.is_finished() {
break;
}
std::thread::sleep(std::time::Duration::from_millis(10));
}
assert!(handle.is_finished(), "socket::serve did not stop after max_requests");
handle.join().unwrap();
assert_eq!(recorded_persona.lock().unwrap().as_str(), "nibu");
// serve_gate fails loudly when socket parent is an existing regular file.
let regular_file = dir.path().join("not-a-dir");
fs::write(&regular_file, b"x").unwrap();
assert!(serve_gate(cfg(&dir.path().join("bad-state"), None), MockChat::new(), &regular_file.join("gate.sock"), || t0).is_err());
}
}