@@ -36,7 +36,7 @@ class TestA2aCommands:
3636
3737 def test_a2a_list_success (self , mock_console ) -> None :
3838 """Test a2a list command."""
39- mock_agents = [{"id" : 1 , "name" : "agent1" , "url" : "http://example.com" , "description" : "desc1" , "enabled" : True }]
39+ mock_agents = [{"id" : "agent-1" , "name" : "agent1" , "url" : "http://example.com" , "description" : "desc1" , "enabled" : True }]
4040
4141 with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
4242 with patch ("cforge.commands.resources.a2a.make_authenticated_request" , return_value = mock_agents ):
@@ -68,9 +68,49 @@ def test_a2a_list_error(self, mock_console) -> None:
6868 with pytest .raises (typer .Exit ):
6969 a2a_list (json_output = False )
7070
71+ def test_a2a_list_with_active_only_true (self , mock_console ) -> None :
72+ """Test a2a list with --active-only flag set to True."""
73+ mock_agents = [{"id" : "agent-1" , "name" : "agent1" , "enabled" : True }]
74+
75+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
76+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" , return_value = mock_agents ) as mock_req :
77+ with patch ("cforge.commands.resources.a2a.print_table" ):
78+ a2a_list (active_only = True , json_output = False )
79+
80+ # Verify that include_inactive=False was passed to API
81+ call_args = mock_req .call_args
82+ assert call_args [1 ]["params" ]["include_inactive" ] is False
83+
84+ def test_a2a_list_with_active_only_false (self , mock_console ) -> None :
85+ """Test a2a list with --active-only flag set to False (default)."""
86+ mock_agents = [{"id" : "agent-1" , "name" : "agent1" , "enabled" : True }, {"id" : "agent-2" , "name" : "agent2" , "enabled" : False }]
87+
88+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
89+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" , return_value = mock_agents ) as mock_req :
90+ with patch ("cforge.commands.resources.a2a.print_table" ):
91+ a2a_list (active_only = False , json_output = False )
92+
93+ # Verify that include_inactive=True was passed to API
94+ call_args = mock_req .call_args
95+ assert call_args [1 ]["params" ]["include_inactive" ] is True
96+
97+ def test_a2a_list_default_shows_all (self , mock_console ) -> None :
98+ """Test a2a list default behavior shows all agents."""
99+ mock_agents = [{"id" : "agent-1" , "name" : "agent1" , "enabled" : True }, {"id" : "agent-2" , "name" : "agent2" , "enabled" : False }]
100+
101+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
102+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" , return_value = mock_agents ) as mock_req :
103+ with patch ("cforge.commands.resources.a2a.print_table" ):
104+ # Call with explicit active_only=False (default value)
105+ a2a_list (active_only = False , json_output = False )
106+
107+ # Verify that include_inactive=True was passed to API (default behavior)
108+ call_args = mock_req .call_args
109+ assert call_args [1 ]["params" ]["include_inactive" ] is True
110+
71111 def test_a2a_get_success (self , mock_console ) -> None :
72112 """Test a2a get command."""
73- mock_agent = {"id" : 1 , "name" : "test" }
113+ mock_agent = {"id" : "agent-1" , "name" : "test" }
74114
75115 with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
76116 with patch ("cforge.commands.resources.a2a.make_authenticated_request" , return_value = mock_agent ):
@@ -79,7 +119,7 @@ def test_a2a_get_success(self, mock_console) -> None:
79119
80120 def test_a2a_create_from_file (self , mock_console ) -> None :
81121 """Test a2a create from file."""
82- mock_result = {"id" : 1 , "name" : "new_agent" }
122+ mock_result = {"id" : "agent-1" , "name" : "new_agent" }
83123
84124 with tempfile .TemporaryDirectory () as temp_dir :
85125 data_file = Path (temp_dir ) / "agent.json"
@@ -98,7 +138,7 @@ def test_a2a_create_file_not_found(self, mock_console) -> None:
98138
99139 def test_a2a_create_interactive (self , mock_console ) -> None :
100140 """Test a2a create interactive mode."""
101- mock_result = {"id" : 1 , "name" : "new_agent" }
141+ mock_result = {"id" : "agent-1" , "name" : "new_agent" }
102142
103143 with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
104144 with patch ("cforge.commands.resources.a2a.prompt_for_schema" , return_value = {"name" : "test" , "url" : "http://example.com" }):
@@ -108,7 +148,7 @@ def test_a2a_create_interactive(self, mock_console) -> None:
108148
109149 def test_a2a_create_with_options (self , mock_console ) -> None :
110150 """Test a2a create with command-line options."""
111- mock_result = {"id" : 1 , "name" : "new_agent" }
151+ mock_result = {"id" : "agent-1" , "name" : "new_agent" }
112152
113153 with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
114154 with patch ("cforge.commands.resources.a2a.prompt_for_schema" , return_value = {"name" : "test" , "url" : "http://example.com" , "description" : "desc" }) as mock_prompt :
@@ -124,7 +164,7 @@ def test_a2a_create_with_options(self, mock_console) -> None:
124164
125165 def test_a2a_update_success (self , mock_console ) -> None :
126166 """Test a2a update command."""
127- mock_result = {"id" : 1 , "name" : "updated" }
167+ mock_result = {"id" : "agent-1" , "name" : "updated" }
128168
129169 with tempfile .TemporaryDirectory () as temp_dir :
130170 data_file = Path (temp_dir ) / "update.json"
@@ -193,6 +233,67 @@ def test_a2a_get_error(self, mock_console) -> None:
193233 with pytest .raises (typer .Exit ):
194234 a2a_get (agent_id = "1" )
195235
236+ def test_a2a_toggle_from_disabled_to_enabled (self , mock_console ) -> None :
237+ """Test toggling an A2A agent from disabled to enabled."""
238+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
239+ # Create side_effect list with two responses
240+ side_effects = [{"id" : "1" , "name" : "test" , "enabled" : False }, {"id" : "1" , "name" : "test" , "enabled" : True }] # GET current status # POST toggle result
241+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" , side_effect = side_effects ) as mock_req :
242+ with patch ("cforge.commands.resources.a2a.print_json" ):
243+ a2a_toggle (agent_id = "1" )
244+
245+ # Verify two calls were made
246+ assert mock_req .call_count == 2
247+
248+ # Verify first call was GET to check current status
249+ get_call = mock_req .call_args_list [0 ]
250+ assert get_call [0 ][0 ] == "GET"
251+ assert get_call [0 ][1 ] == "/a2a/1"
252+
253+ # Verify second call was POST with activate=True
254+ post_call = mock_req .call_args_list [1 ]
255+ assert post_call [0 ][0 ] == "POST"
256+ assert post_call [0 ][1 ] == "/a2a/1/toggle"
257+ assert post_call [1 ]["params" ]["activate" ] is True
258+
259+ def test_a2a_toggle_from_enabled_to_disabled (self , mock_console ) -> None :
260+ """Test toggling an A2A agent from enabled to disabled."""
261+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
262+ # Create side_effect list with two responses
263+ side_effects = [{"id" : "1" , "name" : "test" , "enabled" : True }, {"id" : "1" , "name" : "test" , "enabled" : False }] # GET current status # POST toggle result
264+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" , side_effect = side_effects ) as mock_req :
265+ with patch ("cforge.commands.resources.a2a.print_json" ):
266+ a2a_toggle (agent_id = "1" )
267+
268+ # Verify two calls were made
269+ assert mock_req .call_count == 2
270+
271+ # Verify first call was GET to check current status
272+ get_call = mock_req .call_args_list [0 ]
273+ assert get_call [0 ][0 ] == "GET"
274+ assert get_call [0 ][1 ] == "/a2a/1"
275+
276+ # Verify second call was POST with activate=False
277+ post_call = mock_req .call_args_list [1 ]
278+ assert post_call [0 ][0 ] == "POST"
279+ assert post_call [0 ][1 ] == "/a2a/1/toggle"
280+ assert post_call [1 ]["params" ]["activate" ] is False
281+
282+ def test_a2a_toggle_detects_current_status (self , mock_console ) -> None :
283+ """Test that toggle command detects current status before toggling."""
284+ with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
285+ with patch ("cforge.commands.resources.a2a.make_authenticated_request" ) as mock_req :
286+ # Mock an agent that is currently enabled
287+ mock_req .side_effect = [{"id" : "1" , "name" : "test" , "enabled" : True }, {"id" : "1" , "name" : "test" , "enabled" : False }]
288+ with patch ("cforge.commands.resources.a2a.print_json" ):
289+ a2a_toggle (agent_id = "1" )
290+
291+ # Verify GET was called first to detect current status
292+ calls = mock_req .call_args_list
293+ assert len (calls ) == 2
294+ assert calls [0 ][0 ][0 ] == "GET" # First call is GET
295+ assert calls [1 ][0 ][0 ] == "POST" # Second call is POST
296+
196297 def test_a2a_toggle_error (self , mock_console ) -> None :
197298 """Test a2a toggle error handling."""
198299 with patch ("cforge.commands.resources.a2a.get_console" , return_value = mock_console ):
0 commit comments