gabriel / muse public
test_agent_config_envelope.py python
58 lines 1.9 KB
Raw
1 """Envelope tests for ``muse agent-config`` subcommands."""
2 from __future__ import annotations
3 import json, os, pathlib
4 import pytest
5 from tests.cli_test_helper import CliRunner, InvokeResult
6
7 runner = CliRunner()
8
9 type _EnvDict = dict[str, str | int | list[str]]
10
11 def _invoke(repo: pathlib.Path, args: list[str]) -> InvokeResult:
12 saved = os.getcwd()
13 try:
14 os.chdir(repo)
15 return runner.invoke(None, args)
16 finally:
17 os.chdir(saved)
18
19 @pytest.fixture()
20 def repo(tmp_path: pathlib.Path) -> pathlib.Path:
21 saved = os.getcwd()
22 try:
23 os.chdir(tmp_path)
24 runner.invoke(None, ["init"])
25 finally:
26 os.chdir(saved)
27 return tmp_path
28
29 _CMDS = ["init", "status", "inspect"]
30
31 class TestAgentConfigEnvelope:
32 def _check(self, r: InvokeResult) -> "_EnvDict":
33 assert r.exit_code == 0, r.output
34 d = json.loads(r.output)
35 for field in ("muse_version", "schema", "timestamp", "warnings"):
36 assert field in d, f"missing {field}"
37 assert "schema_version" not in d
38 return d
39
40 def test_init_envelope(self, repo: pathlib.Path) -> None:
41 self._check(_invoke(repo, ["agent-config", "init", "-j"]))
42
43 def test_status_envelope(self, repo: pathlib.Path) -> None:
44 _invoke(repo, ["agent-config", "init"])
45 self._check(_invoke(repo, ["agent-config", "status", "-j"]))
46
47 def test_inspect_envelope(self, repo: pathlib.Path) -> None:
48 _invoke(repo, ["agent-config", "init"])
49 self._check(_invoke(repo, ["agent-config", "inspect", "-j"]))
50
51 def test_sync_envelope(self, repo: pathlib.Path) -> None:
52 _invoke(repo, ["agent-config", "init"])
53 _invoke(repo, ["agent-config", "set", "--adapters", "claude"])
54 self._check(_invoke(repo, ["agent-config", "sync", "-j"]))
55
56 def test_read_envelope(self, repo: pathlib.Path) -> None:
57 _invoke(repo, ["agent-config", "init"])
58 self._check(_invoke(repo, ["agent-config", "read", "-j"]))
File History 1 commit