|
16 | 16 | pytest tests/test_agent.py -v |
17 | 17 | """ |
18 | 18 |
|
19 | | -import asyncio |
20 | 19 | import pytest |
21 | 20 | import pytest_asyncio |
22 | 21 |
|
@@ -71,46 +70,39 @@ async def test_send_event_and_stream(self, test_agent: AsyncAgentTest): |
71 | 70 | user_message = "Hello, this is a test message!" |
72 | 71 |
|
73 | 72 | # Flags to track what we've received |
74 | | - task_creation_found = False |
75 | 73 | user_echo_found = False |
76 | 74 | agent_response_found = False |
77 | 75 | all_events = [] |
78 | 76 |
|
79 | 77 | # Stream events |
80 | 78 | async for event in stream_agent_response(test_agent.client, test_agent.task_id, timeout=30.0): |
81 | | - #async for event in test_agent.send_event_and_stream(user_message, timeout_seconds=30.0): |
82 | 79 | all_events.append(event) |
83 | 80 | event_type = event.get("type") |
84 | 81 |
|
85 | | - if event_type == "full": |
| 82 | + if event_type == 'connected': |
| 83 | + await test_agent.send_event(user_message, timeout_seconds=30.0) |
| 84 | + |
| 85 | + elif event_type == "full": |
86 | 86 | content = event.get("content", {}) |
87 | 87 | if content.get("content") is None: |
88 | 88 | continue # Skip empty content |
89 | 89 |
|
90 | 90 | if content.get("type") == "text" and content.get("author") == "agent": |
91 | | - # Check for initial task creation message |
92 | | - if "Hello! I've received your task" in content.get("content", ""): |
93 | | - task_creation_found = True |
94 | 91 | # Check for agent response to user message |
95 | | - elif "Hello! I've received your message" in content.get("content", ""): |
| 92 | + if "Hello! I've received your message" in content.get("content", ""): |
96 | 93 | agent_response_found = True |
| 94 | + assert user_echo_found, "User echo should be found before agent response" |
97 | 95 |
|
98 | 96 | elif content.get("type") == "text" and content.get("author") == "user": |
99 | 97 | # Check for user message echo (may or may not be present) |
100 | 98 | if content.get("content") == user_message: |
101 | 99 | user_echo_found = True |
102 | 100 |
|
103 | 101 | # Exit early if we've found expected messages |
104 | | - if task_creation_found and agent_response_found and user_echo_found: |
| 102 | + if agent_response_found and user_echo_found: |
105 | 103 | break |
106 | 104 |
|
107 | | - print('all events', all_events) |
108 | | - messages = await test_agent.client.messages.list(task_id=test_agent.task_id) |
109 | | - print('all messages', messages) |
110 | | - # Validate we saw expected messages |
111 | | - assert task_creation_found, "Did not receive task creation message" |
112 | 105 | assert agent_response_found, "Did not receive agent response to user message" |
113 | | - # User echo is optional; no assert |
114 | 106 | assert user_echo_found, "User echo message not found" |
115 | 107 | assert len(all_events) > 0, "Should receive events" |
116 | 108 |
|
|
0 commit comments