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 <noreply@anthropic.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user