Skip to content

Commit a2d4974

Browse files
test(reasoning-delta): tighten vacuous-pass assertions
The two stream-event tests were only asserting on data conditional on a ReasoningDeltaEvent being emitted at all, so a regression that stopped emitting the event entirely would have passed silently. * test_reasoning_delta_snapshot_accumulates: assert that snapshots is non-empty before checking monotonic length and the "Hello world" inclusion (previously gated on `if snapshots:`). * test_no_reasoning_delta_event_without_reasoning: count yielded events and assert the stream produced at least one, so the negative not-isinstance assertion can't pass on an empty event stream. Picked up the remaining nitpicks from the CodeRabbit review of PR #3.
1 parent 996be13 commit a2d4974

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

tests/test_reasoning_delta_stream_event.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,17 @@ async def test_reasoning_delta_snapshot_accumulates() -> None:
6161
if isinstance(event, ReasoningDeltaEvent):
6262
snapshots.append(event.snapshot)
6363

64+
# The stream must have produced at least one snapshot, otherwise the
65+
# subsequent monotonic and content checks would silently pass on a
66+
# broken implementation that never emits ReasoningDeltaEvent at all.
67+
assert snapshots, "expected at least one ReasoningDeltaEvent snapshot"
68+
6469
# Each snapshot must be at least as long as the previous one
6570
for i in range(1, len(snapshots)):
6671
assert len(snapshots[i]) >= len(snapshots[i - 1])
6772

6873
# Last snapshot must contain the full reasoning text
69-
if snapshots:
70-
assert "Hello world" in snapshots[-1]
74+
assert "Hello world" in snapshots[-1]
7175

7276

7377
@pytest.mark.asyncio
@@ -79,11 +83,17 @@ async def test_no_reasoning_delta_event_without_reasoning() -> None:
7983
agent = Agent(name="A", model=model)
8084
result = Runner.run_streamed(agent, input="hi")
8185

86+
event_count = 0
8287
async for event in result.stream_events():
88+
event_count += 1
8389
assert not isinstance(event, ReasoningDeltaEvent), (
8490
"Got unexpected ReasoningDeltaEvent for a plain text response"
8591
)
8692

93+
# Sanity: ensure the run actually streamed something so the
94+
# negative assertion above isn't passing on an empty event stream.
95+
assert event_count > 0, "expected the stream to yield at least one event"
96+
8797

8898
@pytest.mark.asyncio
8999
async def test_reasoning_delta_event_type_field() -> None:

0 commit comments

Comments
 (0)