Skip to content

The agent that grows with you

test(gateway/stream): pin the stream-duplicate invariants to two tests

teknium19612a1a24991
diff --git a/tests/gateway/test_stream_consumer.py b/tests/gateway/test_stream_consumer.py
index 417e356898b..ca5ea8ddaf3 100644
--- a/tests/gateway/test_stream_consumer.py
+++ b/tests/gateway/test_stream_consumer.py
@@ -581,6 +581,38 @@ class TestFinalResponseDeliveryGuard:
)
+ @pytest.mark.asyncio
+ async def test_failed_first_send_leaves_no_uneditable_partial_preview(self):
+ """A failed first send disables edits: a preview sent after it could never be updated and
+ would stay on screen truncated next to the final. Only the complete reply reaches the chat."""
+ delivered = []
+ results = iter([SimpleNamespace(success=False, error="timeout")])
+
+ async def send(**kw):
+ result = next(results, None) or SimpleNamespace(success=True, message_id=f"m{len(delivered) + 1}")
+ if result.success:
+ delivered.append(kw["content"])
+ return result
+
+ adapter = MagicMock()
+ adapter.send = AsyncMock(side_effect=send)
+ adapter.edit_message = AsyncMock(return_value=SimpleNamespace(success=True))
+ adapter.MAX_MESSAGE_LENGTH = 4096
+ config = StreamConsumerConfig(edit_interval=0.01, buffer_threshold=5, cursor="")
+ consumer = GatewayStreamConsumer(adapter, "chat_123", config)
+
+ consumer.on_delta("preview never landed ")
+ task = asyncio.create_task(consumer.run())
+ await asyncio.sleep(0.08)
+ consumer.on_delta("and more streamed text ")
+ await asyncio.sleep(0.08)
+ consumer.on_delta("then the end.")
+ consumer.finish()
+ await asyncio.wait_for(task, timeout=10)
+
+ assert delivered == ["preview never landed and more streamed text then the end."]
+
+
class TestFinalContentDeliveredGuard:
"""Regression coverage for #25010 — _final_content_delivered must only be
set when the final response is actually confirmed delivered to the user,
diff --git a/tests/gateway/test_stream_consumer_oversized_leftover.py b/tests/gateway/test_stream_consumer_oversized_leftover.py
index 40cf977f5d0..87a76e2ce0b 100644
--- a/tests/gateway/test_stream_consumer_oversized_leftover.py
+++ b/tests/gateway/test_stream_consumer_oversized_leftover.py
@@ -15,8 +15,8 @@ stripped, and whose concatenations shared a prefix. The gateway's normal final
send was correctly suppressed, which is what places the duplicate inside the
consumer rather than in the gateway's delivery ledger.
-Contract pinned here: on a non-final lane the CONSUMER owns chunking. The adapter
-must never be handed a payload larger than one message outside the final lane.
+Contract pinned here: on a non-final lane the CONSUMER owns chunking, so no line
+of the answer reaches the channel twice as a new message.
"""
import asyncio
@@ -90,24 +90,6 @@ async def _run(adapter):
return consumer
-async def test_non_final_lane_never_hands_the_adapter_an_oversized_payload():
- adapter = _make_plain_adapter()
- sends, _edits = _wire(adapter)
-
- await _run(adapter)
-
- oversized = [
- len(c) for c, notify in sends
- if not notify and len(c) > adapter.MAX_MESSAGE_LENGTH
- ]
- assert not oversized, (
- "a non-final send handed the adapter a payload it has to chunk and cap "
- f"itself (lengths {oversized}); the turn-final lane then republishes the "
- "same text with a different denominator"
- )
-
-
@pytest.mark.asyncio
async def test_no_tail_line_is_published_twice_across_new_messages():
adapter = _make_plain_adapter()