Skip to content

Commit 1b07fdf

Browse files
Add mapping read-helper callsite centralization guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent d6a85b3 commit 1b07fdf

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ This runs lint, format checks, compile checks, tests, and package build.
173173
- `tests/test_mapping_copy_helper_import_boundary.py` (shared mapping copy-helper import boundary enforcement),
174174
- `tests/test_mapping_helpers_usage.py` (shared mapping read/copy helper usage centralization),
175175
- `tests/test_mapping_keys_access_usage.py` (centralized key-iteration boundaries),
176+
- `tests/test_mapping_read_helper_call_usage.py` (shared mapping read-helper runtime callsite centralization),
176177
- `tests/test_mapping_read_helper_import_boundary.py` (shared mapping read-helper import boundary enforcement),
177178
- `tests/test_mapping_read_keys_helper_import_boundary.py` (shared mapping read-keys helper import boundary enforcement),
178179
- `tests/test_mapping_reader_usage.py` (shared mapping-read parser usage),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"tests/test_manager_transport_boundary.py",
4545
"tests/test_mapping_copy_helper_import_boundary.py",
4646
"tests/test_mapping_helpers_usage.py",
47+
"tests/test_mapping_read_helper_call_usage.py",
4748
"tests/test_mapping_read_keys_helper_import_boundary.py",
4849
"tests/test_mapping_read_helper_import_boundary.py",
4950
"tests/test_mapping_reader_usage.py",
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
from tests.guardrail_ast_utils import collect_name_call_lines, read_module_ast
6+
from tests.test_mapping_reader_usage import MAPPING_READER_TARGET_FILES
7+
8+
pytestmark = pytest.mark.architecture
9+
10+
HYPERBROWSER_ROOT = Path(__file__).resolve().parents[1] / "hyperbrowser"
11+
EXPECTED_READ_HELPER_CALL_FILES = {
12+
path.relative_to("hyperbrowser") for path in MAPPING_READER_TARGET_FILES
13+
}
14+
15+
16+
def _python_files() -> list[Path]:
17+
return sorted(HYPERBROWSER_ROOT.rglob("*.py"))
18+
19+
20+
def test_read_string_key_mapping_usage_is_centralized():
21+
files_with_calls: set[Path] = set()
22+
violations: list[str] = []
23+
24+
for path in _python_files():
25+
relative_path = path.relative_to(HYPERBROWSER_ROOT)
26+
module = read_module_ast(path)
27+
helper_calls = collect_name_call_lines(module, "read_string_key_mapping")
28+
if not helper_calls:
29+
continue
30+
files_with_calls.add(relative_path)
31+
if relative_path in EXPECTED_READ_HELPER_CALL_FILES:
32+
continue
33+
for line in helper_calls:
34+
violations.append(f"{relative_path}:{line}")
35+
36+
assert violations == []
37+
assert files_with_calls == EXPECTED_READ_HELPER_CALL_FILES

0 commit comments

Comments
 (0)