File size: 4,678 Bytes
310260a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | """
Integration Tests for Agent List Tasks (User Story 2)
Tests the end-to-end workflow of AI agent listing tasks via chat endpoint.
"""
import pytest
from tests.utils.agent_helpers import (
invoke_agent_with_message,
assert_tool_called,
extract_tool_calls
)
from tests.utils.task_helpers import create_multiple_tasks
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_lists_tasks_via_chat_endpoint(test_user, test_session):
"""
Test: Agent lists tasks via chat endpoint
Verifies that AI agent can list tasks through natural language interaction.
"""
# Setup: Create some tasks
create_multiple_tasks(test_session, test_user.id, count=3, title_prefix="Task")
# Execute
response = await invoke_agent_with_message(
user_id=test_user.id,
message="Show me my tasks"
)
# Assert agent called list_tasks tool
assert_tool_called(response, "list_tasks")
# Verify response contains task information
assert response["content"] is not None
assert len(response["content"]) > 0
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_lists_tasks_with_natural_language_show_my_tasks(test_user, test_session):
"""
Test: Agent lists tasks with natural language "show my tasks"
Verifies that agent recognizes "show my tasks" intent and lists tasks.
"""
# Setup: Create tasks
create_multiple_tasks(test_session, test_user.id, count=2, title_prefix="My Task")
# Execute
response = await invoke_agent_with_message(
user_id=test_user.id,
message="Show my tasks"
)
# Assert agent called list_tasks tool
assert_tool_called(response, "list_tasks")
# Extract tool calls to verify result
tool_calls = extract_tool_calls(response)
list_tasks_call = next((tc for tc in tool_calls if tc["tool"] == "list_tasks"), None)
assert list_tasks_call is not None
# Verify tool returned tasks
result = list_tasks_call.get("result", {})
assert "tasks" in result
assert len(result["tasks"]) == 2
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_lists_tasks_after_creating_multiple_tasks(test_user, test_session):
"""
Test: Agent lists tasks after creating multiple tasks
Verifies that agent can create tasks and then list them in sequence.
"""
# Create first task
response1 = await invoke_agent_with_message(
user_id=test_user.id,
message="Add a task to buy milk"
)
assert_tool_called(response1, "create_task")
# Create second task
response2 = await invoke_agent_with_message(
user_id=test_user.id,
message="Add a task to buy eggs"
)
assert_tool_called(response2, "create_task")
# List tasks
response3 = await invoke_agent_with_message(
user_id=test_user.id,
message="What are my tasks?"
)
assert_tool_called(response3, "list_tasks")
# Verify list_tasks returned both tasks
tool_calls = extract_tool_calls(response3)
list_tasks_call = next((tc for tc in tool_calls if tc["tool"] == "list_tasks"), None)
result = list_tasks_call.get("result", {})
assert result["total"] == 2
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_lists_tasks_with_empty_list(test_user, test_session):
"""
Test: Agent lists tasks with empty list
Verifies that agent handles empty task list gracefully.
"""
# Execute without creating any tasks
response = await invoke_agent_with_message(
user_id=test_user.id,
message="Show me my tasks"
)
# Assert agent called list_tasks tool
assert_tool_called(response, "list_tasks")
# Verify agent provides appropriate response for empty list
assert response["content"] is not None
# Agent should indicate no tasks exist
@pytest.mark.integration
@pytest.mark.asyncio
async def test_agent_lists_tasks_with_various_natural_language_phrases(test_user, test_session):
"""
Test: Agent lists tasks with various natural language phrases
Verifies that agent recognizes different ways of asking for task list.
"""
# Setup: Create tasks
create_multiple_tasks(test_session, test_user.id, count=2)
# Test various phrases
phrases = [
"What do I need to do?",
"List my todos",
"What are my tasks?",
"Show me my task list"
]
for phrase in phrases:
response = await invoke_agent_with_message(
user_id=test_user.id,
message=phrase
)
# Assert agent called list_tasks tool for each phrase
assert_tool_called(response, "list_tasks")
|