Skip to content

Commit fc33fac

Browse files
declan-scaleclaude
andcommitted
test(pydantic-ai): assert content-equality + real await in on_result tests
Strengthen backward-compat guarantees for the on_result callback: - test_streaming_output_unchanged_with_callback now asserts model_dump() equality per yielded pair, not just type, proving the callback does not alter streamed message content. - test_async_callback_is_awaited adds a real suspension point (await asyncio.sleep(0)) before its side effect, so the assertion only passes if the converter actually awaits the returned coroutine. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 7a30e6e commit fc33fac

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

tests/lib/adk/test_pydantic_ai_sync.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import json
6+
import asyncio
67
from typing import Any, AsyncIterator
78

89
import pytest
@@ -524,6 +525,7 @@ async def test_streaming_output_unchanged_with_callback(self):
524525
assert len(out_with) == len(out_without)
525526
for a, b in zip(out_with, out_without):
526527
assert type(a) is type(b)
528+
assert a.model_dump() == b.model_dump()
527529
assert len(captured) == 1
528530

529531
async def test_no_callback_no_error(self):
@@ -534,15 +536,22 @@ async def test_no_callback_no_error(self):
534536
assert out == []
535537

536538
async def test_async_callback_is_awaited(self):
537-
"""An async on_result callable is properly awaited."""
538-
captured: list[AgentRunResultEvent] = []
539+
"""An async on_result callable is properly awaited.
540+
541+
The callback suspends (``await asyncio.sleep(0)``) before recording its
542+
side effect, so ``awaited`` is only populated if the converter actually
543+
awaits the returned coroutine — distinguishing "awaited" from
544+
"called-but-not-awaited."
545+
"""
546+
awaited: list[AgentRunResultEvent] = []
539547

540548
async def on_result_async(event: AgentRunResultEvent) -> None:
541-
captured.append(event)
549+
await asyncio.sleep(0)
550+
awaited.append(event)
542551

543552
result_event = self._make_result_event("async_output")
544553
events = [result_event]
545554
await _collect(convert_pydantic_ai_to_agentex_events(_aiter(events), on_result=on_result_async))
546555

547-
assert len(captured) == 1
548-
assert captured[0].result.output == "async_output"
556+
assert len(awaited) == 1
557+
assert awaited[0].result.output == "async_output"

0 commit comments

Comments
 (0)