Skip to content

Commit 4532485

Browse files
Reuse shared route builders in agent request helpers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent 1002107 commit 4532485

File tree

7 files changed

+55
-6
lines changed

7 files changed

+55
-6
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ This runs lint, format checks, compile checks, tests, and package build.
8080
- `tests/test_agent_helper_boundary.py` (agent manager boundary enforcement for shared request/response helpers),
8181
- `tests/test_agent_operation_metadata_usage.py` (shared agent operation-metadata usage enforcement),
8282
- `tests/test_agent_payload_helper_usage.py` (shared agent start-payload helper usage enforcement),
83+
- `tests/test_agent_route_builder_usage.py` (shared agent read/stop route-builder usage enforcement),
8384
- `tests/test_agent_start_helper_usage.py` (shared agent start-request helper usage enforcement),
8485
- `tests/test_agent_stop_helper_usage.py` (shared agent stop-request helper usage enforcement),
8586
- `tests/test_agent_task_read_helper_usage.py` (shared agent task read-helper usage enforcement),

hyperbrowser/client/managers/agent_stop_utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from hyperbrowser.models import BasicResponse
44

5+
from .job_route_builders import build_job_action_route
56
from .response_utils import parse_response_model
67

78

@@ -13,7 +14,9 @@ def stop_agent_task(
1314
operation_name: str,
1415
) -> BasicResponse:
1516
response = client.transport.put(
16-
client._build_url(f"{route_prefix}/{job_id}/stop"),
17+
client._build_url(
18+
build_job_action_route(route_prefix, job_id, "/stop"),
19+
),
1720
)
1821
return parse_response_model(
1922
response.data,
@@ -30,7 +33,9 @@ async def stop_agent_task_async(
3033
operation_name: str,
3134
) -> BasicResponse:
3235
response = await client.transport.put(
33-
client._build_url(f"{route_prefix}/{job_id}/stop"),
36+
client._build_url(
37+
build_job_action_route(route_prefix, job_id, "/stop"),
38+
),
3439
)
3540
return parse_response_model(
3641
response.data,

hyperbrowser/client/managers/agent_task_read_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from typing import Any, Type, TypeVar
22

3+
from .job_route_builders import build_job_route, build_job_status_route
34
from .response_utils import parse_response_model
45

56
T = TypeVar("T")
@@ -14,7 +15,7 @@ def get_agent_task(
1415
operation_name: str,
1516
) -> T:
1617
response = client.transport.get(
17-
client._build_url(f"{route_prefix}/{job_id}"),
18+
client._build_url(build_job_route(route_prefix, job_id)),
1819
)
1920
return parse_response_model(
2021
response.data,
@@ -32,7 +33,7 @@ def get_agent_task_status(
3233
operation_name: str,
3334
) -> T:
3435
response = client.transport.get(
35-
client._build_url(f"{route_prefix}/{job_id}/status"),
36+
client._build_url(build_job_status_route(route_prefix, job_id)),
3637
)
3738
return parse_response_model(
3839
response.data,
@@ -50,7 +51,7 @@ async def get_agent_task_async(
5051
operation_name: str,
5152
) -> T:
5253
response = await client.transport.get(
53-
client._build_url(f"{route_prefix}/{job_id}"),
54+
client._build_url(build_job_route(route_prefix, job_id)),
5455
)
5556
return parse_response_model(
5657
response.data,
@@ -68,7 +69,7 @@ async def get_agent_task_status_async(
6869
operation_name: str,
6970
) -> T:
7071
response = await client.transport.get(
71-
client._build_url(f"{route_prefix}/{job_id}/status"),
72+
client._build_url(build_job_status_route(route_prefix, job_id)),
7273
)
7374
return parse_response_model(
7475
response.data,

hyperbrowser/client/managers/job_route_builders.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,11 @@ def build_job_status_route(
1010
job_id: str,
1111
) -> str:
1212
return f"{route_prefix}/{job_id}/status"
13+
14+
15+
def build_job_action_route(
16+
route_prefix: str,
17+
job_id: str,
18+
action_suffix: str,
19+
) -> str:
20+
return f"{route_prefix}/{job_id}{action_suffix}"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
def test_agent_task_read_helpers_use_shared_job_route_builders():
9+
module_text = Path(
10+
"hyperbrowser/client/managers/agent_task_read_utils.py"
11+
).read_text(encoding="utf-8")
12+
assert "job_route_builders import build_job_route, build_job_status_route" in module_text
13+
assert "build_job_route(route_prefix, job_id)" in module_text
14+
assert "build_job_status_route(route_prefix, job_id)" in module_text
15+
assert 'f"{route_prefix}/{job_id}"' not in module_text
16+
assert 'f"{route_prefix}/{job_id}/status"' not in module_text
17+
18+
19+
def test_agent_stop_helpers_use_shared_job_route_builders():
20+
module_text = Path("hyperbrowser/client/managers/agent_stop_utils.py").read_text(
21+
encoding="utf-8"
22+
)
23+
assert "job_route_builders import build_job_action_route" in module_text
24+
assert 'build_job_action_route(route_prefix, job_id, "/stop")' in module_text
25+
assert 'f"{route_prefix}/{job_id}/stop"' not in module_text

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"tests/test_agent_helper_boundary.py",
1111
"tests/test_agent_operation_metadata_usage.py",
1212
"tests/test_agent_payload_helper_usage.py",
13+
"tests/test_agent_route_builder_usage.py",
1314
"tests/test_agent_start_helper_usage.py",
1415
"tests/test_agent_task_read_helper_usage.py",
1516
"tests/test_agent_stop_helper_usage.py",

tests/test_job_route_builders.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from hyperbrowser.client.managers.job_route_builders import (
2+
build_job_action_route,
23
build_job_route,
34
build_job_status_route,
45
)
@@ -15,3 +16,10 @@ def test_build_job_status_route_composes_job_status_route_path():
1516
build_job_status_route("/web/crawl", "job_456")
1617
== "/web/crawl/job_456/status"
1718
)
19+
20+
21+
def test_build_job_action_route_composes_job_action_route_path():
22+
assert (
23+
build_job_action_route("/task/browser-use", "job_123", "/stop")
24+
== "/task/browser-use/job_123/stop"
25+
)

0 commit comments

Comments
 (0)