test_apply_archive_envelope.py
python
sha256:88ac91129873e6a496e9189515aa690eb893ae25d69c8f72af141a2be5068eb3
docs: docstring sprint contract→find-symbol — idiomatic run…
Sonnet 4.6
patch
139 days ago
| 1 | """Envelope tests for apply, apply_patch, archive.""" |
| 2 | from __future__ import annotations |
| 3 | import json, pathlib |
| 4 | import pytest |
| 5 | from tests.cli_test_helper import CliRunner |
| 6 | runner = CliRunner() |
| 7 | |
| 8 | _FIELDS = ("muse_version", "schema", "timestamp", "warnings") |
| 9 | |
| 10 | def _has_envelope(d: dict) -> None: |
| 11 | for f in _FIELDS: |
| 12 | assert f in d, f"missing {f}" |
| 13 | assert "schema_version" not in d |
| 14 | |
| 15 | class TestApplyEnvelope: |
| 16 | def test_apply_json(self, tmp_path): |
| 17 | fake = tmp_path / "fake.patch" |
| 18 | fake.write_text("# fake patch\n") |
| 19 | r = runner.invoke(None, ["apply", str(fake), "--json"]) |
| 20 | # may fail with user error but must emit JSON |
| 21 | try: |
| 22 | d = json.loads(r.output) |
| 23 | _has_envelope(d) |
| 24 | except (json.JSONDecodeError, AssertionError): |
| 25 | pytest.skip("apply errored before JSON output") |
| 26 | |
| 27 | class TestApplyPatchEnvelope: |
| 28 | def test_check_has_envelope(self): |
| 29 | r = runner.invoke(None, ["apply-patch", "nonexistent.patch", "--check", "--json"]) |
| 30 | try: |
| 31 | d = json.loads(r.output) |
| 32 | _has_envelope(d) |
| 33 | except (json.JSONDecodeError, AssertionError): |
| 34 | pytest.skip("apply-patch errored before JSON output") |
| 35 | |
| 36 | class TestArchiveEnvelope: |
| 37 | def test_list_has_envelope(self): |
| 38 | r = runner.invoke(None, ["archive", "--list", "--json"]) |
| 39 | assert r.exit_code == 0, r.output |
| 40 | d = json.loads(r.output) |
| 41 | _has_envelope(d) |
File History
1 commit
sha256:88ac91129873e6a496e9189515aa690eb893ae25d69c8f72af141a2be5068eb3
docs: docstring sprint contract→find-symbol — idiomatic run…
Sonnet 4.6
patch
139 days ago