From b85898ee58d2df02004ee573a9fe144ccd29a70a Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 13:34:04 +0100 Subject: [PATCH] dungeon waves: the fixture's Warden stands at a watched gatehouse, out of the player's room; tests follow the hierarchy Co-Authored-By: Claude Opus 5.5 --- crates/ghostlight-dungeon/src/knobs.rs | 13 ++++--- crates/ghostlight-dungeon/src/waves.rs | 49 ++++++++++++++++++-------- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/crates/ghostlight-dungeon/src/knobs.rs b/crates/ghostlight-dungeon/src/knobs.rs index de53e7c..5fc1f5f 100644 --- a/crates/ghostlight-dungeon/src/knobs.rs +++ b/crates/ghostlight-dungeon/src/knobs.rs @@ -463,7 +463,7 @@ mod tests { assert!(refusal(¤t, &world, json!({"depth": 3, "colour": "red"})).contains("`colour`"), "an unknown field is refused"); assert!(refusal(¤t, &world, json!({})).contains("changed nothing")); assert!(tune(¤t, "[1]", &world, 0).unwrap_err().contains("not a JSON object")); - let person = id_text(world.subjects.iter().find(|subject| subject.label == "Warden").unwrap().id); + let person = id_text(world.subjects.iter().find(|subject| subject.label == "Player").unwrap().id); assert!(refusal(¤t, &world, json!({"focus_add": [{"target": person, "lease_minutes": 5}]})).contains("not an institution")); // One good field beside a bad one changes nothing: the call is refused whole. assert!(tune(¤t, r#"{"depth": 4, "bands": [-1]}"#, &world, 0).is_err()); @@ -523,9 +523,12 @@ mod tests { /// institution's own, none for an institution the world no longer holds. #[tokio::test] async fn a_target_is_the_node_that_governs_it() { - let (_, hierarchy, commons, gate) = world().await; - assert_eq!(Target::Place(commons).node(&hierarchy), Some(hierarchy.root())); - assert_eq!(Target::Place(gate).node(&hierarchy), Some(hierarchy.root())); + let (world, hierarchy, commons, gate) = world().await; + let anchor = |target: Target| hierarchy.nodes[&target.node(&hierarchy).unwrap()].anchor; + assert_eq!(anchor(Target::Place(commons)), NodeAnchor::Place(commons)); + assert_eq!(anchor(Target::Place(gate)), NodeAnchor::Place(gate)); + let warden = world.subjects.iter().find(|subject| subject.label == "Warden").unwrap().id; + assert_eq!(anchor(Target::Institution(warden)), NodeAnchor::Institution(warden)); assert_eq!(Target::Institution(opaque::()).node(&hierarchy), None); } @@ -580,7 +583,7 @@ mod tests { let view = gears_view(&knobs, &world, &hierarchy, &[commons], &[(200, 2), (0, 0), (0, 0), (0, 0)]); assert!(view.contains("60, 360, 1440, 10080. Depth 2"), "{view}"); assert!(view.contains("wave 200000 tokens, elaboration 200000 tokens")); - assert!(view.contains("The player\'s focus runs world.")); + assert!(view.contains("The player\'s focus runs The Commons > world.")); assert!(view.contains(&format!("Your focus: Gatehouse [{}], 60 more minutes.", id_text(gate)))); assert!(!view.contains("Your focus: The Commons"), "a lapsed lease is not shown"); assert!(view.contains("Asked to run in this turn\'s wave: Gatehouse.")); diff --git a/crates/ghostlight-dungeon/src/waves.rs b/crates/ghostlight-dungeon/src/waves.rs index 9144b52..272b253 100644 --- a/crates/ghostlight-dungeon/src/waves.rs +++ b/crates/ghostlight-dungeon/src/waves.rs @@ -398,7 +398,7 @@ pub(crate) mod tests { use super::*; use crate::{ catalog::timeline_id, - knobs::{self, DmKnobs}, + knobs::{self, DmKnobs, KnobStore, Lease}, play::tests::{ScriptedPort, call_event, output, text_event}, state_layout::{prepare_admitted_state_layout, prepare_timeline_directory}, timelines::{Shared, Timelines}, @@ -426,6 +426,13 @@ pub(crate) mod tests { VerifiedPrincipalEvidence::new("waves-account", Utc::now() + chrono::Duration::hours(4)) } + #[derive(Clone, Copy, PartialEq, Eq)] + enum Warden { + InTheRoom, + AtTheGate, + AtTheWatchedGate, + } + /// One timeline whose world holds a player and a `Warden` an operational /// agent decides for, on a state root the test can reopen. pub(crate) struct Fixture { @@ -435,18 +442,24 @@ pub(crate) mod tests { } impl Fixture { - /// The Warden stands in a gatehouse down the road from the player: out - /// of the player's room, so a wave may turn him. + /// The Warden stands in a gatehouse down the road from the player, out of + /// the player's room, and the DM is watching the gatehouse: a lease that + /// never ends, so his node is open and one band from nothing. pub(crate) async fn new() -> Self { - Self::build(true).await + Self::build(Warden::AtTheWatchedGate).await + } + + /// The same, with nobody watching the gatehouse. + async fn unwatched() -> Self { + Self::build(Warden::AtTheGate).await } /// The Warden stands in the player's own room. async fn in_the_room() -> Self { - Self::build(false).await + Self::build(Warden::InTheRoom).await } - async fn build(warden_away: bool) -> Self { + async fn build(warden: Warden) -> Self { let directory = tempfile::tempdir().unwrap(); let root = std::fs::canonicalize(directory.path()).unwrap(); prepare_admitted_state_layout(&root).unwrap(); @@ -488,7 +501,8 @@ pub(crate) mod tests { .await .unwrap(); } - if warden_away { + let mut watched = None; + if warden != Warden::InTheRoom { let snapshot = world.snapshot().await.unwrap(); let warden = snapshot.subjects.iter().find(|subject| subject.label == "Warden").unwrap().id; let commons = snapshot.place_of(warden).unwrap(); @@ -516,9 +530,16 @@ pub(crate) mod tests { ]) .unwrap(); PlayPort::new(world.clone()).submit_patch(CommandId::new(), decoded.patch).await.unwrap(); + watched = world.snapshot().await.unwrap().places.iter().find(|place| place.label == "Gatehouse").map(|place| place.id); } drop(world); task.await.unwrap(); + if let (Warden::AtTheWatchedGate, Some(gate)) = (warden, watched) { + let mut store = KnobStore::open(timeline.join("gestalt-knobs.cc")).unwrap(); + let mut doc = store.current(); + doc.focus.push(Lease { target: Target::Place(gate), until: u64::MAX }); + store.replace(doc).unwrap(); + } Self { _directory: directory, root, @@ -859,7 +880,7 @@ pub(crate) mod tests { assert!(first.contains("The world beyond the room, and the gears you may turn"), "{first}"); assert!(first.contains("60, 360, 1440, 10080") && first.contains("Depth 2"), "the knobs as they stand"); assert!(first.contains("wave 200000 tokens, elaboration 200000 tokens")); - assert!(first.contains("The player's focus runs world."), "the focus path by label"); + assert!(first.contains("The player's focus runs The Commons > world."), "the focus path by label"); assert!(first.contains("band 0: ") && first.contains("over 1 node turns"), "what the wave's node turn cost"); host.play.run(&who, Uuid::new_v4().to_string(), "I wait again.".into()).await.unwrap(); let second = serde_json::to_string(&port.seen_requests()[3]).unwrap(); @@ -888,7 +909,7 @@ pub(crate) mod tests { )])); let (timelines, mut stopped) = fixture.open(port.clone()); let host = timelines.host(&fixture.id).await.unwrap(); - assert_eq!(host.knobs.lock().await.current(), DmKnobs::default(), "a Begin's knobs until the DM tunes"); + assert_eq!(host.knobs.lock().await.current().knobs, DmKnobs::default().knobs, "a Begin's knobs until the DM tunes"); host.play.run(&principal(), Uuid::new_v4().to_string(), "I wait.".into()).await.unwrap(); assert_eq!(host.knobs.lock().await.current().knobs.depth, 3); drop(host); @@ -948,18 +969,18 @@ pub(crate) mod tests { assert!(!looks_at_gate(60), "and has ended at minute 60"); } - /// What `run_world` of the player's own place does to a timeline whose clock + /// What `run_world` of the gatehouse does to a timeline whose clock /// has not moved, with the wave lane allowing `wave` tokens: the wave it /// froze, whether the Warden acted, and the knobs after. async fn forced_wave(wave: u64) -> (WaveRecord, bool, DmKnobs, usize) { - let fixture = Fixture::new().await; + let fixture = Fixture::unwatched().await; let port = ScriptedPort::new(vec![]); let (timelines, _stopped) = fixture.open(port.clone()); let host = timelines.host(&fixture.id).await.unwrap(); allow(&host, |allowances| allowances.wave = wave).await; let world = host.world.snapshot().await.unwrap(); - let commons = id_text(player_places(&world)[0]); - for answer in dm_turn_script(vec![(crate::play::RUN_WORLD_TOOL, serde_json::json!({"targets": [commons]}))]) { + let gate = id_text(world.places.iter().find(|place| place.label == "Gatehouse").unwrap().id); + for answer in dm_turn_script(vec![(crate::play::RUN_WORLD_TOOL, serde_json::json!({"targets": [gate]}))]) { port.push_answer(Ok(answer)); } port.push_answer(Ok(speaks("w0", "The gate holds."))); @@ -981,7 +1002,7 @@ pub(crate) mod tests { let (wave, acted, after, requests) = forced_wave(200_000).await; let report = wave.report.expect("closed"); assert_eq!(report.nodes.len(), 1); - assert_eq!(report.nodes[0].label, "world"); + assert_eq!(report.nodes[0].label, "Gatehouse"); assert!(acted, "the Warden took the turn the DM asked for"); assert_eq!(wave.opened_now, 0, "no time had passed: only the DM's ask made it due"); assert_eq!(wave.forced.len(), 1);