@@ -229,3 +229,44 @@ async def test_close(self, transport: AsyncTransport, mock_httpx_client: AsyncMo
229229 await transport .close ()
230230
231231 mock_httpx_client .aclose .assert_called_once ()
232+
233+ async def test_config_not_mutated_on_repeated_initialization (self ) -> None :
234+ """Test that config dict is not mutated when creating multiple AsyncTransport instances."""
235+ # Create a config with headers
236+ original_config = {
237+ "timeout" : 30.0 ,
238+ "headers" : {"Custom-Header" : "value" , "Another-Header" : "another-value" },
239+ "follow_redirects" : True ,
240+ }
241+
242+ with patch ("httpx.AsyncClient" ) as mock_client_class :
243+ # First initialization - should not mutate original config
244+ AsyncTransport (base_url = "https://api.example.com" , api_key = "test-key-1" , config = original_config )
245+
246+ # Verify the config still has headers after first initialization
247+ assert "headers" in original_config
248+ assert original_config ["headers" ] == {"Custom-Header" : "value" , "Another-Header" : "another-value" }
249+
250+ # Second initialization with same config - should still work
251+ AsyncTransport (base_url = "https://api.example.com" , api_key = "test-key-2" , config = original_config )
252+
253+ # Verify the config still has headers after second initialization
254+ assert "headers" in original_config
255+ assert original_config ["headers" ] == {"Custom-Header" : "value" , "Another-Header" : "another-value" }
256+ assert original_config ["timeout" ] == 30.0
257+ assert original_config ["follow_redirects" ] is True
258+
259+ # Verify both clients were created with the expected headers
260+ assert mock_client_class .call_count == 2
261+
262+ # Check first call
263+ first_call_args = mock_client_class .call_args_list [0 ][1 ]
264+ assert first_call_args ["headers" ]["Authorization" ] == "Bearer test-key-1"
265+ assert first_call_args ["headers" ]["Custom-Header" ] == "value"
266+ assert first_call_args ["headers" ]["Another-Header" ] == "another-value"
267+
268+ # Check second call
269+ second_call_args = mock_client_class .call_args_list [1 ][1 ]
270+ assert second_call_args ["headers" ]["Authorization" ] == "Bearer test-key-2"
271+ assert second_call_args ["headers" ]["Custom-Header" ] == "value"
272+ assert second_call_args ["headers" ]["Another-Header" ] == "another-value"
0 commit comments