Skip to content

Commit a451f57

Browse files
Centralize web manager operation metadata
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent cbccec7 commit a451f57

10 files changed

Lines changed: 110 additions & 20 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ This runs lint, format checks, compile checks, tests, and package build.
133133
- `tests/test_started_job_helper_boundary.py` (centralization boundary enforcement for started-job helper primitives),
134134
- `tests/test_tool_mapping_reader_usage.py` (tools mapping-helper usage),
135135
- `tests/test_type_utils_usage.py` (type `__mro__` boundary centralization in `hyperbrowser/type_utils.py`),
136+
- `tests/test_web_operation_metadata_usage.py` (web manager operation-metadata usage enforcement),
136137
- `tests/test_web_pagination_internal_reuse.py` (web pagination helper internal reuse of shared job pagination helpers),
137138
- `tests/test_web_payload_helper_usage.py` (web manager payload-helper usage enforcement),
138139
- `tests/test_web_route_constants_usage.py` (web manager route-constant usage enforcement).

hyperbrowser/client/managers/async_manager/web/batch_fetch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_operation_metadata import BATCH_FETCH_OPERATION_METADATA
1213
from ...web_route_constants import BATCH_FETCH_JOB_ROUTE_PREFIX
1314
from ...web_payload_utils import build_batch_fetch_start_payload
1415
from ...web_payload_utils import build_batch_fetch_get_params
@@ -35,6 +36,7 @@
3536

3637

3738
class BatchFetchManager:
39+
_OPERATION_METADATA = BATCH_FETCH_OPERATION_METADATA
3840
_ROUTE_PREFIX = BATCH_FETCH_JOB_ROUTE_PREFIX
3941

