Files
windroost/p2_godot_sample/scripts/vfx_test.gd
T
wushenghua 8440576e9d fix: audit logs and repair 693 hidden runtime errors
AGENTS.md says exit code zero alone is insufficient: logs must be scanned for
script errors, parse/resource/import failures, ObjectDB leaks and cleanup.
The 21 existing gates each grepped only their own PASS marker and never did
this cross-check. tools/audit_logs.py scans all test logs and immediately
found 708 error lines that every PASS marker had been hiding.

693 were the same Tween callback error: tween_callback().bind(label) hits a
Godot 4 Variant conversion bug ("Cannot convert Object to Object"), so the
floating-damage reclaim callback failed on every frame and the Label nodes
were never returned to the pool - a real runtime leak in long fights. Fixed
with a zero-argument lambda that captures the label directly. One more was an
unescaped % in a boss_phase_test assertion; fixed.

The remaining notes are Godot headless releasing its static ResourceLoader
cache at process exit (5 AudioStreamWAVs), not a product leak. The audit counts
them separately as NOTE and does not fail on them; all in-run errors still
fail hard. SfxPlayer also gained release_resources() on tree exit as a hedge.

tools/run_p2_checks.sh now runs 22 gates including the log audit; all pass.
PRODUCTION/41 records the evidence and the lesson: a PASS marker is not proof
when the log is full of errors.
2026-11-17 14:46:00 +08:00

121 lines
3.9 KiB
GDScript

extends SceneTree
## VFX evidence.
##
## 1. Each sheet advances deterministically through all of its frames and
## finishes, including the low-power frame-step path.
## 2. Authoritative battle events spawn the matching effect: shield break,
## ultimate cast and a normal hit. The mapping is event -> effect, so a
## VFX can never show something the simulation did not do.
const EFFECTS := ["hit_light", "shield_break", "ultimate_burst"]
const OUTPUT_PATH := "res://artifacts/vfx_test.json"
var _problems: Array = []
var _steps: Array = []
func _init() -> void:
_run.call_deferred()
func _run() -> void:
await _test_sheets()
await _test_event_mapping()
var passed := _problems.is_empty()
var report := {
"schema": 1,
"kind": "windroost_vfx_test",
"style": "pixel_sheet_nearest",
"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("vfx_test.json"), FileAccess.WRITE)
if file != null:
file.store_string(JSON.stringify(report, "\t", true))
file.close()
for entry in _steps:
print("VFX_STEP %s" % JSON.stringify(entry))
if passed:
print("VFX_PASS %d effects and event bindings verified" % EFFECTS.size())
else:
print("VFX_FAIL %s" % "; ".join(_problems))
quit(0 if passed else 1)
func _test_sheets() -> void:
for effect in EFFECTS:
for low_power in [false, true]:
var vfx := VfxView.new()
add_root_child(vfx)
var configured := vfx.configure(effect, low_power)
_check(configured, "%s failed to configure" % effect)
if not configured:
continue
var step := vfx.frame_step()
var expected_step := (2 if vfx.frame_count() > 4 else 1) if low_power else 1
_check(step == expected_step, "%s low_power=%s step %d, expected %d" % [effect, str(low_power), step, expected_step])
var last_frame := -1
var guard := 0
while not vfx.finished and guard < 200:
vfx.step(1.0 / 12.0)
last_frame = vfx.current_frame()
guard += 1
_check(vfx.finished, "%s low_power=%s never finished" % [effect, str(low_power)])
_check(last_frame == vfx.frame_count() - 1, "%s did not reach its final frame" % effect)
_record("sheet", {
"effect": effect, "low_power": low_power, "frames": vfx.frame_count(),
"step": step, "last_frame": last_frame, "finished": vfx.finished,
})
root.remove_child(vfx)
vfx.free()
func _test_event_mapping() -> void:
var scene = load("res://scripts/battle_scene.gd").new()
add_root_child(scene)
var battle := scene as BattleScene
battle.set_process(false)
battle.setup("zh_CN", "P3A-N10-MANUAL", 10001)
battle.advance_ticks(300)
await process_frame
var seen: Dictionary = {}
for effect in battle.hud.active_vfx_ids():
seen[effect] = true
# The boss fight generates shield breaks and an ultimate at seed 10001.
_check(seen.has("shield_break"), "a shield_break event should spawn the shield_break VFX")
_check(seen.has("ultimate_burst"), "a cast_ultimate event should spawn the ultimate_burst VFX")
_check(seen.has("hit_light"), "click and burst events should spawn the hit_light VFX")
_check(battle.hud.floating_number_count() > 0, "HP deltas should produce floating damage numbers")
_record("event_mapping", {
"scenario": "P3A-N10-MANUAL",
"spawned_effects": battle.hud.active_vfx_ids(),
"floating_numbers": battle.hud.floating_number_count(),
"event_count": (battle.state.get("event_log", []) as Array).size(),
})
if battle.hud.sfx != null:
battle.hud.sfx.release_resources()
root.remove_child(scene)
scene.free()
func add_root_child(node: Node) -> void:
root.add_child(node)
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)