Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /tests /unit /test_plugin_manager.py
| """ | |
| Unit tests for zen_ai_pentest.plugin_manager. | |
| Comprehensive, fast, isolated tests covering dataclasses, enums, BaseTool, | |
| PluginRegistry and the module-level singleton registry. | |
| """ | |
| import json | |
| import logging | |
| import os | |
| import platform | |
| import sys | |
| import types | |
| from unittest import mock | |
| from unittest.mock import MagicMock, patch | |
| import pytest | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) | |
| from zen_ai_pentest.plugin_manager import ( | |
| BaseTool, | |
| PluginRegistry, | |
| ToolCategory, | |
| ToolMetadata, | |
| ToolResult, | |
| ToolRiskLevel, | |
| get_registry, | |
| ) | |
| # ----------------------------------------------------------------------------- | |
| # Helpers | |
| # ----------------------------------------------------------------------------- | |
| def _minimal_metadata(**overrides) -> ToolMetadata: | |
| defaults = { | |
| "name": "test_tool", | |
| "version": "1.0.0", | |
| "category": ToolCategory.NETWORK_SCANNING, | |
| "description": "A test tool", | |
| "author": "tester", | |
| "risk_level": ToolRiskLevel.LOW, | |
| } | |
| defaults.update(overrides) | |
| return ToolMetadata(**defaults) | |
| class ConcreteTool(BaseTool): | |
| """Concrete BaseTool implementation for unit tests.""" | |
| METADATA = _minimal_metadata(name="concrete_tool") | |
| def validate_input(self, target: str, options: dict) -> bool: | |
| return bool(target) | |
| def build_command(self, target: str, options: dict) -> list: | |
| return ["concrete_tool", target] | |
| def parse_output(self, stdout: str, stderr: str) -> dict: | |
| return {"stdout": stdout, "stderr": stderr} | |
| class AltTool(BaseTool): | |
| """Another concrete implementation with different metadata.""" | |
| METADATA = _minimal_metadata( | |
| name="alt_tool", | |
| category=ToolCategory.WEB_APPLICATION, | |
| risk_level=ToolRiskLevel.HIGH, | |
| tags=["web", "fast"], | |
| ) | |
| def validate_input(self, target: str, options: dict) -> bool: | |
| return True | |
| def build_command(self, target: str, options: dict) -> list: | |
| return ["alt_tool", target] | |
| def parse_output(self, stdout: str, stderr: str) -> dict: | |
| return {"raw": stdout} | |
| def fresh_registry(monkeypatch): | |
| """Provide a fresh PluginRegistry and reset the module singleton.""" | |
| monkeypatch.setattr("zen_ai_pentest.plugin_manager._registry", None) | |
| yield PluginRegistry(plugin_dirs=[]) | |
| # ----------------------------------------------------------------------------- | |
| # Enums | |
| # ----------------------------------------------------------------------------- | |
| class TestToolCategory: | |
| def test_all_values_are_strings(self): | |
| for cat in ToolCategory: | |
| assert isinstance(cat.value, str) | |
| def test_expected_members_exist(self): | |
| assert ToolCategory.NETWORK_SCANNING.value == "network_scanning" | |
| assert ToolCategory.WEB_APPLICATION.value == "web_application" | |
| assert ToolCategory.AI_LLM_SECURITY.value == "ai_llm_security" | |
| class TestToolRiskLevel: | |
| def test_all_values_are_strings(self): | |
| for level in ToolRiskLevel: | |
| assert isinstance(level.value, str) | |
| def test_ordering_values(self): | |
| assert ToolRiskLevel.LOW.value == "low" | |
| assert ToolRiskLevel.CRITICAL.value == "critical" | |
| # ----------------------------------------------------------------------------- | |
| # ToolMetadata | |
| # ----------------------------------------------------------------------------- | |
| class TestToolMetadata: | |
| def test_creation_and_defaults(self): | |
| meta = _minimal_metadata() | |
| assert meta.name == "test_tool" | |
| assert meta.version == "1.0.0" | |
| assert meta.docker_image is None | |
| assert meta.binary_path is None | |
| assert meta.dependencies == [] | |
| assert meta.tags == [] | |
| assert meta.supported_platforms == ["linux"] | |
| assert meta.max_execution_time == 300 | |
| assert meta.max_memory_mb == 1024 | |
| assert meta.max_cpu_percent == 50.0 | |
| assert meta.requires_root is False | |
| assert meta.requires_network is True | |
| assert meta.output_formats == ["json", "text"] | |
| assert isinstance(meta.created_at, str) | |
| assert isinstance(meta.updated_at, str) | |
| def test_to_dict_serializes_enums(self): | |
| meta = _minimal_metadata() | |
| d = meta.to_dict() | |
| assert d["category"] == "network_scanning" | |
| assert d["risk_level"] == "low" | |
| assert d["name"] == meta.name | |
| def test_from_dict_round_trip(self): | |
| meta = _minimal_metadata(tags=["a", "b"], dependencies=["dep1"]) | |
| d = meta.to_dict() | |
| restored = ToolMetadata.from_dict(d) | |
| assert restored.name == meta.name | |
| assert restored.category == meta.category | |
| assert restored.risk_level == meta.risk_level | |
| assert restored.tags == meta.tags | |
| assert restored.dependencies == meta.dependencies | |
| def test_from_dict_uses_defaults_for_missing_optional_keys(self): | |
| payload = { | |
| "name": "sparse", | |
| "version": "0.1.0", | |
| "category": "utility", | |
| "description": "minimal", | |
| "author": "me", | |
| "risk_level": "medium", | |
| } | |
| meta = ToolMetadata.from_dict(payload) | |
| assert meta.dependencies == [] | |
| assert meta.tags == [] | |
| assert meta.supported_platforms == ["linux"] | |
| assert meta.max_execution_time == 300 | |
| assert meta.output_formats == ["json", "text"] | |
| # ----------------------------------------------------------------------------- | |
| # ToolResult | |
| # ----------------------------------------------------------------------------- | |
| class TestToolResult: | |
| def test_creation_and_defaults(self): | |
| result = ToolResult( | |
| tool_name="nmap", | |
| success=True, | |
| return_code=0, | |
| stdout="out", | |
| stderr="err", | |
| execution_time=1.23, | |
| ) | |
| assert result.output_files == [] | |
| assert result.parsed_output == {} | |
| assert result.findings == [] | |
| assert result.error_message is None | |
| assert isinstance(result.timestamp, str) | |
| def test_to_dict(self): | |
| result = ToolResult( | |
| tool_name="nmap", | |
| success=True, | |
| return_code=0, | |
| stdout="out", | |
| stderr="err", | |
| execution_time=1.23, | |
| findings=[{"port": 80}], | |
| ) | |
| d = result.to_dict() | |
| assert d["tool_name"] == "nmap" | |
| assert d["findings"] == [{"port": 80}] | |
| assert "timestamp" in d | |
| def test_from_dict_behavior_via_unpacking(self): | |
| # ToolResult does not expose from_dict; verify dictionary unpacking works. | |
| payload = { | |
| "tool_name": "nmap", | |
| "success": False, | |
| "return_code": 1, | |
| "stdout": "", | |
| "stderr": "fail", | |
| "execution_time": 0.5, | |
| "parsed_output": {"key": "value"}, | |
| } | |
| result = ToolResult(**payload) | |
| assert result.success is False | |
| assert result.parsed_output == {"key": "value"} | |
| # ----------------------------------------------------------------------------- | |
| # BaseTool | |
| # ----------------------------------------------------------------------------- | |
| class TestBaseTool: | |
| def test_cannot_instantiate_abstract_class(self): | |
| meta = _minimal_metadata() | |
| with pytest.raises(TypeError): | |
| BaseTool(meta) | |
| def test_concrete_subclass_init(self): | |
| meta = _minimal_metadata() | |
| tool = ConcreteTool(meta) | |
| assert tool.metadata == meta | |
| assert tool.logger.name == f"tool.{meta.name}" | |
| assert tool._execution_history == [] | |
| assert tool._performance_metrics["total_executions"] == 0 | |
| def test_pre_execute_logs_info(self, caplog): | |
| caplog.set_level(logging.INFO) | |
| tool = ConcreteTool(_minimal_metadata()) | |
| tool.pre_execute("target", {}) | |
| assert "Pre-execution hook" in caplog.text | |
| def test_post_execute_returns_result(self, caplog): | |
| caplog.set_level(logging.INFO) | |
| tool = ConcreteTool(_minimal_metadata()) | |
| result = ToolResult(tool_name="t", success=True, return_code=0, stdout="", stderr="", execution_time=0.1) | |
| returned = tool.post_execute(result) | |
| assert returned is result | |
| assert "Post-execution hook" in caplog.text | |
| def test_get_performance_score_default(self): | |
| tool = ConcreteTool(_minimal_metadata()) | |
| assert tool.get_performance_score() == 0.5 | |
| def test_update_metrics_calculates_success_rate_and_average_time(self): | |
| tool = ConcreteTool(_minimal_metadata()) | |
| tool.update_metrics(ToolResult(tool_name="t", success=True, return_code=0, stdout="", stderr="", execution_time=2.0)) | |
| tool.update_metrics(ToolResult(tool_name="t", success=False, return_code=1, stdout="", stderr="", execution_time=4.0)) | |
| assert tool._performance_metrics["total_executions"] == 2 | |
| assert tool._performance_metrics["successful_executions"] == 1 | |
| assert tool._performance_metrics["failed_executions"] == 1 | |
| assert tool._performance_metrics["average_execution_time"] == 3.0 | |
| assert tool.get_performance_score() == 0.5 | |
| def test_to_dict(self): | |
| meta = _minimal_metadata() | |
| tool = ConcreteTool(meta) | |
| d = tool.to_dict() | |
| assert d["metadata"] == meta.to_dict() | |
| assert d["performance_metrics"]["total_executions"] == 0 | |
| assert d["execution_history_count"] == 0 | |
| # ----------------------------------------------------------------------------- | |
| # PluginRegistry | |
| # ----------------------------------------------------------------------------- | |
| class TestPluginRegistryRegister: | |
| def test_register_valid_metadata(self, fresh_registry): | |
| registry = fresh_registry | |
| ok = registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| assert ok is True | |
| assert "concrete_tool" in registry.get_all() | |
| assert registry.get("concrete_tool").metadata.name == "concrete_tool" | |
| def test_register_missing_metadata_on_class(self, fresh_registry): | |
| class NoMeta(BaseTool): | |
| def validate_input(self, target, options): | |
| return True | |
| def build_command(self, target, options): | |
| return [] | |
| def parse_output(self, stdout, stderr): | |
| return {} | |
| registry = fresh_registry | |
| ok = registry.register("no_meta", NoMeta) | |
| assert ok is False | |
| def test_register_missing_metadata_argument(self, fresh_registry): | |
| registry = fresh_registry | |
| ok = registry.register("no_meta_arg", ConcreteTool, metadata=None) | |
| # ConcreteTool has METADATA, so class attribute is used. | |
| assert ok is True | |
| def test_register_pre_register_hook_blocks(self, fresh_registry): | |
| registry = fresh_registry | |
| registry.add_hook("pre_register", lambda name, cls, meta: False) | |
| ok = registry.register("blocked", ConcreteTool, ConcreteTool.METADATA) | |
| assert ok is False | |
| assert registry.get("blocked") is None | |
| def test_register_pre_register_hook_allows(self, fresh_registry): | |
| registry = fresh_registry | |
| calls = [] | |
| registry.add_hook("pre_register", lambda name, cls, meta: calls.append(name) or True) | |
| ok = registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| assert ok is True | |
| assert calls == ["concrete_tool"] | |
| assert registry.get("concrete_tool") is not None | |
| def test_register_version_incompatibility(self, fresh_registry): | |
| registry = fresh_registry | |
| registry._version_compatibility["test_tool"] = ["2.0.0"] | |
| meta = _minimal_metadata(name="test_tool", version="1.0.0") | |
| class VTool(BaseTool): | |
| METADATA = meta | |
| def validate_input(self, target, options): | |
| return True | |
| def build_command(self, target, options): | |
| return [] | |
| def parse_output(self, stdout, stderr): | |
| return {} | |
| ok = registry.register("test_tool", VTool, meta) | |
| assert ok is False | |
| def test_post_register_hook_runs_on_success(self, fresh_registry): | |
| registry = fresh_registry | |
| calls = [] | |
| registry.add_hook("post_register", lambda name, instance: calls.append(name)) | |
| registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| assert calls == ["concrete_tool"] | |
| def test_on_error_hook_called_when_register_raises(self, fresh_registry): | |
| registry = fresh_registry | |
| errors = [] | |
| registry.add_hook("on_error", lambda name, exc: errors.append((name, exc))) | |
| class BadTool(BaseTool): | |
| METADATA = _minimal_metadata(name="bad") | |
| def __init__(self, metadata): | |
| raise RuntimeError("boom") | |
| def validate_input(self, target, options): | |
| return True | |
| def build_command(self, target, options): | |
| return [] | |
| def parse_output(self, stdout, stderr): | |
| return {} | |
| ok = registry.register("bad", BadTool, BadTool.METADATA) | |
| assert ok is False | |
| assert any(name == "bad" and str(exc) == "boom" for name, exc in errors) | |
| class TestPluginRegistryAccessors: | |
| def populated(self, fresh_registry): | |
| registry = fresh_registry | |
| registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| registry.register("alt_tool", AltTool, AltTool.METADATA) | |
| return registry | |
| def test_get_returns_none_for_unknown(self, populated): | |
| assert populated.get("missing") is None | |
| def test_get_all_returns_copy(self, populated): | |
| all_plugins = populated.get_all() | |
| all_plugins.pop("concrete_tool") | |
| assert populated.get("concrete_tool") is not None | |
| def test_get_by_category(self, populated): | |
| network = populated.get_by_category(ToolCategory.NETWORK_SCANNING) | |
| web = populated.get_by_category(ToolCategory.WEB_APPLICATION) | |
| assert set(network.keys()) == {"concrete_tool"} | |
| assert set(web.keys()) == {"alt_tool"} | |
| def test_get_by_tag(self, populated): | |
| web = populated.get_by_tag("web") | |
| fast = populated.get_by_tag("fast") | |
| missing = populated.get_by_tag("missing") | |
| assert set(web.keys()) == {"alt_tool"} | |
| assert set(fast.keys()) == {"alt_tool"} | |
| assert missing == {} | |
| def test_get_by_risk_level(self, populated): | |
| low_and_below = populated.get_by_risk_level(ToolRiskLevel.LOW) | |
| high_and_below = populated.get_by_risk_level(ToolRiskLevel.HIGH) | |
| assert set(low_and_below.keys()) == {"concrete_tool"} | |
| assert set(high_and_below.keys()) == {"concrete_tool", "alt_tool"} | |
| class TestPluginRegistryLifecycle: | |
| def test_unregister_existing(self, fresh_registry): | |
| registry = fresh_registry | |
| registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| assert registry.unregister("concrete_tool") is True | |
| assert registry.get("concrete_tool") is None | |
| def test_unregister_missing(self, fresh_registry): | |
| registry = fresh_registry | |
| assert registry.unregister("missing") is False | |
| class TestPluginRegistryFilesystem: | |
| def test_discover_plugins_with_mock_filesystem(self, tmp_path, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| registry._plugin_dirs = [str(tmp_path)] | |
| plugin_dir = tmp_path / "network" | |
| plugin_dir.mkdir() | |
| (plugin_dir / "nmap_plugin.py").write_text("# fake") | |
| (plugin_dir / "ignore.txt").write_text("skip") | |
| (tmp_path / "generic_plugin.py").write_text("# fake") | |
| loaded = [] | |
| def fake_load(path): | |
| loaded.append(path) | |
| monkeypatch.setattr(registry, "_load_plugin_file", fake_load) | |
| discovered = registry.discover_plugins() | |
| assert len(discovered) == 2 | |
| assert all(p.endswith("_plugin.py") for p in discovered) | |
| assert sorted(loaded) == sorted(discovered) | |
| def test_discover_plugins_missing_directory(self, fresh_registry): | |
| registry = fresh_registry | |
| registry._plugin_dirs = ["/nonexistent/path/for/plugins"] | |
| discovered = registry.discover_plugins() | |
| assert discovered == [] | |
| def test_discover_plugins_handles_load_error(self, tmp_path, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| registry._plugin_dirs = [str(tmp_path)] | |
| (tmp_path / "bad_plugin.py").write_text("# fake") | |
| def fake_load(path): | |
| raise RuntimeError("load failure") | |
| monkeypatch.setattr(registry, "_load_plugin_file", fake_load) | |
| discovered = registry.discover_plugins() | |
| assert discovered == [] | |
| class TestPluginRegistryLoadPluginFile: | |
| def test_load_plugin_file_mock_importlib(self, tmp_path, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| plugin_file = tmp_path / "sample_plugin.py" | |
| plugin_file.write_text("# not executed") | |
| meta = _minimal_metadata(name="dynamic_sample") | |
| class DynamicSample(BaseTool): | |
| METADATA = meta | |
| def validate_input(self, target, options): | |
| return True | |
| def build_command(self, target, options): | |
| return [] | |
| def parse_output(self, stdout, stderr): | |
| return {} | |
| fake_module = types.ModuleType("fake_module") | |
| fake_module.DynamicSample = DynamicSample | |
| fake_spec = MagicMock() | |
| fake_spec.loader = MagicMock() | |
| fake_module_ref = fake_module | |
| def fake_module_from_spec(spec): | |
| return fake_module_ref | |
| with ( | |
| patch("zen_ai_pentest.plugin_manager.importlib.util.spec_from_file_location") as mock_spec, | |
| patch("zen_ai_pentest.plugin_manager.importlib.util.module_from_spec", side_effect=fake_module_from_spec), | |
| ): | |
| mock_spec.return_value = fake_spec | |
| registry._load_plugin_file(str(plugin_file)) | |
| assert registry.get("dynamic_sample") is not None | |
| class TestPluginRegistryCompatibility: | |
| def test_check_compatibility_platform_match(self, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| meta = _minimal_metadata(supported_platforms=["linux", "windows"]) | |
| assert registry._check_compatibility(meta) is True | |
| def test_check_compatibility_platform_mismatch(self, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| meta = _minimal_metadata(supported_platforms=["windows"]) | |
| assert registry._check_compatibility(meta) is False | |
| def test_check_compatibility_version_match(self, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| registry._version_compatibility["allowed_tool"] = ["1.0.0", "1.1.0"] | |
| meta = _minimal_metadata(name="allowed_tool", version="1.1.0") | |
| assert registry._check_compatibility(meta) is True | |
| def test_check_compatibility_version_mismatch(self, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| registry._version_compatibility["allowed_tool"] = ["2.0.0"] | |
| meta = _minimal_metadata(name="allowed_tool", version="1.0.0") | |
| assert registry._check_compatibility(meta) is False | |
| class TestPluginRegistryHooks: | |
| def test_add_hook_unknown_event_is_ignored(self, fresh_registry): | |
| registry = fresh_registry | |
| registry.add_hook("unknown_event", lambda: None) | |
| assert "unknown_event" not in registry._hooks | |
| def test_add_and_remove_hook(self, fresh_registry): | |
| registry = fresh_registry | |
| def callback(name, cls, meta): | |
| return True | |
| registry.add_hook("pre_register", callback) | |
| assert callback in registry._hooks["pre_register"] | |
| registry.remove_hook("pre_register", callback) | |
| assert callback not in registry._hooks["pre_register"] | |
| def test_remove_hook_unknown_event_is_ignored(self, fresh_registry): | |
| registry = fresh_registry | |
| registry.remove_hook("unknown_event", lambda: None) # should not raise | |
| class TestPluginRegistryCatalog: | |
| def test_export_catalog(self, tmp_path, fresh_registry): | |
| registry = fresh_registry | |
| registry.register("concrete_tool", ConcreteTool, ConcreteTool.METADATA) | |
| out = tmp_path / "catalog.json" | |
| registry.export_catalog(str(out)) | |
| data = json.loads(out.read_text()) | |
| assert data["total_count"] == 1 | |
| assert "network_scanning" in data["categories"] | |
| assert data["tools"][0]["metadata"]["name"] == "concrete_tool" | |
| def test_import_catalog(self, tmp_path, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| catalog = { | |
| "tools": [ | |
| { | |
| "metadata": { | |
| "name": "imported_tool", | |
| "version": "1.0.0", | |
| "category": "utility", | |
| "description": "imported", | |
| "author": "importer", | |
| "risk_level": "low", | |
| "supported_platforms": ["linux"], | |
| "binary_path": "/bin/imported", | |
| } | |
| } | |
| ] | |
| } | |
| catalog_path = tmp_path / "catalog.json" | |
| catalog_path.write_text(json.dumps(catalog)) | |
| count = registry.import_catalog(str(catalog_path)) | |
| assert count == 1 | |
| tool = registry.get("imported_tool") | |
| assert tool is not None | |
| assert tool.metadata.category == ToolCategory.UTILITY | |
| def test_import_catalog_skips_invalid_entries(self, tmp_path, fresh_registry, monkeypatch, caplog): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| catalog = { | |
| "tools": [ | |
| {"metadata": {"name": "bad", "category": "not_a_real_category"}}, | |
| { | |
| "metadata": { | |
| "name": "good", | |
| "version": "1.0.0", | |
| "category": "utility", | |
| "description": "ok", | |
| "author": "ok", | |
| "risk_level": "low", | |
| } | |
| }, | |
| ] | |
| } | |
| catalog_path = tmp_path / "catalog.json" | |
| catalog_path.write_text(json.dumps(catalog)) | |
| count = registry.import_catalog(str(catalog_path)) | |
| assert count == 1 | |
| assert registry.get("good") is not None | |
| def test_import_catalog_partial_registration(self, tmp_path, fresh_registry, monkeypatch): | |
| registry = fresh_registry | |
| monkeypatch.setattr("platform.system", lambda: "Linux") | |
| catalog = { | |
| "tools": [ | |
| { | |
| "metadata": { | |
| "name": "compatible", | |
| "version": "1.0.0", | |
| "category": "utility", | |
| "description": "ok", | |
| "author": "ok", | |
| "risk_level": "low", | |
| "supported_platforms": ["linux"], | |
| } | |
| }, | |
| { | |
| "metadata": { | |
| "name": "incompatible", | |
| "version": "1.0.0", | |
| "category": "utility", | |
| "description": "bad", | |
| "author": "ok", | |
| "risk_level": "low", | |
| "supported_platforms": ["windows"], | |
| } | |
| }, | |
| ] | |
| } | |
| catalog_path = tmp_path / "catalog.json" | |
| catalog_path.write_text(json.dumps(catalog)) | |
| count = registry.import_catalog(str(catalog_path)) | |
| assert count == 1 | |
| assert registry.get("compatible") is not None | |
| assert registry.get("incompatible") is None | |
| class TestPluginRegistryCreateToolClass: | |
| def test_create_tool_class_basic(self, fresh_registry): | |
| registry = fresh_registry | |
| meta = _minimal_metadata(name="dynamic", binary_path="/usr/bin/dynamic") | |
| cls = registry._create_tool_class(meta) | |
| assert issubclass(cls, BaseTool) | |
| instance = cls(meta) | |
| assert instance.validate_input("target", {"opt": 1}) is True | |
| assert instance.build_command("target", {"opt": 1}) == ["/usr/bin/dynamic", "target", "--opt", "1"] | |
| assert instance.parse_output("out", "err") == {"raw_output": "out"} | |
| def test_create_tool_class_uses_name_when_no_binary(self, fresh_registry): | |
| registry = fresh_registry | |
| meta = _minimal_metadata(name="dynamic") | |
| cls = registry._create_tool_class(meta) | |
| instance = cls(meta) | |
| assert instance.build_command("target", {}) == ["dynamic", "target"] | |
| # ----------------------------------------------------------------------------- | |
| # Singleton | |
| # ----------------------------------------------------------------------------- | |
| class TestGetRegistry: | |
| def test_singleton_behavior(self, monkeypatch): | |
| monkeypatch.setattr("zen_ai_pentest.plugin_manager._registry", None) | |
| r1 = get_registry() | |
| r2 = get_registry() | |
| assert r1 is r2 | |
| assert isinstance(r1, PluginRegistry) | |
| def test_singleton_returns_existing_instance(self, monkeypatch): | |
| fake = PluginRegistry(plugin_dirs=[]) | |
| monkeypatch.setattr("zen_ai_pentest.plugin_manager._registry", fake) | |
| assert get_registry() is fake | |
Xet Storage Details
- Size:
- 25.9 kB
- Xet hash:
- 42b030dfc0baa51451f4b5b958a9e531a8be7ff8e2649d98e902af4473ac2a93
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.