First structure #3
This commit is contained in:
commit
828534c1f5
15 files changed
+646
No files matched your search
@@ -0,0 +1,104 @@
|
||||
"""Tests for explicit plugin registry loading."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
from mcc.core.plugin_registry import (
|
||||
PluginRegistry,
|
||||
RegistryEntry,
|
||||
)
|
||||
|
||||
|
||||
class FakeProvider:
|
||||
"""Test provider that returns a fixed list of registered entries."""
|
||||
|
||||
def __init__(self, registered_entries: list[RegistryEntry]) -> None:
|
||||
"""Store entries for later retrieval.
|
||||
|
||||
Args:
|
||||
registered_entries: Entries the fake registry should return.
|
||||
"""
|
||||
self._registered_entries = registered_entries
|
||||
|
||||
def entries(self) -> list[RegistryEntry]:
|
||||
"""Return the configured entries."""
|
||||
return self._registered_entries
|
||||
|
||||
|
||||
def write_manifest(path: Path, plugin_id: str) -> None:
|
||||
"""Write a minimal valid test manifest.
|
||||
|
||||
Args:
|
||||
path: Destination file.
|
||||
plugin_id: Stable identifier to write into the manifest.
|
||||
"""
|
||||
path.write_text(
|
||||
json.dumps(
|
||||
{
|
||||
"schema_version": 1,
|
||||
"id": plugin_id,
|
||||
"api_version": "1",
|
||||
"name": "Example",
|
||||
"description": "Test plugin.",
|
||||
"category": "system",
|
||||
"subcategory": "information",
|
||||
"frontends": ["gui", "tui"],
|
||||
"capabilities": ["read-only"],
|
||||
}
|
||||
),
|
||||
encoding="utf-8",
|
||||
)
|
||||
|
||||
|
||||
def test_registry_loads_registered_plugin(tmp_path: Path) -> None:
|
||||
"""A valid explicitly registered plugin should be returned."""
|
||||
plugin_id = "org.mageia.mcc.example"
|
||||
manifest_path = tmp_path / "plugin.json"
|
||||
write_manifest(manifest_path, plugin_id)
|
||||
|
||||
provider = FakeProvider(
|
||||
[RegistryEntry(plugin_id=plugin_id, manifest_path=str(manifest_path))]
|
||||
)
|
||||
|
||||
result = PluginRegistry(provider).load()
|
||||
|
||||
assert len(result.plugins) == 1
|
||||
assert result.plugins[0].plugin_id == plugin_id
|
||||
assert result.errors == ()
|
||||
|
||||
|
||||
def test_registry_reports_missing_manifest(tmp_path: Path) -> None:
|
||||
"""A missing manifest should produce an error without crashing."""
|
||||
provider = FakeProvider(
|
||||
[
|
||||
RegistryEntry(
|
||||
plugin_id="org.mageia.mcc.missing",
|
||||
manifest_path=str(tmp_path / "missing.json"),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
result = PluginRegistry(provider).load()
|
||||
|
||||
assert result.plugins == ()
|
||||
assert len(result.errors) == 1
|
||||
|
||||
|
||||
def test_registry_rejects_id_mismatch(tmp_path: Path) -> None:
|
||||
"""A manifest cannot claim an ID different from its registry entry."""
|
||||
manifest_path = tmp_path / "plugin.json"
|
||||
write_manifest(manifest_path, "org.mageia.mcc.actual")
|
||||
|
||||
provider = FakeProvider(
|
||||
[
|
||||
RegistryEntry(
|
||||
plugin_id="org.mageia.mcc.expected",
|
||||
manifest_path=str(manifest_path),
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
result = PluginRegistry(provider).load()
|
||||
|
||||
assert result.plugins == ()
|
||||
assert "does not match" in result.errors[0].message
|
||||
Reference in new issue
Block a user