fix: treat SSE stream without [DONE] as truncated (retry, no cache)

This commit is contained in:
2026-07-16 05:26:21 -04:00
parent 7cc6aa5b23
commit 200053fbdc
2 changed files with 31 additions and 0 deletions
+27
View File
@@ -259,6 +259,33 @@ async def test_qwen_thinking_stripped():
assert thinking2 == ""
@pytest.mark.asyncio
async def test_truncated_stream_without_done_raises():
"""SSE 流耗尽但未收 [DONE] → _SseAnomaly(进重试,不当成功)。"""
from adapters.llm import _SseAnomaly
async def _lines():
yield 'data: {"choices":[{"delta":{"content":""}}]}'
# 无 data: [DONE] —— 模拟服务端截断
client = _build_client()
with pytest.raises(_SseAnomaly):
await client._consume_stream(_lines())
@pytest.mark.asyncio
async def test_complete_stream_with_done_ok():
"""正常带 [DONE] 的流不抛异常,正确累积 content。"""
async def _lines():
yield 'data: {"choices":[{"delta":{"content":"完整"}}]}'
yield "data: [DONE]"
client = _build_client()
content, _thinking, _ttft, _gap, _usage = await client._consume_stream(_lines())
assert content == "完整"
@pytest.mark.asyncio
async def test_parent_call_id_forwarded_to_telemetry():
"""parent_call_id 和 session_id 正确传递到遥测记录。"""