| """ |
| Integration Tests for Multi-Turn Conversation Flow |
| |
| Tests conversation context retention and multi-turn interactions. |
| """ |
|
|
| import pytest |
|
|
| from tests.utils.agent_helpers import invoke_agent_with_message, create_mock_conversation_history |
|
|
|
|
| @pytest.mark.integration |
| @pytest.mark.asyncio |
| async def test_multi_turn_conversation_with_context_retention(test_user, test_session): |
| """ |
| Test: Multi-turn conversation with context retention |
| |
| Verifies that agent maintains context across multiple turns. |
| """ |
| |
| response1 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="Add a task to call the dentist" |
| ) |
|
|
| |
| assert "content" in response1 |
|
|
| |
| history = create_mock_conversation_history([ |
| ("user", "Add a task to call the dentist"), |
| ("assistant", response1.get("content", "Task created")) |
| ]) |
|
|
| response2 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="Also add one to buy milk", |
| conversation_history=history |
| ) |
|
|
| |
| assert "content" in response2 |
|
|
| |
| from tests.utils.task_helpers import count_tasks |
| task_count = count_tasks(test_session, test_user.id) |
| assert task_count >= 2 |
|
|
|
|
| @pytest.mark.integration |
| @pytest.mark.asyncio |
| async def test_agent_references_previous_task_in_conversation(test_user, test_session): |
| """ |
| Test: Agent references previous task in conversation |
| |
| Verifies that agent can reference tasks created earlier in the conversation. |
| """ |
| |
| response1 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="Remind me to submit the report" |
| ) |
|
|
| |
| history = create_mock_conversation_history([ |
| ("user", "Remind me to submit the report"), |
| ("assistant", response1.get("content", "Task created")) |
| ]) |
|
|
| response2 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="What tasks do I have?", |
| conversation_history=history |
| ) |
|
|
| |
| assert "content" in response2 |
| assert len(response2["content"]) > 0 |
|
|
|
|
| @pytest.mark.integration |
| @pytest.mark.asyncio |
| async def test_conversation_maintains_user_context_across_turns(test_user): |
| """ |
| Test: Conversation maintains user context across turns |
| |
| Verifies that user_id context is maintained throughout conversation. |
| """ |
| |
| response1 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="Create a task to review code" |
| ) |
|
|
| assert "content" in response1 |
|
|
| |
| history = create_mock_conversation_history([ |
| ("user", "Create a task to review code"), |
| ("assistant", response1.get("content", "Task created")) |
| ]) |
|
|
| response2 = await invoke_agent_with_message( |
| user_id=test_user.id, |
| message="Show my tasks", |
| conversation_history=history |
| ) |
|
|
| |
| assert "content" in response2 |
|
|