extends SceneTree var checks := 0 var failures := 0 func expect(ok: bool, message: String) -> void: checks += 1 if not ok: failures += 1; push_error(message) func _initialize() -> void: call_deferred("run") func run() -> void: var runtime: Variant = load("res://autoload/simulation_runtime.gd").new() var clock: Variant = load("res://autoload/game_clock.gd").new() var state: Variant = load("res://autoload/game_state.gd").new() clock.reset(1,6,0); state.reset() expect(runtime.initialize(clock,state,424242)[&"valid"], "initialize") clock.set_paused(true) expect(runtime.enable_production_operations()[&"ok"], "enable arrivals") expect(runtime.weather.schedule(&"storm",390)[&"ok"] and runtime.weather.schedule(&"clear",420)[&"ok"], "schedule storm and recovery") clock.advance_minutes(29) runtime.set_operations_test_boundary_hook(&"ARRIVAL_PLAN", func(_payload: Dictionary, _phase: StringName, _token: Variant) -> Dictionary: return {&"ok": false}) clock.advance_minutes(1) expect(clock.absolute_minute == 390 and runtime.get_operations_report()[&"runtime_failure_latched"], "arrival failure pauses at weather boundary") expect(runtime.weather.get_kind() == &"storm" and runtime.weather.get_minute() == 390, "weather commits before failed arrival") var weather_before: Dictionary = runtime.weather.create_snapshot() var path := "user://tests/weather_recovery_%d" % OS.get_process_id() expect(runtime.save_to_path(path)[&"ok"], "write interrupted weather to actual save package") expect(runtime.load_from_path(path)[&"ok"] and runtime.weather.create_snapshot() == weather_before, "disk load preserves storm and pending recovery") expect(runtime.get_operations_report()[&"deferred_runtime_minute"] == 390, "disk load preserves failed boundary for retry") runtime.set_operations_test_boundary_hook(&"ARRIVAL_PLAN", Callable()) var arrivals := {&"count":0} runtime.guest_service.guest_spawned.connect(func(_guest: GuestRuntime) -> void: arrivals[&"count"] += 1) expect(runtime.acknowledge_operations_pause()[&"ok"], "retry failed storm boundary") expect(arrivals[&"count"] == 0 and runtime.weather.create_snapshot() == weather_before, "retry neither admits storm guests nor duplicates weather transition") var completed: Dictionary = runtime.create_snapshot() expect(runtime.restore_snapshot(completed) and runtime.create_snapshot() == completed, "completed retry restores exactly") clock.advance_minutes(30) expect(runtime.weather.get_kind() == &"clear" and runtime.weather.create_snapshot()[&"pending"].is_empty(), "disk-restored recovery occurs once at scheduled minute") expect(not runtime.get_operations_report()[&"runtime_failure_latched"], "recovery resumes ordinary operations") expect(SaveService.delete_save(path), "delete isolated test save") runtime.free(); clock.free(); state.free() print("Weather recovery: %d checks, %d failures" % [checks, failures]); quit(failures)