Files
settled-reach/client/tests/test_snapshot_parsing.gd
T
jpmschweitzerandClaude Opus 4.6 3368231396 fix(client): address PR review — input bug, bounds checks, fixture tests
- Fix input_mapper double-check bug (redundant InputEventKey + pressed filter)
- Add bounds checking for position arrays in entity_renderer and game_state
- Make test snapshot deterministic (incrementing counter, not wall clock)
- Fix tween overlap in monologue_display (cancel active tween before new one)
- Extract TILE_SIZE constant from magic number 32
- Add 5 D-030 Layer 1 fixture tests for snapshot parsing (7/7 total passing)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-11 17:53:24 +01:00

73 lines
2.4 KiB
GDScript

## D-030 Layer 1: Fixture-based tests for snapshot parsing
## Validates that GameState correctly parses ObserverSnapshot data
class_name TestSnapshotParsing
extends GdUnitTestSuite
# Valid snapshot fixture
var _valid_snapshot: Dictionary = {
"tick": 1,
"player": {
"position": [10, 15],
"health": 85
},
"entities": [
{"id": 1, "type": "npc", "position": [12, 8], "name": "Test NPC"},
{"id": 2, "type": "npc", "position": [5, 20], "name": "Second NPC"},
],
"fog": {"radius": 8},
"hud": {"perception_mode": "baseline", "time": "14:30"}
}
func test_apply_valid_snapshot() -> void:
GameState.apply_snapshot(_valid_snapshot)
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
assert_that(GameState.visible_entities.size()).is_equal(2)
assert_that(GameState.fog_state).is_equal({"radius": 8})
assert_that(GameState.hud_data).is_equal({"perception_mode": "baseline", "time": "14:30"})
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_malformed_position_no_crash() -> void:
var bad_snapshot: Dictionary = {
"player": {"position": "not_an_array"},
}
# Reset
GameState.player_position = Vector2.ZERO
# Should not crash — logs warning instead
GameState.apply_snapshot(bad_snapshot)
assert_that(GameState.player_position).is_equal(Vector2.ZERO)
func test_missing_fields_partial_update() -> void:
# First apply valid snapshot
GameState.apply_snapshot(_valid_snapshot)
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
# Apply snapshot with only HUD data — player position unchanged
GameState.apply_snapshot({"hud": {"perception_mode": "thermal", "time": "22:00"}})
assert_that(GameState.player_position).is_equal(Vector2(10, 15))
assert_that(GameState.hud_data.perception_mode).is_equal("thermal")
func test_sim_bridge_test_snapshot_deterministic() -> void:
SimBridge._test_tick = 0
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 structure is stable
assert_that(snap1.has("player")).is_true()
assert_that(snap1.has("entities")).is_true()
assert_that(snap1.has("fog")).is_true()
assert_that(snap1.has("hud")).is_true()