Skip to content

Commit 549ea4a

Browse files
Require concrete list crawl responses in tool wrappers
Co-authored-by: Shri Sukhani <shrisukhani@users.noreply.github.com>
1 parent a640487 commit 549ea4a

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

hyperbrowser/tools/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def _read_crawl_page_field(page: Any, *, field_name: str, page_index: int) -> An
426426
def _render_crawl_markdown_output(response_data: Any) -> str:
427427
if response_data is None:
428428
return ""
429-
if not isinstance(response_data, list):
429+
if type(response_data) is not list:
430430
raise HyperbrowserError("crawl tool response data must be a list")
431431
try:
432432
crawl_pages = list(response_data)

tests/test_tools_response_handling.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -838,19 +838,19 @@ def test_crawl_tool_uses_unknown_url_for_blank_page_urls():
838838
assert "page body" in output
839839

840840

841-
def test_crawl_tool_wraps_response_iteration_failures():
841+
def test_crawl_tool_rejects_list_subclass_response_data():
842842
class _BrokenList(list):
843843
def __iter__(self):
844844
raise RuntimeError("cannot iterate pages")
845845

846846
client = _SyncCrawlClient(_Response(data=_BrokenList([SimpleNamespace()])))
847847

848848
with pytest.raises(
849-
HyperbrowserError, match="Failed to iterate crawl tool response data"
849+
HyperbrowserError, match="crawl tool response data must be a list"
850850
) as exc_info:
851851
WebsiteCrawlTool.runnable(client, {"url": "https://example.com"})
852852

853-
assert exc_info.value.original_error is not None
853+
assert exc_info.value.original_error is None
854854

855855

856856
def test_browser_use_tool_rejects_non_string_final_result():
@@ -1154,6 +1154,24 @@ async def run() -> None:
11541154
asyncio.run(run())
11551155

11561156

1157+
def test_async_crawl_tool_rejects_list_subclass_response_data():
1158+
class _BrokenList(list):
1159+
def __iter__(self):
1160+
raise RuntimeError("cannot iterate pages")
1161+
1162+
async def run() -> None:
1163+
client = _AsyncCrawlClient(_Response(data=_BrokenList([SimpleNamespace()])))
1164+
with pytest.raises(
1165+
HyperbrowserError, match="crawl tool response data must be a list"
1166+
) as exc_info:
1167+
await WebsiteCrawlTool.async_runnable(
1168+
client, {"url": "https://example.com"}
1169+
)
1170+
assert exc_info.value.original_error is None
1171+
1172+
asyncio.run(run())
1173+
1174+
11571175
def test_async_browser_use_tool_rejects_non_string_final_result():
11581176
async def run() -> None:
11591177
client = _AsyncBrowserUseClient(

0 commit comments

Comments
 (0)