Skip to content

Commit 25277f3

Browse files
Add default-prefix constant import boundary guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 22f7b14 commit 25277f3

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-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_default_constant_import_boundary.py` (extension/session file-message default constant import boundary enforcement),
138139
- `tests/test_file_message_default_constant_usage.py` (extension/session file-message default-prefix constant usage enforcement),
139140
- `tests/test_file_message_prefix_literal_boundary.py` (extension/session file-message prefix literal centralization in shared metadata modules),
140141
- `tests/test_file_open_error_helper_import_boundary.py` (shared file-open error-message 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_default_constant_import_boundary.py",
5354
"tests/test_file_message_default_constant_usage.py",
5455
"tests/test_file_message_prefix_literal_boundary.py",
5556
"tests/test_file_open_error_helper_import_boundary.py",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
EXPECTED_EXTENSION_DEFAULT_CONSTANT_CONSUMERS = (
9+
"hyperbrowser/client/managers/async_manager/extension.py",
10+
"hyperbrowser/client/managers/extension_create_utils.py",
11+
"hyperbrowser/client/managers/extension_operation_metadata.py",
12+
"hyperbrowser/client/managers/sync_manager/extension.py",
13+
"tests/test_extension_create_metadata_usage.py",
14+
"tests/test_extension_operation_metadata.py",
15+
"tests/test_extension_operation_metadata_usage.py",
16+
"tests/test_file_message_default_constant_import_boundary.py",
17+
"tests/test_file_message_default_constant_usage.py",
18+
)
19+
20+
EXPECTED_SESSION_DEFAULT_CONSTANT_CONSUMERS = (
21+
"hyperbrowser/client/managers/session_operation_metadata.py",
22+
"hyperbrowser/client/managers/session_upload_utils.py",
23+
"tests/test_file_message_default_constant_import_boundary.py",
24+
"tests/test_file_message_default_constant_usage.py",
25+
"tests/test_session_operation_metadata.py",
26+
"tests/test_session_upload_metadata_usage.py",
27+
)
28+
29+
30+
def _discover_modules_with_text(fragment: str) -> list[str]:
31+
discovered_modules: list[str] = []
32+
for module_path in sorted(Path("hyperbrowser").rglob("*.py")):
33+
module_text = module_path.read_text(encoding="utf-8")
34+
if fragment not in module_text:
35+
continue
36+
discovered_modules.append(module_path.as_posix())
37+
for module_path in sorted(Path("tests").glob("test_*.py")):
38+
module_text = module_path.read_text(encoding="utf-8")
39+
if fragment not in module_text:
40+
continue
41+
discovered_modules.append(module_path.as_posix())
42+
return discovered_modules
43+
44+
45+
def test_extension_default_message_constants_are_centralized():
46+
discovered_modules = _discover_modules_with_text("EXTENSION_DEFAULT_")
47+
assert discovered_modules == list(EXPECTED_EXTENSION_DEFAULT_CONSTANT_CONSUMERS)
48+
49+
50+
def test_session_default_message_constants_are_centralized():
51+
discovered_modules = _discover_modules_with_text("SESSION_DEFAULT_UPLOAD_")
52+
assert discovered_modules == list(EXPECTED_SESSION_DEFAULT_CONSTANT_CONSUMERS)

0 commit comments

Comments
 (0)