Something went wrong. Try again.
MCP based ACP agent
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657"""Unit tests for session lifecycle.
The session/persistence contract (create/load/add_message round-trips) istested in tests/memory/test_store.py, which owns the storage layer. Here wecover the cancellation-persistence contract (thinking-only turns must survive)against the in-memory fake client. The prompt context builders that used tolive alongside these helpers moved to ``crow_cli.agent.prompt`` and are testedin ``test_prompt.py``."""
import logging
import pytest
from crow_cli.agent.session import ( AgentSession, lookup_or_create_prompt,)
class TestCancelledTurnPersistence: """A turn cancelled while the model is still thinking has no content and no tool calls — the accumulated reasoning is the only record of what the agent was doing. It must be persisted so reconstruction hands it back to the next turn (and query_session can show it)."""
@pytest.fixture async def session(self, memory_service, sample_prompt_template): prompt_id = await lookup_or_create_prompt( sample_prompt_template, name="test-prompt" ) return await AgentSession.create( prompt_id=prompt_id, prompt_args={"name": "Crow", "workspace": "/tmp", "display_tree": "test/"}, tool_definitions=[], request_params={}, model_identifier="test-model", cwd="/tmp", agent_idx=1, )
async def test_thinking_only_turn_is_persisted(self, session, memory_service): await session.add_assistant_response( ["thinking ", "about the task"], [], [], logging.getLogger("test") ) stored = memory_service._messages[session.agent_id] assert stored[-1] == { "role": "assistant", "content": "", "reasoning_content": "thinking about the task", }
async def test_empty_turn_is_not_persisted(self, session, memory_service): before = len(memory_service._messages[session.agent_id]) await session.add_assistant_response([], [], [], logging.getLogger("test")) assert len(memory_service._messages[session.agent_id]) == before