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)