"""Envelope tests for code compare 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 class TestCompareEnvelope: def test_compare_has_envelope(self) -> None: # Get two commit IDs from the log log_r = runner.invoke(None, ["log", "--json"]) assert log_r.exit_code == 0, log_r.output commits = json.loads(log_r.output)["commits"] assert len(commits) >= 2, "Need at least 2 commits to compare" ref_a = commits[-1]["commit_id"] ref_b = commits[0]["commit_id"] r = runner.invoke(None, ["code", "compare", ref_a, ref_b, "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output))