refactor(egress): separate matching, DLP, and context concerns
tracker-policy-pr / check-pr (pull_request) Successful in 12s
test / integration-macos (pull_request) Has been skipped
lint / lint (push) Failing after 56s
test / unit (pull_request) Successful in 53s
test / integration-docker (pull_request) Successful in 54s
test / integration-firecracker (pull_request) Successful in 4m1s
test / coverage (pull_request) Failing after 23s
test / publish-infra (pull_request) Has been skipped
tracker-policy-pr / check-pr (pull_request) Successful in 12s
test / integration-macos (pull_request) Has been skipped
lint / lint (push) Failing after 56s
test / unit (pull_request) Successful in 53s
test / integration-docker (pull_request) Successful in 54s
test / integration-firecracker (pull_request) Successful in 4m1s
test / coverage (pull_request) Failing after 23s
test / publish-infra (pull_request) Has been skipped
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
"""Architecture rules that should fail before coupling becomes entrenched."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class TestCliBackendBoundaries(unittest.TestCase):
|
||||
def test_cli_does_not_import_a_concrete_backend(self) -> None:
|
||||
forbidden = (
|
||||
"backend.docker", "backend.firecracker", "backend.macos_container",
|
||||
"bot_bottle.backend.docker", "bot_bottle.backend.firecracker",
|
||||
"bot_bottle.backend.macos_container",
|
||||
)
|
||||
violations: list[str] = []
|
||||
for path in (ROOT / "bot_bottle" / "cli").rglob("*.py"):
|
||||
tree = ast.parse(path.read_text(), filename=str(path))
|
||||
for node in ast.walk(tree):
|
||||
module = node.module if isinstance(node, ast.ImportFrom) else None
|
||||
if module and module.startswith(forbidden):
|
||||
violations.append(f"{path.relative_to(ROOT)}:{node.lineno}: {module}")
|
||||
if isinstance(node, ast.Import):
|
||||
violations.extend(
|
||||
f"{path.relative_to(ROOT)}:{node.lineno}: {alias.name}"
|
||||
for alias in node.names if alias.name.startswith(forbidden)
|
||||
)
|
||||
self.assertEqual([], violations, "generic CLI imports concrete backend internals:\n" +
|
||||
"\n".join(violations))
|
||||
|
||||
|
||||
class TestRuntimeModuleSizes(unittest.TestCase):
|
||||
def test_egress_modules_stay_focused(self) -> None:
|
||||
caps = {
|
||||
"addon_core.py": 900, # compatibility + policy-schema parsing only
|
||||
"types.py": 180,
|
||||
"matching.py": 180,
|
||||
"dlp.py": 180,
|
||||
"context.py": 140,
|
||||
}
|
||||
directory = ROOT / "bot_bottle" / "gateway" / "egress"
|
||||
oversized = [f"{name} ({len((directory / name).read_text().splitlines())}>{cap})"
|
||||
for name, cap in caps.items()
|
||||
if len((directory / name).read_text().splitlines()) > cap]
|
||||
self.assertEqual([], oversized, "split a module rather than raising its cap: " +
|
||||
", ".join(oversized))
|
||||
Reference in New Issue
Block a user