"""Envelope tests for bundle subcommands.""" from __future__ import annotations import json import pathlib import pytest from tests.cli_test_helper import CliRunner runner = CliRunner() _FIELDS = ("muse_version", "schema", "timestamp", "warnings") def _check(d: Mapping[str, object]) -> None: for f in _FIELDS: assert f in d, f"missing {f}" assert "schema_version" not in d class TestBundleEnvelope: def test_create_has_envelope(self, tmp_path: pathlib.Path) -> None: out = tmp_path / "test.bundle" r = runner.invoke(None, ["bundle", "create", str(out), "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) def test_verify_has_envelope(self, tmp_path: pathlib.Path) -> None: out = tmp_path / "test.bundle" runner.invoke(None, ["bundle", "create", str(out)]) r = runner.invoke(None, ["bundle", "verify", str(out), "--json"]) # exit_code may be 1 if bundle has integrity issues (working tree diverged) d = json.loads(r.output) _check(d) def test_inspect_has_envelope(self, tmp_path: pathlib.Path) -> None: out = tmp_path / "test.bundle" runner.invoke(None, ["bundle", "create", str(out)]) r = runner.invoke(None, ["bundle", "inspect", str(out), "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output)) def test_list_heads_has_envelope(self, tmp_path: pathlib.Path) -> None: out = tmp_path / "test.bundle" runner.invoke(None, ["bundle", "create", str(out)]) r = runner.invoke(None, ["bundle", "list-heads", str(out), "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output))