test(server): add Entity::to_bits roundtrip and TickRate switch tests

- Entity::to_bits() roundtrip test guards against bevy version changes
  silently breaking wire IDs (Hoshe #1)
- PROTOCOL_VERSION constant used in test helpers instead of hardcoded 4
- TickRate switch mid-accumulation test verifies Half→Full→Paused→Half
  transitions preserve accumulator state correctly (Tyre N3)
- POI mid-range test now asserts priority=1 (Hoshe #4)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-12 22:52:59 +01:00
co-authored by Claude Opus 4.6
parent 02fa89b1d7
commit 0157d1fa38
2 changed files with 61 additions and 1 deletions
+31
View File
@@ -199,6 +199,37 @@ mod tests {
assert_eq!(time.day(), 3);
}
#[test]
fn tick_rate_switch_mid_accumulation() {
// Half->Full with 0.5 remainder: Full should tick immediately (0.5 + 1.0 >= 1.0)
let mut world = bevy_ecs::world::World::new();
world.insert_resource(SimulationTime { tick_rate: TickRate::Half, ..Default::default() });
let mut schedule = bevy_ecs::schedule::Schedule::default();
schedule.add_systems(advance_tick);
// Frame 1: Half rate, accumulate 0.5, no tick
schedule.run(&mut world);
assert_eq!(world.resource::<SimulationTime>().tick, 0);
// Switch to Full mid-accumulation (0.5 remainder)
world.resource_mut::<SimulationTime>().tick_rate = TickRate::Full;
// Frame 2: Full rate adds 1.0 to 0.5 remainder → tick fires
schedule.run(&mut world);
assert_eq!(world.resource::<SimulationTime>().tick, 1);
// Switch to Paused: no advance regardless of accumulator
world.resource_mut::<SimulationTime>().tick_rate = TickRate::Paused;
schedule.run(&mut world);
assert_eq!(world.resource::<SimulationTime>().tick, 1);
// Switch back to Half: accumulator still has 0.5 from overshoot
world.resource_mut::<SimulationTime>().tick_rate = TickRate::Half;
schedule.run(&mut world);
// 0.5 (leftover) + 0.5 (Half) = 1.0 → tick fires
assert_eq!(world.resource::<SimulationTime>().tick, 2);
}
#[test]
fn half_rate_no_drift_over_10000_frames() {
let mut world = bevy_ecs::world::World::new();