Skip to content

Commit e1d976d

Browse files
Add AST import helper contract test and boundary allowance
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 997990f commit e1d976d

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ This runs lint, format checks, compile checks, tests, and package build.
9393
- `tests/test_ast_function_source_utils.py` (shared AST function-source helper contract validation),
9494
- `tests/test_ast_import_helper_import_boundary.py` (shared AST import-helper import boundary enforcement across test modules),
9595
- `tests/test_ast_import_helper_usage.py` (shared AST import-helper usage enforcement across AST import-boundary guard suites),
96+
- `tests/test_ast_import_utils.py` (shared AST import-helper contract validation),
9697
- `tests/test_binary_file_open_helper_usage.py` (shared binary file open helper usage enforcement),
9798
- `tests/test_browser_use_payload_helper_usage.py` (browser-use payload helper usage enforcement),
9899
- `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
@@ -22,6 +22,7 @@
2222
"tests/test_ast_function_source_utils.py",
2323
"tests/test_ast_import_helper_import_boundary.py",
2424
"tests/test_ast_import_helper_usage.py",
25+
"tests/test_ast_import_utils.py",
2526
"tests/test_guardrail_ast_utils.py",
2627
"tests/test_helper_transport_usage_boundary.py",
2728
"tests/test_manager_model_dump_usage.py",

tests/test_ast_import_helper_import_boundary.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
pytestmark = pytest.mark.architecture
99

10+
EXPECTED_EXTRA_IMPORTER_MODULES = ("tests/test_ast_import_utils.py",)
11+
1012

1113
def _imports_ast_import_helper(module_text: str) -> bool:
1214
module_ast = ast.parse(module_text)
@@ -28,4 +30,5 @@ def test_ast_import_helper_imports_are_centralized():
2830
continue
2931
discovered_modules.append(module_path.as_posix())
3032

31-
assert discovered_modules == sorted(AST_IMPORT_GUARD_MODULES)
33+
expected_modules = sorted([*AST_IMPORT_GUARD_MODULES, *EXPECTED_EXTRA_IMPORTER_MODULES])
34+
assert discovered_modules == expected_modules

tests/test_ast_import_utils.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import pytest
2+
3+
from tests.ast_import_utils import imports_collect_function_sources
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
def test_imports_collect_function_sources_detects_expected_import():
9+
module_text = (
10+
"from tests.ast_function_source_utils import collect_function_sources\n"
11+
"collect_function_sources('tests/test_job_request_wrapper_internal_reuse.py')\n"
12+
)
13+
14+
assert imports_collect_function_sources(module_text) is True
15+
16+
17+
def test_imports_collect_function_sources_ignores_non_matching_imports():
18+
module_text = (
19+
"from tests.ast_function_source_utils import something_else\n"
20+
"from tests.other_helper import collect_function_sources\n"
21+
)
22+
23+
assert imports_collect_function_sources(module_text) is False

0 commit comments

Comments
 (0)