"""Public command and archive identity validation fails before side effects.""" from types import SimpleNamespace from unittest.mock import Mock import pytest from obliteratus import cli from obliteratus.checkpoint_provenance import ArtifactIdentity, ToolIdentity, build_provenance from obliteratus.run_archive import RunArchive pytestmark = pytest.mark.cpu @pytest.mark.parametrize("argv", [ ["preflight", "distributed", "private-config"], ["run", "private-config", "distributed", "preflight"], ]) def test_misplaced_distributed_preflight_command_never_dispatches(monkeypatch, capsys, argv): dispatch = Mock() monkeypatch.setattr(cli, "_cmd_distributed", dispatch) monkeypatch.setattr(cli, "_cmd_run", dispatch) with pytest.raises(SystemExit) as caught: cli.main(argv) assert caught.value.code == 2 assert "command shape is invalid" in capsys.readouterr().out dispatch.assert_not_called() def test_archive_refuses_mismatched_provenance_attribute_without_mutation(tmp_path): archive = RunArchive(tmp_path) run_id = archive.begin(["org/model"]) directory = archive._run_dir(run_id) before = {path.name: path.read_bytes() for path in directory.iterdir() if path.is_file()} record = build_provenance( sources=(ArtifactIdentity("generated", "boundary-test", "v1", "sha256:" + "a" * 64),), converter=ToolIdentity("test", "1", "c" * 40), obliteratus_commit="c" * 40, configuration_digest=None, tokenizer=None, base_model=None, command=("checkpoint", "attach"), environment={"python": "test", "platform": "cpu", "packages": {}}, source_topology={}, lineage=(), input_digests=("sha256:" + "a" * 64,), output_digests=("sha256:" + "b" * 64,), transformations=(), observed_scopes=("model_weights",), lost_state=(), ) inconsistent = SimpleNamespace(to_json=record.to_json, artifact_id="substituted-identity") with pytest.raises(ValueError, match="checkpoint provenance contract is invalid"): archive.attach_checkpoint_provenance(run_id, inconsistent) assert {path.name: path.read_bytes() for path in directory.iterdir() if path.is_file()} == before