extends SceneTree const FixtureCleanup := preload("res://tests/helpers/ui_audio_fixture_cleanup.gd") var checks := 0 var failures := 0 func _initialize() -> void: call_deferred("_run") func expect(value: bool, label: String) -> void: checks += 1 if not value: failures += 1 push_error(label) func _run() -> void: var clock: Variant = root.get_node("GameClock") var runtime: Variant = root.get_node("SimulationRuntime") var state: Variant = root.get_node("GameState") clock.reset() state.reset() runtime.initialize(clock, state, 927) clock.set_paused(true) var legacy_snapshot: Dictionary = runtime.create_snapshot() legacy_snapshot[&"clock"][&"speed"] = 4 expect(runtime.restore_snapshot(legacy_snapshot) and clock.speed == 3, "full Runtime migrates legacy x4 saves") var main: Control = load("res://scenes/main/main.tscn").instantiate() main.set("manual_save_path", "user://tests/original_controls_%d" % OS.get_process_id()) root.add_child(main) await process_frame runtime.configure_save_policy({&"enabled": false, &"daily_checkpoint_enabled": false}) for id: StringName in [&"a", &"b"]: runtime.facility_service.create_instance({&"instance_id": id, &"definition_id": &"standard_room"}) main.set("_selected_entity_id", &"a") main.set("_selected_entity_kind", &"facility") main.call("_refresh_selected_entity") var picker := main.get("related_facility_picker") as OptionButton expect(picker.visible and picker.item_count == 2, "inspector exposes one related facility") picker.item_selected.emit(1) expect(runtime.facility_service.get_instance(&"a").related_facility_id == &"b", "UI submits real paused command") runtime.facility_service.set_operational_status(&"b", {&"power_available": false}) main.call("_refresh_selected_entity") expect("未成立" in (main.get("selected_detail_label") as Label).text, "inspector displays unavailable dependency") expect("未設定" in (main.get("selected_detail_label") as Label).text, "unknown customer capacity is not fabricated") var buttons: Dictionary = main.get("speed_buttons") expect(buttons.has(3) and not buttons.has(4), "original maximum speed has a real UI button") (buttons[3] as Button).pressed.emit() expect(clock.speed == 3, "x3 button controls clock") clock.set_paused(true) # Test the transactional Authority closure boundary with actual discovered evidence. var evidence := AuthorityEvidence.new().configure(&"closure", &"audit", 60, {&"facility_id": &"a", &"created_at": 360}) expect(runtime.authority_service.register_evidence(evidence).is_success(), "closure evidence registered") expect(runtime.authority_service.attempt_discover_evidence(&"closure", &"inspector", Vector3i.ZERO, 360).is_success(), "inspection discovers reached evidence") var payload := {&"resolution_id": &"test", &"inspection_id": &"inspection", &"absolute_minute": 360, &"fine_amount": 0, &"result": &"TEMPORARY_CLOSURE", &"evidence_ids": ["closure"]} var before: Dictionary = runtime.facility_service.create_snapshot() var events_before: Dictionary = runtime.domain_events.create_snapshot() var ids_before: Dictionary = runtime.id_generator.create_snapshot() var validation: Dictionary = runtime.call("_apply_authority_resolution_boundary", payload, &"validate", null) expect(validation[&"ok"], "zero-fine closure validates") var applied: Dictionary = runtime.call("_apply_authority_resolution_boundary", payload, &"apply", validation[&"token"]) expect(applied[&"ok"] and runtime.facility_service.get_instance(&"a").operation_state == FacilityInstance.OperationState.SUSPENDED, "zero-fine inspection still suspends target") expect(runtime.facility_service.get_instance(&"b").suspension_reason.is_empty(), "unrelated facility is not suspended") var rolled_back: Dictionary = runtime.call("_apply_authority_resolution_boundary", payload, &"rollback", validation[&"token"]) expect(rolled_back[&"ok"] and runtime.facility_service.create_snapshot() == before, "rollback restores facility and financial state") expect(runtime.domain_events.create_snapshot() == events_before and runtime.id_generator.create_snapshot() == ids_before, "rollback restores emitted events and stable IDs") if DisplayServer.get_name() != "headless": root.size = Vector2i(1440, 900) main.call("_set_management_panel_open", true) main.call("_refresh_selected_entity") for frame in 6: await process_frame await RenderingServer.frame_post_draw var capture_path := "res://artifacts/original-2026-09-27/facility-controls.png" expect(root.get_texture().get_image().save_png(capture_path) == OK, "real inspector capture saved") var _audio_cleanup_final: Dictionary = await FixtureCleanup.free_owner_and_wait(self, main) if not bool(_audio_cleanup_final.get(&"passed", false)): push_error("Ordinary fixture audio cleanup failed: %s" % str(_audio_cleanup_final)) quit(96) return await process_frame print("%s: %d checks" % ["PASS" if failures == 0 else "FAIL", checks]) quit(failures)