extends SceneTree ## Visible-node cap evidence for P2-BAT-03. ## ## The contract allows at most five full enemy nodes and five visible hero ## nodes in the battle stage. Background heroes must not get a Sprite or a ## collision body. This test supplies more content than the cap and checks ## the actual node counts, including after the content shrinks again. const OUTPUT_PATH := "res://artifacts/visible_node_test.json" var _problems: Array = [] var _steps: Array = [] func _init() -> void: _run.call_deferred() func _run() -> void: var scene = load("res://scripts/battle_scene.gd").new() root.add_child(scene) var battle := scene as BattleScene battle.set_process(false) battle.setup("zh_CN", "P3A-N03-SEMI", 10001) var heroes: Array = [] for hero_id in ["H01", "H02", "H04", "H05", "H06", "H03"]: heroes.append({"id": hero_id, "signature": "auto", "energy": 0.0, "energy_max": 100.0}) battle.hud.set_roster(heroes) var enemies: Array = [] for index in range(7): enemies.append({ "id": "E-R1-F1-V1#%d" % (index + 1), "content_id": "E-R1-F1-V1", "kind": "normal", "hp": 100.0, "max_hp": 100.0, "armor": 1.0, "shield": 0.0, "weak_tag": "aoe", "shield_broken": false, "dead": false, }) battle.hud.set_enemies(enemies, "") await process_frame await process_frame var counts := battle.hud.visible_node_counts() _check(int(counts["enemy_units"]) <= 5, "enemy unit count %s exceeds 5" % str(counts["enemy_units"])) _check(int(counts["enemy_plates"]) <= 5, "enemy plate count %s exceeds 5" % str(counts["enemy_plates"])) _check(int(counts["enemy_hit_areas"]) <= 5, "enemy hit area count %s exceeds 5" % str(counts["enemy_hit_areas"])) _check(int(counts["hero_units"]) <= 5, "visible hero unit count %s exceeds 5" % str(counts["hero_units"])) _record("over_cap_content", counts) # Non-visible heroes must not have spawned any art: only H01 has an atlas, # so a leaked unit for H02/H04 would fail to configure and stay absent. _check(int(counts["hero_units"]) == 5, "the hero cap should render exactly 5 units, got %s" % str(counts["hero_units"])) # set_roster runs every frame; calling it again with identical data must # reuse the same card nodes, not rebuild them (perf regression: ~2100 # nodes/sec were allocated before the diff-by-id fix). var ids_before: Array = battle.hud.roster_card_ids_for_test() battle.hud.set_roster(heroes) await process_frame var ids_after: Array = battle.hud.roster_card_ids_for_test() if ids_before != ids_after: _problems.append("set_roster rebuilt cards with identical roster: %s -> %s" % [str(ids_before), str(ids_after)]) _record("roster_reuse", {"before": ids_before.size(), "after": ids_after.size(), "same": ids_before == ids_after}) # Shrinking the content must release the stale nodes. battle.hud.set_enemies(enemies.slice(0, 1), "") battle.hud.set_roster(heroes.slice(0, 1)) await process_frame await process_frame var shrunk := battle.hud.visible_node_counts() _check(int(shrunk["enemy_units"]) == 1, "stale enemy units were not released") _check(int(shrunk["hero_units"]) == 1, "stale hero units were not released") _record("after_shrink", shrunk) var passed := _problems.is_empty() var report := { "schema": 1, "kind": "windroost_visible_node_test", "overall": "PASS" if passed else "FAIL", "problems": _problems, "steps": _steps, } var artifact_dir := ProjectSettings.globalize_path("res://artifacts") DirAccess.make_dir_recursive_absolute(artifact_dir) var file := FileAccess.open(artifact_dir.path_join("visible_node_test.json"), FileAccess.WRITE) if file != null: file.store_string(JSON.stringify(report, "\t", true)) file.close() for entry in _steps: print("VISIBLE_NODE_STEP %s" % JSON.stringify(entry)) if passed: print("VISIBLE_NODE_PASS caps and stale-node cleanup verified") else: print("VISIBLE_NODE_FAIL %s" % "; ".join(_problems)) quit(0 if passed else 1) func _check(condition: bool, message: String) -> void: if not condition: _problems.append(message) func _record(name: String, data: Dictionary) -> void: var entry := data.duplicate() entry["step"] = name _steps.append(entry)