fix(client): address PR #11 review — type safety, perf, tests
Add Dictionary validation in game_state visible_tiles loop to prevent crash on malformed data (Hoshe critical). Skip redundant modulate.a writes (Hoshe suggestion). Add 3 tests: malformed visible_tiles, facing rotation accuracy, v1 backward compatibility. Clarify D-033 Phase 1/Phase 2 comments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -322,6 +322,29 @@ func test_multi_entity_visibility_sectors() -> void:
|
||||
assert_that(snapshot.entities[3].visibility).is_equal("Forward")
|
||||
|
||||
|
||||
# -- v1 backward compatibility (no v2 fields → graceful null defaults) --------
|
||||
|
||||
func test_decode_v1_snapshot_graceful_defaults() -> void:
|
||||
# Minimal v1 snapshot — only tick + entities, no v2 fields
|
||||
var v1_raw := {"tick": 10, "entities": [
|
||||
{"entity_id": 1, "x": 5.0, "y": 5.0, "z": 0, "kind": "Player"},
|
||||
]}
|
||||
var encoded: Variant = Messagepack.encode(v1_raw)
|
||||
assert_that(encoded.status).is_null()
|
||||
|
||||
var snapshot: Variant = Protocol.decode_snapshot(encoded.value)
|
||||
assert_that(snapshot).is_not_null()
|
||||
assert_that(snapshot.tick).is_equal(10)
|
||||
assert_that(snapshot.entities.size()).is_equal(1)
|
||||
# v2 fields should be null/empty, not crash
|
||||
assert_that(snapshot.version).is_null()
|
||||
assert_that(snapshot.game_time).is_null()
|
||||
assert_that(snapshot.player_facing).is_null()
|
||||
assert_that(snapshot.visible_tiles.size()).is_equal(0)
|
||||
# Entity should have null visibility
|
||||
assert_that(snapshot.entities[0].visibility).is_null()
|
||||
|
||||
|
||||
# -- Batch input fixture (D-030 Layer 1 bidirectional symmetry) ----------------
|
||||
|
||||
func test_decode_batch_input_fixture() -> void:
|
||||
|
||||
Reference in New Issue
Block a user