diff --git a/tests/unit/litellm_core_utils/test_streaming_handler.py b/tests/unit/litellm_core_utils/test_streaming_handler.py index ca5f9c5a63f..e3201263a3c 100644 --- a/tests/unit/litellm_core_utils/test_streaming_handler.py +++ b/tests/unit/litellm_core_utils/test_streaming_handler.py @@ -576,11 +576,6 @@ _GET_WEATHER_CALL: Final = { "abcd", 0, ), - ( - (_stream_chunk({"reasoning_content": "Still thinking"}),), - "Still thinking", - 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 == "Still thinking" + + def test_strip_sse_data_from_chunk(): """Test the static method that strips 'data: ' prefix from SSE chunks""" # Test with string inputs