From 07d34b6ac9d2c00e954fd08d1dac26df599a0de9 Mon Sep 17 00:00:00 2001 From: Natalie Date: Wed, 24 Jun 2026 04:06:17 -0400 Subject: [PATCH] =?UTF-8?q?test(@projects/@magic-civilization):=20?= =?UTF-8?q?=F0=9F=90=9B=20instantiate=20scenes=20(not=20bare=20scripts)=20?= =?UTF-8?q?in=20ecology=20UI=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit test_ecology_tile_inspector + test_ecology_grudge_badge did TileInfoPanelScript.new() / CombatPreviewScript.new() — bare scripts whose @onready %UniqueName labels resolve to null and log "Node not found" for every label, which GUT flags as unexpected errors. Instantiate the real .tscn instead (tile_info_panel.tscn lacks EcologySpeciesList, so the "absent list" scenario still holds). Clears both tests + removes ~13 cross-test %node error bleeds. GUT: 31 → 27 failing; Node-not-found errors 22 → 9. Co-Authored-By: Claude Opus 4.8 (1M context) --- src/game/engine/tests/unit/test_ecology_grudge_badge.gd | 6 ++++-- src/game/engine/tests/unit/test_ecology_tile_inspector.gd | 7 +++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/game/engine/tests/unit/test_ecology_grudge_badge.gd b/src/game/engine/tests/unit/test_ecology_grudge_badge.gd index 36512332..a5244cb4 100644 --- a/src/game/engine/tests/unit/test_ecology_grudge_badge.gd +++ b/src/game/engine/tests/unit/test_ecology_grudge_badge.gd @@ -5,6 +5,8 @@ extends GutTest ## grudge_against result. Tests are headless-compatible (no display server needed). const CombatPreviewScript: GDScript = preload("res://engine/scenes/combat/combat_preview.gd") +## Full scene so the @onready %nodes resolve (bare .new() logs Node-not-found). +const PREVIEW_SCENE: PackedScene = preload("res://engine/scenes/combat/combat_preview.tscn") ## Minimal mock that satisfies the grudge_against() call signature. ## Extends RefCounted so it can be stored in a typed GdFaunaEcology field — @@ -40,7 +42,7 @@ func before_all() -> void: func test_grudge_badge_not_shown_without_fauna_ecology() -> void: ## When _fauna_ecology is null, no badge node should be added. - var preview: CombatPreviewScript = CombatPreviewScript.new() + var preview: CombatPreviewScript = PREVIEW_SCENE.instantiate() as CombatPreviewScript add_child_autofree(preview) # Don't inject fauna ecology — stays null. var atk: MockWildDefender = MockWildDefender.new() @@ -51,7 +53,7 @@ func test_grudge_badge_not_shown_without_fauna_ecology() -> void: func test_grudge_badge_not_shown_for_regular_unit() -> void: ## Regular units (no ecology_species_id) must never show a grudge badge. - var preview: CombatPreviewScript = CombatPreviewScript.new() + var preview: CombatPreviewScript = PREVIEW_SCENE.instantiate() as CombatPreviewScript add_child_autofree(preview) # Even with a grudge-always mock, regular units without the wild fields # should not trigger the badge. diff --git a/src/game/engine/tests/unit/test_ecology_tile_inspector.gd b/src/game/engine/tests/unit/test_ecology_tile_inspector.gd index 53b6bec8..157b3837 100644 --- a/src/game/engine/tests/unit/test_ecology_tile_inspector.gd +++ b/src/game/engine/tests/unit/test_ecology_tile_inspector.gd @@ -5,6 +5,9 @@ extends GutTest ## Headless-compatible (no display server required). const TileInfoPanelScript: GDScript = preload("res://engine/scenes/world_map/tile_info_panel.gd") +## Instantiate the full scene (not a bare script) so the @onready %nodes resolve; +## a bare .new() logs "Node not found" for every unique-name label. +const PANEL_SCENE: PackedScene = preload("res://engine/scenes/world_map/tile_info_panel.tscn") func before_all() -> void: @@ -14,7 +17,7 @@ func before_all() -> void: func test_ecology_list_absent_does_not_crash() -> void: ## When the scene does not include an EcologySpeciesList node, ## _populate_ecology_species should silently no-op. - var panel: TileInfoPanelScript = TileInfoPanelScript.new() + var panel: TileInfoPanelScript = PANEL_SCENE.instantiate() as TileInfoPanelScript add_child_autofree(panel) # _ecology_list will be null (no scene node named EcologySpeciesList). # Must not crash. @@ -24,7 +27,7 @@ func test_ecology_list_absent_does_not_crash() -> void: func test_set_fauna_ecology_stores_reference() -> void: ## set_fauna_ecology assigns _fauna_ecology — used by _populate_ecology_species. - var panel: TileInfoPanelScript = TileInfoPanelScript.new() + var panel: TileInfoPanelScript = PANEL_SCENE.instantiate() as TileInfoPanelScript add_child_autofree(panel) var mock: RefCounted = RefCounted.new() # Assign via the setter. The panel's typed field won't accept a plain