Files
windroost/p2_godot_sample/scripts/longrun_stability_test.gd
T
wushenghua 66b6cf2926 refactor: unify upgrade cost + long-run stability gate (PRODUCTION/49 goal)
Wrote PRODUCTION/49 as the authoritative ongoing-optimization goal after
analyzing what remains. Executed all owner-independent items:

A1 upgrade cost single source of truth: game_root hardcoded 120*1.15^(lvl-1)
in two places while battle HUD read mvp_battle_rules.json — a balance change
would desync displayed cost from the actual debit. All three call sites now use
ProfileStore.upgrade_cost(level) (rules-driven). upgrade_cost_test proves the
helper matches an independent formula at Lv1/5/12, the skyport card shows the
authoritative cost, and the real debit equals it (210 at Lv5). 5 stages pass.

A2 long-run stability gate: new longrun_stability_test drives 400 frames of a
real battle with continuous damage/VFX and asserts floating numbers <=16,
roster cards constant (3), pop tweens <=4, visible units <=5, and no growth
from warmup to frame 400. This guards the leak classes fixed earlier.

A4 evidence audit updated (PRODUCTION/48 sections 4b/4c) with all fixes and
the one honest design-open item (ultimate energy recharge has no authoritative
sim contract, so not invented).

Both tests registered in run_p2_checks.sh. Full gate P2_CHECKS_PASS, log audit
clean, 0 script/lambda errors. prototype/ untracked.
2026-11-18 05:09:32 +08:00

120 lines
4.2 KiB
GDScript

extends SceneTree
## Long-run presentation stability (automated_verified).
##
## Leaks in pooled floating numbers, VFX nodes, roster cards or feedback pop
## tracking all showed up only after sustained play. This drives a real battle
## for hundreds of frames with continuous damage/VFX and asserts the live node
## counts stay bounded instead of growing linearly with frame count.
const OUTPUT_PATH := "res://artifacts/longrun_stability_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _snapshot(hud: BattleHud, fb: FeedbackService) -> Dictionary:
var counts := hud.visible_node_counts()
return {
"floating": hud.floating_number_count(),
"vfx": hud.active_vfx_ids().size(),
"roster_cards": hud.roster_card_ids_for_test().size(),
"pop_tweens": fb.tracked_pop_count_for_test(),
"enemy_units": int(counts.get("enemy_units", 0)),
"hero_units": int(counts.get("hero_units", 0)),
}
func _run() -> void:
var scene := load("res://scripts/battle_scene.gd").new() as BattleScene
root.add_child(scene)
await process_frame
await process_frame
scene.setup("zh_CN", "P3A-N08", 10001)
scene.set_process(false) # we drive frames manually for determinism
var hud := scene.hud
var fb := _fb()
# Feed a roster so cards exist; stable across the run.
var heroes: Array = []
for hid in ["H01", "H02", "H03"]:
heroes.append({"id": hid, "signature": "auto", "energy": 0.0, "energy_max": 100.0})
hud.set_roster(heroes)
# Warm-up: generate a few events so pools reach steady state.
for i in range(20):
hud.show_damage_number("E-R1-F1-V1#1", 20.0 + float(i % 30))
await process_frame
var warm := _snapshot(hud, fb)
_record("warmup", warm)
# Sustained run: continuous damage numbers at every frame; counts must not
# grow past their caps regardless of how many frames elapse.
for i in range(400):
hud.show_damage_number("E-R1-F1-V1#1", 15.0 + float(i % 40))
await process_frame
var after := _snapshot(hud, fb)
_record("after_400_frames", after)
# Bounds (caps from the contracts / fixes):
# floating numbers <= 16 (MAX_FLOATING_NUMBERS)
# roster cards == 3 (no rebuild growth)
# pop tweens <= 4 (bounded feedback)
# visible units <= 5 each
_check(after["floating"] <= 16, "floating numbers grew unbounded: %d" % after["floating"])
_check(after["roster_cards"] == 3, "roster cards changed count: %d" % after["roster_cards"])
_check(after["pop_tweens"] <= 4, "pop tweens grew unbounded: %d" % after["pop_tweens"])
_check(after["enemy_units"] <= 5, "enemy units grew unbounded: %d" % after["enemy_units"])
_check(after["hero_units"] <= 5, "hero units grew unbounded: %d" % after["hero_units"])
# The key regression signal: counts after 400 frames must not exceed the
# warmup steady state by more than a small margin (in-flight tweens).
_check(after["floating"] <= warm["floating"] + 2,
"floating numbers grew from warmup %d to %d over 400 frames" % [warm["floating"], after["floating"]])
_check(after["roster_cards"] == warm["roster_cards"],
"roster cards grew from %d to %d" % [warm["roster_cards"], after["roster_cards"]])
root.remove_child(scene)
scene.free()
_finish()
func _fb() -> FeedbackService:
return root.get_node_or_null("Feedback") as FeedbackService
func _check(condition: bool, message: String) -> void:
if not condition:
_problems.append(message)
func _finish() -> void:
var passed := _problems.is_empty()
var report := {
"schema": 1, "kind": "windroost_longrun_stability_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("longrun_stability_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("LONGRUN_STEP %s" % JSON.stringify(entry))
if passed:
print("LONGRUN_PASS node counts bounded over 400 frames")
else:
print("LONGRUN_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _record(name: String, data: Dictionary) -> void:
var entry := data.duplicate()
entry["step"] = name
_steps.append(entry)