Files
TheTree_mock/tests/performance/test_lazy_digest.gd
T
Takeshi 5dde0c5ec2 Record original-alignment implementation and traceability checkpoint
Capture current source, content data, tests, asset licenses, and original-specification traceability. Original implementation remains incomplete. The accepted matching UI generation passed 154 suites and 12,253 checks, with eight rendered staff-contract screens reviewed. Latest native Windows and full-original acceptance remain outstanding.
2026-09-30 23:52:24 +09:00

40 lines
2.3 KiB
GDScript

extends SceneTree
var failures := 0
var checks := 0
func _initialize() -> void:call_deferred("run")
func expect(ok: bool, label: String) -> void:
checks+=1
if not ok:failures+=1;push_error(label)
func run() -> void:
var runtime: Variant = root.get_node("SimulationRuntime")
var clock: Variant = root.get_node("GameClock")
var state: Variant = root.get_node("GameState")
clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,42515);clock.set_paused(true)
runtime.configure_save_policy({&"enabled":false,&"daily_checkpoint_enabled":false})
var baseline: Dictionary = runtime.create_snapshot()
var notices: Array[int] = []
runtime.state_updated.connect(func(_snapshot: Dictionary):notices.append(clock.absolute_minute))
clock.advance_one_minute()
expect(runtime.get("_latest_digest_dirty"),"no digest consumer leaves computation pending")
var snapshot: Dictionary=runtime.latest_snapshot.duplicate(true)
expect(runtime.latest_digest==SimulationDigest.compute(snapshot),"lazy digest matches exact published snapshot")
expect(not runtime.get("_latest_digest_dirty"),"repeated reads reuse current publication digest")
var prior: String=runtime.latest_digest
clock.advance_one_minute()
expect(runtime.get("_latest_digest_dirty") and runtime.latest_digest!=prior,"new publication invalidates old hash")
expect(notices.size()==2,"lightweight notification emitted per publication")
var lazy_end: Dictionary=runtime.create_snapshot()
expect(runtime.restore_snapshot(baseline),"restore pre-run state")
var observed: Array[Dictionary]=[]
var observer := func(value: Dictionary,digest: String): observed.append({"snapshot":value.duplicate(true),"digest":digest})
runtime.snapshot_published.connect(observer)
clock.advance_minutes(2)
expect(observed.size()==2,"legacy observer still receives every publication")
for row: Dictionary in observed:
expect(row["digest"]==SimulationDigest.compute(row["snapshot"]),"legacy observer receives exact eager hash")
expect(runtime.create_snapshot()==lazy_end,"lazy and observed runs preserve identical simulation state")
runtime.snapshot_published.disconnect(observer)
clock.advance_one_minute()
expect(runtime.get("_latest_digest_dirty"),"disconnecting legacy observer restores lazy computation")
print("Lazy digest: %d checks, %d failures" % [checks,failures]);quit(failures)