From 2262bd0aceccee64471822f9e2ffe526164478dd Mon Sep 17 00:00:00 2001 From: rain <1504569896@qq.com> Date: Sun, 20 Sep 2026 20:13:13 +0000 Subject: [PATCH] test(responses): cover pydantic and unsupported chunk dispatch Follow-up for #41109 coverage: chunk_parser now accepts pydantic BaseModel chunks and falls back to the static translator for other types. Signed-off-by: rain <1504569896@qq.com> --- ...responses_transformation_transformation.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py index f2d595cf556..b3a32df9011 100644 --- a/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py +++ b/tests/test_litellm/completion_extras/litellm_responses_transformation/test_completion_extras_litellm_responses_transformation_transformation.py @@ -4495,3 +4495,31 @@ def test_chunk_parser_unrelated_item_done_leaves_message_buffer_intact(): } ) assert result.choices[0].delta.content == "tail text" + + +def test_chunk_parser_accepts_pydantic_base_model_chunk(): + """A pydantic BaseModel chunk is dispatched through the same event path.""" + from pydantic import BaseModel + + from litellm.completion_extras.litellm_responses_transformation.transformation import ( + OpenAiResponsesToChatCompletionStreamIterator, + ) + + class _DeltaChunk(BaseModel): + type: str + delta: str + + iterator = OpenAiResponsesToChatCompletionStreamIterator(streaming_response=None, sync_stream=True) + result = iterator.chunk_parser(_DeltaChunk(type="response.output_text.delta", delta="hi")) + assert result.choices[0].delta.content == "hi" + + +def test_chunk_parser_falls_back_to_static_translation_for_unsupported_chunks(): + """Chunks that are neither dict nor BaseModel reach the stateless translator.""" + from litellm.completion_extras.litellm_responses_transformation.transformation import ( + OpenAiResponsesToChatCompletionStreamIterator, + ) + + iterator = OpenAiResponsesToChatCompletionStreamIterator(streaming_response=None, sync_stream=True) + with pytest.raises(ValueError): + iterator.chunk_parser("not a structured chunk")