@@ -195,6 +195,62 @@ def __getitem__(self, key: str) -> object:
195195 assert exc_info .value .original_error is not None
196196
197197
198+ def test_scrape_tool_preserves_hyperbrowser_mapping_inspection_failures ():
199+ class _BrokenContainsResponse (Mapping [str , object ]):
200+ def __iter__ (self ):
201+ yield "data"
202+
203+ def __len__ (self ) -> int :
204+ return 1
205+
206+ def __contains__ (self , key : object ) -> bool :
207+ _ = key
208+ raise HyperbrowserError ("custom contains failure" )
209+
210+ def __getitem__ (self , key : str ) -> object :
211+ _ = key
212+ return {"markdown" : "ok" }
213+
214+ client = _SyncScrapeClient (_BrokenContainsResponse ()) # type: ignore[arg-type]
215+
216+ with pytest .raises (HyperbrowserError , match = "custom contains failure" ) as exc_info :
217+ WebsiteScrapeTool .runnable (client , {"url" : "https://example.com" })
218+
219+ assert exc_info .value .original_error is None
220+
221+
222+ def test_scrape_tool_preserves_hyperbrowser_mapping_data_read_failures ():
223+ class _BrokenResponse (Mapping [str , object ]):
224+ def __iter__ (self ):
225+ yield "data"
226+
227+ def __len__ (self ) -> int :
228+ return 1
229+
230+ def __contains__ (self , key : object ) -> bool :
231+ return key == "data"
232+
233+ def __getitem__ (self , key : str ) -> object :
234+ _ = key
235+ raise HyperbrowserError ("custom data read failure" )
236+
237+ client = _SyncScrapeClient (_BrokenResponse ()) # type: ignore[arg-type]
238+
239+ with pytest .raises (HyperbrowserError , match = "custom data read failure" ) as exc_info :
240+ WebsiteScrapeTool .runnable (client , {"url" : "https://example.com" })
241+
242+ assert exc_info .value .original_error is None
243+
244+
245+ def test_scrape_tool_rejects_object_responses_without_data_attribute ():
246+ client = _SyncScrapeClient (object ()) # type: ignore[arg-type]
247+
248+ with pytest .raises (
249+ HyperbrowserError , match = "scrape tool response must include 'data'"
250+ ):
251+ WebsiteScrapeTool .runnable (client , {"url" : "https://example.com" })
252+
253+
198254def test_scrape_tool_preserves_hyperbrowser_response_data_read_failures ():
199255 client = _SyncScrapeClient (
200256 _Response (data_error = HyperbrowserError ("custom scrape data failure" ))
0 commit comments