extends SceneTree ## CONTROLLED_FIXTURE. No production placement, recorder or eligibility claim. const Rooms := preload("res://scripts/special/peeping_room_service.gd") var checks := 0 var failures := 0 var fixtures: Array[Dictionary] = [] func _initialize() -> void: call_deferred("_run") func expect(ok: bool, label: String) -> void: checks += 1 if not ok: failures += 1 push_error(label) func fixture(build_bath := true) -> Dictionary: var clock: Variant = load("res://autoload/game_clock.gd").new() var state: Variant = load("res://autoload/game_state.gd").new() var runtime: Variant = load("res://autoload/simulation_runtime.gd").new() clock.reset(1, 6, 0) state.reset() expect(runtime.initialize(clock, state, 1302)[&"valid"], "CONTROLLED_FIXTURE real Runtime initializes") clock.set_paused(true) runtime.configure_save_policy({&"enabled": false, &"daily_checkpoint_enabled": false}) var f := {&"clock": clock, &"state": state, &"runtime": runtime, &"target": &"", &"origin": Vector3i(-6, 1, 1)} fixtures.append(f) if build_bath: var built: CommandResult = runtime.submit_command(&"build_facility", {&"definition_id": &"public_bath", &"origin": Vector3i(-6, 0, 0)}) expect(built.is_success(), "real paid public bath construction") clock.advance_minutes(runtime.definition_registry.get_facility(&"public_bath").build_minutes) for target: FacilityInstance in runtime.facility_service.get_instances(): if target.definition_id == &"public_bath": f[&"target"] = target.instance_id expect(not f[&"target"].is_empty(), "completed FRONT target has real stable identity") return f func place(f: Dictionary, origin: Variant = null) -> StringName: var report: Dictionary = f[&"runtime"].peeping_room_service.controlled_fixture_place(f[&"origin"] if origin == null else origin) expect(report[&"ok"], "CONTROLLED_FIXTURE only room placement: " + String(report[&"reason"])) return report.get(&"room_id", &"") func enable_fixture(f: Dictionary, room: StringName) -> void: var runtime: Variant = f[&"runtime"] expect(runtime.peeping_room_service.controlled_fixture_set_stopped(room, false), "CONTROLLED_FIXTURE explicitly enables ledger exercise") expect(runtime.facility_service.set_operational_status(f[&"target"], {&"power_available": true, &"operator_open": true}, f[&"clock"].absolute_minute).is_success(), "CONTROLLED_FIXTURE target conditions") func rejects_atomically(runtime: Variant, snapshot: Dictionary) -> bool: var before := var_to_bytes(runtime.create_snapshot()) return not runtime.restore_snapshot(snapshot) and before == var_to_bytes(runtime.create_snapshot()) func finish(label: String) -> void: for f: Dictionary in fixtures: f[&"runtime"].free() f[&"clock"].free() f[&"state"].free() fixtures.clear() print("%s: %d checks, %d failures" % [label, checks, failures]) quit(1 if failures else 0)