Skip to content

Commit 5efcf46

Browse files
committed
test: Integration tests for toggle and list functionality
Branch: InitialCLI Signed-off-by: Gabe Goodhart <ghart@us.ibm.com>
1 parent 847c301 commit 5efcf46

6 files changed

Lines changed: 483 additions & 0 deletions

File tree

tests/commands/resources/test_a2a.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,3 +362,89 @@ def test_a2a_lifecycle(self, mock_console, authorized_mock_client) -> None:
362362
# Verify it's gone
363363
with pytest.raises(click.exceptions.Exit):
364364
a2a_get(a2a_id)
365+
366+
def test_a2a_list_active_only_integration(self, mock_console, authorized_mock_client) -> None:
367+
"""Test --active-only flag filters correctly with real server."""
368+
with patch_functions("cforge.commands.resources.a2a", print_json=None, get_console=mock_console) as mocks:
369+
# Create an A2A agent
370+
a2a_body = {
371+
"name": "test-a2a-active",
372+
"endpoint_url": "http://test.example.com",
373+
"description": "Test A2A for active-only",
374+
}
375+
with patch("cforge.commands.resources.a2a.prompt_for_schema", return_value=a2a_body):
376+
a2a_create(None)
377+
a2a_id = mocks.print_json.call_args[0][0]["id"]
378+
mocks.print_json.reset_mock()
379+
380+
# List with active_only=True should include it (starts enabled)
381+
a2a_list(active_only=True, json_output=True)
382+
active_agents = mocks.print_json.call_args[0][0]
383+
assert any(a["id"] == a2a_id for a in active_agents)
384+
mocks.print_json.reset_mock()
385+
386+
# Disable the A2A agent
387+
a2a_toggle(agent_id=a2a_id)
388+
mocks.print_json.reset_mock()
389+
390+
# List with active_only=True should NOT include it now
391+
a2a_list(active_only=True, json_output=True)
392+
active_agents = mocks.print_json.call_args[0][0]
393+
assert not any(a["id"] == a2a_id for a in active_agents)
394+
mocks.print_json.reset_mock()
395+
396+
# List with active_only=False should still include it
397+
a2a_list(active_only=False, json_output=True)
398+
all_agents = mocks.print_json.call_args[0][0]
399+
assert any(a["id"] == a2a_id for a in all_agents)
400+
mocks.print_json.reset_mock()
401+
402+
# Re-enable the A2A agent
403+
a2a_toggle(agent_id=a2a_id)
404+
mocks.print_json.reset_mock()
405+
406+
# List with active_only=True should include it again
407+
a2a_list(active_only=True, json_output=True)
408+
active_agents = mocks.print_json.call_args[0][0]
409+
assert any(a["id"] == a2a_id for a in active_agents)
410+
411+
# Clean up
412+
a2a_delete(a2a_id, confirm=True)
413+
414+
def test_a2a_toggle_status_detection_integration(self, mock_console, authorized_mock_client) -> None:
415+
"""Test toggle command detects current status correctly with real server."""
416+
with patch_functions("cforge.commands.resources.a2a", print_json=None, get_console=mock_console) as mocks:
417+
# Create an A2A agent
418+
a2a_body = {
419+
"name": "test-a2a-toggle",
420+
"endpoint_url": "http://test-toggle.example.com",
421+
"description": "Test A2A for toggle detection",
422+
}
423+
with patch("cforge.commands.resources.a2a.prompt_for_schema", return_value=a2a_body):
424+
a2a_create(None)
425+
a2a_id = mocks.print_json.call_args[0][0]["id"]
426+
initial_status = mocks.print_json.call_args[0][0]["enabled"]
427+
assert initial_status is True, "New A2A agent should start enabled"
428+
mocks.print_json.reset_mock()
429+
430+
# Toggle (should detect enabled and switch to disabled)
431+
a2a_toggle(agent_id=a2a_id)
432+
mocks.print_json.reset_mock()
433+
434+
# Verify status changed by getting it
435+
a2a_get(a2a_id)
436+
current_status = mocks.print_json.call_args[0][0]["enabled"]
437+
assert current_status is False, "A2A agent should now be disabled"
438+
mocks.print_json.reset_mock()
439+
440+
# Toggle again (should detect disabled and switch to enabled)
441+
a2a_toggle(agent_id=a2a_id)
442+
mocks.print_json.reset_mock()
443+
444+
# Verify status changed back
445+
a2a_get(a2a_id)
446+
final_status = mocks.print_json.call_args[0][0]["enabled"]
447+
assert final_status is True, "A2A agent should be enabled again"
448+
449+
# Clean up
450+
a2a_delete(a2a_id, confirm=True)

