extends "res://tests/ui/test_first_operating_day.gd" var _testing_autosave := false func _finish() -> void: if _failures > 0 or _testing_autosave: super._finish() return _testing_autosave = true var path := "user://tests/selection_autosave_%d/slot" % OS.get_process_id() var queued_path := path + "_queued" SaveService.delete_save(path) SaveService.delete_save(queued_path) var facilities: Array = _runtime.facility_service.get_instances() _expect(facilities.size() >= 2, "real opening provides two selection targets") if facilities.size() < 2: super._finish() return var first_id: StringName = facilities[0].instance_id var second_id: StringName = facilities[1].instance_id _main.call("_on_facility_selected", first_id) _runtime.configure_save_policy({&"enabled": true, &"daily_checkpoint_enabled": true, &"autosave_path": path, &"autosave_generations": 3}) await _advance(3240 - _clock.absolute_minute) var generation := SaveService.load_snapshot(SaveService.get_autosave_path(path, 0)) _expect(generation.get(&"ok", false), "06:00 checkpoint writes an actual autosave package") _expect(generation.get(&"manifest", {}).get("interface_selection", {}).get("id", "") == String(first_id), "daily autosave captures the selected facility") _main.call("_on_facility_selected", second_id) var loaded: Dictionary = _runtime.load_recovery_candidate(path, &"autosave", 0) _expect(loaded.get(&"ok", false), "explicit autosave candidate restores successfully") _expect(_main.get("_selected_entity_id") == first_id, "direct autosave load restores selection through the common notification") _expect(_main.get("world_preview").selected_entity_id == first_id, "direct load restores map highlight") if OS.get_environment("THE_TREE_AUTOSAVE_CAPTURE") != "": for frame: int in 5: await process_frame await RenderingServer.frame_post_draw var screenshot := root.get_texture().get_image() _expect(screenshot != null and screenshot.save_png(OS.get_environment("THE_TREE_AUTOSAVE_CAPTURE")) == OK, "capture actual autosave recovery selection") _expect(_runtime.queue_manual_checkpoint(queued_path).get(&"ok", false), "queue a checkpoint while first target is selected") _main.call("_on_facility_selected", second_id) await _advance(1) var queued := SaveService.load_snapshot(queued_path) _expect(queued.get(&"manifest", {}).get("interface_selection", {}).get("id", "") == String(second_id), "queued checkpoint uses selection at actual save time") _main.call("_on_facility_selected", first_id) _expect(_runtime.load_from_path(queued_path).get(&"ok", false), "direct strict load succeeds") _expect(_main.get("_selected_entity_id") == second_id, "direct strict load restores its own selection") _expect(not _runtime.load_from_path(path + "_missing").get(&"ok", true), "missing direct load fails") _expect(_main.get("_selected_entity_id") == second_id, "failed direct load preserves selection") _runtime.configure_save_policy({&"enabled": false, &"daily_checkpoint_enabled": false}) SaveService.delete_save(path) SaveService.delete_save(queued_path) super._finish()