Skip to content

Commit 4a0f92d

Browse files
Add file-message prefix literal boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 2f7043b commit 4a0f92d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ This runs lint, format checks, compile checks, tests, and package build.
135135
- `tests/test_extension_request_internal_reuse.py` (extension request-helper internal reuse of shared model request helpers),
136136
- `tests/test_extension_route_constants_usage.py` (extension manager route-constant usage enforcement),
137137
- `tests/test_extract_payload_helper_usage.py` (extract start-payload helper usage enforcement),
138+
- `tests/test_file_message_prefix_literal_boundary.py` (extension/session file-message prefix literal centralization in shared metadata modules),
138139
- `tests/test_file_open_error_helper_import_boundary.py` (shared file-open error-message helper import boundary enforcement),
139140
- `tests/test_file_open_error_helper_usage.py` (shared file-open error-message helper usage enforcement),
140141
- `tests/test_file_path_display_helper_import_boundary.py` (shared file-path display helper import boundary enforcement),

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_message_prefix_literal_boundary.py",
5354
"tests/test_file_open_error_helper_import_boundary.py",
5455
"tests/test_file_open_error_helper_usage.py",
5556
"tests/test_file_path_display_helper_import_boundary.py",
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
HYPERBROWSER_ROOT = Path(__file__).resolve().parents[1] / "hyperbrowser"
9+
ALLOWED_LITERAL_MODULES = {
10+
Path("client/managers/extension_operation_metadata.py"),
11+
Path("client/managers/session_operation_metadata.py"),
12+
}
13+
FORBIDDEN_PREFIX_LITERALS = (
14+
"Extension file not found at path",
15+
"Extension file path must point to a file",
16+
"Failed to open extension file at path",
17+
"Upload file not found at path",
18+
"Upload file path must point to a file",
19+
"Failed to open upload file at path",
20+
)
21+
22+
23+
def test_file_message_prefix_literals_are_centralized_in_metadata_modules():
24+
violations: list[str] = []
25+
26+
for module_path in sorted(HYPERBROWSER_ROOT.rglob("*.py")):
27+
relative_path = module_path.relative_to(HYPERBROWSER_ROOT)
28+
if relative_path in ALLOWED_LITERAL_MODULES:
29+
continue
30+
module_text = module_path.read_text(encoding="utf-8")
31+
for literal in FORBIDDEN_PREFIX_LITERALS:
32+
if literal in module_text:
33+
violations.append(f"{relative_path}:{literal}")
34+
35+
assert violations == []

0 commit comments

Comments
 (0)