fix(visualizers): normalize ids in lifecycle mutators like get()

VisualizerRegistry.get() normalizes the id (strip + lower) before the catalog
lookup, but set_enabled/install_bundled/uninstall keyed the catalog with the
raw id and forwarded it to the store. Catalog keys are always lowercase
(VisualizerManifest._valid_id lowercases them), so a valid id in a different
case or with surrounding whitespace — e.g. the raw path param from the
visualizers router — was rejected as not installed/not found, or would have
persisted store state under a key the catalog never matches. Normalize the id
at the top of each mutator, matching get().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Rudy Celekli
2026-10-26 10:38:51 -04:00
co-authored by Claude Opus 4.8
parent a31d82624c
commit a0460192ca
2 changed files with 20 additions and 0 deletions
+3
View File
@@ -80,6 +80,7 @@ class VisualizerRegistry:
]
def set_enabled(self, visualizer_id: str, enabled: bool) -> None:
visualizer_id = str(visualizer_id or "").strip().lower()
plugin = self._catalog.get(visualizer_id)
if plugin is None or plugin.manifest.id not in self._installed:
raise VisualizerStoreError(f"visualizer is not installed: {visualizer_id}")
@@ -87,6 +88,7 @@ class VisualizerRegistry:
self.reload()
def install_bundled(self, visualizer_id: str) -> None:
visualizer_id = str(visualizer_id or "").strip().lower()
plugin = self._catalog.get(visualizer_id)
if plugin is None or plugin.origin != "bundled":
raise VisualizerStoreError(f"bundled visualizer not found: {visualizer_id}")
@@ -94,6 +96,7 @@ class VisualizerRegistry:
self.reload()
def uninstall(self, visualizer_id: str) -> None:
visualizer_id = str(visualizer_id or "").strip().lower()
plugin = self._catalog.get(visualizer_id)
if plugin is None:
raise VisualizerStoreError(f"visualizer not found: {visualizer_id}")
@@ -80,6 +80,23 @@ def test_registry_lifecycle_for_bundled_and_imported_types(tmp_path: Path) -> No
assert registry.get("number_line", require_enabled=False) is None
def test_lifecycle_mutators_accept_mixed_case_ids(tmp_path: Path) -> None:
# ``get`` normalizes the id (strip + lower) but the lifecycle mutators keyed
# the catalog with the raw id, so a valid id in a different case was rejected
# as "not installed"/"not found" even though ``get`` accepts it.
registry = _registry(tmp_path)
registry.install_bundled("GeoGebra")
assert registry.get("geogebra") is not None
registry.set_enabled("GeoGebra", False)
assert registry.get("geogebra") is None
assert registry.get("geogebra", require_enabled=False) is not None
registry.uninstall("GeoGebra")
assert registry.get("geogebra", require_enabled=False) is None
def test_import_rejects_reserved_id_and_path_traversal(tmp_path: Path) -> None:
registry = _registry(tmp_path)
with pytest.raises(VisualizerStoreError, match="reserved"):