gabriel / muse public
test_plugin_registry.py python
87 lines 3.3 KB
Raw
sha256:660fcac1df3ab28f61862e961890bd2ca8b754fa0242079d93ca1e25037ec8a6 chore(tests): add docstring to tests/__init__.py so rc14 tr… Human 26 days ago
1 """Unit tests for muse.plugins.registry — resolve_plugin, read_domain, registered_domains."""
2
3 import json
4 import pathlib
5
6 import pytest
7
8 from muse._version import __version__
9 from muse.core.errors import MuseCLIError
10 from muse.domain import MuseDomainPlugin
11 from muse.plugins.code.plugin import CodePlugin
12 from muse.plugins.registry import read_domain, registered_domains, resolve_plugin
13
14
15 def _make_repo(tmp_path: pathlib.Path, domain: str = "code") -> pathlib.Path:
16 """Scaffold a minimal .muse/repo.json so registry helpers can run."""
17 muse_dir = tmp_path / ".muse"
18 muse_dir.mkdir()
19 (muse_dir / "repo.json").write_text(
20 json.dumps({"repo_id": "test-id", "schema_version": __version__, "domain": domain})
21 )
22 return tmp_path
23
24
25 class TestReadDomain:
26 def test_returns_stored_domain(self, tmp_path: pathlib.Path) -> None:
27 root = _make_repo(tmp_path, domain="code")
28 assert read_domain(root) == "code"
29
30 def test_defaults_to_code_when_key_missing(self, tmp_path: pathlib.Path) -> None:
31 muse_dir = tmp_path / ".muse"
32 muse_dir.mkdir()
33 (muse_dir / "repo.json").write_text(json.dumps({"repo_id": "x"}))
34 assert read_domain(tmp_path) == "code"
35
36 def test_defaults_to_code_when_repo_json_absent(self, tmp_path: pathlib.Path) -> None:
37 (tmp_path / ".muse").mkdir()
38 assert read_domain(tmp_path) == "code"
39
40 def test_defaults_to_code_when_muse_dir_absent(self, tmp_path: pathlib.Path) -> None:
41 assert read_domain(tmp_path) == "code"
42
43
44 class TestResolvePlugin:
45 def test_returns_code_plugin_for_code_domain(self, tmp_path: pathlib.Path) -> None:
46 root = _make_repo(tmp_path, domain="code")
47 plugin = resolve_plugin(root)
48 assert isinstance(plugin, CodePlugin)
49
50 def test_returned_plugin_satisfies_protocol(self, tmp_path: pathlib.Path) -> None:
51 root = _make_repo(tmp_path, domain="code")
52 plugin = resolve_plugin(root)
53 assert isinstance(plugin, MuseDomainPlugin)
54
55 def test_raises_for_unknown_domain(self, tmp_path: pathlib.Path) -> None:
56 root = _make_repo(tmp_path, domain="unknown-domain")
57 with pytest.raises(MuseCLIError, match="unknown-domain"):
58 resolve_plugin(root)
59
60 def test_raises_error_mentions_registered_domains(self, tmp_path: pathlib.Path) -> None:
61 root = _make_repo(tmp_path, domain="bogus")
62 with pytest.raises(MuseCLIError, match="code"):
63 resolve_plugin(root)
64
65 def test_defaults_to_code_plugin_when_no_domain_key(self, tmp_path: pathlib.Path) -> None:
66 muse_dir = tmp_path / ".muse"
67 muse_dir.mkdir()
68 (muse_dir / "repo.json").write_text(json.dumps({"repo_id": "x"}))
69 plugin = resolve_plugin(tmp_path)
70 assert isinstance(plugin, CodePlugin)
71
72
73 class TestRegisteredDomains:
74 def test_includes_code(self) -> None:
75 assert "code" in registered_domains()
76
77 def test_midi_suspended(self) -> None:
78 """MIDI domain is temporarily suspended pending its own security audit."""
79 assert "midi" not in registered_domains()
80
81 def test_returns_sorted_list(self) -> None:
82 domains = registered_domains()
83 assert domains == sorted(domains)
84
85 def test_returns_list_of_strings(self) -> None:
86 domains = registered_domains()
87 assert all(isinstance(d, str) for d in domains)
File History 5 commits
sha256:660fcac1df3ab28f61862e961890bd2ca8b754fa0242079d93ca1e25037ec8a6 chore(tests): add docstring to tests/__init__.py so rc14 tr… Human 26 days ago
sha256:d8316ffae901be06347e16ab55be11868eb519dd16ade3e8aa16a99e662f7e62 baseline: rc14 re-baseline after rc3 store corruption recovery Human patch 26 days ago
sha256:50d413a635f57761c3fce1f70251b957b6423821525bf330747ef4007339222e Merge branch 'dev' into main Human 29 days ago
sha256:fb67fed5a4d3e40de84bdd163de94ef1386570bef1dd1a020a732c8a038962ce Merge branch 'dev' into main Human 48 days ago
sha256:1c4b3e3a9a1f300774c3ee662b572a698d5fd405bf765a71e6011a2e9c3eaaaa feat: Muse — version control for the agent era Human 100 days ago