Skip to content

Commit 9d3f7d9

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

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ This runs lint, format checks, compile checks, tests, and package build.
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),
162162
- `tests/test_session_request_wrapper_internal_reuse.py` (parsed session-request wrapper internal reuse of session resource helpers),
163+
- `tests/test_session_resource_wrapper_internal_reuse.py` (session resource-wrapper internal reuse of shared model raw request helpers),
163164
- `tests/test_session_route_constants_usage.py` (session manager route-constant usage enforcement),
164165
- `tests/test_session_upload_helper_usage.py` (session upload-input normalization helper usage enforcement),
165166
- `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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
"tests/test_session_request_helper_usage.py",
9393
"tests/test_session_request_internal_reuse.py",
9494
"tests/test_session_request_wrapper_internal_reuse.py",
95+
"tests/test_session_resource_wrapper_internal_reuse.py",
9596
"tests/test_session_route_constants_usage.py",
9697
"tests/test_session_upload_helper_usage.py",
9798
"tests/test_start_and_wait_default_constants_usage.py",
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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_RESOURCE_WRAPPER_TO_MODEL_HELPER = {
12+
"post_session_resource": "post_model_response_data(",
13+
"get_session_resource": "get_model_response_data(",
14+
"put_session_resource": "put_model_response_data(",
15+
}
16+
17+
ASYNC_RESOURCE_WRAPPER_TO_MODEL_HELPER = {
18+
"post_session_resource_async": "post_model_response_data_async(",
19+
"get_session_resource_async": "get_model_response_data_async(",
20+
"put_session_resource_async": "put_model_response_data_async(",
21+
}
22+
23+
24+
def _collect_function_sources() -> dict[str, str]:
25+
module_text = MODULE_PATH.read_text(encoding="utf-8")
26+
module_ast = ast.parse(module_text)
27+
function_sources: dict[str, str] = {}
28+
for node in module_ast.body:
29+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
30+
function_source = ast.get_source_segment(module_text, node)
31+
if function_source is not None:
32+
function_sources[node.name] = function_source
33+
return function_sources
34+
35+
36+
def test_sync_session_resource_wrappers_delegate_to_model_helpers():
37+
function_sources = _collect_function_sources()
38+
for wrapper_name, helper_call in SYNC_RESOURCE_WRAPPER_TO_MODEL_HELPER.items():
39+
wrapper_source = function_sources[wrapper_name]
40+
assert helper_call in wrapper_source
41+
assert "client.transport." not in wrapper_source
42+
43+
44+
def test_async_session_resource_wrappers_delegate_to_model_helpers():
45+
function_sources = _collect_function_sources()
46+
for wrapper_name, helper_call in ASYNC_RESOURCE_WRAPPER_TO_MODEL_HELPER.items():
47+
wrapper_source = function_sources[wrapper_name]
48+
assert helper_call in wrapper_source
49+
assert "client.transport." not in wrapper_source

0 commit comments

Comments
 (0)