Files
EvoScientist-Multi/tests/test_evoskills_command.py
T
dinos 690b903f85 test: standardize async tests on pytest-asyncio auto mode (#338)
* 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).
2026-07-08 18:37:48 +00:00

103 lines
3.5 KiB
Python

"""Tests for the /evoskills command (InstallSkills)."""
from unittest.mock import AsyncMock, MagicMock, patch
def _ctx(supports_interactive=True):
from EvoScientist.commands.base import CommandContext
ui = MagicMock()
ui.supports_interactive = supports_interactive
ui.wait_for_skill_browse = AsyncMock()
return CommandContext(agent=None, thread_id="tid", ui=ui), ui
_INDEX = [
{
"name": "paper-writing",
"description": "author papers",
"install_source": "repo@paper-writing",
"tags": ["writing"],
},
{
"name": "research-ideation",
"description": "brainstorm ideas",
"install_source": "repo@research-ideation",
"tags": ["core"],
},
]
class TestInstallSkills:
async def test_picker_cancel_no_install(self):
from EvoScientist.commands.implementation.skills import InstallSkills
ctx, ui = _ctx()
ui.wait_for_skill_browse.return_value = None # cancelled
with (
patch(
"EvoScientist.tools.skills_manager.fetch_remote_skill_index",
return_value=_INDEX,
),
patch(
"EvoScientist.tools.skills_manager.install_skill",
) as install_mock,
):
await InstallSkills().execute(ctx, [])
install_mock.assert_not_called()
msgs = [c.args[0] for c in ui.append_system.call_args_list]
assert any("Browse cancelled" in m for m in msgs)
async def test_picker_returns_selections_installs_each(self):
from EvoScientist.commands.implementation.skills import InstallSkills
ctx, ui = _ctx()
ui.wait_for_skill_browse.return_value = [
"repo@paper-writing",
"repo@research-ideation",
]
with (
patch(
"EvoScientist.tools.skills_manager.fetch_remote_skill_index",
return_value=_INDEX,
),
patch(
"EvoScientist.tools.skills_manager.install_skill",
return_value={"success": True, "name": "x"},
) as install_mock,
):
await InstallSkills().execute(ctx, [])
assert install_mock.call_count == 2
async def test_channel_auto_install_on_tag(self):
"""Non-interactive UI + tag arg → auto-installs matching skills."""
from EvoScientist.commands.implementation.skills import InstallSkills
ctx, ui = _ctx(supports_interactive=False)
with (
patch(
"EvoScientist.tools.skills_manager.fetch_remote_skill_index",
return_value=_INDEX,
),
patch(
"EvoScientist.tools.skills_manager.install_skill",
return_value={"success": True, "name": "x"},
) as install_mock,
):
await InstallSkills().execute(ctx, ["core"])
# "core" matches research-ideation only → 1 install, no picker call
assert install_mock.call_count == 1
ui.wait_for_skill_browse.assert_not_called()
async def test_fetch_failure_prints_error(self):
from EvoScientist.commands.implementation.skills import InstallSkills
ctx, ui = _ctx()
with patch(
"EvoScientist.tools.skills_manager.fetch_remote_skill_index",
side_effect=RuntimeError("network fail"),
):
await InstallSkills().execute(ctx, [])
msgs = [c.args[0] for c in ui.append_system.call_args_list]
assert any("Failed to fetch" in m for m in msgs)