diff --git a/crates/agent-core/tests/helper_reconcile.rs b/crates/agent-core/tests/helper_reconcile.rs index de22819..b4cdc39 100644 --- a/crates/agent-core/tests/helper_reconcile.rs +++ b/crates/agent-core/tests/helper_reconcile.rs @@ -466,6 +466,31 @@ struct Fixture { identity: HelperIdentity, } +#[test] +fn idle_anchor_checks_the_head_but_abandonment_rejects_damaged_history() { + let (mut f, sync, _, request, mut guard) = denial_case(); + let mut sync = sync.with_periodic_idle_integrity_checks(); + f.clock.now += Duration::seconds(1); + let capture = f.snapshot(&mut sync, 7); + let raw = f.request(&capture); + let ready = f.decision(&capture, &raw, 7, true); + assert!(f.apply(&mut sync, &ready, &raw).unwrap().ready); + guard.intent_recorded_at = f.clock.now; + f.db.execute( + "UPDATE helper_sync_decisions SET response=X'00' WHERE checkpoint < ?1", + [capture.checkpoint], + ).unwrap(); + + let anchor = sync.no_start_anchor(&f.db, &guard, 7, &f.clock, &f.boot).unwrap(); + guard.anchor_sha256 = hash(&serde_json::to_vec(&anchor).unwrap()); + let before = denial_ledger_bytes(&f.db); + assert!( + sync.abandon_no_start(&mut f.db, &guard, &anchor, &request, &f.clock, &f.boot) + .is_err() + ); + assert_eq!(denial_ledger_bytes(&f.db), before); +} + #[test] fn checkpoint_repair_verifies_complete_signed_history_and_detects_removed_predecessor() { let mut f = Fixture::new();