from __future__ import annotations from dataclasses import replace from pathlib import Path import runpy import pytest ROOT = Path(__file__).resolve().parents[2] def test_recovery_constraint_survives_failed_inventory_retry(tmp_path: Path) -> None: helpers = runpy.run_path(str(ROOT / "tests" / "part_replace" / "test_controller.py")) controller, markers, certification_path = helpers["_create_controller"](tmp_path) project_id = controller.projects[0].project_id inventory, _ = helpers["_ingest"](controller, tmp_path, project_id, markers[0]) helpers["_certify"](certification_path, inventory) helpers["_ready_for_apply"](controller, project_id, inventory) command = controller.prepare_apply(project_id, 0) helpers["_publish_bridge_snapshot"]( controller, command, "applied", helpers["_snapshot"](project_id, markers[0], "WRONG-1", "unsafe", symbol="LIB:NEW"), ) assert not controller.verify_apply(project_id, 0).passed undo = controller.prepare_undo(project_id) helpers["_publish_bridge_snapshot"]( controller, undo, "undo_verified", inventory, status_command=command ) controller.confirm_undo(project_id) controller.reconcile(project_id) command = controller.prepare_inventory(project_id) wrong_inventory = replace(inventory, components=()) helpers["_publish_bridge_snapshot"](controller, command, "inventory_exported", wrong_inventory) with pytest.raises(helpers["ControllerError"], match="recovery_snapshot_mismatch"): controller.ingest_inventory(project_id) controller = helpers["BatchController"].open(controller.root) step = controller.operator_step() helpers["_publish_bridge_snapshot"](controller, step.command, "inventory_exported", wrong_inventory) step = controller.operator_step() assert not step.complete, "previously rejected inventory became verified_saved after Continue"