Skip to content

Commit a5a02b0

Browse files
Add AST call-symbol helper usage guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent e6dcb83 commit a5a02b0

6 files changed

Lines changed: 62 additions & 0 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ This runs lint, format checks, compile checks, tests, and package build.
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),
9191
- `tests/test_ast_call_symbol_helper_import_boundary.py` (shared AST call-helper import boundary enforcement across test modules),
92+
- `tests/test_ast_call_symbol_helper_usage.py` (shared AST call-helper usage enforcement across AST boundary guard suites),
9293
- `tests/test_ast_function_source_helper_usage.py` (shared AST function-source helper usage enforcement across architecture guard suites),
9394
- `tests/test_ast_function_source_import_boundary.py` (shared AST function-source helper import boundary enforcement across test modules),
9495
- `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
@@ -18,6 +18,7 @@
1818
"tests/test_agent_stop_helper_usage.py",
1919
"tests/test_agent_terminal_status_helper_usage.py",
2020
"tests/test_ast_call_symbol_helper_import_boundary.py",
21+
"tests/test_ast_call_symbol_helper_usage.py",
2122
"tests/test_ast_function_source_helper_usage.py",
2223
"tests/test_ast_function_source_import_boundary.py",
2324
"tests/test_ast_function_source_utils.py",

tests/test_ast_call_symbol_helper_import_boundary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99

1010
EXPECTED_CALLS_SYMBOL_IMPORTERS = (
11+
"tests/test_ast_call_symbol_helper_usage.py",
1112
"tests/test_ast_function_source_helper_usage.py",
1213
"tests/test_ast_import_helper_usage.py",
1314
"tests/test_ast_import_utils.py",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from tests.ast_import_utils import calls_symbol, imports_symbol_from_module
6+
7+
pytestmark = pytest.mark.architecture
8+
9+
10+
AST_CALL_SYMBOL_GUARD_MODULES = (
11+
"tests/test_ast_function_source_helper_usage.py",
12+
"tests/test_ast_import_helper_usage.py",
13+
"tests/test_ast_symbol_import_helper_usage.py",
14+
)
15+
16+
17+
def test_ast_call_symbol_guard_modules_reuse_shared_helper():
18+
violating_modules: list[str] = []
19+
for module_path in AST_CALL_SYMBOL_GUARD_MODULES:
20+
module_text = Path(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+
violating_modules.append(module_path)
27+
continue
28+
if not calls_symbol(module_text, "calls_symbol"):
29+
violating_modules.append(module_path)
30+
continue
31+
if "def _calls_symbol" in module_text:
32+
violating_modules.append(module_path)
33+
34+
assert violating_modules == []
35+
36+
37+
def test_ast_call_symbol_guard_inventory_stays_in_sync():
38+
excluded_modules = {
39+
"tests/test_ast_call_symbol_helper_import_boundary.py",
40+
"tests/test_ast_call_symbol_helper_usage.py",
41+
"tests/test_ast_import_utils.py",
42+
}
43+
discovered_modules: list[str] = []
44+
for module_path in sorted(Path("tests").glob("test_*.py")):
45+
normalized_path = module_path.as_posix()
46+
if normalized_path in excluded_modules:
47+
continue
48+
module_text = module_path.read_text(encoding="utf-8")
49+
if not imports_symbol_from_module(
50+
module_text,
51+
module="tests.ast_import_utils",
52+
symbol="calls_symbol",
53+
):
54+
continue
55+
discovered_modules.append(normalized_path)
56+
57+
assert sorted(AST_CALL_SYMBOL_GUARD_MODULES) == discovered_modules

tests/test_ast_import_utils_module_import_boundary.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
EXPECTED_EXTRA_IMPORTERS = (
1818
"tests/test_ast_call_symbol_helper_import_boundary.py",
19+
"tests/test_ast_call_symbol_helper_usage.py",
1920
"tests/test_ast_import_helper_import_boundary.py",
2021
"tests/test_ast_import_helper_secondary_import_boundary.py",
2122
"tests/test_ast_module_import_helper_import_boundary.py",

tests/test_ast_symbol_import_helper_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
AST_SYMBOL_IMPORT_GUARD_MODULES = (
1111
"tests/test_ast_call_symbol_helper_import_boundary.py",
12+
"tests/test_ast_call_symbol_helper_usage.py",
1213
"tests/test_ast_import_helper_secondary_import_boundary.py",
1314
"tests/test_ast_import_helper_usage.py",
1415
"tests/test_ast_module_import_helper_import_boundary.py",

0 commit comments

Comments
 (0)