690b903f85
* chore: add pytest-asyncio in auto mode * test: migrate channel and stream tests to native async Convert run_async() wrapper tests to plain 'async def test_*' under pytest-asyncio auto mode. collect_events() in stream_v3_fakes becomes a coroutine awaited at every call site. * test: migrate command and model/middleware tests to native async Convert run_async() wrappers (import, alias, and fixture forms) to plain 'async def test_*'. Multi-call tests merge onto one loop as sequential awaits; none asserted on loop identity. * test: migrate TUI, notifier, gateway, and session tests to native async TUI/notifier/gateway files convert run_async wrappers to plain async tests. test_sessions.py's unittest.TestCase classes move to unittest.IsolatedAsyncioTestCase (pytest-asyncio does not await async methods on plain TestCase; converting blindly would have made ~70 tests silently vacuous). Its setUpClass keeps a one-shot asyncio.run() since IsolatedAsyncioTestCase has no async class-level hook. TestLoadingWidget in test_tui_widgets.py drops its TestCase base for the same reason. * test: replace direct asyncio.run() calls with native async tests Convert tests that called asyncio.run() (directly or via a local _run helper) to plain 'async def test_*'; delete the local helpers. * test: drop undeclared anyio markers and delete run_async helper The @pytest.mark.anyio tests relied on anyio being a transitive dep of httpx; auto-mode pytest-asyncio collects them natively. run_async() and its fixture are unreferenced after the migration, so remove them — pytest-asyncio's per-test loop teardown covers the pending-task cancellation the helper existed for (verified: full suite runs with no 'Event loop is closed' errors or destroyed-task warnings).
112 lines
4.1 KiB
Python
112 lines
4.1 KiB
Python
"""Tests for the /mcp command (MCPCommand subcommand dispatch)."""
|
|
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
|
|
def _ctx():
|
|
from EvoScientist.commands.base import CommandContext
|
|
|
|
ui = MagicMock()
|
|
ui.supports_interactive = True
|
|
return CommandContext(agent=None, thread_id="tid", ui=ui), ui
|
|
|
|
|
|
class TestMCPCommandDispatch:
|
|
async def test_no_args_lists(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, ui = _ctx()
|
|
with patch("EvoScientist.mcp.load_mcp_config", return_value={}):
|
|
await MCPCommand().execute(ctx, [])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("No MCP servers configured" in m for m in msgs)
|
|
|
|
async def test_list_subcommand(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, ui = _ctx()
|
|
cfg = {
|
|
"srv1": {"transport": "stdio", "tools": ["foo"], "expose_to": ["main"]},
|
|
}
|
|
with patch("EvoScientist.mcp.load_mcp_config", return_value=cfg):
|
|
await MCPCommand().execute(ctx, ["list"])
|
|
ui.mount_renderable.assert_called_once()
|
|
|
|
async def test_add_subcommand_dispatches(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, _ui = _ctx()
|
|
with (
|
|
patch(
|
|
"EvoScientist.mcp.parse_mcp_add_args",
|
|
return_value={"name": "srv1"},
|
|
),
|
|
patch(
|
|
"EvoScientist.mcp.add_mcp_server",
|
|
return_value={"transport": "stdio"},
|
|
) as add_mock,
|
|
):
|
|
await MCPCommand().execute(ctx, ["add", "srv1", "python"])
|
|
add_mock.assert_called_once()
|
|
|
|
async def test_edit_subcommand_dispatches(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, _ui = _ctx()
|
|
with (
|
|
patch(
|
|
"EvoScientist.mcp.parse_mcp_edit_args",
|
|
return_value=("srv1", {"tools": ["bar"]}),
|
|
),
|
|
patch(
|
|
"EvoScientist.mcp.edit_mcp_server",
|
|
) as edit_mock,
|
|
):
|
|
await MCPCommand().execute(ctx, ["edit", "srv1", "--tools", "bar"])
|
|
edit_mock.assert_called_once_with("srv1", tools=["bar"])
|
|
|
|
async def test_remove_subcommand_success(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, ui = _ctx()
|
|
with patch("EvoScientist.mcp.remove_mcp_server", return_value=True):
|
|
await MCPCommand().execute(ctx, ["remove", "srv1"])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("Removed MCP server: srv1" in m for m in msgs)
|
|
|
|
async def test_remove_subcommand_not_found(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, ui = _ctx()
|
|
with patch("EvoScientist.mcp.remove_mcp_server", return_value=False):
|
|
await MCPCommand().execute(ctx, ["remove", "missing"])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("Server not found" in m for m in msgs)
|
|
|
|
async def test_install_delegates_to_install_mcp_command(self):
|
|
"""/mcp install should instantiate InstallMCPCommand and execute it."""
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, _ui = _ctx()
|
|
with patch(
|
|
"EvoScientist.commands.implementation.mcp_install.InstallMCPCommand"
|
|
) as klass:
|
|
instance = MagicMock()
|
|
instance.execute = MagicMock(return_value=None)
|
|
|
|
async def fake_execute(ctx, args):
|
|
return None
|
|
|
|
instance.execute = fake_execute
|
|
klass.return_value = instance
|
|
await MCPCommand().execute(ctx, ["install", "foo"])
|
|
klass.assert_called_once()
|
|
|
|
async def test_unknown_subcommand_prints_help(self):
|
|
from EvoScientist.commands.implementation.mcp import MCPCommand
|
|
|
|
ctx, ui = _ctx()
|
|
await MCPCommand().execute(ctx, ["bogus"])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("MCP commands:" in m for m in msgs)
|