Skip to content

Commit 15f5493

Browse files
Add safe key-display usage centralization guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 90b371e commit 15f5493

3 files changed

Lines changed: 36 additions & 0 deletions

File tree

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_usage.py` (safe mapping-key display helper usage centralization),
200201
- `tests/test_schema_injection_helper_usage.py` (shared schema injection helper usage enforcement in payload builders),
201202
- `tests/test_session_operation_metadata_import_boundary.py` (session operation-metadata import boundary enforcement),
202203
- `tests/test_session_operation_metadata_usage.py` (session manager operation-metadata usage 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_usage.py",
132133
"tests/test_schema_injection_helper_usage.py",
133134
"tests/test_session_operation_metadata_import_boundary.py",
134135
"tests/test_session_operation_metadata_usage.py",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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_SAFE_KEY_DISPLAY_CALL_FILES = {
11+
Path("mapping_utils.py"),
12+
Path("client/managers/list_parsing_utils.py"),
13+
}
14+
15+
16+
def _python_files() -> list[Path]:
17+
return sorted(HYPERBROWSER_ROOT.rglob("*.py"))
18+
19+
20+
def test_safe_key_display_usage_is_centralized():
21+
violations: list[str] = []
22+
23+
for path in _python_files():
24+
relative_path = path.relative_to(HYPERBROWSER_ROOT)
25+
module = read_module_ast(path)
26+
helper_calls = collect_name_call_lines(module, "safe_key_display_for_error")
27+
if not helper_calls:
28+
continue
29+
if relative_path in ALLOWED_SAFE_KEY_DISPLAY_CALL_FILES:
30+
continue
31+
for line in helper_calls:
32+
violations.append(f"{relative_path}:{line}")
33+
34+
assert violations == []

0 commit comments

Comments
 (0)