Skip to content

Commit 0b9271d

Browse files
Add safe key-display import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 15f5493 commit 0b9271d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ This runs lint, format checks, compile checks, tests, and package build.
197197
- `tests/test_request_helper_transport_boundary.py` (request-helper transport boundary enforcement through shared model request helpers),
198198
- `tests/test_request_wrapper_internal_reuse.py` (request-wrapper internal reuse of shared model request helpers across profile/team/extension/computer-action modules),
199199
- `tests/test_response_parse_usage_boundary.py` (centralized `parse_response_model(...)` usage boundary enforcement),
200+
- `tests/test_safe_key_display_helper_import_boundary.py` (safe mapping-key display helper import boundary enforcement),
200201
- `tests/test_safe_key_display_helper_usage.py` (safe mapping-key display helper usage centralization),
201202
- `tests/test_schema_injection_helper_usage.py` (shared schema injection helper usage enforcement in payload builders),
202203
- `tests/test_session_operation_metadata_import_boundary.py` (session operation-metadata import boundary enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"tests/test_computer_action_payload_helper_usage.py",
130130
"tests/test_computer_action_request_helper_usage.py",
131131
"tests/test_computer_action_request_internal_reuse.py",
132+
"tests/test_safe_key_display_helper_import_boundary.py",
132133
"tests/test_safe_key_display_helper_usage.py",
133134
"tests/test_schema_injection_helper_usage.py",
134135
"tests/test_session_operation_metadata_import_boundary.py",
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
EXPECTED_SAFE_KEY_DISPLAY_IMPORTERS = (
10+
"hyperbrowser/client/managers/list_parsing_utils.py",
11+
"tests/test_mapping_utils.py",
12+
)
13+
14+
15+
def _imports_safe_key_display_helper(module_text: str) -> bool:
16+
module_ast = ast.parse(module_text)
17+
for node in module_ast.body:
18+
if not isinstance(node, ast.ImportFrom):
19+
continue
20+
if node.module != "hyperbrowser.mapping_utils":
21+
continue
22+
if any(alias.name == "safe_key_display_for_error" for alias in node.names):
23+
return True
24+
return False
25+
26+
27+
def test_safe_key_display_helper_imports_are_centralized():
28+
discovered_modules: list[str] = []
29+
30+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
31+
module_text = module_path.read_text(encoding="utf-8")
32+
if _imports_safe_key_display_helper(module_text):
33+
discovered_modules.append(module_path.as_posix())
34+
35+
for module_path in sorted(Path("tests").glob("test_*.py")):
36+
module_text = module_path.read_text(encoding="utf-8")
37+
if _imports_safe_key_display_helper(module_text):
38+
discovered_modules.append(module_path.as_posix())
39+
40+
assert discovered_modules == list(EXPECTED_SAFE_KEY_DISPLAY_IMPORTERS)

0 commit comments

Comments
 (0)