From a0460192ca6a79bc8a26d5ff989326cf4f619361 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Mon, 26 Oct 2026 10:38:51 -0400 Subject: [PATCH] fix(visualizers): normalize ids in lifecycle mutators like get() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- deeptutor/visualizers/registry.py | 3 +++ tests/visualizers/test_registry_and_tool.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/deeptutor/visualizers/registry.py b/deeptutor/visualizers/registry.py index 72822702d..3dc53fa3d 100644 --- a/deeptutor/visualizers/registry.py +++ b/deeptutor/visualizers/registry.py @@ -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}") diff --git a/tests/visualizers/test_registry_and_tool.py b/tests/visualizers/test_registry_and_tool.py index e34f017ab..fc9d4a69e 100644 --- a/tests/visualizers/test_registry_and_tool.py +++ b/tests/visualizers/test_registry_and_tool.py @@ -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"):