extends "res://tests/special/peeping_room_fixture.gd" func _run() -> void: var f := fixture() var runtime: Variant = f[&"runtime"] var empty: Dictionary = runtime.create_snapshot() expect(not empty[&"systems"][&"runtime"].has(&"special_peeping_rooms"), "empty service does not alter existing snapshot keys") expect(runtime.restore_snapshot(empty) and var_to_bytes(empty) == var_to_bytes(runtime.create_snapshot()), "pre-extension v14 absence exact roundtrip") var legacy := empty.duplicate(true) legacy[&"systems"][&"runtime"][&"runtime_schema_version"] = 13 legacy[&"systems"][&"runtime"].erase(&"auto_purchase_plans") expect(runtime.restore_snapshot(legacy) and runtime.peeping_room_service.is_empty(), "genuine v13 absent section migrates empty") expect(runtime.restore_snapshot(empty), "restore canonical baseline before controlled room") var room := place(f) enable_fixture(f, room) expect(runtime.peeping_room_service.controlled_fixture_record_evidence(room, &"fixture.save", f[&"clock"].absolute_minute)[&"ok"], "controlled evidence before mid-state save") expect(runtime.submit_command(&"peeping_room_relink", {&"room_id": room, &"target_instance_id": f[&"target"]}, &"player", room, 0, f[&"clock"].absolute_minute + 1).is_success(), "future explicit relink remains pending at checkpoint") var snapshot: Dictionary = runtime.create_snapshot() expect(snapshot[&"systems"][&"runtime"][&"runtime_schema_version"] == 14, "extension never bumps Runtime version") expect(runtime.restore_snapshot(snapshot) and var_to_bytes(snapshot) == var_to_bytes(runtime.create_snapshot()), "exact typed room/evidence whole Runtime roundtrip") var directory := "user://tests/p13_reference_save_%d" % OS.get_process_id() var saved := SaveService.save_snapshot(directory, snapshot) expect(saved[&"ok"], "actual SaveService writes section in format 1") var loaded := SaveService.load_snapshot(directory) expect(loaded[&"ok"], "actual SaveService reads section") if loaded[&"ok"]: expect(loaded[&"manifest"]["format_version"] == 1, "existing format mapping unchanged") expect(runtime.restore_snapshot(loaded[&"snapshot"]), "loaded physical package reaches Runtime validation") expect(var_to_bytes(snapshot) == var_to_bytes(runtime.create_snapshot()), "physical save retains all typed fields") for mutation in range(18): var bad := snapshot.duplicate(true) var data: Dictionary = bad[&"systems"][&"runtime"] var section: Dictionary = data[&"special_peeping_rooms"] match mutation: 0: data.erase(&"special_peeping_rooms") 1: data[&"special_peeping_rooms"] = null 2: section[&"version"] = 2 3: section[&"version"] = 1.0 4: section[&"unknown"] = true 5: section.erase(&"evidence") 6: section[&"rooms"].append(section[&"rooms"][0].duplicate(true)) 7: section[&"evidence"].append(section[&"evidence"][0].duplicate(true)) 8: section[&"rooms"][0][&"target_instance_id"] = &"missing.target" 9: section[&"rooms"][0][&"target_definition_id"] = &"adult_private_room" 10: section[&"rooms"][0][&"origin"] = Vector3i(8, 1, 1) 11: section[&"rooms"][0][&"stopped"] = 1 12: section[&"evidence"][0][&"room_id"] = &"peeping_room.999999999999" 13: section[&"evidence"][0][&"source_event_key"] = &"aliased.event" 14: section[&"evidence"][0][&"minute"] = f[&"clock"].absolute_minute + 1 15: data[&"id_generator"]["counters"]["peeping_room"] = 0 16: section.erase(&"version") section["version"] = 1 17: section[&"rooms"][0][&"link_state"] = &"TARGET_LOST" section[&"rooms"][0][&"stopped"] = true section[&"rooms"][0][&"stop_reason"] = &"TARGET_LOST" expect(rejects_atomically(runtime, bad), "malformed/current missing/reference/duplicate rejection atomic case %d" % mutation) var orphan := empty.duplicate(true) orphan[&"systems"][&"runtime"][&"world"] = snapshot[&"systems"][&"runtime"][&"world"].duplicate(true) expect(rejects_atomically(runtime, orphan), "world-owned room without any section rejects atomically") var removed_world := snapshot.duplicate(true) removed_world[&"systems"][&"runtime"][&"world"] = empty[&"systems"][&"runtime"][&"world"].duplicate(true) expect(rejects_atomically(runtime, removed_world), "section-owned room without world occupancy rejects atomically") expect(runtime.restore_snapshot(empty) and runtime.peeping_room_service.is_empty(), "absent legacy section clears previous nonempty service on valid load") finish("Peeping room save")