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).
120 lines
4.7 KiB
Python
120 lines
4.7 KiB
Python
"""Tests for the /resume command."""
|
|
|
|
from unittest.mock import AsyncMock, MagicMock
|
|
|
|
from tests.fakes import FakeGraphGateway, FakeThreadStore
|
|
|
|
|
|
def _ctx(thread_id="current", workspace_dir="/ws", thread_store=None):
|
|
from EvoScientist.commands.base import CommandContext
|
|
|
|
store = thread_store or FakeThreadStore()
|
|
ui = MagicMock()
|
|
ui.supports_interactive = True
|
|
ui.wait_for_thread_pick = AsyncMock()
|
|
ui.handle_session_resume = AsyncMock()
|
|
return CommandContext(
|
|
agent=None,
|
|
thread_id=thread_id,
|
|
ui=ui,
|
|
workspace_dir=workspace_dir,
|
|
graph_gateway=FakeGraphGateway(thread_store=store),
|
|
), ui
|
|
|
|
|
|
class TestResumeCommand:
|
|
async def test_with_arg_resolves_and_calls_ui(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx(
|
|
thread_store=FakeThreadStore(
|
|
resolved_thread_id="target-tid",
|
|
metadata={"workspace_dir": "/restored"},
|
|
)
|
|
)
|
|
await ResumeCommand().execute(ctx, ["target-tid"])
|
|
ui.handle_session_resume.assert_awaited_once_with("target-tid", "/restored")
|
|
# ctx mutations
|
|
assert ctx.thread_id == "target-tid"
|
|
assert ctx.workspace_dir == "/restored"
|
|
|
|
async def test_no_arg_empty_threads_prints_message(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx()
|
|
await ResumeCommand().execute(ctx, [])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("No sessions to resume" in m for m in msgs)
|
|
ui.wait_for_thread_pick.assert_not_called()
|
|
ui.handle_session_resume.assert_not_called()
|
|
|
|
async def test_no_arg_calls_picker(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx()
|
|
ui.wait_for_thread_pick.return_value = "picked-tid"
|
|
threads = [{"thread_id": "picked-tid", "preview": "p", "message_count": 1}]
|
|
store = FakeThreadStore(
|
|
threads=threads,
|
|
resolved_thread_id="picked-tid",
|
|
)
|
|
ctx.graph_gateway = FakeGraphGateway(thread_store=store)
|
|
await ResumeCommand().execute(ctx, [])
|
|
ui.wait_for_thread_pick.assert_awaited_once()
|
|
ui.handle_session_resume.assert_awaited_once()
|
|
|
|
async def test_picker_cancel_returns(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx()
|
|
ui.wait_for_thread_pick.return_value = None
|
|
threads = [{"thread_id": "t1", "preview": "", "message_count": 0}]
|
|
store = FakeThreadStore(threads=threads)
|
|
ctx.graph_gateway = FakeGraphGateway(thread_store=store)
|
|
await ResumeCommand().execute(ctx, [])
|
|
ui.handle_session_resume.assert_not_called()
|
|
|
|
async def test_ambiguous_prefix(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx(thread_store=FakeThreadStore(matches=["abc-one", "abc-two"]))
|
|
await ResumeCommand().execute(ctx, ["abc"])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("Ambiguous" in m for m in msgs)
|
|
ui.handle_session_resume.assert_not_called()
|
|
|
|
async def test_not_found(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx()
|
|
await ResumeCommand().execute(ctx, ["missing"])
|
|
msgs = [c.args[0] for c in ui.append_system.call_args_list]
|
|
assert any("not found" in m for m in msgs)
|
|
ui.handle_session_resume.assert_not_called()
|
|
|
|
async def test_prefix_resolves_to_unique_match(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx(
|
|
thread_store=FakeThreadStore(
|
|
resolved_thread_id="abc-one",
|
|
metadata={"workspace_dir": "/ws1"},
|
|
)
|
|
)
|
|
await ResumeCommand().execute(ctx, ["abc"])
|
|
ui.handle_session_resume.assert_awaited_once_with("abc-one", "/ws1")
|
|
assert ctx.thread_id == "abc-one"
|
|
|
|
async def test_empty_workspace_metadata_preserves_ctx_workspace(self):
|
|
from EvoScientist.commands.implementation.session import ResumeCommand
|
|
|
|
ctx, ui = _ctx(
|
|
workspace_dir="/keep",
|
|
thread_store=FakeThreadStore(resolved_thread_id="tid", metadata={}),
|
|
)
|
|
await ResumeCommand().execute(ctx, ["tid"])
|
|
# ResumeCommand only overwrites ctx.workspace_dir if metadata has one
|
|
assert ctx.workspace_dir == "/keep"
|
|
# Callback still fires with the metadata value (empty string)
|
|
ui.handle_session_resume.assert_awaited_once_with("tid", "")
|