Skip to content

Commit 03920b9

Browse files
Add file-path display helper import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 8b3c16e commit 03920b9

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ This runs lint, format checks, compile checks, tests, and package build.
133133
- `tests/test_extension_request_internal_reuse.py` (extension request-helper internal reuse of shared model request helpers),
134134
- `tests/test_extension_route_constants_usage.py` (extension manager route-constant usage enforcement),
135135
- `tests/test_extract_payload_helper_usage.py` (extract start-payload helper usage enforcement),
136+
- `tests/test_file_path_display_helper_import_boundary.py` (shared file-path display helper import boundary enforcement),
136137
- `tests/test_file_path_display_helper_usage.py` (shared file-path display helper usage enforcement),
137138
- `tests/test_guardrail_ast_utils.py` (shared AST guard utility contract),
138139
- `tests/test_helper_transport_usage_boundary.py` (manager-helper transport usage boundary enforcement through shared model request helpers),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"tests/test_model_request_wrapper_internal_reuse.py",
5151
"tests/test_tool_mapping_reader_usage.py",
5252
"tests/test_display_helper_usage.py",
53+
"tests/test_file_path_display_helper_import_boundary.py",
5354
"tests/test_file_path_display_helper_usage.py",
5455
"tests/test_binary_file_open_helper_usage.py",
5556
"tests/test_browser_use_payload_helper_usage.py",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
EXPECTED_FORMAT_FILE_PATH_IMPORTERS = (
10+
"hyperbrowser/client/managers/extension_create_utils.py",
11+
"hyperbrowser/client/managers/session_upload_utils.py",
12+
"tests/test_file_utils.py",
13+
)
14+
15+
16+
def _imports_format_file_path_for_error(module_text: str) -> bool:
17+
module_ast = ast.parse(module_text)
18+
for node in module_ast.body:
19+
if not isinstance(node, ast.ImportFrom):
20+
continue
21+
if any(alias.name == "format_file_path_for_error" for alias in node.names):
22+
return True
23+
return False
24+
25+
26+
def test_format_file_path_for_error_imports_are_centralized():
27+
discovered_modules: list[str] = []
28+
29+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
30+
module_text = module_path.read_text(encoding="utf-8")
31+
if _imports_format_file_path_for_error(module_text):
32+
discovered_modules.append(module_path.as_posix())
33+
34+
for module_path in sorted(Path("tests").glob("test_*.py")):
35+
module_text = module_path.read_text(encoding="utf-8")
36+
if _imports_format_file_path_for_error(module_text):
37+
discovered_modules.append(module_path.as_posix())
38+
39+
assert discovered_modules == list(EXPECTED_FORMAT_FILE_PATH_IMPORTERS)

0 commit comments

Comments
 (0)