diff --git a/crates/ghostlight/src/controllers.rs b/crates/ghostlight/src/controllers.rs index 5d43704..3badf70 100644 --- a/crates/ghostlight/src/controllers.rs +++ b/crates/ghostlight/src/controllers.rs @@ -13943,7 +13943,18 @@ mod tests { ); assert_eq!(session.lens, lens); assert_eq!(session.instructions, lens.instructions()); - prompts.insert(agent_prompt.clone()); + // The world structure prints this world's ids, which differ + // between the eight worlds; everything else must not. + prompts.insert( + agent_prompt + .split('[') + .enumerate() + .map(|(index, part)| match (index, part.split_once(']')) { + (0, _) | (_, None) => part.to_owned(), + (_, Some((_, rest))) => rest.to_owned(), + }) + .collect::(), + ); texts.insert(session.instructions.clone()); } let second = elaboration_runner(&mailbox, script.clone(), store.clone()); @@ -14344,9 +14355,9 @@ 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. + /// Fair claims: whichever entry a bound of one starts first is refused, and + /// so is its repair. 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( @@ -14356,20 +14367,15 @@ mod tests { 0, ) .await; - let far = roads[1]; + let good = shed_on_the_named_road(vec![ + ("The Unwalked Road", roads[0]), + ("The Far Road", 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}"), - ) + if call == 0 || wire_of(request).contains(REFUSAL_TURN) { + refused_round(call) } else { - shed_round( - json!({"ref": "existing", "value": serde_json::to_value(far).unwrap()}), - "The Shed on The Far Road", - &format!("shed-{call}"), - ) + good(call, request) } })); let runner = sweep_runner(&mailbox, port.clone(), fresh_store()); @@ -14378,7 +14384,7 @@ mod tests { 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()); + assert_eq!(snapshot.boundaries.len(), 1, "one entry answered, one still refused"); drop(runner); drop(mailbox); task.await.unwrap(); @@ -15417,11 +15423,21 @@ mod tests { .unwrap(); results.push(runner.sweep(pool(1), usize::MAX).await); assert_eq!(port.calls(), tick + 1, "tick {tick}: one inference per sweep"); + // Past `MAX_REFUSALS` the session ends and its deficit id, which + // moves with the ancestry, starts a new one; rows may grow then, + // but only one session is ever in flight. assert_eq!( - store.journal.lock().unwrap().work.len(), + store.elaboration_in_flight().await.unwrap().len(), 1, - "tick {tick}: the store gained a row" + "tick {tick}: an orphan session is in flight" ); + if tick < crate::elaboration::MAX_REFUSALS { + assert_eq!( + store.journal.lock().unwrap().work.len(), + 1, + "tick {tick}: the store gained a row" + ); + } } // The sixth round is the last the budget allows; how that round ends // is not this test's subject. diff --git a/crates/ghostlight/src/elaboration.rs b/crates/ghostlight/src/elaboration.rs index 438e908..0dbd105 100644 --- a/crates/ghostlight/src/elaboration.rs +++ b/crates/ghostlight/src/elaboration.rs @@ -280,6 +280,32 @@ pub(super) fn valid_elaboration_progression( .. }, ) => refusal_reopens(existing, existing_refusals, next, next_refusals), + // The refusal that ends the session: the same reopening, stored as the + // end instead of another repair. + ( + ElaborationCheckpoint::ReadyToSubmit { + completed: existing, + refusals: existing_refusals, + .. + }, + ElaborationCheckpoint::NoPatch { + completed: next, + refusals: next_refusals, + .. + }, + ) => refusal_reopens(existing, existing_refusals, next, next_refusals), + ( + SeedCheckpoint::ReadyToSubmit { + completed: existing, + refusals: existing_refusals, + .. + }, + SeedCheckpoint::NoPatch { + completed: next, + refusals: next_refusals, + .. + }, + ) => refusal_reopens(existing, existing_refusals, next, next_refusals), _ => false, } }