tests: bands, entries and institutions at their bounds; the view's cost is the wave's own charge; the player's place is listed once

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-12-03 14:37:06 +01:00
commit 14320d1bdc
2 changed files with 71 additions and 1 deletions

View file

@ -431,6 +431,25 @@ mod tests {
(world, hierarchy, commons, gate)
}
/// The same world with `count` more places declared, and every place's id.
async fn crowded_world(count: usize) -> (WorldSnapshot, Vec<EntityId>) {
let fixture = Fixture::new().await;
let (timelines, _stopped) = fixture.open(ScriptedPort::new(vec![]));
let host = timelines.host(&fixture.id).await.unwrap();
let declared: Vec<String> = (0..count)
.map(|number| json!({"handle": format!("p{number}"), "label": format!("Place {number}"), "container": null}).to_string())
.collect();
let calls: Vec<(&str, &str)> = declared.iter().map(|call| ("declare_place", call.as_str())).collect();
let decoded = ghostlight::decode_authoring_calls(&calls).unwrap();
ghostlight::PlayPort::new(host.world.clone())
.submit_patch(ghostlight::CommandId::new(), decoded.patch)
.await
.unwrap();
let world = host.world.snapshot().await.unwrap();
let places = world.places.iter().map(|place| place.id).collect();
(world, places)
}
fn refusal(current: &DmKnobs, world: &WorldSnapshot, arguments: serde_json::Value) -> String {
tune(current, &arguments.to_string(), world, 0).expect_err("the call is refused")
}
@ -484,6 +503,8 @@ mod tests {
"elaboration_allowance": 5_000_000,
"focus_add": [{"target": id_text(gate), "lease_minutes": 30}],
});
let eight = json!({"bands": [1, 2, 3, 4, 5, 6, 7, 8]});
assert_eq!(tune(&current, &eight.to_string(), &world, 0).unwrap().0.knobs.bands.len(), 8, "eight periods is the most");
let (next, said) = tune(&current, &asked.to_string(), &world, 100).unwrap();
assert_eq!(next.knobs.bands, vec![5, 525_600]);
assert_eq!((next.knobs.depth, next.knobs.max_node_turns), (8, 32));
@ -503,6 +524,46 @@ mod tests {
assert_eq!(tune(&current, &two.to_string(), &world, 0).unwrap().0.focus.len(), 2);
}
/// Eight focus entries are the most: the ninth is refused whole, and an
/// entry the DM already holds is renewed, not added.
#[tokio::test]
async fn the_document_holds_eight_focus_entries_and_no_more() {
let (world, places) = crowded_world(8).await;
let asked = |place: EntityId| json!({"focus_add": [{"target": id_text(place), "lease_minutes": 30}]}).to_string();
let mut doc = DmKnobs::default();
for place in &places[..8] {
doc = tune(&doc, &asked(*place), &world, 0).unwrap().0;
}
assert_eq!(doc.focus.len(), 8, "eight entries are admitted");
assert!(tune(&doc, &asked(places[8]), &world, 0).unwrap_err().contains("9 focus entries"));
assert_eq!(tune(&doc, &asked(places[0]), &world, 5).unwrap().0.focus.len(), 8, "renewing is not adding");
assert_eq!(tune(&doc, &asked(places[8]), &world, 30).unwrap().0.focus.len(), 1, "lapsed entries make room");
let named = |count: usize| {
let ids: Vec<String> = places[..count].iter().map(|place| id_text(*place)).collect();
run_world(&json!({"targets": ids}).to_string(), &world)
};
assert_eq!(named(8).unwrap().len(), 8);
assert!(named(9).unwrap_err().contains("got 9"));
}
/// An institution is named like a place and is the DM's focus or ask; a
/// person is not.
#[tokio::test]
async fn an_institution_is_named_by_its_id_and_labelled_by_its_name() {
let (mut world, hierarchy, _, _) = world().await;
let warden = world.subjects.iter().find(|subject| subject.label == "Warden").unwrap().id;
let asked = json!({"focus_add": [{"target": id_text(warden), "lease_minutes": 30}]}).to_string();
let (doc, _) = tune(&DmKnobs::default(), &asked, &world, 0).unwrap();
assert_eq!(doc.focus, vec![Lease { target: Target::Institution(warden), until: 30 }]);
assert_eq!(run_world(&json!({"targets": [id_text(warden)]}).to_string(), &world).unwrap(), vec![Target::Institution(warden)]);
let mut retired = world.clone();
retired.subjects.iter_mut().find(|subject| subject.id == warden).unwrap().retired = true;
assert!(tune(&DmKnobs::default(), &asked, &retired, 0).unwrap_err().contains("not an institution"), "a retired institution is not named");
world.now = ghostlight::FictionalMinutes(0);
let view = gears_view(&doc, &world, &hierarchy, &[], &[(0, 0)]);
assert!(view.contains(&format!("Your focus: Warden [{}], 30 more minutes.", id_text(warden))), "{view}");
}
#[tokio::test]
async fn run_world_names_places_and_institutions_the_view_prints() {
let (world, _, commons, gate) = world().await;

View file

@ -881,7 +881,12 @@ pub(crate) mod tests {
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 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");
let charged = wave_of(&host, 1).await.unwrap().report.unwrap().nodes[0].tokens;
assert!(charged > 1);
assert!(
first.contains(&format!("band 0: {charged} tokens over 1 node turns")),
"what the wave's node turn cost, on average, in its band"
);
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();
assert!(!second.contains("Off-screen since your last turn") && !second.contains("Crown"), "{second}");
@ -965,6 +970,10 @@ pub(crate) mod tests {
then.now = FictionalMinutes(now);
focus_of(&then, &hierarchy, &dm).places.contains(&gate)
};
let commons = player_places(&world)[0];
let mut also = dm.clone();
also.focus = vec![Lease { target: Target::Place(commons), until: u64::MAX }];
assert_eq!(focus_of(&world, &hierarchy, &also).places, vec![commons], "the player's own place is not listed twice");
assert!(looks_at_gate(59), "a lease of 60 holds at minute 59");
assert!(!looks_at_gate(60), "and has ended at minute 60");
}