Skip to content

Commit 0988df5

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

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ This runs lint, format checks, compile checks, tests, and package build.
122122
- `tests/test_job_query_params_helper_usage.py` (shared scrape/crawl query-param helper usage enforcement),
123123
- `tests/test_job_request_helper_usage.py` (shared scrape/crawl/extract request-helper usage enforcement),
124124
- `tests/test_job_request_internal_reuse.py` (shared job request helper internal reuse of shared model request helpers),
125+
- `tests/test_job_request_wrapper_internal_reuse.py` (parsed job-request wrapper internal reuse of shared model request helpers),
125126
- `tests/test_job_route_builder_usage.py` (shared job/web request-helper route-builder usage enforcement),
126127
- `tests/test_job_route_constants_usage.py` (shared scrape/crawl/extract route-constant usage enforcement),
127128
- `tests/test_job_start_payload_helper_usage.py` (shared scrape/crawl start-payload helper usage enforcement),

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"tests/test_job_poll_helper_boundary.py",
7373
"tests/test_job_poll_helper_usage.py",
7474
"tests/test_job_request_internal_reuse.py",
75+
"tests/test_job_request_wrapper_internal_reuse.py",
7576
"tests/test_job_route_builder_usage.py",
7677
"tests/test_job_route_constants_usage.py",
7778
"tests/test_job_request_helper_usage.py",
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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/job_request_utils.py")
10+
11+
SYNC_WRAPPER_TO_MODEL_HELPER = {
12+
"start_job": "post_model_request(",
13+
"get_job_status": "get_model_request(",
14+
"get_job": "get_model_request(",
15+
"put_job_action": "put_model_request(",
16+
}
17+
18+
ASYNC_WRAPPER_TO_MODEL_HELPER = {
19+
"start_job_async": "post_model_request_async(",
20+
"get_job_status_async": "get_model_request_async(",
21+
"get_job_async": "get_model_request_async(",
22+
"put_job_action_async": "put_model_request_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_job_request_wrappers_delegate_to_model_helpers():
39+
function_sources = _collect_function_sources()
40+
for wrapper_name, helper_call in SYNC_WRAPPER_TO_MODEL_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+
assert "parse_response_model(" not in wrapper_source
45+
46+
47+
def test_async_job_request_wrappers_delegate_to_model_helpers():
48+
function_sources = _collect_function_sources()
49+
for wrapper_name, helper_call in ASYNC_WRAPPER_TO_MODEL_HELPER.items():
50+
wrapper_source = function_sources[wrapper_name]
51+
assert helper_call in wrapper_source
52+
assert "client.transport." not in wrapper_source
53+
assert "parse_response_model(" not in wrapper_source

0 commit comments

Comments
 (0)