tests/commands/resources/test_mcp_servers.py

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,83 @@ def test_mcp_servers_lifecycle(self, mock_console, authorized_mock_client, mock_
347347
# Verify it's gone
348348
with pytest.raises(click.exceptions.Exit):
349349
mcp_servers_get(mcp_server_id)
350+
351+
def test_mcp_servers_list_active_only_integration(self, mock_console, authorized_mock_client, mock_mcp_server) -> None:
352+
"""Test --active-only flag filters correctly with real server."""
353+
with patch_functions("cforge.commands.resources.mcp_servers", print_json=None) as mocks:
354+
# Create a new MCP Server
355+
with patch("cforge.commands.resources.mcp_servers.prompt_for_schema", return_value=mock_mcp_server):
356+
mcp_servers_create(None)
357+
mcp_server_id = mocks.print_json.call_args[0][0]["id"]
358+
mocks.print_json.reset_mock()
359+
360+
# List with active_only=True should include it (starts enabled)
361+
mcp_servers_list(active_only=True, json_output=True)
362+
active_servers = mocks.print_json.call_args[0][0]
363+
assert any(s["id"] == mcp_server_id for s in active_servers), "Enabled server should appear in active-only list"
364+
mocks.print_json.reset_mock()
365+
366+
# Disable it
367+
mcp_servers_toggle(mcp_server_id)
368+
mocks.print_json.reset_mock()
369+
370+
# List with active_only=True should NOT include it
371+
mcp_servers_list(active_only=True, json_output=True)
372+
active_servers = mocks.print_json.call_args[0][0]
373+
assert not any(s["id"] == mcp_server_id for s in active_servers), "Disabled server should NOT appear in active-only list"
374+
mocks.print_json.reset_mock()
375+
376+
# List with active_only=False should include it
377+
mcp_servers_list(active_only=False, json_output=True)
378+
all_servers = mocks.print_json.call_args[0][0]
379+
assert any(s["id"] == mcp_server_id for s in all_servers), "Disabled server should appear in full list"
380+
mocks.print_json.reset_mock()
381+
382+
# Re-enable it
383+
mcp_servers_toggle(mcp_server_id)
384+
mocks.print_json.reset_mock()
385+
386+
# List with active_only=True should include it again
387+
mcp_servers_list(active_only=True, json_output=True)
388+
active_servers = mocks.print_json.call_args[0][0]
389+
assert any(s["id"] == mcp_server_id for s in active_servers), "Re-enabled server should appear in active-only list"
390+
391+
# Cleanup
392+
mcp_servers_delete(mcp_server_id)
393+
394+
def test_mcp_servers_toggle_status_detection_integration(self, mock_console, authorized_mock_client, mock_mcp_server) -> None:
395+
"""Test toggle command detects current status correctly with real server."""
396+
with patch_functions("cforge.commands.resources.mcp_servers", print_json=None, get_console=mock_console) as mocks:
397+
# Create a new MCP Server (starts enabled)
398+
with patch("cforge.commands.resources.mcp_servers.prompt_for_schema", return_value=mock_mcp_server):
399+
mcp_servers_create(None)
400+
mcp_server_id = mocks.print_json.call_args[0][0]["id"]
401+
mocks.print_json.reset_mock()
402+
403+
# Get initial status (should be enabled)
404+
mcp_servers_get(mcp_server_id)
405+
initial_status = mocks.print_json.call_args[0][0]["enabled"]
406+
assert initial_status is True, "New server should start enabled"
407+
mocks.print_json.reset_mock()
408+
409+
# Toggle (should detect enabled and switch to disabled)
410+
mcp_servers_toggle(mcp_server_id)
411+
mocks.print_json.reset_mock()
412+
413+
# Verify status changed by getting it again
414+
mcp_servers_get(mcp_server_id)
415+
current_status = mocks.print_json.call_args[0][0]["enabled"]
416+
assert current_status is False, "Server should now be disabled"
417+
mocks.print_json.reset_mock()
418+
419+
# Toggle again (should detect disabled and switch to enabled)
420+
mcp_servers_toggle(mcp_server_id)
421+
mocks.print_json.reset_mock()
422+
423+
# Verify status changed back
424+
mcp_servers_get(mcp_server_id)
425+
final_status = mocks.print_json.call_args[0][0]["enabled"]
426+
assert final_status is True, "Server should be enabled again"
427+
428+
# Cleanup
429+
mcp_servers_delete(mcp_server_id)

tests/commands/resources/test_prompts.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,76 @@ def test_prompts_lifecycle(self, mock_console, authorized_mock_client) -> None:
383383
# Make sure it's gone
384384
with pytest.raises(click.exceptions.Exit):
385385
prompts_get(prompt_id)
386+
387+
def test_prompts_list_active_only_integration(self, mock_console, registered_mcp_server) -> None:
388+
"""Test --active-only flag filters correctly with real server."""
389+
with patch_functions("cforge.commands.resources.prompts", print_json=None, get_console=mock_console) as mocks:
390+
# Get the prompts from the registered server
391+
prompts_list(mcp_server_id=None, active_only=False, json_output=True)
392+
all_prompts = mocks.print_json.call_args[0][0]
393+
assert len(all_prompts) >= 1, "Should have at least one prompt from registered server"
394+
prompt_id = all_prompts[0]["id"]
395+
mocks.print_json.reset_mock()
396+
397+
# Verify it starts enabled (prompts from MCP servers start enabled)
398+
prompts_list(mcp_server_id=None, active_only=True, json_output=True)
399+
active_prompts = mocks.print_json.call_args[0][0]
400+
assert any(p["id"] == prompt_id for p in active_prompts), "Prompt should start in active-only list"
401+
mocks.print_json.reset_mock()
402+
403+
# Disable it
404+
prompts_toggle(prompt_id)
405+
mocks.print_json.reset_mock()
406+
407+
# List with active_only=True should NOT include it
408+
prompts_list(mcp_server_id=None, active_only=True, json_output=True)
409+
active_prompts = mocks.print_json.call_args[0][0]
410+
assert not any(p["id"] == prompt_id for p in active_prompts), "Disabled prompt should NOT appear in active-only list"
411+
mocks.print_json.reset_mock()
412+
413+
# List with active_only=False should include it
414+
prompts_list(mcp_server_id=None, active_only=False, json_output=True)
415+
all_prompts = mocks.print_json.call_args[0][0]
416+
assert any(p["id"] == prompt_id for p in all_prompts), "Disabled prompt should appear in full list"
417+
mocks.print_json.reset_mock()
418+
419+
# Re-enable it
420+
prompts_toggle(prompt_id)
421+
mocks.print_json.reset_mock()
422+
423+
# List with active_only=True should include it again
424+
prompts_list(mcp_server_id=None, active_only=True, json_output=True)
425+
active_prompts = mocks.print_json.call_args[0][0]
426+
assert any(p["id"] == prompt_id for p in active_prompts), "Re-enabled prompt should appear in active-only list"
427+
428+
def test_prompts_toggle_status_detection_integration(self, mock_console, registered_mcp_server) -> None:
429+
"""Test toggle command detects current status correctly with real server."""
430+
with patch_functions("cforge.commands.resources.prompts", print_json=None, get_console=mock_console) as mocks:
431+
# Get a prompt from the registered server
432+
prompts_list(mcp_server_id=None, active_only=False, json_output=True)
433+
all_prompts = mocks.print_json.call_args[0][0]
434+
prompt_id = all_prompts[0]["id"]
435+
initial_status = all_prompts[0]["isActive"]
436+
assert initial_status is True, "Prompt from MCP server should start active"
437+
mocks.print_json.reset_mock()
438+
439+
# Toggle (should detect active and switch to inactive)
440+
prompts_toggle(prompt_id)
441+
mocks.print_json.reset_mock()
442+
443+
# Verify status changed by listing again
444+
prompts_list(mcp_server_id=None, active_only=False, json_output=True)
445+
all_prompts = mocks.print_json.call_args[0][0]
446+
prompt = [p for p in all_prompts if p["id"] == prompt_id][0]
447+
assert prompt["isActive"] is False, "Prompt should now be inactive"
448+
mocks.print_json.reset_mock()
449+
450+
# Toggle again (should detect inactive and switch to active)
451+
prompts_toggle(prompt_id)
452+
mocks.print_json.reset_mock()
453+
454+
# Verify status changed back
455+
prompts_list(mcp_server_id=None, active_only=False, json_output=True)
456+
all_prompts = mocks.print_json.call_args[0][0]
457+
prompt = [p for p in all_prompts if p["id"] == prompt_id][0]
458+
assert prompt["isActive"] is True, "Prompt should be active again"

tests/commands/resources/test_resources.py

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,3 +416,76 @@ def test_resources_lifecycle(self, mock_console, authorized_mock_client) -> None
416416
# Make sure it's gone
417417
with pytest.raises(click.exceptions.Exit):
418418
resources_get(resource_id)
419+
420+
def test_resources_list_active_only_integration(self, mock_console, registered_mcp_server) -> None:
421+
"""Test --active-only flag filters correctly with real server."""
422+
with patch_functions("cforge.commands.resources.resources", print_json=None, get_console=mock_console) as mocks:
423+
# Get the resources from the registered server
424+
resources_list(mcp_server_id=None, active_only=False, json_output=True)
425+
all_resources = mocks.print_json.call_args[0][0]
426+
assert len(all_resources) >= 1, "Should have at least one resource from registered server"
427+
resource_id = all_resources[0]["id"]
428+
mocks.print_json.reset_mock()
429+
430+
# Verify it starts enabled (resources from MCP servers start enabled)
431+
resources_list(mcp_server_id=None, active_only=True, json_output=True)
432+
active_resources = mocks.print_json.call_args[0][0]
433+
assert any(r["id"] == resource_id for r in active_resources), "Resource should start in active-only list"
434+
mocks.print_json.reset_mock()
435+
436+
# Disable it
437+
resources_toggle(resource_id)
438+
mocks.print_json.reset_mock()
439+
440+
# List with active_only=True should NOT include it
441+
resources_list(mcp_server_id=None, active_only=True, json_output=True)
442+
active_resources = mocks.print_json.call_args[0][0]
443+
assert not any(r["id"] == resource_id for r in active_resources), "Disabled resource should NOT appear in active-only list"
444+
mocks.print_json.reset_mock()
445+
446+
# List with active_only=False should include it
447+
resources_list(mcp_server_id=None, active_only=False, json_output=True)
448+
all_resources = mocks.print_json.call_args[0][0]
449+
assert any(r["id"] == resource_id for r in all_resources), "Disabled resource should appear in full list"
450+
mocks.print_json.reset_mock()
451+
452+
# Re-enable it
453+
resources_toggle(resource_id)
454+
mocks.print_json.reset_mock()
455+
456+
# List with active_only=True should include it again
457+
resources_list(mcp_server_id=None, active_only=True, json_output=True)
458+
active_resources = mocks.print_json.call_args[0][0]
459+
assert any(r["id"] == resource_id for r in active_resources), "Re-enabled resource should appear in active-only list"
460+
461+
def test_resources_toggle_status_detection_integration(self, mock_console, registered_mcp_server) -> None:
462+
"""Test toggle command detects current status correctly with real server."""
463+
with patch_functions("cforge.commands.resources.resources", print_json=None, get_console=mock_console) as mocks:
464+
# Get a resource from the registered server
465+
resources_list(mcp_server_id=None, active_only=False, json_output=True)
466+
all_resources = mocks.print_json.call_args[0][0]
467+
resource_id = all_resources[0]["id"]
468+
initial_status = all_resources[0]["isActive"]
469+
assert initial_status is True, "Resource from MCP server should start active"
470+
mocks.print_json.reset_mock()
471+
472+
# Toggle (should detect active and switch to inactive)
473+
resources_toggle(resource_id)
474+
mocks.print_json.reset_mock()
475+
476+
# Verify status changed by listing again
477+
resources_list(mcp_server_id=None, active_only=False, json_output=True)
478+
all_resources = mocks.print_json.call_args[0][0]
479+
resource = [r for r in all_resources if r["id"] == resource_id][0]
480+
assert resource["isActive"] is False, "Resource should now be inactive"
481+
mocks.print_json.reset_mock()
482+
483+
# Toggle again (should detect inactive and switch to active)
484+
resources_toggle(resource_id)
485+
mocks.print_json.reset_mock()
486+
487+
# Verify status changed back
488+
resources_list(mcp_server_id=None, active_only=False, json_output=True)
489+
all_resources = mocks.print_json.call_args[0][0]
490+
resource = [r for r in all_resources if r["id"] == resource_id][0]
491+
assert resource["isActive"] is True, "Resource should be active again"

0 commit comments

Comments
 (0)