"""Envelope tests for breakage command.""" from __future__ import annotations from collections.abc import Mapping import json 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 assert isinstance(d["warnings"], list) class TestBreakageEnvelope: def test_breakage_has_envelope(self) -> None: r = runner.invoke(None, ["code", "breakage", "--json"]) # exit_code may be 1 when breakage issues are found in a dirty working # tree; the envelope must be present regardless. assert r.exit_code in (0, 1), r.output d = json.loads(r.output) _check(d) assert "warning_count" in d