53 lines
3.5 KiB
GDScript
53 lines
3.5 KiB
GDScript
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 Runtime")
|
|
clock.set_paused(true)
|
|
expect(runtime.enable_production_operations()[&"ok"], "enable production arrivals")
|
|
var original: Dictionary = runtime.create_snapshot()
|
|
var legacy := original.duplicate(true)
|
|
legacy[&"systems"][&"runtime"][&"runtime_schema_version"] = 10
|
|
preload("res://tests/fixtures/pre_auto_purchase_runtime.gd").strip_empty(legacy[&"systems"][&"runtime"])
|
|
legacy[&"systems"][&"runtime"].erase(&"weather")
|
|
legacy[&"systems"][&"runtime"].erase(&"facility_cleanliness")
|
|
expect(runtime.restore_snapshot(legacy) and runtime.weather.get_kind() == &"clear" and runtime.weather.get_minute() == 360, "v10 migrates to neutral weather at saved minute")
|
|
expect(runtime.create_snapshot() == original, "old neutral save migration preserves other state")
|
|
var malformed := original.duplicate(true)
|
|
malformed[&"systems"][&"runtime"][&"weather"][&"minute"] = 361
|
|
expect(not runtime.restore_snapshot(malformed) and runtime.create_snapshot() == original, "future weather clock rejects atomically")
|
|
malformed = original.duplicate(true)
|
|
malformed[&"systems"][&"runtime"].erase(&"weather")
|
|
expect(not runtime.restore_snapshot(malformed), "new schema cannot silently lose weather")
|
|
expect(runtime.weather.schedule(&"storm",390)[&"ok"] and runtime.weather.schedule(&"clear",420)[&"ok"], "schedule weather boundaries")
|
|
clock.advance_minutes(29)
|
|
var before: Dictionary = runtime.create_snapshot()
|
|
expect(runtime.weather.get_kind() == &"clear", "storm does not apply before boundary")
|
|
var spawned := {&"count":0}
|
|
runtime.guest_service.guest_spawned.connect(func(_guest: GuestRuntime) -> void: spawned[&"count"] += 1)
|
|
clock.advance_minutes(1)
|
|
expect(runtime.weather.get_kind() == &"storm" and spawned[&"count"] == 0, "storm starts before same-minute production admission")
|
|
var boundary: Dictionary = runtime.call("_operations_arrival_boundary", {}, OperationsCoordinator.PHASE_CAPTURE, null)
|
|
expect(boundary[&"capacity_remaining"] == 0, "storm exposes zero admission capacity")
|
|
var stopped: Dictionary = runtime.create_snapshot()
|
|
expect(runtime.restore_snapshot(stopped) and runtime.create_snapshot() == stopped, "storm and recovery schedule round trip exactly")
|
|
clock.advance_minutes(30)
|
|
expect(runtime.weather.get_kind() == &"clear", "scheduled recovery resumes weather at boundary")
|
|
boundary = runtime.call("_operations_arrival_boundary", {}, OperationsCoordinator.PHASE_CAPTURE, null)
|
|
expect(boundary[&"capacity_remaining"] > 0, "recovery restores admission capacity")
|
|
var recovered: Dictionary = runtime.create_snapshot()
|
|
expect(runtime.restore_snapshot(before), "rewind before storm")
|
|
clock.advance_minutes(31)
|
|
expect(runtime.create_snapshot() == recovered, "full Runtime weather and arrivals replay identically")
|
|
expect(not runtime.get_operations_report()[&"runtime_failure_latched"], "weather does not quarantine operations")
|
|
runtime.free(); clock.free(); state.free()
|
|
print("Runtime weather: %d checks, %d failures" % [checks, failures]); quit(failures)
|