Skip to content

Commit fa9aec6

Browse files
Add session request wrapper internal reuse architecture guard
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1d40396 commit fa9aec6

3 files changed

Lines changed: 55 additions & 2 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ This runs lint, format checks, compile checks, tests, and package build.
159159
- `tests/test_session_profile_update_helper_usage.py` (session profile-update parameter helper usage enforcement),
160160
- `tests/test_session_request_helper_usage.py` (session manager request-helper usage enforcement),
161161
- `tests/test_session_request_internal_reuse.py` (session request-helper internal reuse of shared model raw request helpers),
162+
- `tests/test_session_request_wrapper_internal_reuse.py` (parsed session-request wrapper internal reuse of session resource helpers),
162163
- `tests/test_session_route_constants_usage.py` (session manager route-constant usage enforcement),
163164
- `tests/test_session_upload_helper_usage.py` (session upload-input normalization helper usage enforcement),
164165
- `tests/test_start_and_wait_default_constants_usage.py` (shared start-and-wait default-constant usage enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,11 @@
8888
"tests/test_schema_injection_helper_usage.py",
8989
"tests/test_session_operation_metadata_usage.py",
9090
"tests/test_session_parse_usage_boundary.py",
91+
"tests/test_session_profile_update_helper_usage.py",
92+
"tests/test_session_request_helper_usage.py",
9193
"tests/test_session_request_internal_reuse.py",
94+
"tests/test_session_request_wrapper_internal_reuse.py",
9295
"tests/test_session_route_constants_usage.py",
93-
"tests/test_session_request_helper_usage.py",
94-
"tests/test_session_profile_update_helper_usage.py",
9596
"tests/test_session_upload_helper_usage.py",
9697
"tests/test_start_and_wait_default_constants_usage.py",
9798
"tests/test_start_job_context_helper_usage.py",
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import ast
2+
from pathlib import Path
3+
4+
import pytest
5+
6+
pytestmark = pytest.mark.architecture
7+
8+
9+
MODULE_PATH = Path("hyperbrowser/client/managers/session_request_utils.py")
10+
11+
SYNC_PARSED_WRAPPER_TO_RESOURCE_HELPER = {
12+
"post_session_model": "post_session_resource(",
13+
"get_session_model": "get_session_resource(",
14+
"put_session_model": "put_session_resource(",
15+
"get_session_recordings": "get_session_resource(",
16+
}
17+
18+
ASYNC_PARSED_WRAPPER_TO_RESOURCE_HELPER = {
19+
"post_session_model_async": "post_session_resource_async(",
20+
"get_session_model_async": "get_session_resource_async(",
21+
"put_session_model_async": "put_session_resource_async(",
22+
"get_session_recordings_async": "get_session_resource_async(",
23+
}
24+
25+
26+
def _collect_function_sources() -> dict[str, str]:
27+
module_text = MODULE_PATH.read_text(encoding="utf-8")
28+
module_ast = ast.parse(module_text)
29+
function_sources: dict[str, str] = {}
30+
for node in module_ast.body:
31+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
32+
function_source = ast.get_source_segment(module_text, node)
33+
if function_source is not None:
34+
function_sources[node.name] = function_source
35+
return function_sources
36+
37+
38+
def test_sync_parsed_session_wrappers_delegate_to_resource_helpers():
39+
function_sources = _collect_function_sources()
40+
for wrapper_name, helper_call in SYNC_PARSED_WRAPPER_TO_RESOURCE_HELPER.items():
41+
wrapper_source = function_sources[wrapper_name]
42+
assert helper_call in wrapper_source
43+
assert "client.transport." not in wrapper_source
44+
45+
46+
def test_async_parsed_session_wrappers_delegate_to_resource_helpers():
47+
function_sources = _collect_function_sources()
48+
for wrapper_name, helper_call in ASYNC_PARSED_WRAPPER_TO_RESOURCE_HELPER.items():
49+
wrapper_source = function_sources[wrapper_name]
50+
assert helper_call in wrapper_source
51+
assert "client.transport." not in wrapper_source

0 commit comments

Comments
 (0)