|
| 1 | +"""Tests for repo contrib package discovery wiring.""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +import importlib.util |
| 6 | +import sys |
| 7 | +from pathlib import Path |
| 8 | +from types import ModuleType |
| 9 | + |
| 10 | +REPO_ROOT = Path(__file__).resolve().parents[3] |
| 11 | +SCRIPT_PATH = REPO_ROOT / "scripts" / "contrib_packages.py" |
| 12 | +MODULE_NAME = "agent_control_repo_contrib_packages" |
| 13 | + |
| 14 | + |
| 15 | +def load_contrib_packages_module() -> ModuleType: |
| 16 | + """Load the repo contrib-packages script as a module for testing.""" |
| 17 | + |
| 18 | + module = sys.modules.get(MODULE_NAME) |
| 19 | + if module is not None: |
| 20 | + return module |
| 21 | + |
| 22 | + spec = importlib.util.spec_from_file_location(MODULE_NAME, SCRIPT_PATH) |
| 23 | + assert spec is not None |
| 24 | + assert spec.loader is not None |
| 25 | + |
| 26 | + module = importlib.util.module_from_spec(spec) |
| 27 | + sys.modules[MODULE_NAME] = module |
| 28 | + spec.loader.exec_module(module) |
| 29 | + return module |
| 30 | + |
| 31 | + |
| 32 | +def test_discover_contrib_packages_returns_expected_metadata() -> None: |
| 33 | + """Test that real contrib packages are discovered with stable metadata.""" |
| 34 | + |
| 35 | + module = load_contrib_packages_module() |
| 36 | + |
| 37 | + packages = module.discover_contrib_packages() |
| 38 | + |
| 39 | + assert [(package.name, package.package, package.extra) for package in packages] == [ |
| 40 | + ("budget", "agent-control-evaluator-budget", "budget"), |
| 41 | + ("cisco", "agent-control-evaluator-cisco", "cisco"), |
| 42 | + ("galileo", "agent-control-evaluator-galileo", "galileo"), |
| 43 | + ] |
| 44 | + |
| 45 | + |
| 46 | +def test_verify_contrib_packages_has_no_repo_wiring_drift() -> None: |
| 47 | + """Test that contrib package wiring stays aligned with repo metadata.""" |
| 48 | + |
| 49 | + module = load_contrib_packages_module() |
| 50 | + |
| 51 | + packages = module.discover_contrib_packages() |
| 52 | + |
| 53 | + assert module.verify_contrib_packages(packages) == [] |
0 commit comments