2026-11-15 16:08:57 +01:00
|
|
|
"""Tests for explicit plugin registry loading."""
|
|
|
|
|
|
|
|
|
|
import json
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
from mcc.core.plugin_registry import (
|
|
|
|
|
PluginRegistry,
|
|
|
|
|
RegistryEntry,
|
|
|
|
|
)
|
|
|
|
|
|
2026-11-15 17:06:22 +01:00
|
|
|
from mcc.core.static_plugin_provider import StaticRegistryProvider
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_static_provider_returns_configured_entries() -> None:
|
|
|
|
|
"""The static provider returns only the entries configured in code."""
|
|
|
|
|
entries = (
|
|
|
|
|
RegistryEntry(
|
|
|
|
|
plugin_id="org.mageia.mcc.example",
|
|
|
|
|
manifest_path="/plugins/example-readonly/plugin.json",
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
provider = StaticRegistryProvider(registered_entries=entries)
|
|
|
|
|
|
|
|
|
|
assert provider.entries() == list(entries)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_registry_loads_plugin_from_static_provider(tmp_path: Path) -> None:
|
|
|
|
|
"""The registry can load a manifest supplied by the static provider."""
|
|
|
|
|
plugin_id = "org.mageia.mcc.example"
|
|
|
|
|
manifest_path = tmp_path / "plugin.json"
|
|
|
|
|
write_manifest(manifest_path, plugin_id)
|
|
|
|
|
provider = StaticRegistryProvider(
|
|
|
|
|
registered_entries=(
|
|
|
|
|
RegistryEntry(
|
|
|
|
|
plugin_id=plugin_id,
|
|
|
|
|
manifest_path=str(manifest_path),
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
result = PluginRegistry(provider).load()
|
|
|
|
|
|
|
|
|
|
assert [plugin.plugin_id for plugin in result.plugins] == [plugin_id]
|
|
|
|
|
assert result.errors == ()
|
|
|
|
|
|
2026-11-15 16:08:57 +01:00
|
|
|
|
|
|
|
|
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
|