@@ -300,6 +300,46 @@ def strip(self, chars=None): # type: ignore[override]
300300 assert isinstance (exc_info .value .original_error , TypeError )
301301
302302
303+ @pytest .mark .parametrize ("runner" , [_run_scrape_tool_sync , _run_scrape_tool_async ])
304+ def test_tool_wrappers_wrap_param_key_empty_check_length_failures (runner ):
305+ class _BrokenStripKey (str ):
306+ class _NormalizedKey (str ):
307+ def __len__ (self ):
308+ raise RuntimeError ("tool param key length exploded" )
309+
310+ def strip (self , chars = None ): # type: ignore[override]
311+ _ = chars
312+ return self ._NormalizedKey ("url" )
313+
314+ with pytest .raises (
315+ HyperbrowserError , match = "Failed to normalize tool param key"
316+ ) as exc_info :
317+ runner ({_BrokenStripKey ("url" ): "https://example.com" })
318+
319+ assert isinstance (exc_info .value .original_error , RuntimeError )
320+
321+
322+ @pytest .mark .parametrize ("runner" , [_run_scrape_tool_sync , _run_scrape_tool_async ])
323+ def test_tool_wrappers_preserve_hyperbrowser_param_key_empty_check_length_failures (
324+ runner ,
325+ ):
326+ class _BrokenStripKey (str ):
327+ class _NormalizedKey (str ):
328+ def __len__ (self ):
329+ raise HyperbrowserError ("custom tool param key length failure" )
330+
331+ def strip (self , chars = None ): # type: ignore[override]
332+ _ = chars
333+ return self ._NormalizedKey ("url" )
334+
335+ with pytest .raises (
336+ HyperbrowserError , match = "custom tool param key length failure"
337+ ) as exc_info :
338+ runner ({_BrokenStripKey ("url" ): "https://example.com" })
339+
340+ assert exc_info .value .original_error is None
341+
342+
303343@pytest .mark .parametrize ("runner" , [_run_scrape_tool_sync , _run_scrape_tool_async ])
304344def test_tool_wrappers_wrap_param_key_character_validation_failures (runner ):
305345 class _BrokenIterKey (str ):
0 commit comments