4042
def __init__(self, client):
@@ -52,7 +54,7 @@ async def start(
5254
return parse_response_model(
5355
response.data,
5456
model=StartBatchFetchJobResponse,
55-
operation_name="batch fetch start",
57+
operation_name=self._OPERATION_METADATA.start_operation_name,
5658
)
5759

5860
async def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
@@ -62,7 +64,7 @@ async def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
6264
return parse_response_model(
6365
response.data,
6466
model=BatchFetchJobStatusResponse,
65-
operation_name="batch fetch status",
67+
operation_name=self._OPERATION_METADATA.status_operation_name,
6668
)
6769

6870
async def get(
@@ -76,7 +78,7 @@ async def get(
7678
return parse_response_model(
7779
response.data,
7880
model=BatchFetchJobResponse,
79-
operation_name="batch fetch job",
81+
operation_name=self._OPERATION_METADATA.job_operation_name,
8082
)
8183

8284
async def start_and_wait(
@@ -90,8 +92,8 @@ async def start_and_wait(
9092
job_start_resp = await self.start(params)
9193
job_id, operation_name = build_started_job_context(
9294
started_job_id=job_start_resp.job_id,
93-
start_error_message="Failed to start batch fetch job",
94-
operation_name_prefix="batch fetch job ",
95+
start_error_message=self._OPERATION_METADATA.start_error_message,
96+
operation_name_prefix=self._OPERATION_METADATA.operation_name_prefix,
9597
)
9698

9799
job_status = await poll_until_terminal_status_async(

hyperbrowser/client/managers/async_manager/web/crawl.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_operation_metadata import WEB_CRAWL_OPERATION_METADATA
1213
from ...web_route_constants import WEB_CRAWL_JOB_ROUTE_PREFIX
1314
from ...web_payload_utils import build_web_crawl_start_payload
1415
from ...web_payload_utils import build_web_crawl_get_params
@@ -35,6 +36,7 @@
3536

3637

3738
class WebCrawlManager:
39+
_OPERATION_METADATA = WEB_CRAWL_OPERATION_METADATA
3840
_ROUTE_PREFIX = WEB_CRAWL_JOB_ROUTE_PREFIX
3941

4042
def __init__(self, client):
@@ -50,7 +52,7 @@ async def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobRespons
5052
return parse_response_model(
5153
response.data,
5254
model=StartWebCrawlJobResponse,
53-
operation_name="web crawl start",
55+
operation_name=self._OPERATION_METADATA.start_operation_name,
5456
)
5557

5658
async def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
@@ -60,7 +62,7 @@ async def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
6062
return parse_response_model(
6163
response.data,
6264
model=WebCrawlJobStatusResponse,
63-
operation_name="web crawl status",
65+
operation_name=self._OPERATION_METADATA.status_operation_name,
6466
)
6567

6668
async def get(
@@ -74,7 +76,7 @@ async def get(
7476
return parse_response_model(
7577
response.data,
7678
model=WebCrawlJobResponse,
77-
operation_name="web crawl job",
79+
operation_name=self._OPERATION_METADATA.job_operation_name,
7880
)
7981

8082
async def start_and_wait(
@@ -88,8 +90,8 @@ async def start_and_wait(
8890
job_start_resp = await self.start(params)
8991
job_id, operation_name = build_started_job_context(
9092
started_job_id=job_start_resp.job_id,
91-
start_error_message="Failed to start web crawl job",
92-
operation_name_prefix="web crawl job ",
93+
start_error_message=self._OPERATION_METADATA.start_error_message,
94+
operation_name_prefix=self._OPERATION_METADATA.operation_name_prefix,
9395
)
9496

9597
job_status = await poll_until_terminal_status_async(

hyperbrowser/client/managers/sync_manager/web/batch_fetch.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_operation_metadata import BATCH_FETCH_OPERATION_METADATA
1213
from ...web_route_constants import BATCH_FETCH_JOB_ROUTE_PREFIX
1314
from ...web_payload_utils import build_batch_fetch_start_payload
1415
from ...web_payload_utils import build_batch_fetch_get_params
@@ -35,6 +36,7 @@
3536

3637

3738
class BatchFetchManager:
39+
_OPERATION_METADATA = BATCH_FETCH_OPERATION_METADATA
3840
_ROUTE_PREFIX = BATCH_FETCH_JOB_ROUTE_PREFIX
3941

4042
def __init__(self, client):
@@ -50,7 +52,7 @@ def start(self, params: StartBatchFetchJobParams) -> StartBatchFetchJobResponse:
5052
return parse_response_model(
5153
response.data,
5254
model=StartBatchFetchJobResponse,
53-
operation_name="batch fetch start",
55+
operation_name=self._OPERATION_METADATA.start_operation_name,
5456
)
5557

5658
def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
@@ -60,7 +62,7 @@ def get_status(self, job_id: str) -> BatchFetchJobStatusResponse:
6062
return parse_response_model(
6163
response.data,
6264
model=BatchFetchJobStatusResponse,
63-
operation_name="batch fetch status",
65+
operation_name=self._OPERATION_METADATA.status_operation_name,
6466
)
6567

6668
def get(
@@ -74,7 +76,7 @@ def get(
7476
return parse_response_model(
7577
response.data,
7678
model=BatchFetchJobResponse,
77-
operation_name="batch fetch job",
79+
operation_name=self._OPERATION_METADATA.job_operation_name,
7880
)
7981

8082
def start_and_wait(
@@ -88,8 +90,8 @@ def start_and_wait(
8890
job_start_resp = self.start(params)
8991
job_id, operation_name = build_started_job_context(
9092
started_job_id=job_start_resp.job_id,
91-
start_error_message="Failed to start batch fetch job",
92-
operation_name_prefix="batch fetch job ",
93+
start_error_message=self._OPERATION_METADATA.start_error_message,
94+
operation_name_prefix=self._OPERATION_METADATA.operation_name_prefix,
9395
)
9496

9597
job_status = poll_until_terminal_status(

hyperbrowser/client/managers/sync_manager/web/crawl.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
)
1010
from ...page_params_utils import build_page_batch_params
1111
from ...job_status_utils import is_default_terminal_job_status
12+
from ...web_operation_metadata import WEB_CRAWL_OPERATION_METADATA
1213
from ...web_route_constants import WEB_CRAWL_JOB_ROUTE_PREFIX
1314
from ...web_payload_utils import build_web_crawl_start_payload
1415
from ...web_payload_utils import build_web_crawl_get_params
@@ -33,6 +34,7 @@
3334

3435

3536
class WebCrawlManager:
37+
_OPERATION_METADATA = WEB_CRAWL_OPERATION_METADATA
3638
_ROUTE_PREFIX = WEB_CRAWL_JOB_ROUTE_PREFIX
3739

3840
def __init__(self, client):
@@ -48,7 +50,7 @@ def start(self, params: StartWebCrawlJobParams) -> StartWebCrawlJobResponse:
4850
return parse_response_model(
4951
response.data,
5052
model=StartWebCrawlJobResponse,
51-
operation_name="web crawl start",
53+
operation_name=self._OPERATION_METADATA.start_operation_name,
5254
)
5355

5456
def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
@@ -58,7 +60,7 @@ def get_status(self, job_id: str) -> WebCrawlJobStatusResponse:
5860
return parse_response_model(
5961
response.data,
6062
model=WebCrawlJobStatusResponse,
61-
operation_name="web crawl status",
63+
operation_name=self._OPERATION_METADATA.status_operation_name,
6264
)
6365

6466
def get(
@@ -72,7 +74,7 @@ def get(
7274
return parse_response_model(
7375
response.data,
7476
model=WebCrawlJobResponse,
75-
operation_name="web crawl job",
77+
operation_name=self._OPERATION_METADATA.job_operation_name,
7678
)
7779

7880
def start_and_wait(
@@ -86,8 +88,8 @@ def start_and_wait(
8688
job_start_resp = self.start(params)
8789
job_id, operation_name = build_started_job_context(
8890
started_job_id=job_start_resp.job_id,
89-
start_error_message="Failed to start web crawl job",
90-
operation_name_prefix="web crawl job ",
91+
start_error_message=self._OPERATION_METADATA.start_error_message,
92+
operation_name_prefix=self._OPERATION_METADATA.operation_name_prefix,
9193
)
9294

9395
job_status = poll_until_terminal_status(
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass(frozen=True)
5+
class WebOperationMetadata:
6+
start_operation_name: str
7+
status_operation_name: str
8+
job_operation_name: str
9+
start_error_message: str
10+
operation_name_prefix: str
11+
12+
13+
BATCH_FETCH_OPERATION_METADATA = WebOperationMetadata(
14+
start_operation_name="batch fetch start",
15+
status_operation_name="batch fetch status",
16+
job_operation_name="batch fetch job",
17+
start_error_message="Failed to start batch fetch job",
18+
operation_name_prefix="batch fetch job ",
19+
)
20+
21+
WEB_CRAWL_OPERATION_METADATA = WebOperationMetadata(
22+
start_operation_name="web crawl start",
23+
status_operation_name="web crawl status",
24+
job_operation_name="web crawl job",
25+
start_error_message="Failed to start web crawl job",
26+
operation_name_prefix="web crawl job ",
27+
)

tests/test_architecture_marker_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"tests/test_start_and_wait_default_constants_usage.py",
6464
"tests/test_start_job_context_helper_usage.py",
6565
"tests/test_started_job_helper_boundary.py",
66+
"tests/test_web_operation_metadata_usage.py",
6667
"tests/test_web_pagination_internal_reuse.py",
6768
"tests/test_web_payload_helper_usage.py",
6869
"tests/test_web_route_constants_usage.py",

tests/test_core_type_helper_usage.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"hyperbrowser/client/managers/polling_defaults.py",
4949
"hyperbrowser/client/managers/session_upload_utils.py",
5050
"hyperbrowser/client/managers/session_profile_update_utils.py",
51+
"hyperbrowser/client/managers/web_operation_metadata.py",
5152
"hyperbrowser/client/managers/web_route_constants.py",
5253
"hyperbrowser/client/managers/web_pagination_utils.py",
5354
"hyperbrowser/client/managers/web_payload_utils.py",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from hyperbrowser.client.managers.web_operation_metadata import (
2+
BATCH_FETCH_OPERATION_METADATA,
3+
WEB_CRAWL_OPERATION_METADATA,
4+
)
5+
6+
7+
def test_batch_fetch_operation_metadata_values():
8+
assert BATCH_FETCH_OPERATION_METADATA.start_operation_name == "batch fetch start"
9+
assert BATCH_FETCH_OPERATION_METADATA.status_operation_name == "batch fetch status"
10+
assert BATCH_FETCH_OPERATION_METADATA.job_operation_name == "batch fetch job"
11+
assert (
12+
BATCH_FETCH_OPERATION_METADATA.start_error_message
13+
== "Failed to start batch fetch job"
14+
)
15+
assert BATCH_FETCH_OPERATION_METADATA.operation_name_prefix == "batch fetch job "
16+
17+
18+
def test_web_crawl_operation_metadata_values():
19+
assert WEB_CRAWL_OPERATION_METADATA.start_operation_name == "web crawl start"
20+
assert WEB_CRAWL_OPERATION_METADATA.status_operation_name == "web crawl status"
21+
assert WEB_CRAWL_OPERATION_METADATA.job_operation_name == "web crawl job"
22+
assert (
23+
WEB_CRAWL_OPERATION_METADATA.start_error_message
24+
== "Failed to start web crawl job"
25+
)
26+
assert WEB_CRAWL_OPERATION_METADATA.operation_name_prefix == "web crawl job "
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from pathlib import Path
2+
3+
import pytest
4+
5+
pytestmark = pytest.mark.architecture
6+
7+
8+
MODULES = (
9+
"hyperbrowser/client/managers/sync_manager/web/batch_fetch.py",
10+
"hyperbrowser/client/managers/async_manager/web/batch_fetch.py",
11+
"hyperbrowser/client/managers/sync_manager/web/crawl.py",
12+
"hyperbrowser/client/managers/async_manager/web/crawl.py",
13+
)
14+
15+
16+
def test_web_managers_use_shared_operation_metadata():
17+
for module_path in MODULES:
18+
module_text = Path(module_path).read_text(encoding="utf-8")
19+
assert "web_operation_metadata import" in module_text
20+
assert "_OPERATION_METADATA = " in module_text
21+
assert "operation_name=self._OPERATION_METADATA." in module_text
22+
assert "start_error_message=self._OPERATION_METADATA." in module_text
23+
assert "operation_name_prefix=self._OPERATION_METADATA." in module_text
24+
assert 'operation_name="' not in module_text
25+
assert 'start_error_message="' not in module_text
26+
assert 'operation_name_prefix="' not in module_text

0 commit comments

Comments
 (0)