Skip to content

Commit 5aa48f9

Browse files
Add symbol-level AST import helper boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 512fb4f commit 5aa48f9

4 files changed

Lines changed: 35 additions & 0 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ This runs lint, format checks, compile checks, tests, and package build.
9898
- `tests/test_ast_import_utils.py` (shared AST import-helper contract validation),
9999
- `tests/test_ast_import_utils_module_import_boundary.py` (shared AST import-helper module import boundary enforcement across test modules),
100100
- `tests/test_ast_module_import_helper_import_boundary.py` (shared AST module-import helper import boundary enforcement across test modules),
101+
- `tests/test_ast_symbol_import_helper_import_boundary.py` (shared AST symbol-import helper import boundary enforcement across test modules),
101102
- `tests/test_binary_file_open_helper_usage.py` (shared binary file open helper usage enforcement),
102103
- `tests/test_browser_use_payload_helper_usage.py` (browser-use payload helper usage enforcement),
103104
- `tests/test_ci_workflow_quality_gates.py` (CI guard-stage + make-target enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"tests/test_ast_import_utils.py",
2828
"tests/test_ast_import_utils_module_import_boundary.py",
2929
"tests/test_ast_module_import_helper_import_boundary.py",
30+
"tests/test_ast_symbol_import_helper_import_boundary.py",
3031
"tests/test_guardrail_ast_utils.py",
3132
"tests/test_helper_transport_usage_boundary.py",
3233
"tests/test_manager_model_dump_usage.py",

tests/test_ast_import_utils_module_import_boundary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"tests/test_ast_import_helper_import_boundary.py",
2020
"tests/test_ast_import_helper_secondary_import_boundary.py",
2121
"tests/test_ast_module_import_helper_import_boundary.py",
22+
"tests/test_ast_symbol_import_helper_import_boundary.py",
2223
"tests/test_ast_import_utils.py",
2324
"tests/test_ast_import_utils_module_import_boundary.py",
2425
)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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_IMPORTS_SYMBOL_FROM_MODULE_IMPORTERS = (
11+
"tests/test_ast_call_symbol_helper_import_boundary.py",
12+
"tests/test_ast_import_helper_secondary_import_boundary.py",
13+
"tests/test_ast_import_helper_usage.py",
14+
"tests/test_ast_import_utils.py",
15+
"tests/test_ast_module_import_helper_import_boundary.py",
16+
"tests/test_ast_symbol_import_helper_import_boundary.py",
17+
)
18+
19+
20+
def test_imports_symbol_from_module_imports_are_centralized():
21+
discovered_modules: list[str] = []
22+
for module_path in sorted(Path("tests").glob("test_*.py")):
23+
module_text = module_path.read_text(encoding="utf-8")
24+
if not imports_symbol_from_module(
25+
module_text,
26+
module="tests.ast_import_utils",
27+
symbol="imports_symbol_from_module",
28+
):
29+
continue
30+
discovered_modules.append(module_path.as_posix())
31+
32+
assert discovered_modules == list(EXPECTED_IMPORTS_SYMBOL_FROM_MODULE_IMPORTERS)

0 commit comments

Comments
 (0)