fix(client): address PR #4 review feedback

Hoshe critical fixes:
- _action_enum_to_wire uses InputMapper.Action constants instead of
  fragile integer literals; OPEN_MENU explicitly handled as client-only
- Remove int() coercion on tick/entity_id — use direct assignment since
  GDScript int is signed 64-bit (safe for realistic tick values)
- Check encode result before buffering in send_input() — reject empty
  bytes instead of corrupting the outbound stream
- Test snapshot now uses Protocol format {tick, entities} instead of
  legacy schema; GameState updated to derive player position from
  entity data; main.gd and world_renderer.gd updated accordingly

Hoshe warnings:
- 5 negative tests added (truncated bytes, wrong type, missing fields,
  empty bytes, encode validation) — 20/20 tests pass
- receive_bytes signal is emitted at consume time in poll_snapshot by
  design (documented in code)

Tyre suggestions:
- Remove duplicated root-level fixtures — single source of truth in
  client/tests/fixtures/msgpack/
- gen_fixtures.rs writes directly to client/ directory
- Add `make fixtures` target for regeneration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-11 19:32:49 +01:00
co-authored by Claude Opus 4.6
parent 9af9b3f3aa
commit bc9a691bc1
15 changed files with 109 additions and 89 deletions
+8 -3
View File
@@ -31,8 +31,11 @@ static func decode_snapshot(bytes: PackedByteArray) -> Variant:
if entity != null:
entities.append(entity)
# GDScript int is signed 64-bit. Rust tick is u64 but will not exceed 2^63
# in any realistic scenario (would require ~29 billion years at 10 ticks/min).
var tick: int = raw["tick"]
return {
"tick": int(raw["tick"]),
"tick": tick,
"entities": entities,
}
@@ -44,8 +47,9 @@ static func _decode_entity(raw: Dictionary) -> Variant:
push_warning("Protocol: entity missing required fields: %s" % str(raw.keys()))
return null
var entity_id: int = raw["entity_id"]
return {
"entity_id": int(raw["entity_id"]),
"entity_id": entity_id,
"x": float(raw["x"]),
"y": float(raw["y"]),
"z": int(raw["z"]),
@@ -108,7 +112,8 @@ static func decode_player_input(bytes: PackedByteArray) -> Variant:
push_error("Protocol: player_input missing required fields")
return null
var tick: int = raw["tick"]
return {
"tick": int(raw["tick"]),
"tick": tick,
"action": _decode_enum_variant(raw["action"]),
}
+1
View File
@@ -0,0 +1 @@
uid://fkmd537xvwxe