test(simulation): sprint 10 — replay loading, content scaling, serialization v9, observer tests

#483: Replay loading in test-client — JSONL file loading, tick-scheduled
PlayerInput sending, 13 unit tests, 3 sample replay files.
#500: Content scaling test — baseline + extra NPC comparative, tick budget
assertion (D-026), determinism check across content packs.
#514: Serialization tests for protocol v9 — blocked_entities roundtrip,
backward compat (v5→v9, v8→v9), regenerated msgpack fixtures.
Observer perception tests for confrontation + walk-away mechanics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-18 12:58:27 +01:00
co-authored by Claude Opus 4.6
parent 273d29f26f
commit 6c62e2228f
23 changed files with 782 additions and 3 deletions
+210
View File
@@ -2030,3 +2030,213 @@ fn no_cognitive_delay_component_means_empty_pending_recognitions() {
"no CognitiveDelay component should produce empty pending_recognitions"
);
}
// -----------------------------------------------------------------------
// blocked_entities debug field tests (#514)
// -----------------------------------------------------------------------
#[test]
fn blocked_entities_empty_when_all_visible() {
let mut world = setup_world(32, 32);
let mut registry = EntityRegistry::new(0);
let npc = world
.spawn((crate::npc::Npc, TilePosition::new(16, 14, 0)))
.id();
registry.register(npc);
let player = world
.spawn((
PlayerCharacter,
TilePosition::new(16, 16, 0),
Facing(FacingDirection::North),
KnowledgeGraph::new(),
NearbyInteractionBuffer::default(),
MonologueBuffer::default(),
))
.id();
registry.register(player);
world.insert_resource(registry);
run_observer_pipeline(&mut world);
let buffer = world.resource::<SnapshotBuffer>();
let snapshot = buffer.snapshot.as_ref().unwrap();
assert!(
snapshot.blocked_entities.is_empty(),
"no blocked entities when NPC is in LOS"
);
}
#[test]
fn npc_behind_wall_appears_in_blocked_entities() {
let mut world = setup_world(32, 32);
let mut registry = EntityRegistry::new(0);
// Wall between player and NPC
world
.resource_mut::<WalkabilityMap>()
.set_walkable(&TilePosition::new(16, 14, 0), false);
// NPC behind the wall
let npc = world
.spawn((crate::npc::Npc, TilePosition::new(16, 12, 0)))
.id();
let npc_sid = registry.register(npc);
let player = world
.spawn((
PlayerCharacter,
TilePosition::new(16, 16, 0),
Facing(FacingDirection::North),
KnowledgeGraph::new(),
NearbyInteractionBuffer::default(),
MonologueBuffer::default(),
))
.id();
registry.register(player);
world.insert_resource(registry);
run_observer_pipeline(&mut world);
let buffer = world.resource::<SnapshotBuffer>();
let snapshot = buffer.snapshot.as_ref().unwrap();
assert!(
snapshot.blocked_entities.contains(&npc_sid.0),
"NPC behind wall should appear in blocked_entities"
);
// Not in visible entities
let npc_visible = snapshot
.entities
.iter()
.any(|e| e.entity_id == npc_sid.0);
assert!(!npc_visible, "NPC should not be in visible entities");
}
#[test]
fn npc_behind_player_appears_in_blocked_entities() {
let mut world = setup_world(32, 32);
let mut registry = EntityRegistry::new(0);
// NPC far behind player (south, outside vision cone)
let npc = world
.spawn((crate::npc::Npc, TilePosition::new(16, 26, 0)))
.id();
let npc_sid = registry.register(npc);
let player = world
.spawn((
PlayerCharacter,
TilePosition::new(16, 16, 0),
Facing(FacingDirection::North),
KnowledgeGraph::new(),
NearbyInteractionBuffer::default(),
MonologueBuffer::default(),
))
.id();
registry.register(player);
world.insert_resource(registry);
run_observer_pipeline(&mut world);
let buffer = world.resource::<SnapshotBuffer>();
let snapshot = buffer.snapshot.as_ref().unwrap();
assert!(
snapshot.blocked_entities.contains(&npc_sid.0),
"NPC in blind spot should appear in blocked_entities"
);
}
#[test]
fn different_z_level_not_in_blocked_entities() {
let mut world = setup_world(32, 32);
let mut registry = EntityRegistry::new(0);
// NPC on a different z-level
let npc = world
.spawn((crate::npc::Npc, TilePosition::new(16, 14, 1)))
.id();
let npc_sid = registry.register(npc);
let player = world
.spawn((
PlayerCharacter,
TilePosition::new(16, 16, 0),
Facing::default(),
KnowledgeGraph::new(),
NearbyInteractionBuffer::default(),
MonologueBuffer::default(),
))
.id();
registry.register(player);
world.insert_resource(registry);
run_observer_pipeline(&mut world);
let buffer = world.resource::<SnapshotBuffer>();
let snapshot = buffer.snapshot.as_ref().unwrap();
assert!(
!snapshot.blocked_entities.contains(&npc_sid.0),
"NPC on different z-level should NOT be in blocked_entities"
);
}
#[test]
fn blocked_entities_sorted_ascending() {
// Multiple blocked NPCs should appear in ascending entity_id order
let mut world = setup_world(32, 32);
let mut registry = EntityRegistry::new(0);
// Wall blocks north
world
.resource_mut::<WalkabilityMap>()
.set_walkable(&TilePosition::new(16, 14, 0), false);
// Two NPCs behind wall + one behind player
let npc_a = world
.spawn((crate::npc::Npc, TilePosition::new(16, 12, 0)))
.id();
let npc_a_sid = registry.register(npc_a);
let npc_b = world
.spawn((crate::npc::Npc, TilePosition::new(16, 10, 0)))
.id();
let npc_b_sid = registry.register(npc_b);
let npc_c = world
.spawn((crate::npc::Npc, TilePosition::new(16, 26, 0)))
.id();
let npc_c_sid = registry.register(npc_c);
let player = world
.spawn((
PlayerCharacter,
TilePosition::new(16, 16, 0),
Facing(FacingDirection::North),
KnowledgeGraph::new(),
NearbyInteractionBuffer::default(),
MonologueBuffer::default(),
))
.id();
registry.register(player);
world.insert_resource(registry);
run_observer_pipeline(&mut world);
let buffer = world.resource::<SnapshotBuffer>();
let snapshot = buffer.snapshot.as_ref().unwrap();
assert!(snapshot.blocked_entities.len() >= 3);
// Must be sorted ascending (BTreeSet guarantee)
for i in 1..snapshot.blocked_entities.len() {
assert!(
snapshot.blocked_entities[i - 1] < snapshot.blocked_entities[i],
"blocked_entities not sorted: {:?}",
snapshot.blocked_entities
);
}
// All three NPCs should be present
assert!(snapshot.blocked_entities.contains(&npc_a_sid.0));
assert!(snapshot.blocked_entities.contains(&npc_b_sid.0));
assert!(snapshot.blocked_entities.contains(&npc_c_sid.0));
}