"""Envelope tests for ``muse agent-config`` subcommands.""" from __future__ import annotations import json, os, pathlib import pytest from tests.cli_test_helper import CliRunner, InvokeResult runner = CliRunner() type _EnvDict = dict[str, str | int | list[str]] def _invoke(repo: pathlib.Path, args: list[str]) -> InvokeResult: saved = os.getcwd() try: os.chdir(repo) return runner.invoke(None, args) finally: os.chdir(saved) @pytest.fixture() def repo(tmp_path: pathlib.Path) -> pathlib.Path: saved = os.getcwd() try: os.chdir(tmp_path) runner.invoke(None, ["init"]) finally: os.chdir(saved) return tmp_path _CMDS = ["init", "status", "inspect"] class TestAgentConfigEnvelope: def _check(self, r: InvokeResult) -> "_EnvDict": assert r.exit_code == 0, r.output d = json.loads(r.output) for field in ("muse_version", "schema", "timestamp", "warnings"): assert field in d, f"missing {field}" assert "schema_version" not in d return d def test_init_envelope(self, repo: pathlib.Path) -> None: self._check(_invoke(repo, ["agent-config", "init", "-j"])) def test_status_envelope(self, repo: pathlib.Path) -> None: _invoke(repo, ["agent-config", "init"]) self._check(_invoke(repo, ["agent-config", "status", "-j"])) def test_inspect_envelope(self, repo: pathlib.Path) -> None: _invoke(repo, ["agent-config", "init"]) self._check(_invoke(repo, ["agent-config", "inspect", "-j"])) def test_sync_envelope(self, repo: pathlib.Path) -> None: _invoke(repo, ["agent-config", "init"]) _invoke(repo, ["agent-config", "set", "--adapters", "claude"]) self._check(_invoke(repo, ["agent-config", "sync", "-j"])) def test_read_envelope(self, repo: pathlib.Path) -> None: _invoke(repo, ["agent-config", "init"]) self._check(_invoke(repo, ["agent-config", "read", "-j"]))