Files
settled-reach/client/tests/test_snapshot_parsing.gd
T
jpmschweitzerandClaude Opus 4.6 0db120ed58 feat(client): Sprint 2 proof E2E tests + dynamic test snapshot (#357)
Three E2E proof tests verify all acceptance criteria through the real
server pipeline: player movement, v2 snapshot with visible_tiles,
wall hiding (NPC behind wall invisible), corner reveal (move around
wall to see NPC). Dynamic test snapshot tracks player position from
queued inputs with simple LOS and Manhattan-distance visibility for
standalone demo mode. 88 client + 112 server tests passing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-12 01:45:54 +01:00

70 lines
2.5 KiB
GDScript

## D-030 Layer 1: Fixture-based tests for snapshot parsing
## Validates that GameState correctly parses Protocol-format ObserverSnapshot data
class_name TestSnapshotParsing
extends GdUnitTestSuite
# Valid snapshot in Protocol format (matches Protocol.decode_snapshot output)
var _valid_snapshot: Dictionary = {
"tick": 1,
"entities": [
{"entity_id": 1, "x": 10.0, "y": 15.0, "z": 0, "kind": {"variant": "Npc", "data": null}},
{"entity_id": 2, "x": 5.0, "y": 20.0, "z": 0, "kind": {"variant": "Npc", "data": null}},
],
}
func test_apply_valid_snapshot() -> void:
GameState.player_entity_id = 1
GameState.apply_snapshot(_valid_snapshot)
assert_that(GameState.current_tick).is_equal(1)
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
assert_that(GameState.visible_entities.size()).is_equal(2)
func test_empty_snapshot_no_crash() -> void:
# Reset state
GameState.player_position = Vector2.ZERO
GameState.visible_entities = []
GameState.apply_snapshot({})
# State should remain at defaults
assert_that(GameState.player_position).is_equal(Vector2.ZERO)
assert_that(GameState.visible_entities.size()).is_equal(0)
func test_no_player_entity_position_unchanged() -> void:
GameState.player_entity_id = 999 # No entity with this ID
GameState.player_position = Vector2(5, 5)
GameState.apply_snapshot(_valid_snapshot)
# Position stays at previous value since no matching entity
assert_that(GameState.player_position).is_equal(Vector2(5, 5))
func test_missing_fields_partial_update() -> void:
# First apply valid snapshot
GameState.player_entity_id = 1
GameState.apply_snapshot(_valid_snapshot)
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
# Apply snapshot with no entities — player position unchanged (no matching entity)
GameState.apply_snapshot({"tick": 2})
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
assert_that(GameState.current_tick).is_equal(2)
func test_sim_bridge_test_snapshot_deterministic() -> void:
SimBridge._test_tick = 0
SimBridge._test_player_pos = Vector2i(10, 10)
SimBridge._test_facing = "North"
SimBridge._test_input_queue.clear()
var snap1 = SimBridge._test_snapshot()
var snap2 = SimBridge._test_snapshot()
assert_that(snap1.tick).is_equal(1)
assert_that(snap2.tick).is_equal(2)
# Snapshot matches Protocol format
assert_that(snap1.has("tick")).is_true()
assert_that(snap1.has("entities")).is_true()
assert_that(snap1.entities.size()).is_greater(0)
assert_that(snap1.entities[0].has("entity_id")).is_true()
assert_that(snap1.entities[0].has("kind")).is_true()