test_plugin_registry.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 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.paths import muse_dir, repo_json_path |
| 10 | from muse.core.errors import MuseCLIError |
| 11 | from muse.domain import MuseDomainPlugin |
| 12 | from muse.plugins.code.plugin import CodePlugin |
| 13 | from muse.plugins.registry import read_domain, registered_domains, resolve_plugin |
| 14 | |
| 15 | |
| 16 | def _make_repo(tmp_path: pathlib.Path, domain: str = "code") -> pathlib.Path: |
| 17 | """Scaffold a minimal .muse/repo.json so registry helpers can run.""" |
| 18 | dot_muse = muse_dir(tmp_path) |
| 19 | dot_muse.mkdir() |
| 20 | repo_json_path(tmp_path).write_text( |
| 21 | json.dumps({"repo_id": "test-id", "schema_version": __version__, "domain": domain}) |
| 22 | ) |
| 23 | return tmp_path |
| 24 | |
| 25 | |
| 26 | class TestReadDomain: |
| 27 | def test_returns_stored_domain(self, tmp_path: pathlib.Path) -> None: |
| 28 | root = _make_repo(tmp_path, domain="code") |
| 29 | assert read_domain(root) == "code" |
| 30 | |
| 31 | def test_defaults_to_code_when_key_missing(self, tmp_path: pathlib.Path) -> None: |
| 32 | dot_muse = muse_dir(tmp_path) |
| 33 | dot_muse.mkdir() |
| 34 | repo_json_path(tmp_path).write_text(json.dumps({"repo_id": "x"})) |
| 35 | assert read_domain(tmp_path) == "code" |
| 36 | |
| 37 | def test_defaults_to_code_when_repo_json_absent(self, tmp_path: pathlib.Path) -> None: |
| 38 | muse_dir(tmp_path).mkdir() |
| 39 | assert read_domain(tmp_path) == "code" |
| 40 | |
| 41 | def test_defaults_to_code_when_muse_dir_absent(self, tmp_path: pathlib.Path) -> None: |
| 42 | assert read_domain(tmp_path) == "code" |
| 43 | |
| 44 | |
| 45 | class TestResolvePlugin: |
| 46 | def test_returns_code_plugin_for_code_domain(self, tmp_path: pathlib.Path) -> None: |
| 47 | root = _make_repo(tmp_path, domain="code") |
| 48 | plugin = resolve_plugin(root) |
| 49 | assert isinstance(plugin, CodePlugin) |
| 50 | |
| 51 | def test_returned_plugin_satisfies_protocol(self, tmp_path: pathlib.Path) -> None: |
| 52 | root = _make_repo(tmp_path, domain="code") |
| 53 | plugin = resolve_plugin(root) |
| 54 | assert isinstance(plugin, MuseDomainPlugin) |
| 55 | |
| 56 | def test_raises_for_unknown_domain(self, tmp_path: pathlib.Path) -> None: |
| 57 | root = _make_repo(tmp_path, domain="unknown-domain") |
| 58 | with pytest.raises(MuseCLIError, match="unknown-domain"): |
| 59 | resolve_plugin(root) |
| 60 | |
| 61 | def test_raises_error_mentions_registered_domains(self, tmp_path: pathlib.Path) -> None: |
| 62 | root = _make_repo(tmp_path, domain="bogus") |
| 63 | with pytest.raises(MuseCLIError, match="code"): |
| 64 | resolve_plugin(root) |
| 65 | |
| 66 | def test_defaults_to_code_plugin_when_no_domain_key(self, tmp_path: pathlib.Path) -> None: |
| 67 | dot_muse = muse_dir(tmp_path) |
| 68 | dot_muse.mkdir() |
| 69 | repo_json_path(tmp_path).write_text(json.dumps({"repo_id": "x"})) |
| 70 | plugin = resolve_plugin(tmp_path) |
| 71 | assert isinstance(plugin, CodePlugin) |
| 72 | |
| 73 | |
| 74 | class TestRegisteredDomains: |
| 75 | def test_includes_code(self) -> None: |
| 76 | assert "code" in registered_domains() |
| 77 | |
| 78 | def test_midi_suspended(self) -> None: |
| 79 | """MIDI domain is temporarily suspended pending its own security audit.""" |
| 80 | assert "midi" not in registered_domains() |
| 81 | |
| 82 | def test_returns_sorted_list(self) -> None: |
| 83 | domains = registered_domains() |
| 84 | assert domains == sorted(domains) |
| 85 | |
| 86 | def test_returns_list_of_strings(self) -> None: |
| 87 | domains = registered_domains() |
| 88 | assert all(isinstance(d, str) for d in domains) |