from __future__ import annotations
import pytest
from cli_agent_mcp.config import Config
from cli_agent_mcp.handlers.base import ToolContext
from cli_agent_mcp.handlers.claude_slash import ClaudeSlashListHandler
from cli_agent_mcp.shared.invokers.types import ExecutionResult
def _make_ctx() -> ToolContext:
cfg = Config(tools={"claude"})
return ToolContext(
config=cfg,
gui_manager=None,
registry=None,
push_to_gui=lambda _ev: None,
push_user_prompt=lambda _source, _prompt, _task_note: None,
make_event_callback=lambda _source, _task_note, _task_index: None,
mcp_context=None,
)
@pytest.mark.asyncio
async def test_claude_slash_list_always_returns_full_output(monkeypatch: pytest.MonkeyPatch) -> None:
# Import the module so we can patch the symbols used by the handler.
import cli_agent_mcp.handlers.claude_slash as mod
class StubInvoker:
def __init__(self, event_callback=None) -> None:
pass
async def list_slash_commands(self, _params) -> ExecutionResult:
return ExecutionResult(success=True, session_id="sid", agent_messages="RESULT")
monkeypatch.setattr(mod, "ClaudeAgentSDKInvoker", StubInvoker)
append_calls: list[dict] = []
def stub_append_to_handoff_file(**kwargs):
append_calls.append(kwargs)
return True, "/abs/handoff.md"
monkeypatch.setattr(mod, "_append_to_handoff_file", stub_append_to_handoff_file)
ctx = _make_ctx()
handler = ClaudeSlashListHandler()
out_no_file = await handler.handle({"workspace": "."}, ctx)
assert "RESULT" in out_no_file[0].text
assert append_calls == []
out_with_file = await handler.handle({"workspace": ".", "handoff_file": "handoff.md"}, ctx)
assert "RESULT" in out_with_file[0].text
assert len(append_calls) == 1
# handoff_file must not change the returned output; it's purely an additional persistence feature.
assert out_with_file[0].text == out_no_file[0].text