Tests: a repair has a fresh round budget, a refused entry yields to untried ones, a refused session is abandoned

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-02 22:20:31 +01:00
commit 00e3467ed7
2 changed files with 132 additions and 5 deletions

View file

@ -14150,6 +14150,16 @@ mod tests {
}
}
/// The prompt's `Answer:` line alone: the world structure the prompt also
/// prints names every road, so a script choosing by road reads this line.
fn answer_of(request: &PreparedInference) -> String {
prompt_of(request)
.lines()
.find(|line| line.starts_with("Answer:"))
.expect("the prompt carries its answer")
.to_owned()
}
fn wire_of(request: &PreparedInference) -> String {
serde_json::to_string(&request.invocation.request.input).unwrap()
}
@ -14192,7 +14202,7 @@ mod tests {
roads: Vec<(&'static str, EntityId)>,
) -> impl Fn(usize, &PreparedInference) -> Result<InferenceOutput, InferenceFault> {
move |call, request| {
let prompt = prompt_of(request);
let prompt = answer_of(request);
let (label, road) = roads
.iter()
.find(|(label, _)| prompt.contains(label))
@ -14334,6 +14344,81 @@ mod tests {
task.await.unwrap();
}
/// Fair claims: the first entry's patch is always refused. A bound of one
/// starts it in the first sweep; the second sweep starts the entry nobody
/// has tried, not the refused one again, and commits it.
#[tokio::test]
async fn a_refused_entry_is_not_retried_ahead_of_an_untried_one() {
let (_directory, mailbox, task, _commons, roads) = dead_end_world(
crate::tests::stock_weights(),
&["The Unwalked Road", "The Far Road"],
Roots::Commons,
0,
)
.await;
let far = roads[1];
let port = Arc::new(SweepPort::new(move |call, request| {
if answer_of(request).contains("The Unwalked Road") {
shed_round(
json!({"ref": "draft", "value": "nowhere"}),
"The Shed on The Unwalked Road",
&format!("refused-{call}"),
)
} else {
shed_round(
json!({"ref": "existing", "value": serde_json::to_value(far).unwrap()}),
"The Shed on The Far Road",
&format!("shed-{call}"),
)
}
}));
let runner = sweep_runner(&mailbox, port.clone(), fresh_store());
let first = runner.sweep(pool(2), 1).await.unwrap();
assert_eq!((first.started, first.rejected), (1, 1));
let second = runner.sweep(pool(2), 1).await.unwrap();
assert_eq!((second.started, second.committed), (1, 1), "{second:?}");
let snapshot = mailbox.snapshot().await.unwrap();
assert!(place_labelled(&snapshot, "The Shed on The Far Road").is_some());
drop(runner);
drop(mailbox);
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]
async fn a_session_the_world_keeps_refusing_is_abandoned_and_no_longer_claimed() {
let (_directory, mailbox, task, _commons, roads) = dead_end_world(
crate::tests::stock_weights(),
&["The Unwalked Road"],
Roots::Commons,
0,
)
.await;
let _ = roads;
let port = Arc::new(SweepPort::new(|call, _| {
shed_round(
json!({"ref": "draft", "value": "nowhere"}),
"The Shed on The Unwalked Road",
&format!("refused-{call}"),
)
}));
let runner = sweep_runner(&mailbox, port.clone(), fresh_store());
for _ in 0..crate::elaboration::MAX_REFUSALS {
let report = runner.sweep(pool(1), 1).await.unwrap();
assert_eq!(report.rejected, 1, "{report:?}");
}
let last = runner.sweep(pool(1), 1).await.unwrap();
assert_eq!(last.abandoned, 1, "{last:?}");
let calls = port.calls();
let after = runner.sweep(pool(1), 1).await.unwrap();
assert_eq!((after.claimed, after.started), (0, 0), "{after:?}");
assert_eq!(port.calls(), calls, "an abandoned session ran inference again");
drop(runner);
drop(mailbox);
task.await.unwrap();
}
/// The same two entries under a pool of one: the first session is held
/// inside the provider boundary with no permit free, and the second starts
/// only after the first has finished.
@ -14696,7 +14781,7 @@ mod tests {
.await;
let far = shed_on_the_named_road(vec![("The Far Road", roads[1])]);
let port = Arc::new(SweepPort::new(move |call, request| {
if prompt_of(request).contains("The Unwalked Road") {
if answer_of(request).contains("The Unwalked Road") {
Err(InferenceFault::retryable("the fixture connector is at capacity"))
} else {
far(call, request)
@ -14815,7 +14900,7 @@ mod tests {
) -> Result<InferenceOutput, InferenceFault> {
let call = self.calls.fetch_add(1, Ordering::SeqCst);
self.both.wait().await;
if prompt_of(&request).contains("The Unwalked Road") {
if answer_of(&request).contains("The Unwalked Road") {
self.faulted.add_permits(1);
return Err(InferenceFault::integrity_violation(
"the fixture port disputes this receipt",
@ -14917,7 +15002,7 @@ mod tests {
request: PreparedInference,
) -> Result<InferenceOutput, InferenceFault> {
let call = self.calls.fetch_add(1, Ordering::SeqCst);
if prompt_of(&request).contains("The Unwalked Road") {
if answer_of(&request).contains("The Unwalked Road") {
if self.first_unwalked.swap(false, Ordering::SeqCst) {
self.both.wait().await;
self.panicking.add_permits(1);
@ -15374,7 +15459,7 @@ mod tests {
.find(|jurisdiction| *jurisdiction != claimed)
.unwrap();
let port = Arc::new(SweepPort::new(|call, request| {
if prompt_of(request).contains("The Unwalked Road") && call == 0 {
if answer_of(request).contains("The Unwalked Road") && call == 0 {
refused_round(call)
} else {
idle_round(call)

View file

@ -2914,4 +2914,46 @@ mod tests {
if evidence == &EvidenceRef::new("vault:forged"))
));
}
/// The refusal that follows a round which spent the whole budget is still
/// repairable: the repair attempt has the whole budget again, and the oracle
/// reports it, rather than the session dying at "exceeded its round budget".
#[test]
fn a_refusal_opens_a_fresh_round_budget_for_the_repair() {
let drafting = || output(vec![("declare_place", place("shed"))]);
let submitting = || output(vec![("declare_place", place("shed")), ("submit", serde_json::json!({}))]);
let mut completed: Vec<InferenceOutput> = (0..ELABORATION_ROUND_BUDGET - 1).map(|_| drafting()).collect();
completed.push(submitting());
let refusals = vec![Refusal {
after_round: completed.len(),
mismatches: vec![Mismatch::EmptyHandle { position: 0 }],
}];
// The refused draft used every round the budget allows.
assert!(matches!(
evaluate_elaboration_loop("p", &refusals, &completed, ELABORATION_ROUND_BUDGET),
Ok(ElaborationLoopEvaluation::Continue { .. })
));
assert_eq!(
ElaborationOracle::new(&completed, &refusals, ELABORATION_ROUND_BUDGET).remaining_rounds()
as usize,
ELABORATION_ROUND_BUDGET
);
// The repair submits in one round and finalizes.
completed.push(submitting());
assert!(matches!(
evaluate_elaboration_loop("p", &refusals, &completed, ELABORATION_ROUND_BUDGET),
Ok(ElaborationLoopEvaluation::Complete { capture }) if capture.submitted
));
// A repair that never submits ends at the budget, not before and not after.
let mut idle: Vec<InferenceOutput> = completed[..completed.len() - 1].to_vec();
idle.extend((0..ELABORATION_ROUND_BUDGET - 1).map(|_| drafting()));
assert!(matches!(
evaluate_elaboration_loop("p", &refusals, &idle, ELABORATION_ROUND_BUDGET),
Ok(ElaborationLoopEvaluation::Continue { .. })
));
idle.push(drafting());
assert!(matches!(
evaluate_elaboration_loop("p", &refusals, &idle, ELABORATION_ROUND_BUDGET),
Ok(ElaborationLoopEvaluation::Complete { .. })
));
}
}