extends "res://tests/special/peeping_room_fixture.gd" func _run() -> void: var f := fixture() var runtime: Variant = f[&"runtime"] # Direct executor invocation distinguishes read-only domain state from queue receipts. var validation := SimulationCommand.new() validation.command_type = &"peeping_room_validate" validation.payload = {&"origin": f[&"origin"]} var before := var_to_bytes(runtime.create_snapshot()) expect(runtime._execute_peeping_room(validation).is_success(), "read-only validator executor") expect(before == var_to_bytes(runtime.create_snapshot()), "validator changes no whole Runtime bytes") var public_validation: CommandResult = runtime.submit_command(&"peeping_room_validate", validation.payload) expect(public_validation.is_success(), "registered validation command runs through real queue") var placement := SimulationCommand.new() placement.command_type = &"peeping_room_place" placement.payload = validation.payload.duplicate(true) var placement_before := var_to_bytes(runtime.create_snapshot()) var direct_unavailable: CommandResult = runtime._execute_peeping_room(placement) expect(not direct_unavailable.is_success() and direct_unavailable.details[&"reason"] == &"BUILD_DEFINITION_PENDING_D04", "direct production placement unavailable with precise reason") expect(placement_before == var_to_bytes(runtime.create_snapshot()), "direct placement adds no room, occupancy, cost or ID in whole typed Runtime") var domain_before := var_to_bytes([runtime.world_service.create_snapshot(), runtime.economy_service.create_snapshot(), runtime.peeping_room_service.create_snapshot()]) var ids_before: Dictionary = runtime.id_generator.create_snapshot() var counters_before: Dictionary = ids_before["counters"] var event_counter_before: int = counters_before.get("domain_event", 0) var event_ids_before := {} for event: SimulationDomainEvent in runtime.domain_events.recent_events(): event_ids_before[event.event_id] = true var unavailable: CommandResult = runtime.submit_command(&"peeping_room_place", validation.payload) expect(not unavailable.is_success() and unavailable.details[&"reason"] == &"BUILD_DEFINITION_PENDING_D04", "production placement unavailable with precise reason") expect(domain_before == var_to_bytes([runtime.world_service.create_snapshot(), runtime.economy_service.create_snapshot(), runtime.peeping_room_service.create_snapshot()]), "queued placement adds no room, occupancy or cost") var ids_after: Dictionary = runtime.id_generator.create_snapshot() var counters_after: Dictionary = ids_after["counters"] expect(ids_before["version"] == ids_after["version"], "queued placement preserves ID generator version") for prefix: Variant in counters_before: if prefix != "domain_event": expect(counters_after.has(prefix) and counters_after.get(prefix) == counters_before[prefix], "queued placement consumes no non-event ID or removes prefix: %s" % prefix) for prefix: Variant in counters_after: if prefix != "domain_event": expect(counters_before.has(prefix), "queued placement adds no non-event ID prefix: %s" % prefix) expect(counters_after.has("domain_event") and counters_after["domain_event"] == event_counter_before + 1, "queued placement allocates exactly one normal receipt event ID") var new_events: Array[SimulationDomainEvent] = [] for event: SimulationDomainEvent in runtime.domain_events.recent_events(): if not event_ids_before.has(event.event_id): new_events.append(event) expect(new_events.size() == 1, "queued placement publishes exactly one new receipt event") if new_events.size() == 1: var receipt: SimulationDomainEvent = new_events[0] expect(receipt.event_id == StringName("domain_event.%012d" % (event_counter_before + 1)), "placement receipt uses the next domain event ID") expect(receipt.event_type == &"COMMAND_FAILED", "unavailable placement receipt is COMMAND_FAILED") expect(receipt.causation_command_id == unavailable.command_id, "placement receipt causation matches rejected command") var room := place(f) enable_fixture(f, room) var blocked: CommandResult = runtime.submit_command(&"peeping_room_record_evidence", {&"room_id": room, &"source_event_key": &"fixture.command"}) expect(not blocked.is_success() and blocked.details[&"reason"] == &"RECORDER_ELIGIBILITY_PENDING_D04_D08_P16", "registered evidence command cannot reach ledger") var missing: CommandResult = runtime.submit_command(&"peeping_room_record_evidence", {&"room_id": room}) expect(not missing.is_success() and missing.details[&"reason"] == &"SOURCE_EVENT_KEY_REQUIRED", "public command requires named key") var malformed: CommandResult = runtime.submit_command(&"peeping_room_validate", {&"origin": [0, 1, 1]}) expect(not malformed.is_success() and malformed.details[&"reason"] == &"INVALID_PAYLOAD", "wrong payload type safely rejected") expect(runtime.peeping_room_service.create_snapshot()[&"evidence"].is_empty(), "commands cannot inject arbitrary content events") var fixture_command: CommandResult = runtime.submit_command(&"controlled_fixture_place", validation.payload) expect(not fixture_command.is_success(), "no fixture command registration") _mimi_format(f) finish("Peeping room runtime") func _mimi_format(f: Dictionary) -> void: var runtime: Variant = f[&"runtime"] const Quote := preload("res://scripts/supply/supply_purchase_quote_v2.gd") expect(runtime.submit_command(&"build_facility", {&"definition_id": &"warehouse", &"origin": Vector3i(2, 0, 1)}).is_success(), "paid warehouse for independent existing MIMI format path") f[&"clock"].advance_minutes(runtime.definition_registry.get_facility(&"warehouse").build_minutes) var warehouse: StringName = &"" for facility: FacilityInstance in runtime.facility_service.get_instances(): if facility.definition_id == &"warehouse": warehouse = facility.instance_id expect(not warehouse.is_empty(), "completed real warehouse") var mimi := StaffRuntime.new().configure(Quote.MIMI, &"porter", {&"employment_kind": StaffRuntime.EmploymentKind.UNIQUE}) expect(runtime.staff_service.register_staff(mimi).is_success(), "CONTROLLED_FIXTURE existing MIMI unique registration, no natural join claim") expect(runtime.submit_command(&"set_staff_work_assignment", {&"staff_id": Quote.MIMI, &"facility_id": warehouse, &"template_id": &"NIGHT"}).is_success(), "existing persistent MIMI assignment") expect(runtime.submit_command(&"purchase_supplies", {&"warehouse_id": warehouse, &"item_id": SupplyCatalog.RAW_FOOD, &"quantity": 1}).is_success(), "existing real v2 paid purchase") var snapshot: Dictionary = runtime.create_snapshot() expect(snapshot[&"systems"][&"runtime"][&"runtime_schema_version"] == 15 and snapshot[&"systems"][&"runtime"].has(&"special_peeping_rooms"), "v2 purchase history and special section coexist") expect(runtime.restore_snapshot(snapshot) and var_to_bytes(snapshot) == var_to_bytes(runtime.create_snapshot()), "v15 optional section exact typed restore") var directory := "user://tests/p13_reference_mimi_%d" % OS.get_process_id() expect(SaveService.save_snapshot(directory, snapshot)[&"ok"], "physical v15 save accepts validated extension without loosening purchase allowlist") var loaded := SaveService.load_snapshot(directory) expect(loaded[&"ok"], "physical MIMI section save loads") if loaded[&"ok"]: expect(loaded[&"manifest"]["format_version"] == 2 and loaded[&"manifest"]["runtime_schema_version"] == 15, "format2 manifest still exactly15") expect(runtime.restore_snapshot(loaded[&"snapshot"]), "MIMI package restore reaches same staged section validator") var bad := snapshot.duplicate(true) bad[&"systems"][&"runtime"][&"special_peeping_rooms"][&"version"] = 2 expect(not SaveService.save_snapshot(directory + "_bad", bad)[&"ok"], "save-format adapter rejects malformed optional section")