@@ -211,6 +211,58 @@ def test_client_config_rejects_non_string_values():
211211 ClientConfig (api_key = "bad\n key" )
212212
213213
214+ def test_client_config_normalize_base_url_wraps_strip_runtime_errors ():
215+ class _BrokenBaseUrl (str ):
216+ def strip (self , chars = None ): # type: ignore[override]
217+ _ = chars
218+ raise RuntimeError ("base_url strip exploded" )
219+
220+ with pytest .raises (HyperbrowserError , match = "Failed to normalize base_url" ) as exc_info :
221+ ClientConfig .normalize_base_url (_BrokenBaseUrl ("https://example.local" ))
222+
223+ assert isinstance (exc_info .value .original_error , RuntimeError )
224+
225+
226+ def test_client_config_normalize_base_url_preserves_hyperbrowser_strip_errors ():
227+ class _BrokenBaseUrl (str ):
228+ def strip (self , chars = None ): # type: ignore[override]
229+ _ = chars
230+ raise HyperbrowserError ("custom base_url strip failure" )
231+
232+ with pytest .raises (
233+ HyperbrowserError , match = "custom base_url strip failure"
234+ ) as exc_info :
235+ ClientConfig .normalize_base_url (_BrokenBaseUrl ("https://example.local" ))
236+
237+ assert exc_info .value .original_error is None
238+
239+
240+ def test_client_config_normalize_base_url_wraps_non_string_strip_results ():
241+ class _BrokenBaseUrl (str ):
242+ def strip (self , chars = None ): # type: ignore[override]
243+ _ = chars
244+ return object ()
245+
246+ with pytest .raises (HyperbrowserError , match = "Failed to normalize base_url" ) as exc_info :
247+ ClientConfig .normalize_base_url (_BrokenBaseUrl ("https://example.local" ))
248+
249+ assert isinstance (exc_info .value .original_error , TypeError )
250+
251+
252+ def test_client_config_resolve_base_url_from_env_wraps_strip_runtime_errors ():
253+ class _BrokenBaseUrl (str ):
254+ def strip (self , chars = None ): # type: ignore[override]
255+ _ = chars
256+ raise RuntimeError ("environment base_url strip exploded" )
257+
258+ with pytest .raises (
259+ HyperbrowserError , match = "Failed to normalize HYPERBROWSER_BASE_URL"
260+ ) as exc_info :
261+ ClientConfig .resolve_base_url_from_env (_BrokenBaseUrl ("https://example.local" ))
262+
263+ assert isinstance (exc_info .value .original_error , RuntimeError )
264+
265+
214266def test_client_config_wraps_api_key_strip_runtime_errors ():
215267 class _BrokenApiKey (str ):
216268 def strip (self , chars = None ): # type: ignore[override]
0 commit comments