@@ -46,7 +46,7 @@ def test_missing_key_raises_official_error_without_secret(
4646
4747
4848@pytest .mark .parametrize ("client_type" , [CometAPI , AsyncCometAPI ])
49- @pytest .mark .parametrize ("api_key" , ["" , " " ])
49+ @pytest .mark .parametrize ("api_key" , ["" , " " , " \ufeff " , " \ufeff \t " ])
5050def test_explicit_blank_key_does_not_fall_back_to_environment (
5151 client_type : type [CometAPI ] | type [AsyncCometAPI ],
5252 api_key : str ,
@@ -61,11 +61,13 @@ def test_explicit_blank_key_does_not_fall_back_to_environment(
6161
6262
6363@pytest .mark .parametrize ("client_type" , [CometAPI , AsyncCometAPI ])
64+ @pytest .mark .parametrize ("environment_key" , [" \t " , "\ufeff " , " \ufeff \t " ])
6465def test_whitespace_environment_key_is_treated_as_missing (
6566 client_type : type [CometAPI ] | type [AsyncCometAPI ],
67+ environment_key : str ,
6668 monkeypatch : pytest .MonkeyPatch ,
6769) -> None :
68- monkeypatch .setenv ("COMETAPI_KEY" , " \t " )
70+ monkeypatch .setenv ("COMETAPI_KEY" , environment_key )
6971 monkeypatch .setenv ("OPENAI_API_KEY" , "upstream-environment-key" )
7072
7173 with pytest .raises (OpenAIError ) as caught :
@@ -93,7 +95,11 @@ def test_explicit_sync_key_is_trimmed() -> None:
9395 router = ContractRouter ()
9496 http_client = sync_http_client (router )
9597
96- with CometAPI (api_key = f" { API_KEY } \t " , base_url = BASE_URL , http_client = http_client ) as client :
98+ with CometAPI (
99+ api_key = f" \ufeff { API_KEY } \ufeff \t " ,
100+ base_url = BASE_URL ,
101+ http_client = http_client ,
102+ ) as client :
97103 client .models .list ()
98104
99105 assert router .requests [0 ].headers ["authorization" ] == f"Bearer { API_KEY } "
@@ -123,7 +129,7 @@ async def test_explicit_async_key_is_trimmed() -> None:
123129 http_client = async_http_client (router )
124130
125131 async with AsyncCometAPI (
126- api_key = f" { API_KEY } \t " ,
132+ api_key = f" \ufeff { API_KEY } \ufeff \t " ,
127133 base_url = BASE_URL ,
128134 http_client = http_client ,
129135 ) as client :
@@ -171,7 +177,7 @@ def test_explicit_base_url_takes_precedence_over_environment(
171177
172178
173179@pytest .mark .parametrize ("client_type" , [CometAPI , AsyncCometAPI ])
174- @pytest .mark .parametrize ("base_url" , ["" , " " ])
180+ @pytest .mark .parametrize ("base_url" , ["" , " " , " \ufeff " , " \ufeff \t " ])
175181def test_explicit_blank_base_url_does_not_fall_back_to_environment (
176182 client_type : type [CometAPI ] | type [AsyncCometAPI ],
177183 base_url : str ,
@@ -184,7 +190,7 @@ def test_explicit_blank_base_url_does_not_fall_back_to_environment(
184190
185191
186192def test_explicit_sync_string_base_url_is_trimmed () -> None :
187- client = CometAPI (api_key = API_KEY , base_url = f" { BASE_URL } \t " )
193+ client = CometAPI (api_key = API_KEY , base_url = f" \ufeff { BASE_URL } \ufeff \t " )
188194 try :
189195 assert str (client .base_url ) == f"{ BASE_URL } /"
190196 finally :
@@ -248,10 +254,12 @@ def test_default_base_url_is_used_when_no_override_exists(
248254 client .close ()
249255
250256
257+ @pytest .mark .parametrize ("environment_url" , [" \t " , "\ufeff " , " \ufeff \t " ])
251258def test_whitespace_environment_base_url_uses_cometapi_default (
259+ environment_url : str ,
252260 monkeypatch : pytest .MonkeyPatch ,
253261) -> None :
254- monkeypatch .setenv ("COMETAPI_BASE_URL" , " \t " )
262+ monkeypatch .setenv ("COMETAPI_BASE_URL" , environment_url )
255263 monkeypatch .setenv ("OPENAI_BASE_URL" , "https://upstream.example.test/v1" )
256264
257265 client = CometAPI (api_key = API_KEY )
@@ -262,10 +270,12 @@ def test_whitespace_environment_base_url_uses_cometapi_default(
262270
263271
264272@pytest .mark .asyncio
273+ @pytest .mark .parametrize ("environment_url" , [" \t " , "\ufeff " , " \ufeff \t " ])
265274async def test_async_whitespace_environment_base_url_uses_cometapi_default (
275+ environment_url : str ,
266276 monkeypatch : pytest .MonkeyPatch ,
267277) -> None :
268- monkeypatch .setenv ("COMETAPI_BASE_URL" , " \t " )
278+ monkeypatch .setenv ("COMETAPI_BASE_URL" , environment_url )
269279 monkeypatch .setenv ("OPENAI_BASE_URL" , "https://upstream.example.test/v1" )
270280
271281 client = AsyncCometAPI (api_key = API_KEY )
0 commit comments