@@ -212,44 +212,3 @@ async def test_console_logging_creates_async_logging_transport(self):
212212 mock_httpx .AsyncClient .return_value = object ()
213213 client .get_openai_client ()
214214 mock_httpx .AsyncClient .assert_called_once ()
215-
216-
217- # ===========================================================================
218- # User-Agent construction branches (async)
219- # ===========================================================================
220-
221-
222- class TestUserAgentBranchesAsync :
223- @pytest .mark .asyncio
224- async def test_caller_user_agent_used_verbatim (self ):
225- """Branch: 'User-Agent' in default_headers -> use as-is."""
226- client = make_async_client ()
227- mock_cls , _ = mock_openai ("openai/x" )
228- with patch (ASYNC_OPENAI_PATCH , mock_cls ), patch (ASYNC_TOKEN_PROVIDER_PATCH , return_value = "tok" ):
229- client .get_openai_client (default_headers = {"User-Agent" : "AsyncApp/2.0" })
230- real_call = mock_cls .call_args_list [- 1 ]
231- assert real_call .kwargs ["default_headers" ]["User-Agent" ] == "AsyncApp/2.0"
232-
233- @pytest .mark .asyncio
234- async def test_sdk_user_agent_built_without_custom_prefix (self ):
235- """Branch: no caller UA, no _custom_user_agent -> 'AIProjectClient <openai_ua>'."""
236- client = make_async_client (custom_user_agent = None )
237- mock_cls , _ = mock_openai ("openai/async-sdk" )
238- with patch (ASYNC_OPENAI_PATCH , mock_cls ), patch (ASYNC_TOKEN_PROVIDER_PATCH , return_value = "tok" ):
239- client .get_openai_client ()
240- real_call = mock_cls .call_args_list [- 1 ]
241- ua = real_call .kwargs ["default_headers" ]["User-Agent" ]
242- assert "AIProjectClient" in ua
243- assert "openai/async-sdk" in ua
244-
245- @pytest .mark .asyncio
246- async def test_sdk_user_agent_with_custom_prefix (self ):
247- """Branch: no caller UA, _custom_user_agent set -> 'custom-AIProjectClient <openai_ua>'."""
248- client = make_async_client (custom_user_agent = "MyAsyncSDK" )
249- mock_cls , _ = mock_openai ("openai/async-sdk" )
250- with patch (ASYNC_OPENAI_PATCH , mock_cls ), patch (ASYNC_TOKEN_PROVIDER_PATCH , return_value = "tok" ):
251- client .get_openai_client ()
252- real_call = mock_cls .call_args_list [- 1 ]
253- ua = real_call .kwargs ["default_headers" ]["User-Agent" ]
254- assert ua .startswith ("MyAsyncSDK-AIProjectClient" )
255- assert "openai/async-sdk" in ua
0 commit comments