Skip to content

Commit c21c647

Browse files
Add display key-format import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 8b905ed commit c21c647

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ This runs lint, format checks, compile checks, tests, and package build.
121121
- `tests/test_default_terminal_status_helper_usage.py` (default terminal-status helper usage enforcement for non-agent managers),
122122
- `tests/test_display_blank_key_literal_boundary.py` (blank-key display literal centralization in `hyperbrowser/display_utils.py`),
123123
- `tests/test_display_helper_usage.py` (display/key-format helper usage),
124+
- `tests/test_display_key_format_import_boundary.py` (display key-format helper import boundary enforcement),
124125
- `tests/test_docs_python3_commands.py` (`README`/`CONTRIBUTING`/examples python3 command consistency enforcement),
125126
- `tests/test_example_run_instructions.py` (example run-instruction consistency enforcement),
126127
- `tests/test_example_sync_async_parity.py` (sync/async example parity enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"tests/test_tool_mapping_reader_usage.py",
5252
"tests/test_display_blank_key_literal_boundary.py",
5353
"tests/test_display_helper_usage.py",
54+
"tests/test_display_key_format_import_boundary.py",
5455
"tests/test_file_open_default_prefix_literal_boundary.py",
5556
"tests/test_file_message_default_constant_import_boundary.py",
5657
"tests/test_file_message_default_constant_usage.py",
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
EXPECTED_KEY_FORMAT_HELPER_IMPORTERS = (
10+
"hyperbrowser/client/managers/extension_utils.py",
11+
"hyperbrowser/client/managers/response_utils.py",
12+
"hyperbrowser/client/managers/session_utils.py",
13+
"hyperbrowser/tools/__init__.py",
14+
"hyperbrowser/transport/base.py",
15+
"tests/test_display_utils.py",
16+
)
17+
18+
19+
def _imports_format_string_key_for_error(module_text: str) -> bool:
20+
module_ast = ast.parse(module_text)
21+
for node in module_ast.body:
22+
if not isinstance(node, ast.ImportFrom):
23+
continue
24+
if any(alias.name == "format_string_key_for_error" for alias in node.names):
25+
return True
26+
return False
27+
28+
29+
def test_format_string_key_for_error_imports_are_centralized():
30+
discovered_modules: list[str] = []
31+
32+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
33+
module_text = module_path.read_text(encoding="utf-8")
34+
if _imports_format_string_key_for_error(module_text):
35+
discovered_modules.append(module_path.as_posix())
36+
37+
for module_path in sorted(Path("tests").glob("test_*.py")):
38+
module_text = module_path.read_text(encoding="utf-8")
39+
if _imports_format_string_key_for_error(module_text):
40+
discovered_modules.append(module_path.as_posix())
41+
42+
assert discovered_modules == list(EXPECTED_KEY_FORMAT_HELPER_IMPORTERS)

0 commit comments

Comments
 (0)