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"):