From a1c5db94905f2271635246ac628f51a97177f6c1 Mon Sep 17 00:00:00 2001 From: Jeroen Schweitzer Date: Fri, 13 Feb 2026 00:05:07 +0100 Subject: [PATCH] fix(client): make E2E tests resilient to entity ordering Server proof room now has 3 NPCs instead of 1. Find player entity by kind instead of assuming entities[0]. Wall-hides test checks specific NPC position (16.5, 13.5) rather than asserting zero NPC count. Corner-reveal test searches for NPC1 by position. Co-Authored-By: Claude Opus 4.6 --- client/tests/test_e2e_connection.gd | 12 ++++++-- client/tests/test_sprint2_proof.gd | 47 +++++++++++++++++------------ 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/client/tests/test_e2e_connection.gd b/client/tests/test_e2e_connection.gd index 1f3e6df10..d3d9b9a59 100644 --- a/client/tests/test_e2e_connection.gd +++ b/client/tests/test_e2e_connection.gd @@ -109,12 +109,18 @@ func test_send_input_receive_snapshot() -> void: # Server starts at tick 0, snapshot reflects state after processing assert_that(snapshot.tick).is_equal(0) - assert_that(snapshot.entities.size()).is_equal(1) + assert_that(snapshot.entities.size()).is_greater(0) + + # Find the player entity by kind (entity order is not guaranteed) + var player: Dictionary = {} + for entity in snapshot.entities: + if entity.kind.variant == "Player": + player = entity + break + assert_that(player.size()).is_greater(0) # Player started at (16, 16, 0), moved north (y-1) to (16, 15, 0) # Render coords: tile center offset -> (16.5, 15.5, 0) - var player: Dictionary = snapshot.entities[0] assert_float(player.x).is_equal_approx(16.5, 0.001) assert_float(player.y).is_equal_approx(15.5, 0.001) assert_that(player.z).is_equal(0) - assert_that(player.kind.variant).is_equal("Player") diff --git a/client/tests/test_sprint2_proof.gd b/client/tests/test_sprint2_proof.gd index 21a0164d6..21d689b41 100644 --- a/client/tests/test_sprint2_proof.gd +++ b/client/tests/test_sprint2_proof.gd @@ -6,9 +6,10 @@ ## Requires: server binary built (cargo build in server/) ## ## Server proof room layout: -## (16,13) = NPC (16,14) = WALL (16,16) = Player start -## Player facing North → NPC blocked by wall. -## Move East+North around the wall → NPC becomes visible. +## (16,13) = NPC1 (16,14) = WALL (16,16) = Player start +## (14,18) = NPC2 (18,14) = NPC3 +## Player facing North → NPC1 blocked by wall. +## Move East+North around the wall → NPC1 becomes visible. class_name TestSprint2Proof extends GdUnitTestSuite @@ -118,13 +119,17 @@ func test_proof_player_moves_and_v2_snapshot() -> void: var snapshot: Dictionary = await _send_and_receive("MoveNorth") # AC#1: Player moved from (16,16) to (16,15) - var player: Dictionary = snapshot.entities[0] + var player: Dictionary = {} + for entity in snapshot.entities: + if entity.kind.variant == "Player": + player = entity + break + 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) - assert_that(player.kind.variant).is_equal("Player") - # v2 protocol fields present - assert_that(snapshot.version).is_equal(2) + # v4 protocol fields present + assert_that(snapshot.version).is_equal(Protocol.PROTOCOL_VERSION) assert_that(snapshot.player_facing).is_equal("North") assert_that(snapshot.game_time).is_not_null() @@ -143,15 +148,18 @@ func test_proof_wall_hides_entity() -> void: return # After MoveNorth: player at (16,15) facing North. - # Wall at (16,14) blocks LOS to NPC at (16,13). + # Wall at (16,14) blocks LOS to NPC1 at (16,13). var snapshot: Dictionary = await _send_and_receive("MoveNorth") - # Only player should be visible — NPC is behind wall - var npc_count := 0 + # 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. + var hidden_npc_visible := false for entity in snapshot.entities: if entity.kind.variant == "Npc": - npc_count += 1 - assert_that(npc_count).is_equal(0) + if is_equal_approx(entity.x, 16.5) and is_equal_approx(entity.y, 13.5): + hidden_npc_visible = true + break + assert_that(hidden_npc_visible).is_false() # -- AC#4, AC#7: Entity appears via LOS / corner reveal ---------------------------- @@ -172,13 +180,12 @@ func test_proof_corner_reveal() -> void: await _send_and_receive("MoveNorth", 3) var snapshot: Dictionary = await _send_and_receive("MoveNorth", 4) - # Player at (18,13) facing North. NPC at (16,13) is 2 tiles west — - # within peripheral cone, no wall between. NPC should be visible. - var npc_found := false + # Player at (18,13) facing North. NPC1 at (16,13) is 2 tiles west — + # within peripheral cone, no wall between. NPC1 should be visible. + var npc1_found := false for entity in snapshot.entities: if entity.kind.variant == "Npc": - assert_float(entity.x).is_equal_approx(16.5, 0.001) - assert_float(entity.y).is_equal_approx(13.5, 0.001) - npc_found = true - break - assert_that(npc_found).is_true() + if is_equal_approx(entity.x, 16.5) and is_equal_approx(entity.y, 13.5): + npc1_found = true + break + assert_that(npc1_found).is_true()