fix(client): clear the test debt — 2 production bugs, suite fully green (T-973 et al.)

Production fixes surfaced by honest test triage:
- hud_groups.gd: _set_group_z crashed on freed HUD nodes — the typed loop
  variable errors before the is_instance_valid guard runs; prune first
- fog_state.gd: _resize cleared _prev_visible (world-space keys survive
  resizes), so pre-resize tiles never decayed VISIBLE→EXPLORED (D-059)

Test debt (T-928/929/934/935/936/937/938/939, T-864, T-973): lambda
local-capture bugs rewritten with array captures (now assert exact
emission counts), e2e suites updated to the current handshake +
StartupMessage protocol and stream-aware reads against the live binary,
fog perf test measures steady state, chime test pins the shipped 800ms
catalog asset (D-067 amended separately), monologue gdUnit4 API typo,
battery-warning tests follow the MetaScreen on_open lifecycle. 3 sprint2
proof tests revived (corner_reveal had passed from the wrong tile — NPC3
blocks (18,14); route corrected). Soft-skips converted to real do_skip
reporting. T-1068: 7 orphan .gd.uid deleted, _format_pop/_format_radius
deduped into atlas_format.gd (preload, no class_name — headless cache).

Suite: 1264 cases/20 failures → 1268/0, independently re-verified
(2536/2536, exit 0).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 16:22:01 +02:00
co-authored by Claude Fable 5
parent b7a8cd1876
commit c64231e8ee
25 changed files with 603 additions and 269 deletions
+148 -44
View File
@@ -1,14 +1,12 @@
## Sprint 2 Proof: Fog of Perception (#357)
## Verifies all 7 acceptance criteria through the full server pipeline.
## Verifies the original acceptance criteria through the full server pipeline.
##
## SUITE DISABLED (sprint-36): Sprint 2 ACs are long satisfied.
## The room coordinates and player spawn positions below are hardcoded from
## the Sprint 2 room layout, which has evolved (protocol is now v23; Gauntlet
## room layout is different). Live server testing via the Gauntlet infrastructure
## supersedes these tests. Rewrite against the current Gauntlet rooms if
## per-AC regression coverage is needed again.
## REVIVED (T-1068): disabled in sprint-36, re-enabled against the current
## protocol (handshake + StartupMessage exchange per #555/#175, streamed
## snapshots). The proof room layout below is still what main.rs
## setup_proof_room() spawns for non-test-mode servers.
##
## Server proof room layout (Sprint 2 — stale):
## Server proof room layout (setup_proof_room in server/src/main.rs):
## (16,13) = NPC1 (16,14) = WALL (16,16) = Player start
## (14,18) = NPC2 (18,14) = NPC3
## Player facing North → NPC1 blocked by wall.
@@ -57,76 +55,170 @@ func after_test() -> void:
_server_pid = -1
## Send a batch input and receive the snapshot response.
func _send_and_receive(action_name: String, tick: int = 0) -> Variant:
## Find the player entity in a snapshot by kind.
static func _find_player(snapshot: Dictionary) -> Dictionary:
for entity in snapshot.entities:
if entity.kind.variant == "Player":
return entity
return {}
## Send a batch input and receive a snapshot that reflects it.
## The server free-runs at ~20 ticks/sec and STREAMS a snapshot every tick —
## it is not request/response. Drain stale queued snapshots first, then:
## - expect_position != null (Vector2, render coords): wait until the player
## reaches that position and assert it. Deterministic under load — tick
## margins race the free-running server when the test process is descheduled
## between drain and send.
## - expect_position == null: wait for a snapshot at least 2 ticks past the
## drain point (enough for no-op actions).
func _send_and_receive(
action_name: String, tick: int = 0, expect_position: Variant = null
) -> Variant:
# Drain queued stale snapshots, remembering the newest tick seen.
var last_tick: int = -1
_bridge.poll()
var pending := _bridge.poll_message()
while pending.size() > 0:
var stale: Variant = Protocol.decode_snapshot(pending)
if stale != null:
last_tick = stale.tick
_bridge.poll()
pending = _bridge.poll_message()
var inputs: Array = [{"tick": tick, "action_name": action_name}]
var encoded := Protocol.encode_player_inputs(inputs)
assert_that(encoded.size()).is_greater(0)
var send_err := _bridge.send_message(encoded)
assert_that(send_err).is_equal(OK)
var snapshot_bytes := PackedByteArray()
# Wait for a snapshot that reflects the processed input.
var min_tick: int = last_tick + 2
var snapshot: Variant = null
var elapsed := 0.0
while elapsed < RESPONSE_TIMEOUT:
_bridge.poll()
snapshot_bytes = _bridge.poll_message()
if snapshot_bytes.size() > 0:
break
var msg := _bridge.poll_message()
if msg.size() > 0:
var decoded: Variant = Protocol.decode_snapshot(msg)
if decoded == null:
continue # undecodable frame — keep draining
if expect_position != null:
snapshot = decoded # keep latest so a timeout reports actual state
var player := _find_player(decoded)
if (
not player.is_empty()
and is_equal_approx(player.x, expect_position.x)
and is_equal_approx(player.y, expect_position.y)
):
break
elif decoded.tick >= min_tick:
snapshot = decoded
break
continue
await get_tree().create_timer(0.05).timeout
elapsed += 0.05
assert_that(snapshot_bytes.size()).is_greater(0)
var snapshot: Variant = Protocol.decode_snapshot(snapshot_bytes)
assert_that(snapshot).is_not_null()
assert_that(snapshot).override_failure_message(
"no snapshot received within %.1fs after '%s'" % [RESPONSE_TIMEOUT, action_name]
).is_not_null()
if expect_position != null and snapshot != null:
var player := _find_player(snapshot)
var actual := Vector2(player.x, player.y) if not player.is_empty() else Vector2.INF
assert_that(actual.is_equal_approx(expect_position)).override_failure_message(
"player must reach %s after '%s' — last seen %s" % [expect_position, action_name, actual]
).is_true()
return snapshot
## Connect to server, returning true on success.
## Protocol handshake (#555, #175): the server sends a HandshakeMessage as the
## first framed message; the client validates it and replies with a
## StartupMessage carrying world_seed before any input is accepted.
## Mirrors sim_bridge.gd's HANDSHAKING state.
func _do_handshake(world_seed: int = 42) -> bool:
var msg := PackedByteArray()
var elapsed := 0.0
while elapsed < CONNECT_TIMEOUT:
_bridge.poll()
msg = _bridge.poll_message()
if msg.size() > 0:
break
await get_tree().create_timer(0.05).timeout
elapsed += 0.05
if msg.is_empty():
push_warning("No HandshakeMessage received within %.1fs" % CONNECT_TIMEOUT)
return false
var MP = load("res://addons/messagepack/messagepack.gd")
var decoded: Variant = MP.decode(msg)
if decoded.status != null or not (decoded.value is Dictionary):
push_warning("Malformed HandshakeMessage")
return false
var startup_bytes := Protocol.encode_startup_message(world_seed)
if startup_bytes.is_empty():
return false
return _bridge.send_message(startup_bytes) == OK
## Spawn the server, connect, and complete the protocol handshake.
## Binary absence is handled by per-test `_do_skip` — by the time this runs the
## binary exists, so any failure here is a real failure (asserted loudly).
func _connect_to_server() -> bool:
var server_path := _server_binary_path()
if not FileAccess.file_exists(server_path):
push_warning("Sprint 2 proof skipped: server binary not found at %s" % server_path)
return false
var spawned := await _spawn_server(server_path)
assert_bool(spawned).override_failure_message(
"server spawn failed after %d port attempts" % MAX_PORT_ATTEMPTS
).is_true()
if not spawned:
return false
_bridge = LocalBridge.new()
var connected := false
var elapsed := 0.0
while elapsed < CONNECT_TIMEOUT:
if _server_pid > 0 and not OS.is_process_running(_server_pid):
push_warning("Server process died during connection")
return false
break
if _bridge.get_status() == StreamPeerTCP.STATUS_NONE:
_bridge.connect_to_server("127.0.0.1", _test_port)
_bridge.poll()
if _bridge.get_status() == StreamPeerTCP.STATUS_CONNECTED:
return true
connected = true
break
if _bridge.get_status() == StreamPeerTCP.STATUS_ERROR:
_bridge.disconnect_from_server()
_bridge.reset()
await get_tree().create_timer(0.1).timeout
elapsed += 0.1
return false
assert_bool(connected).override_failure_message(
"TCP connect to spawned server failed within %.1fs" % CONNECT_TIMEOUT
).is_true()
if not connected:
return false
# Handshake + startup exchange (#555, #175) — required before input is accepted
var handshake_ok := await _do_handshake()
assert_bool(handshake_ok).override_failure_message(
"protocol handshake + StartupMessage exchange must complete (#555, #175)"
).is_true()
return handshake_ok
# -- AC#1, AC#2, AC#3, AC#5: Movement, camera, tiles, fog -------------------------
func skip_test_proof_player_moves_and_v2_snapshot() -> void:
func test_proof_player_moves_and_v2_snapshot(
_do_skip := not FileAccess.file_exists(_server_binary_path()),
_skip_reason := "server binary not built — run `cargo build` in server/"
) -> void:
var ok := await _connect_to_server()
if not ok:
return
var snapshot: Dictionary = await _send_and_receive("MoveNorth")
var snapshot: Dictionary = await _send_and_receive("MoveNorth", 0, Vector2(16.5, 15.5))
# AC#1: Player moved from (16,16) to (16,15)
var player: Dictionary = {}
for entity in snapshot.entities:
if entity.kind.variant == "Player":
player = entity
break
var player := _find_player(snapshot)
assert_that(player.size()).is_greater(0)
assert_float(player.x).is_equal_approx(16.5, 0.001)
assert_float(player.y).is_equal_approx(15.5, 0.001)
@@ -144,14 +236,17 @@ func skip_test_proof_player_moves_and_v2_snapshot() -> void:
# -- AC#6: Wall hides entity -------------------------------------------------------
func skip_test_proof_wall_hides_entity() -> void:
func test_proof_wall_hides_entity(
_do_skip := not FileAccess.file_exists(_server_binary_path()),
_skip_reason := "server binary not built — run `cargo build` in server/"
) -> void:
var ok := await _connect_to_server()
if not ok:
return
# After MoveNorth: player at (16,15) facing North.
# Wall at (16,14) blocks LOS to NPC1 at (16,13).
var snapshot: Dictionary = await _send_and_receive("MoveNorth")
var snapshot: Dictionary = await _send_and_receive("MoveNorth", 0, Vector2(16.5, 15.5))
# NPC1 at (16,13) should be hidden — wall at (16,14) blocks LOS.
# Other NPCs (NPC2 at (14,18), NPC3 at (18,14)) may be visible.
@@ -166,24 +261,33 @@ func skip_test_proof_wall_hides_entity() -> void:
# -- AC#4, AC#7: Entity appears via LOS / corner reveal ----------------------------
func skip_test_proof_corner_reveal() -> void:
func test_proof_corner_reveal(
_do_skip := not FileAccess.file_exists(_server_binary_path()),
_skip_reason := "server binary not built — run `cargo build` in server/"
) -> void:
var ok := await _connect_to_server()
if not ok:
return
# Step 1: Move East twice to get beside the wall
# (16,16) → MoveEast → (17,16) → MoveEast → (18,16)
await _send_and_receive("MoveEast", 0)
await _send_and_receive("MoveEast", 1)
# Step 1: Move East three times — column x=18 is blocked at (18,14) by
# NPC3 (entities are unwalkable), so route around via x=19.
# (16,16) → (17,16) → (18,16) → (19,16)
await _send_and_receive("MoveEast", 0, Vector2(17.5, 16.5))
await _send_and_receive("MoveEast", 1, Vector2(18.5, 16.5))
await _send_and_receive("MoveEast", 2, Vector2(19.5, 16.5))
# Step 2: Move North past the wall line (y=14)
# (18,16) → MoveNorth → (18,15) → MoveNorth → (18,14) → MoveNorth → (18,13)
await _send_and_receive("MoveNorth", 2)
await _send_and_receive("MoveNorth", 3)
var snapshot: Dictionary = await _send_and_receive("MoveNorth", 4)
# (19,16) → (19,15) → (19,14) → (19,13)
await _send_and_receive("MoveNorth", 3, Vector2(19.5, 15.5))
await _send_and_receive("MoveNorth", 4, Vector2(19.5, 14.5))
await _send_and_receive("MoveNorth", 5, Vector2(19.5, 13.5))
# Player at (18,13) facing North. NPC1 at (16,13) is 2 tiles west —
# within peripheral cone, no wall between. NPC1 should be visible.
# Step 3: Move West onto (18,13) — now facing West, looking straight at
# NPC1 at (16,13) two tiles ahead with no wall between ((17,13) is open).
var snapshot: Dictionary = await _send_and_receive("MoveWest", 6, Vector2(18.5, 13.5))
# Player at (18,13) facing West. NPC1 at (16,13) is 2 tiles dead ahead —
# inside the vision cone, no wall between. NPC1 should be visible.
var npc1_found := false
for entity in snapshot.entities:
if entity.kind.variant == "Npc":