Skip to content

Commit 229627e

Browse files
Add AST call-helper import boundary architecture guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent a0be95c commit 229627e

4 files changed

Lines changed: 41 additions & 2 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ This runs lint, format checks, compile checks, tests, and package build.
8888
- `tests/test_agent_task_read_helper_usage.py` (shared agent task read-helper usage enforcement),
8989
- `tests/test_agent_terminal_status_helper_usage.py` (shared agent terminal-status helper usage enforcement),
9090
- `tests/test_architecture_marker_usage.py` (architecture marker coverage across guard modules),
91+
- `tests/test_ast_call_symbol_helper_import_boundary.py` (shared AST call-helper import boundary enforcement across test modules),
9192
- `tests/test_ast_function_source_helper_usage.py` (shared AST function-source helper usage enforcement across architecture guard suites),
9293
- `tests/test_ast_function_source_import_boundary.py` (shared AST function-source helper import boundary enforcement across test modules),
9394
- `tests/test_ast_function_source_utils.py` (shared AST function-source helper contract validation),

‎tests/test_architecture_marker_usage.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"tests/test_agent_task_read_helper_usage.py",
1818
"tests/test_agent_stop_helper_usage.py",
1919
"tests/test_agent_terminal_status_helper_usage.py",
20+
"tests/test_ast_call_symbol_helper_import_boundary.py",
2021
"tests/test_ast_function_source_helper_usage.py",
2122
"tests/test_ast_function_source_import_boundary.py",
2223
"tests/test_ast_function_source_utils.py",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from tests.ast_import_utils import imports_symbol_from_module
6+
7+
pytestmark = pytest.mark.architecture
8+
9+
10+
EXPECTED_CALLS_SYMBOL_IMPORTERS = (
11+
"tests/test_ast_function_source_helper_usage.py",
12+
"tests/test_ast_import_helper_usage.py",
13+
"tests/test_ast_import_utils.py",
14+
)
15+
16+
17+
def test_calls_symbol_imports_are_centralized():
18+
discovered_modules: list[str] = []
19+
for module_path in sorted(Path("tests").glob("test_*.py")):
20+
module_text = module_path.read_text(encoding="utf-8")
21+
if not imports_symbol_from_module(
22+
module_text,
23+
module="tests.ast_import_utils",
24+
symbol="calls_symbol",
25+
):
26+
continue
27+
discovered_modules.append(module_path.as_posix())
28+
29+
assert discovered_modules == list(EXPECTED_CALLS_SYMBOL_IMPORTERS)

‎tests/test_ast_import_helper_usage.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22

33
import pytest
44

5-
from tests.ast_import_utils import calls_symbol, imports_imports_collect_function_sources
5+
from tests.ast_import_utils import (
6+
calls_symbol,
7+
imports_imports_collect_function_sources,
8+
imports_symbol_from_module,
9+
)
610

711
pytestmark = pytest.mark.architecture
812

@@ -17,7 +21,11 @@ def test_ast_import_guard_modules_reuse_shared_import_helper():
1721
violating_modules: list[str] = []
1822
for module_path in AST_IMPORT_GUARD_MODULES:
1923
module_text = Path(module_path).read_text(encoding="utf-8")
20-
if not imports_imports_collect_function_sources(module_text):
24+
if not imports_symbol_from_module(
25+
module_text,
26+
module="tests.ast_import_utils",
27+
symbol="imports_collect_function_sources",
28+
):
2129
violating_modules.append(module_path)
2230
continue
2331
if not calls_symbol(module_text, "imports_collect_function_sources"):

0 commit comments

Comments
 (0)