4545sys .modules ['azure.core' ] = Mock ()
4646sys .modules ['azure.core.exceptions' ] = Mock ()
4747sys .modules ['azure.identity' ] = Mock ()
48+ sys .modules ['azure.identity.aio' ] = Mock ()
4849sys .modules ['azure.cosmos' ] = Mock (CosmosClient = Mock )
49- sys .modules ['agent_framework' ] = Mock (ChatAgent = Mock , ChatMessage = Mock , HostedCodeInterpreterTool = Mock , Role = Mock )
50+ sys .modules ['agent_framework' ] = Mock (Agent = Mock , Message = Mock , ChatOptions = Mock , ChatMessage = Mock , Role = Mock )
5051sys .modules ['agent_framework_azure_ai' ] = Mock (AzureAIClient = Mock )
5152
5253# Mock additional Azure modules that may be needed
@@ -303,17 +304,13 @@ def test_is_azure_search_requested_no_index_name(self, mock_get_logger, mock_con
303304 assert result is False
304305
305306 @pytest .mark .asyncio
306- @patch ('backend.v4.magentic_agents.foundry_agent.HostedCodeInterpreterTool' )
307307 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
308308 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
309- async def test_collect_tools_with_code_interpreter (self , mock_get_logger , mock_config , mock_code_tool_class ):
310- """Test _collect_tools with code interpreter enabled."""
309+ async def test_collect_tools_with_code_interpreter (self , mock_get_logger , mock_config ):
310+ """Test _collect_tools with code interpreter enabled - now handled server-side ."""
311311 mock_logger = Mock ()
312312 mock_get_logger .return_value = mock_logger
313313
314- mock_code_tool = Mock ()
315- mock_code_tool_class .return_value = mock_code_tool
316-
317314 agent = FoundryAgentTemplate (
318315 agent_name = "TestAgent" ,
319316 agent_description = "Test Description" ,
@@ -329,23 +326,19 @@ async def test_collect_tools_with_code_interpreter(self, mock_get_logger, mock_c
329326
330327 tools = await agent ._collect_tools ()
331328
332- assert len (tools ) == 1
333- assert tools [0 ] == mock_code_tool
334- mock_code_tool_class .assert_called_once ()
335- mock_logger .info .assert_any_call ("Added Code Interpreter tool." )
336- mock_logger .info .assert_any_call ("Total tools collected (MCP path): %d" , 1 )
329+ # HostedCodeInterpreterTool was removed in rc4; code interpreter is now server-side
330+ assert len (tools ) == 0
331+ mock_logger .info .assert_any_call ("Code Interpreter requested \u2014 handled server-side by AzureAIClient." )
332+ mock_logger .info .assert_any_call ("Total tools collected (MCP path): %d" , 0 )
337333
338334 @pytest .mark .asyncio
339- @patch ('backend.v4.magentic_agents.foundry_agent.HostedCodeInterpreterTool' )
340335 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
341336 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
342- async def test_collect_tools_code_interpreter_exception (self , mock_get_logger , mock_config , mock_code_tool_class ):
343- """Test _collect_tools when code interpreter creation fails ."""
337+ async def test_collect_tools_code_interpreter_server_side (self , mock_get_logger , mock_config ):
338+ """Test _collect_tools when code interpreter is enabled - handled server-side in rc4 ."""
344339 mock_logger = Mock ()
345340 mock_get_logger .return_value = mock_logger
346341
347- mock_code_tool_class .side_effect = Exception ("Code interpreter failed" )
348-
349342 agent = FoundryAgentTemplate (
350343 agent_name = "TestAgent" ,
351344 agent_description = "Test Description" ,
@@ -361,8 +354,9 @@ async def test_collect_tools_code_interpreter_exception(self, mock_get_logger, m
361354
362355 tools = await agent ._collect_tools ()
363356
357+ # No tools created locally; code interpreter is handled server-side
364358 assert len (tools ) == 0
365- mock_logger .error . assert_called_with ("Code Interpreter tool creation failed: %s" , mock_code_tool_class . side_effect )
359+ mock_logger .info . assert_any_call ("Code Interpreter requested \u2014 handled server-side by AzureAIClient." )
366360
367361 @pytest .mark .asyncio
368362 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
@@ -639,7 +633,7 @@ class SimpleCreds:
639633 # Verify error was logged (removed specific assertion due to mock corruption issues)
640634
641635 @pytest .mark .asyncio
642- @patch ('backend.v4.magentic_agents.foundry_agent.ChatAgent ' )
636+ @patch ('backend.v4.magentic_agents.foundry_agent.Agent ' )
643637 @patch ('backend.v4.magentic_agents.foundry_agent.agent_registry' )
644638 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
645639 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
@@ -676,11 +670,11 @@ async def test_after_open_reasoning_mode_azure_search(self, mock_get_logger, moc
676670 "TestAgent" ,
677671 "test-index"
678672 )
679- mock_logger .info .assert_any_call ("Initialized ChatAgent '%s'" , "TestAgent" )
673+ mock_logger .info .assert_any_call ("Initialized Agent '%s'" , "TestAgent" )
680674 mock_registry .register_agent .assert_called_once_with (agent )
681675
682676 @pytest .mark .asyncio
683- @patch ('backend.v4.magentic_agents.foundry_agent.ChatAgent ' )
677+ @patch ('backend.v4.magentic_agents.foundry_agent.Agent ' )
684678 @patch ('backend.v4.magentic_agents.foundry_agent.agent_registry' )
685679 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
686680 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
@@ -712,11 +706,11 @@ async def test_after_open_foundry_mode_mcp(self, mock_get_logger, mock_config, m
712706
713707 mock_logger .info .assert_any_call ("Initializing agent in Foundry mode." )
714708 mock_logger .info .assert_any_call ("Initializing agent in MCP mode." )
715- mock_logger .info .assert_any_call ("Initialized ChatAgent '%s'" , "TestAgent" )
709+ mock_logger .info .assert_any_call ("Initialized Agent '%s'" , "TestAgent" )
716710 mock_registry .register_agent .assert_called_once_with (agent )
717711
718712 @pytest .mark .asyncio
719- @patch ('backend.v4.magentic_agents.foundry_agent.ChatAgent ' )
713+ @patch ('backend.v4.magentic_agents.foundry_agent.Agent ' )
720714 @patch ('backend.v4.magentic_agents.foundry_agent.agent_registry' )
721715 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
722716 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
@@ -745,16 +739,16 @@ async def test_after_open_azure_search_setup_failure(self, mock_get_logger, mock
745739 assert "Azure AI Search mode requested but setup failed." in str (exc_info .value )
746740
747741 @pytest .mark .asyncio
748- @patch ('backend.v4.magentic_agents.foundry_agent.ChatAgent ' )
742+ @patch ('backend.v4.magentic_agents.foundry_agent.Agent ' )
749743 @patch ('backend.v4.magentic_agents.foundry_agent.agent_registry' )
750744 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
751745 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
752746 async def test_after_open_chat_agent_creation_error (self , mock_get_logger , mock_config , mock_registry , mock_chat_agent_class ):
753- """Test _after_open when ChatAgent creation fails."""
747+ """Test _after_open when Agent creation fails."""
754748 mock_logger = Mock ()
755749 mock_get_logger .return_value = mock_logger
756750
757- mock_chat_agent_class .side_effect = Exception ("ChatAgent creation failed" )
751+ mock_chat_agent_class .side_effect = Exception ("Agent creation failed" )
758752
759753 agent = FoundryAgentTemplate (
760754 agent_name = "TestAgent" ,
@@ -774,11 +768,11 @@ async def test_after_open_chat_agent_creation_error(self, mock_get_logger, mock_
774768 with pytest .raises (Exception ) as exc_info :
775769 await agent ._after_open ()
776770
777- assert "ChatAgent creation failed" in str (exc_info .value )
778- mock_logger .error .assert_called_with ("Failed to initialize ChatAgent : %s" , mock_chat_agent_class .side_effect )
771+ assert "Agent creation failed" in str (exc_info .value )
772+ mock_logger .error .assert_called_with ("Failed to initialize Agent : %s" , mock_chat_agent_class .side_effect )
779773
780774 @pytest .mark .asyncio
781- @patch ('backend.v4.magentic_agents.foundry_agent.ChatAgent ' )
775+ @patch ('backend.v4.magentic_agents.foundry_agent.Agent ' )
782776 @patch ('backend.v4.magentic_agents.foundry_agent.agent_registry' )
783777 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
784778 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
@@ -817,11 +811,10 @@ async def test_after_open_registry_failure(self, mock_get_logger, mock_config, m
817811 )
818812
819813 @pytest .mark .asyncio
820- @patch ('backend.v4.magentic_agents.foundry_agent.ChatMessage' )
821- @patch ('backend.v4.magentic_agents.foundry_agent.Role' )
814+ @patch ('backend.v4.magentic_agents.foundry_agent.Message' )
822815 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
823816 @patch ('backend.v4.magentic_agents.foundry_agent.logging.getLogger' )
824- async def test_invoke_success (self , mock_get_logger , mock_config , mock_role , mock_chat_message_class ):
817+ async def test_invoke_success (self , mock_get_logger , mock_config , mock_message_class ):
825818 """Test invoke method successfully streams responses."""
826819 mock_logger = Mock ()
827820 mock_get_logger .return_value = mock_logger
@@ -830,15 +823,14 @@ async def test_invoke_success(self, mock_get_logger, mock_config, mock_role, moc
830823 mock_update1 = Mock ()
831824 mock_update2 = Mock ()
832825
833- # Mock run_stream to return an async iterator
834- async def mock_run_stream (messages ):
826+ # Mock run to return an async iterator (source uses self._agent.run, not run_stream)
827+ async def mock_run (messages , stream = True ):
835828 yield mock_update1
836829 yield mock_update2
837- mock_agent .run_stream = mock_run_stream
830+ mock_agent .run = mock_run
838831
839832 mock_message = Mock ()
840- mock_chat_message_class .return_value = mock_message
841- mock_role .USER = "user"
833+ mock_message_class .return_value = mock_message
842834
843835 agent = FoundryAgentTemplate (
844836 agent_name = "TestAgent" ,
@@ -857,7 +849,7 @@ async def mock_run_stream(messages):
857849 updates .append (update )
858850
859851 assert updates == [mock_update1 , mock_update2 ]
860- mock_chat_message_class .assert_called_once_with (role = mock_role . USER , text = "Test prompt" )
852+ mock_message_class .assert_called_once_with (role = "user" , text = "Test prompt" )
861853
862854 @pytest .mark .asyncio
863855 @patch ('backend.v4.magentic_agents.foundry_agent.config' )
0 commit comments