mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-08-06 19:28:06 +00:00
Found by wiping a working device and reinstalling from scratch. Every problem here is invisible until you actually do that, which is why a green test suite and eleven hours of uptime had not surfaced any of them. **Four enabled plugins vanished on restore.** Weather, stocks, music and leaderboard have a registry `id` that differs from the `id` in their own manifest: the registry calls them `weather`, everything else calls them `ledmatrix-weather`. Installation already prefers the manifest id for the directory name and warns when the two disagree, so on disk, in config.json and in a backup they are `ledmatrix-weather` -- but nothing resolved that in reverse. Restore asked the store for `ledmatrix-weather` and got "Plugin not found in registry", four times, and the device came back missing four plugins the user had enabled. Registry lookup now falls back to matching `plugin_path`, which already records `plugins/ledmatrix-weather`. Renaming the published ids would have orphaned `plugin_state.json` entries keyed on the old ones. Exact id still wins, so a path that collides with another entry's id cannot shadow it. Against the live registry and a real 28-plugin install this takes unresolvable directories from five to one -- the one being starlark-apps, which is genuinely not in the registry. **Secrets could not be restored at all.** A fresh install left config_secrets.json group-readable but not group-writable, and the web interface -- which is what performs a restore -- does not necessarily run as the owner. Every other file in the backup restored; secrets failed with EACCES. Now group-writable, so the account running the web UI can put them back. **A partial restore reported "Restore had errors" and nothing else.** That is the same message whether the whole thing failed or it quietly dropped your API keys. It now names what was restored, what failed, and which plugins were not reinstalled. **ytm_auth.json was never in the backup.** It sits in config/ beside the three files that are, and is pure device-local auth: losing it silently signs the user out of YouTube Music. Backed up and restored with the wifi config, which it resembles. **Backups were written inside the directory a reinstall deletes.** config/backups/exports is destroyed by the reinstall the user was told to make it before. Exports now go beside the install, falling back to the old path when that is not writable. **The installer reboots without asking in non-interactive mode**, which the README did not mention -- easy to hit when piping the install, and alarming when a device you are installing onto disappears. Documented, with --no-reboot-prompt. Its log also claimed root:ledmatrix while printing a hardcoded group name rather than the one it used. Tests: registry resolution gets its own suite, including the collision case and third-party entries with an empty plugin_path. The existing round-trip test passed throughout this because its fixture plugin has a directory name equal to its id -- the one shape that cannot fail -- so it now carries ytm_auth too. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Udr6MfaFLUPhX5Fgo67Jf5
108 lines
4.4 KiB
Python
108 lines
4.4 KiB
Python
"""A plugin must be findable in the registry by the id it calls itself.
|
|
|
|
Four shipped plugins have a registry ``id`` that differs from the ``id`` in
|
|
their own ``manifest.json``:
|
|
|
|
directory / manifest.json id registry id
|
|
ledmatrix-weather weather
|
|
ledmatrix-stocks stocks
|
|
ledmatrix-music music
|
|
ledmatrix-leaderboard leaderboard
|
|
|
|
The installer already knows about this: it deliberately names the install
|
|
directory after the *manifest* id (store_manager, "Use manifest ID for
|
|
directory name"), and warns when the two disagree. So on disk, in
|
|
``config.json`` and in a backup manifest, these plugins are called
|
|
``ledmatrix-weather``. Only the registry calls them ``weather``.
|
|
|
|
Nothing resolved that in reverse. Asking the store to install
|
|
``ledmatrix-weather`` -- which is exactly what restoring a backup does --
|
|
failed with "Plugin not found in registry", and four enabled plugins went
|
|
missing from a restored device with no error surfaced to the user.
|
|
|
|
Renaming the registry ids would orphan existing ``plugin_state.json`` entries
|
|
keyed on the old ones, so the lookup resolves ``plugin_path`` instead: the
|
|
registry already records ``plugins/ledmatrix-weather``, which is unambiguous
|
|
and needs no published identity to change.
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
from typing import Any, Dict, List, Optional
|
|
|
|
import pytest
|
|
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
|
|
|
|
from src.plugin_system.store_manager import PluginStoreManager # noqa: E402
|
|
|
|
|
|
# Shaped like the real registry: id and plugin_path basename disagree for the
|
|
# first entry, agree for the second.
|
|
REGISTRY: Dict[str, List[Dict[str, Any]]] = {
|
|
"plugins": [
|
|
{
|
|
"id": "weather",
|
|
"name": "Weather",
|
|
"plugin_path": "plugins/ledmatrix-weather",
|
|
"repo": "https://github.com/ChuckBuilds/ledmatrix-plugins",
|
|
},
|
|
{
|
|
"id": "ledmatrix-flights",
|
|
"name": "Flights",
|
|
"plugin_path": "plugins/ledmatrix-flights",
|
|
"repo": "https://github.com/ChuckBuilds/ledmatrix-plugins",
|
|
},
|
|
{
|
|
"id": "third-party",
|
|
"name": "Third Party",
|
|
"plugin_path": "",
|
|
"repo": "https://github.com/someone/thing",
|
|
},
|
|
]
|
|
}
|
|
|
|
|
|
@pytest.fixture
|
|
def store(monkeypatch: pytest.MonkeyPatch) -> PluginStoreManager:
|
|
manager = PluginStoreManager.__new__(PluginStoreManager)
|
|
monkeypatch.setattr(manager, "fetch_registry", lambda *a, **k: REGISTRY, raising=False)
|
|
return manager
|
|
|
|
|
|
def _ids(entry: Optional[Dict[str, Any]]) -> Optional[str]:
|
|
return entry.get("id") if entry else None
|
|
|
|
|
|
class TestRegistryLookupByManifestId:
|
|
def test_exact_registry_id_still_resolves(self, store: PluginStoreManager) -> None:
|
|
assert _ids(store.get_registry_info("weather")) == "weather"
|
|
|
|
def test_manifest_id_resolves_via_plugin_path(self, store: PluginStoreManager) -> None:
|
|
"""The case that broke restore: asked by the name on disk."""
|
|
assert _ids(store.get_registry_info("ledmatrix-weather")) == "weather", (
|
|
"a plugin installed as 'ledmatrix-weather' could not be found in a "
|
|
"registry that lists it under plugin_path plugins/ledmatrix-weather")
|
|
|
|
def test_matching_id_and_path_unaffected(self, store: PluginStoreManager) -> None:
|
|
assert _ids(store.get_registry_info("ledmatrix-flights")) == "ledmatrix-flights"
|
|
|
|
def test_unknown_plugin_still_returns_none(self, store: PluginStoreManager) -> None:
|
|
assert store.get_registry_info("no-such-plugin") is None
|
|
|
|
def test_empty_plugin_path_is_not_a_wildcard(self, store: PluginStoreManager) -> None:
|
|
"""Third-party entries carry plugin_path "" — that must not match ""."""
|
|
assert store.get_registry_info("") is None
|
|
|
|
def test_exact_id_wins_over_a_path_match(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
"""If some other entry's path collides with a real id, id wins."""
|
|
registry = {
|
|
"plugins": [
|
|
{"id": "decoy", "plugin_path": "plugins/weather"},
|
|
{"id": "weather", "plugin_path": "plugins/ledmatrix-weather"},
|
|
]
|
|
}
|
|
manager = PluginStoreManager.__new__(PluginStoreManager)
|
|
monkeypatch.setattr(manager, "fetch_registry", lambda *a, **k: registry, raising=False)
|
|
assert _ids(manager.get_registry_info("weather")) == "weather"
|