from __future__ import annotations import pytest from backend.services.asset_import_service import ( IMPORTABLE_RECOGNITION_STATUSES, _importable_recognition_status, ) @pytest.mark.parametrize("status", sorted(IMPORTABLE_RECOGNITION_STATUSES)) def test_review_pending_states_are_honoured(status: str) -> None: assert _importable_recognition_status(status) == status @pytest.mark.parametrize("status", ["confirmed", "archived"]) def test_pack_cannot_declare_a_review_outcome(status: str) -> None: """A pack manifest is an untrusted document. Declaring ``confirmed`` would land unvetted material straight in the confirmed library, skipping recognition and human review entirely. """ assert _importable_recognition_status(status) == "pending_recognition" @pytest.mark.parametrize("status", [None, "", " ", "nonsense", 42, {"a": 1}]) def test_unknown_or_missing_status_falls_back_to_pending(status: object) -> None: assert _importable_recognition_status(status) == "pending_recognition" def test_overwrite_requires_explicit_opt_in() -> None: """The guard must collect every collision, not fail on the first one.""" from backend.dto.common import ApiError, ErrorCode from backend.services import asset_import_service as module import inspect body = inspect.getsource(module.AssetImportService._apply_manifest) # The conflict set is computed before any write happens. conflict_index = body.index("conflicts = [") write_index = body.index("for material_payload, creating in planned_materials:", conflict_index) assert conflict_index < write_index, "conflicts must be detected before writing" assert "allow_overwrite" in body assert "conflicting_material_ids" in body def test_route_threads_allow_overwrite() -> None: import inspect from backend.routes import asset_routes body = inspect.getsource(asset_routes.import_asset_pack) assert "allow_overwrite" in body, "the route must expose the opt-in" assert "default=False" in body, "overwrite must be opt-in, not opt-out"