test(streaming): a merged reasoning stream cut mid reasoning now fails
Some checks failed
Cost map pins recheck / rerun-cost-map-guard (push) Has been cancelled
LiteLLM Rust DB / db-queries (push) Has been cancelled
LiteLLM Rust / rust-lint (push) Has been cancelled
LiteLLM Rust / rust-test (push) Has been cancelled
LiteLLM Rust / rust-wheel (push) Has been cancelled
Terraform Provider / gofmt, vet, build, test (push) Has been cancelled
Terraform Provider / Provider endpoints vs proxy OpenAPI schema (push) Has been cancelled

Main's think tag test expected a stream that ends mid reasoning without a finish reason to finish with a closed think block. With this PR that stream fails, so the case moves to its own test that expects MidStreamFallbackError with the open think block as the partial content
This commit is contained in:
yucheng-berri 2026-10-30 12:56:00 -07:00
parent 5f62fdecd1
commit 9dae6bc70b

View file

@ -576,11 +576,6 @@ _GET_WEATHER_CALL: Final = {
"<think>a</think>b<think>c</think>d",
0,
),
(
(_stream_chunk({"reasoning_content": "Still thinking"}),),
"<think>Still thinking</think>",
0,
),
(
(_stream_chunk({"content": "hi"}), _stream_chunk({}, "stop")),
"hi",
@ -592,7 +587,6 @@ _GET_WEATHER_CALL: Final = {
"reasoning_then_function_call",
"reasoning_cut_by_length",
"reasoning_after_answer",
"stream_ends_mid_reasoning",
"answer_without_reasoning",
],
)
@ -626,6 +620,26 @@ async def test_merged_reasoning_stream_keeps_think_tags_balanced(
)
@pytest.mark.asyncio
@pytest.mark.parametrize("sync_mode", [True, False])
async def test_merged_reasoning_stream_cut_mid_reasoning_fails_instead_of_closing_the_think_block(
logging_obj: Logging, sync_mode: bool
) -> None:
response: Final = CustomStreamWrapper(
completion_stream=ModelResponseListIterator(
model_responses=[_stream_chunk({"reasoning_content": "Still thinking"})]
),
model="deepseek-reasoner",
logging_obj=logging_obj,
)
response.merge_reasoning_content_in_choices = True
with pytest.raises(MidStreamFallbackError) as excinfo:
await _collect(response, sync_mode)
assert excinfo.value.generated_content == "<think>Still thinking"
def test_strip_sse_data_from_chunk():
"""Test the static method that strips 'data: ' prefix from SSE chunks"""
# Test with string inputs