Skip to content

Commit 045b29e

Browse files
declan-scaleclaude
andcommitted
test(openai): make created_at forwarding test non-vacuous [greptile]
test_run_agent_streamed_auto_send_forwards_created_at fed an empty stream, so auto_send opened zero streaming contexts and `all(ts == deterministic_ts for ts in recorded_created_ats)` was vacuously true — it could not catch a created_at regression. Emit a tool call + tool response so contexts are actually opened, and assert recorded_created_ats is non-empty before checking each value. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent f82fac8 commit 045b29e

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

tests/lib/adk/providers/test_openai_activities.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -340,11 +340,7 @@ async def mock_stream_events():
340340
# by opening a streaming context with the content as initial_content and
341341
# closing it (no stream_update). So assert on the opened contents.
342342
opened = mock_streaming_context.opened_contents
343-
tool_contents = [
344-
c
345-
for c in opened
346-
if getattr(c, "type", None) in ("tool_request", "tool_response")
347-
]
343+
tool_contents = [c for c in opened if getattr(c, "type", None) in ("tool_request", "tool_response")]
348344
assert len(tool_contents) == 2
349345

350346
# First opened context is the tool request.
@@ -631,11 +627,21 @@ async def test_run_agent_streamed_auto_send_forwards_created_at(self, mock_runne
631627

632628
mock_streaming_result = self._create_streaming_result_mock()
633629

634-
async def _no_events():
635-
return
636-
yield # make it an async generator
630+
# Emit a tool call + tool response so auto_send actually opens streaming
631+
# contexts; an empty stream opens none, making the assertion below
632+
# vacuously true and unable to catch a created_at regression.
633+
async def mock_stream_events():
634+
tool_call_event = Mock()
635+
tool_call_event.type = "run_item_stream_event"
636+
tool_call_event.item = self._create_tool_call_item_mock(self._create_code_interpreter_tool_call_mock())
637+
yield tool_call_event
638+
639+
tool_response_event = Mock()
640+
tool_response_event.type = "run_item_stream_event"
641+
tool_response_event.item = self._create_tool_output_item_mock()
642+
yield tool_response_event
637643

638-
mock_streaming_result.stream_events = _no_events
644+
mock_streaming_result.stream_events = mock_stream_events
639645
mock_runner_run_streamed.return_value = mock_streaming_result
640646

641647
mock_tracer = self._create_mock_tracer()
@@ -655,9 +661,11 @@ async def _no_events():
655661

656662
await env.run(openai_activities.run_agent_streamed_auto_send, params)
657663

664+
# Guard against a vacuous pass: at least one streaming context must have
665+
# been opened so the per-context created_at assertion is meaningful.
666+
assert recorded_created_ats, "expected at least one streaming context to be opened"
658667
assert all(ts == deterministic_ts for ts in recorded_created_ats), (
659-
f"Expected all streaming contexts to receive created_at={deterministic_ts!r}, "
660-
f"got: {recorded_created_ats!r}"
668+
f"Expected all streaming contexts to receive created_at={deterministic_ts!r}, got: {recorded_created_ats!r}"
661669
)
662670

663671
def _setup_streaming_service_mocks(self, openai_service):

0 commit comments

Comments
 (0)