extends SceneTree var checks:=0 var failures:=0 var runtime: Variant var clock: Variant var state: Variant func expect(ok: bool, message: String) -> void: checks+=1 if not ok: failures+=1;push_error(message) func _initialize() -> void: call_deferred("run") func build(id: StringName, origin: Vector3i) -> bool: var result: CommandResult=runtime.submit_command(&"build_facility",{&"definition_id":id,&"origin":origin}) expect(result.is_success(),"legacy batch build %s" % id) if not result.is_success(): return false clock.advance_minutes(runtime.definition_registry.get_facility(id).build_minutes) return true func run() -> void: runtime=load("res://autoload/simulation_runtime.gd").new();clock=load("res://autoload/game_clock.gd").new();state=load("res://autoload/game_state.gd").new() clock.reset(1,6,0);state.reset();runtime.initialize(clock,state,42506);clock.set_paused(true) var paths: Array[String]=FacilityCatalog.FACILITY_PATHS+FacilityCatalog.INFRASTRUCTURE_FACILITY_PATHS+FacilityCatalog.RESCUE_FACILITY_PATHS paths.append_array(["res://tests/fixtures/legacy_premium_room.tres","res://tests/fixtures/legacy_staff_dormitory.tres"]) expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"load both legacy definitions") if not build(&"reception",Vector3i(-6,0,0)) or not build(&"premium_room",Vector3i(-6,2,0)) or not build(&"warehouse",Vector3i(-6,0,1)) or not build(&"staff_dormitory",Vector3i(-6,2,1)): finish();return if not build(&"service_stairs",Vector3i(-7,1,1)) or not build(&"service_stairs",Vector3i(-7,2,1)) or not build(&"service_stairs",Vector3i(-7,3,1)): finish();return paths.erase("res://tests/fixtures/legacy_premium_room.tres");paths.erase("res://tests/fixtures/legacy_staff_dormitory.tres");paths.append_array(FacilityCatalog.ORIGINAL_FACILITY_PATHS) expect(runtime.definition_registry.rebuild_from_paths(paths)[&"valid"],"switch batch to current definitions") var before: Dictionary=runtime.create_snapshot() var path: String="user://saves/dimension_batch_%d" % Time.get_ticks_usec() expect(SaveService.save_snapshot(path,before)[&"ok"],"persist original two-facility source") var migrated: Dictionary=runtime.migrate_facility_dimensions_at_path(path) expect(migrated[&"ok"],"batch disk migration accepts both facilities") var backup:=SaveService.load_snapshot(path+SaveService.MIGRATION_BACKUP_SUFFIX) expect(backup[&"ok"] and backup[&"snapshot"]==before,"one backup contains both original footprints") expect(runtime.create_snapshot()==before,"batch disk migration preserves live world") var loaded:=SaveService.load_snapshot(path) expect(loaded[&"ok"] and runtime.restore_snapshot(loaded[&"snapshot"]),"batch result restores all crosslinks") for room: FacilityInstance in runtime.facility_service.get_instances(): if room.definition_id==&"premium_room": expect(room.occupied_cells.size()==4,"batch premium footprint is four cells") if room.definition_id==&"staff_dormitory": expect(room.occupied_cells.size()==2,"batch dormitory footprint is two cells") var repeated: Dictionary=runtime.migrate_facility_dimensions_at_path(path) expect(repeated[&"ok"] and not repeated.get(&"backup_created",true) and SaveService.load_snapshot(path+SaveService.MIGRATION_BACKUP_SUFFIX)[&"snapshot"]==before,"repeat batch preserves first backup") expect(runtime.restore_snapshot(before),"restore source to test late batch failure") var dorm_id: StringName=&"" for room: FacilityInstance in runtime.facility_service.get_instances(): if room.definition_id==&"staff_dormitory": dorm_id=room.instance_id expect(runtime.staff_service.create_task(&"maintenance",10,clock.absolute_minute,{&"target_entity_id":dorm_id,&"target_cell":Vector3i(-7,3,1)},&"batch_blocker").is_success(),"create valid task at disappearing second-facility entrance") var rejected_source: Dictionary=runtime.create_snapshot() expect(runtime.restore_snapshot(rejected_source) and SaveService.save_snapshot(path,rejected_source)[&"ok"],"late-failure source is valid and saved") var rejected: Dictionary=runtime.migrate_facility_dimensions_at_path(path) expect(not rejected[&"ok"] and rejected.get(&"details",{}).get(&"facility_id",&"")==dorm_id and rejected[&"details"].get(&"rolled_back",false),"second facility failure rolls back isolated first-facility conversion") expect(SaveService.load_snapshot(path)[&"snapshot"]==rejected_source and runtime.create_snapshot()==rejected_source,"late rejection preserves entire disk source and live state") expect(SaveService.load_snapshot(path+SaveService.MIGRATION_BACKUP_SUFFIX)[&"snapshot"]==before,"late rejected batch leaves prior backup intact") SaveService.delete_save(path);SaveService.delete_save(path+SaveService.MIGRATION_BACKUP_SUFFIX) finish() func finish() -> void: runtime.free();clock.free();state.free();print("Dimension batch save: %d checks, %d failures" % [checks,failures]);quit(failures)