File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -153,7 +153,7 @@ def _serialize_extract_tool_data(data: Any) -> str:
153153 if data is None :
154154 return ""
155155 try :
156- return json .dumps (data )
156+ return json .dumps (data , allow_nan = False )
157157 except HyperbrowserError :
158158 raise
159159 except Exception as exc :
Original file line number Diff line number Diff line change 11import asyncio
22from collections .abc import Mapping
3+ import math
34from types import MappingProxyType
45
56import pytest
@@ -371,6 +372,33 @@ async def run():
371372 assert exc_info .value .original_error is not None
372373
373374
375+ def test_extract_tool_runnable_rejects_nan_json_payloads ():
376+ client = _SyncClient (response_data = {"value" : math .nan })
377+
378+ with pytest .raises (
379+ HyperbrowserError , match = "Failed to serialize extract tool response data"
380+ ) as exc_info :
381+ WebsiteExtractTool .runnable (client , {"urls" : ["https://example.com" ]})
382+
383+ assert exc_info .value .original_error is not None
384+
385+
386+ def test_extract_tool_async_runnable_rejects_nan_json_payloads ():
387+ client = _AsyncClient (response_data = {"value" : math .nan })
388+
389+ async def run ():
390+ return await WebsiteExtractTool .async_runnable (
391+ client , {"urls" : ["https://example.com" ]}
392+ )
393+
394+ with pytest .raises (
395+ HyperbrowserError , match = "Failed to serialize extract tool response data"
396+ ) as exc_info :
397+ asyncio .run (run ())
398+
399+ assert exc_info .value .original_error is not None
400+
401+
374402def test_extract_tool_runnable_wraps_unexpected_schema_parse_failures (
375403 monkeypatch : pytest .MonkeyPatch ,
376404):
You can’t perform that action at this time.
0 commit comments