Skip to content

Commit e77ed2b

Browse files
Tahtaclaude
andcommitted
Default to https://api.cleanedweb.com: the broker has no /v1/runs routes and refuses customer keys
The run, result, items and abort routes, schedules and catalog runs all live on the API origin, and the relative Location and links in run responses only resolve there (cleanedweb-openapi FINDINGS.md, finding 1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7e89dbb commit e77ed2b

4 files changed

Lines changed: 24 additions & 22 deletions

File tree

‎src/cleanedweb/_core.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .exceptions import CleanedWebError, error_from_response
1515
from .models import ApiContract, CatalogApi, EndpointContract, RunResult
1616

17-
DEFAULT_BASE_URL = "https://broker.cleanedweb.com"
17+
DEFAULT_BASE_URL = "https://api.cleanedweb.com"
1818
DEFAULT_APP_URL = "https://app.cleanedweb.com"
1919
DEFAULT_SITE_URL = "https://cleanedweb.com"
2020
USER_AGENT = f"cleanedweb-python/{__version__}"
@@ -109,7 +109,7 @@ def raise_for_response(response: httpx.Response, *, idempotency_key: Optional[st
109109
if response.status_code < 400: # a redirect means the request went to the wrong origin
110110
raise CleanedWebError(
111111
f"HTTP {response.status_code} redirect from {response.request.url}: "
112-
"nothing ran; check the base_url (runs go to https://broker.cleanedweb.com)"
112+
"nothing ran; check the base_url (runs go to https://api.cleanedweb.com)"
113113
)
114114
raise error_from_response(
115115
response.status_code, body, dict(response.headers), idempotency_key=idempotency_key

‎tests/conftest.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import pytest
66

7-
BROKER = "https://broker.cleanedweb.com"
7+
API_ORIGIN = "https://api.cleanedweb.com"
88
APP = "https://app.cleanedweb.com"
99
SITE = "https://cleanedweb.com"
1010
API_ID = "generated_aaaaaaaaaaaaaaaaaaaaaaaa"
1111
ENDPOINT_ID = f"{API_ID}_search"
12-
RUN_BASE = f"{BROKER}/v1/catalog/public/apis/{API_ID}/endpoints/{ENDPOINT_ID}"
12+
RUN_BASE = f"{API_ORIGIN}/v1/catalog/public/apis/{API_ID}/endpoints/{ENDPOINT_ID}"
1313
RUN_ID = "0123456789abcdef0123456789abcdef"
1414

1515

‎tests/test_async.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
from .conftest import (
2121
API_ID,
22+
API_ORIGIN,
2223
APP,
23-
BROKER,
2424
ENDPOINT_ID,
2525
INDEX,
2626
LIVE_ITEMS,
@@ -135,8 +135,8 @@ async def test_missing_key(monkeypatch: pytest.MonkeyPatch) -> None:
135135
async def test_result_get_abort_list(cw: AsyncCleanedWeb) -> None:
136136
respx.get(f"{RUN_BASE}/result").mock(return_value=httpx.Response(200, json=final_body()))
137137
assert (await cw.catalog.result(API_ID, ENDPOINT_ID, "k")).complete
138-
respx.get(f"{BROKER}/v1/runs/{RUN_ID}").mock(return_value=httpx.Response(200, json=run_object()))
139-
respx.post(f"{BROKER}/v1/runs/{RUN_ID}/abort").mock(
138+
respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}").mock(return_value=httpx.Response(200, json=run_object()))
139+
respx.post(f"{API_ORIGIN}/v1/runs/{RUN_ID}/abort").mock(
140140
return_value=httpx.Response(202, json={**run_object(), "abort_requested": True})
141141
)
142142
assert (await cw.runs.get(RUN_ID)).status == "running"
@@ -147,7 +147,7 @@ def pages(request: httpx.Request) -> httpx.Response:
147147
return httpx.Response(200, json={"runs": [run_object("finished")], "next_cursor": "c2"})
148148
return httpx.Response(200, json={"runs": [run_object("failed")], "next_cursor": None})
149149

150-
respx.get(f"{BROKER}/v1/runs").mock(side_effect=pages)
150+
respx.get(f"{API_ORIGIN}/v1/runs").mock(side_effect=pages)
151151
assert [r.status for r in [r async for r in cw.runs.iter()]] == ["finished", "failed"]
152152

153153

@@ -159,7 +159,7 @@ async def test_runs_items_pagination(cw: AsyncCleanedWeb, sleeps: List[float]) -
159159
{"items": [{"n": 3}], "next_cursor": 3},
160160
{"items": [], "next_cursor": None},
161161
]
162-
route = respx.get(f"{BROKER}/v1/runs/{RUN_ID}/items").mock(
162+
route = respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/items").mock(
163163
side_effect=[httpx.Response(200, json=r) for r in responses]
164164
)
165165
assert [i["n"] for i in [i async for i in cw.runs.items(RUN_ID)]] == [1, 2]
@@ -170,14 +170,14 @@ async def test_runs_items_pagination(cw: AsyncCleanedWeb, sleeps: List[float]) -
170170

171171
@respx.mock
172172
async def test_runs_result_and_sources_run(cw: AsyncCleanedWeb, sleeps: List[float]) -> None:
173-
respx.get(f"{BROKER}/v1/runs/{RUN_ID}/result").mock(
173+
respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/result").mock(
174174
side_effect=[
175175
httpx.Response(202, json=run_object(), headers={"Retry-After": "4"}),
176176
httpx.Response(200, json=final_body()),
177177
]
178178
)
179179
assert (await cw.runs.result(RUN_ID)).complete and sleeps == [4.0]
180-
respx.post(f"{BROKER}/v1/sources/src_1/run").mock(return_value=httpx.Response(200, json=final_body()))
180+
respx.post(f"{API_ORIGIN}/v1/sources/src_1/run").mock(return_value=httpx.Response(200, json=final_body()))
181181
assert (await cw.sources.run("src_1", {"q": 1}, max_items=2)).complete
182182
with pytest.raises(ValueError):
183183
await cw.sources.run("src_1", expected_version="a", definition_version="b")

‎tests/test_sync.py‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828

2929
from .conftest import (
3030
API_ID,
31+
API_ORIGIN,
3132
APP,
32-
BROKER,
3333
ENDPOINT_ID,
3434
INDEX,
3535
LIVE_ITEMS,
@@ -520,8 +520,8 @@ def test_base_url_is_overridable() -> None:
520520

521521
@respx.mock
522522
def test_runs_get_and_abort(cw: CleanedWeb) -> None:
523-
respx.get(f"{BROKER}/v1/runs/{RUN_ID}").mock(return_value=httpx.Response(200, json=run_object()))
524-
abort = respx.post(f"{BROKER}/v1/runs/{RUN_ID}/abort").mock(
523+
respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}").mock(return_value=httpx.Response(200, json=run_object()))
524+
abort = respx.post(f"{API_ORIGIN}/v1/runs/{RUN_ID}/abort").mock(
525525
return_value=httpx.Response(202, json={**run_object(), "abort_requested": True})
526526
)
527527
run = cw.runs.get(RUN_ID)
@@ -537,7 +537,7 @@ def test_runs_items_follows_cursor_pages(cw: CleanedWeb) -> None:
537537
"2": {"items": [{"n": 3}], "count": 1, "next_cursor": 3, "run_status": "finished"},
538538
"3": {"items": [], "count": 0, "next_cursor": None, "run_status": "finished"},
539539
}
540-
route = respx.get(f"{BROKER}/v1/runs/{RUN_ID}/items").mock(
540+
route = respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/items").mock(
541541
side_effect=lambda request: httpx.Response(200, json=pages[request.url.params["cursor"]])
542542
)
543543
assert [i["n"] for i in cw.runs.items(RUN_ID, limit=2)] == [1, 2, 3]
@@ -552,7 +552,7 @@ def test_runs_items_stops_on_empty_page_unless_following(cw: CleanedWeb, sleeps:
552552
{"items": [{"n": 2}], "next_cursor": 2, "run_status": "running"},
553553
{"items": [], "next_cursor": None, "run_status": "finished"},
554554
]
555-
route = respx.get(f"{BROKER}/v1/runs/{RUN_ID}/items").mock(
555+
route = respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/items").mock(
556556
side_effect=[httpx.Response(200, json=r) for r in responses]
557557
)
558558
assert [i["n"] for i in cw.runs.items(RUN_ID)] == [1]
@@ -563,7 +563,7 @@ def test_runs_items_stops_on_empty_page_unless_following(cw: CleanedWeb, sleeps:
563563

564564
@respx.mock
565565
def test_runs_result_waits_for_the_end(cw: CleanedWeb, sleeps: List[float]) -> None:
566-
respx.get(f"{BROKER}/v1/runs/{RUN_ID}/result").mock(
566+
respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/result").mock(
567567
side_effect=[
568568
httpx.Response(202, json=run_object(), headers={"Retry-After": "5"}),
569569
httpx.Response(200, json=final_body()),
@@ -575,7 +575,9 @@ def test_runs_result_waits_for_the_end(cw: CleanedWeb, sleeps: List[float]) -> N
575575

576576
@respx.mock
577577
def test_runs_result_wait_false_returns_the_running_run(cw: CleanedWeb) -> None:
578-
respx.get(f"{BROKER}/v1/runs/{RUN_ID}/result").mock(return_value=httpx.Response(202, json=run_object()))
578+
respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/result").mock(
579+
return_value=httpx.Response(202, json=run_object())
580+
)
579581
result = cw.runs.result(RUN_ID, wait=False)
580582
assert not result.complete and result.run["status"] == "running"
581583

@@ -589,7 +591,7 @@ def pages(request: httpx.Request) -> httpx.Response:
589591
200, json={"runs": [{**run_object("failed"), "run_id": "b" * 32}], "next_cursor": None}
590592
)
591593

592-
route = respx.get(f"{BROKER}/v1/runs").mock(side_effect=pages)
594+
route = respx.get(f"{API_ORIGIN}/v1/runs").mock(side_effect=pages)
593595
page = cw.runs.list(source_id="src", status="finished", limit=10)
594596
assert page.next_cursor == "c2" and page.runs[0].status == "finished"
595597
assert dict(route.calls[0].request.url.params) == {
@@ -605,10 +607,10 @@ def pages(request: httpx.Request) -> httpx.Response:
605607

606608
@respx.mock
607609
def test_sources_run_200_and_202(cw: CleanedWeb, sleeps: List[float]) -> None:
608-
post = respx.post(f"{BROKER}/v1/sources/src_1/run").mock(
610+
post = respx.post(f"{API_ORIGIN}/v1/sources/src_1/run").mock(
609611
side_effect=[httpx.Response(200, json=final_body()), httpx.Response(202, json=run_object())]
610612
)
611-
result_route = respx.get(f"{BROKER}/v1/runs/{RUN_ID}/result").mock(
613+
result_route = respx.get(f"{API_ORIGIN}/v1/runs/{RUN_ID}/result").mock(
612614
return_value=httpx.Response(200, json=final_body())
613615
)
614616
first = cw.sources.run("src_1", {"q": "x"}, max_items=3, expected_version="v" * 64, idempotency_key="s-1")
@@ -626,7 +628,7 @@ def test_sources_version_selectors_are_exclusive(cw: CleanedWeb) -> None:
626628

627629
@respx.mock
628630
def test_sources_version_conflict(cw: CleanedWeb) -> None:
629-
respx.post(f"{BROKER}/v1/sources/src_1/run").mock(
631+
respx.post(f"{API_ORIGIN}/v1/sources/src_1/run").mock(
630632
return_value=httpx.Response(409, json={"detail": {"code": "builder_definition_version_conflict"}})
631633
)
632634
with pytest.raises(VersionConflictError):

0 commit comments

Comments
 (0)