| 1 | """Tests for compatibility export boundaries.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import re |
| 6 | from pathlib import Path |
| 7 | |
| 8 | |
| 9 | def test_runtime_code_does_not_import_agent_compatibility_modules() -> None: |
| 10 | repo_root = Path(__file__).resolve().parents[1] |
| 11 | src_root = repo_root / "src" / "loader" |
| 12 | pattern = re.compile( |
| 13 | r"(from\s+loader\.agent\.(reasoning|safeguards)\s+import)" |
| 14 | r"|(import\s+loader\.agent\.(reasoning|safeguards))" |
| 15 | r"|(from\s+\.\s*(reasoning|safeguards)\s+import)" |
| 16 | ) |
| 17 | violations: list[str] = [] |
| 18 | |
| 19 | for path in src_root.rglob("*.py"): |
| 20 | relative_path = path.relative_to(src_root) |
| 21 | if relative_path in { |
| 22 | Path("agent/reasoning.py"), |
| 23 | Path("agent/safeguards.py"), |
| 24 | }: |
| 25 | continue |
| 26 | text = path.read_text() |
| 27 | if pattern.search(text): |
| 28 | violations.append(str(relative_path)) |
| 29 | |
| 30 | assert violations == [] |
| 31 | |
| 32 | |
| 33 | def test_agent_loop_stays_off_runtime_controller_modules() -> None: |
| 34 | repo_root = Path(__file__).resolve().parents[1] |
| 35 | loop_path = repo_root / "src" / "loader" / "agent" / "loop.py" |
| 36 | text = loop_path.read_text() |
| 37 | forbidden_runtime_modules = ( |
| 38 | "runtime.conversation", |
| 39 | "runtime.explore", |
| 40 | "runtime.launcher", |
| 41 | "runtime.turn_completion", |
| 42 | "runtime.turn_iteration", |
| 43 | "runtime.turn_loop", |
| 44 | "runtime.turn_preparation", |
| 45 | "runtime.workflow_lanes", |
| 46 | "runtime.workflow_recovery", |
| 47 | "runtime.response_routing", |
| 48 | "runtime.tool_batches", |
| 49 | ) |
| 50 | |
| 51 | for module_name in forbidden_runtime_modules: |
| 52 | assert module_name not in text |