Tests: the promise prompt, abandoned rows' integrity in both lanes, sweep report counts, repair budget end

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 23:58:16 +01:00
commit b31f1e551d
2 changed files with 128 additions and 4 deletions

View file

@ -14420,6 +14420,84 @@ mod tests {
task.await.unwrap();
}
/// The one elaboration row a store holds, whatever its stage.
fn store_row(store: &Arc<RecordingWorkStore>) -> ElaborationCheckpoint {
let stored = store.work.lock().unwrap();
let ControllerWork::Elaboration(checkpoint) = stored.values().next().unwrap().clone() else {
panic!("not an elaboration row");
};
checkpoint
}
/// A missing-structure session's first prompt names the promise, who holds
/// it, who it is owed to, and what answers it.
#[tokio::test]
async fn a_missing_structure_prompt_names_the_promise_and_what_answers_it() {
let (_directory, mailbox, task, snapshot) =
unpositioned_debtor_world(WorldScaleIntentRef::default()).await;
let debtor = snapshot.subjects.iter().find_map(|subject| {
subject.commitments.iter().find(|held| held.counterparty.is_some()).map(|held| (subject, held))
});
let (holder, held) = debtor.expect("the fixture's debtor holds a promise");
let port = Arc::new(SweepPort::new(|call, _| idle_round(call)));
let runner = sweep_runner(&mailbox, port.clone(), fresh_store());
runner.sweep(pool(1), usize::MAX).await.unwrap();
let prompt = prompt_of(&port.seen.lock().unwrap()[0]);
let promise = prompt.lines().find(|line| line.starts_with("Promise:")).expect("a Promise line");
assert!(promise.contains(&holder.label), "{promise}");
assert!(promise.contains(held.statement.as_str()), "{promise}");
assert!(promise.contains("grant_authority") && promise.contains("open_forum"), "{promise}");
drop(runner);
drop(mailbox);
task.await.unwrap();
}
/// The same ending in the seed lane: the third refusal stores the session
/// as a valid row without a patch, and a further step runs no inference.
#[tokio::test]
async fn a_seed_session_the_world_keeps_refusing_is_abandoned() {
let forged = |receipt: &str| {
tool_round(
vec![
(
"declare_fact",
json!({
"handle": "dry",
"label": "The Dry Season",
"statement": "The sere runs dry nine months a year.",
"standing": {"standing": "canonical", "evidence": "Public/Places/Nowhere.md"},
}),
),
("submit", json!({})),
],
receipt,
)
};
let fixture = seed_mailbox(6).await;
let store = fresh_store();
let script = seed_script(vec![forged("r0"), forged("r1"), forged("r2")]);
let runner = seed_runner(&fixture, script.clone(), store.clone(), Arc::new(NullEvidenceSource));
for _ in 0..crate::elaboration::MAX_REFUSALS {
assert_eq!(runner.step().await.unwrap(), SeedOutcome::Rejected);
}
assert_eq!(runner.step().await.unwrap(), SeedOutcome::NoPatch);
let seen = script.seen.lock().unwrap().len();
let stored = store.work.lock().unwrap();
let ControllerWork::Seed(row @ SeedCheckpoint::NoPatch { refusals, .. }) =
stored.values().next().unwrap()
else {
panic!("an abandoned seed session is not stored as NoPatch");
};
assert_eq!(refusals.len(), crate::elaboration::MAX_REFUSALS + 1);
assert!(row.integrity_is_valid());
drop(stored);
assert_eq!(runner.step().await.unwrap(), SeedOutcome::NoPatch);
assert_eq!(script.seen.lock().unwrap().len(), seen, "an abandoned seed session ran inference again");
drop(runner);
drop(fixture.mailbox);
fixture.task.await.unwrap();
}
/// A session the world keeps refusing ends after `MAX_REFUSALS` repairs, is
/// stored without a patch, counted in the report, and takes no slot after.
#[tokio::test]
@ -14446,6 +14524,24 @@ mod tests {
}
let last = runner.sweep(pool(1), 1).await.unwrap();
assert_eq!(last.abandoned, 1, "{last:?}");
// The stored end is a valid row; the same row with its ending refusal
// moved or removed is not.
let ended = store_row(&store);
assert!(ended.integrity_is_valid());
let ElaborationCheckpoint::NoPatch { refusals, .. } = &ended else {
panic!("an abandoned session is not stored as NoPatch");
};
assert_eq!(refusals.len(), crate::elaboration::MAX_REFUSALS + 1);
let tamper = |edit: &dyn Fn(&mut Vec<crate::elaboration::Refusal>)| {
let mut row = ended.clone();
let ElaborationCheckpoint::NoPatch { refusals, .. } = &mut row else { unreachable!() };
edit(refusals);
row.integrity_is_valid()
};
assert!(!tamper(&|refusals| {
refusals.pop();
}));
assert!(!tamper(&|refusals| refusals.last_mut().unwrap().after_round = 1));
let calls = port.calls();
let after = runner.sweep(pool(1), 1).await.unwrap();
assert_eq!((after.claimed, after.started), (0, 0), "{after:?}");

View file

@ -3089,9 +3089,37 @@ mod tests {
Ok(ElaborationLoopEvaluation::Continue { .. })
));
idle.push(drafting());
assert!(matches!(
evaluate_elaboration_loop("p", &refusals, &idle, ELABORATION_ROUND_BUDGET),
Ok(ElaborationLoopEvaluation::Complete { .. })
));
let Ok(ElaborationLoopEvaluation::Complete { capture }) =
evaluate_elaboration_loop("p", &refusals, &idle, ELABORATION_ROUND_BUDGET)
else {
panic!("the repair's last round did not finalize");
};
// What the repair authored is submitted as authored, with the gap named.
assert!(capture.submitted);
assert!(capture.gaps.iter().any(|gap| gap.detail.contains("round budget ended")));
}
#[test]
fn a_sweep_report_counts_each_outcome_once() {
let mut report = SweepReport::default();
for outcome in [
ElaborationOutcome::Committed,
ElaborationOutcome::Rejected,
ElaborationOutcome::Rejected,
ElaborationOutcome::Superseded,
ElaborationOutcome::Superseded,
ElaborationOutcome::Superseded,
ElaborationOutcome::NoPatch,
ElaborationOutcome::NoPatch,
ElaborationOutcome::NoPatch,
ElaborationOutcome::NoPatch,
ElaborationOutcome::Abandoned,
] {
report.count(outcome);
}
assert_eq!(
(report.committed, report.rejected, report.superseded, report.no_patch, report.abandoned),
(1, 2, 3, 4, 1)
);
}
}