Skip to content

Commit f24760d

Browse files
Add mapping helper usage centralization guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 7944446 commit f24760d

3 files changed

Lines changed: 57 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ This runs lint, format checks, compile checks, tests, and package build.
171171
- `tests/test_manager_parse_boundary.py` (manager response-parse boundary enforcement through shared helper modules),
172172
- `tests/test_manager_transport_boundary.py` (manager transport boundary enforcement through shared request helpers),
173173
- `tests/test_mapping_copy_helper_import_boundary.py` (shared mapping copy-helper import boundary enforcement),
174+
- `tests/test_mapping_helpers_usage.py` (shared mapping read/copy helper usage centralization),
174175
- `tests/test_mapping_keys_access_usage.py` (centralized key-iteration boundaries),
175176
- `tests/test_mapping_read_helper_import_boundary.py` (shared mapping read-helper import boundary enforcement),
176177
- `tests/test_mapping_read_keys_helper_import_boundary.py` (shared mapping read-keys helper import boundary enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"tests/test_manager_parse_boundary.py",
4444
"tests/test_manager_transport_boundary.py",
4545
"tests/test_mapping_copy_helper_import_boundary.py",
46+
"tests/test_mapping_helpers_usage.py",
4647
"tests/test_mapping_read_keys_helper_import_boundary.py",
4748
"tests/test_mapping_read_helper_import_boundary.py",
4849
"tests/test_mapping_reader_usage.py",
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
7+
pytestmark = pytest.mark.architecture
8+
9+
HYPERBROWSER_ROOT = Path(__file__).resolve().parents[1] / "hyperbrowser"
10+
ALLOWED_READ_KEYS_CALL_FILES = {
11+
Path("mapping_utils.py"),
12+
Path("tools/__init__.py"),
13+
}
14+
ALLOWED_COPY_VALUES_CALL_FILES = {
15+
Path("mapping_utils.py"),
16+
Path("tools/__init__.py"),
17+
}
18+
19+
20+
def _python_files() -> list[Path]:
21+
return sorted(HYPERBROWSER_ROOT.rglob("*.py"))
22+
23+
24+
def test_read_string_mapping_keys_usage_is_centralized():
25+
violations: list[str] = []
26+
27+
for path in _python_files():
28+
relative_path = path.relative_to(HYPERBROWSER_ROOT)
29+
module = read_module_ast(path)
30+
helper_calls = collect_name_call_lines(module, "read_string_mapping_keys")
31+
if not helper_calls:
32+
continue
33+
if relative_path in ALLOWED_READ_KEYS_CALL_FILES:
34+
continue
35+
for line in helper_calls:
36+
violations.append(f"{relative_path}:{line}")
37+
38+
assert violations == []
39+
40+
41+
def test_copy_mapping_values_by_string_keys_usage_is_centralized():
42+
violations: list[str] = []
43+
44+
for path in _python_files():
45+
relative_path = path.relative_to(HYPERBROWSER_ROOT)
46+
module = read_module_ast(path)
47+
helper_calls = collect_name_call_lines(module, "copy_mapping_values_by_string_keys")
48+
if not helper_calls:
49+
continue
50+
if relative_path in ALLOWED_COPY_VALUES_CALL_FILES:
51+
continue
52+
for line in helper_calls:
53+
violations.append(f"{relative_path}:{line}")
54+
55+
assert violations == []

0 commit comments

Comments
 (0)