"""Envelope tests for commit-tree 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 TestCommitTreeEnvelope: def test_commit_tree_has_envelope(self) -> None: # Get the HEAD snapshot ID from muse log log_r = runner.invoke(None, ["log", "--json"]) assert log_r.exit_code == 0, log_r.output log_d = json.loads(log_r.output) snapshot_id = log_d["commits"][0]["snapshot_id"] r = runner.invoke(None, ["commit-tree", "--snapshot", snapshot_id, "-m", "test", "--json"]) assert r.exit_code == 0, r.output _check(json.loads(r.output))