From afeff773295b3a8c3dcd86f74383cdfa740559bc Mon Sep 17 00:00:00 2001 From: Hamza Hamidi <22576950+hamzahamidi@users.noreply.github.com> Date: Sun, 18 Oct 2026 01:42:14 +0200 Subject: [PATCH] test(llms): cover malformed provider response guards Exercise the independent error and response-shape checks. --- .../chat/test_fireworks_ai_chat_transformation.py | 1 + .../test_ollama_completion_transformation.py | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/unit/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py b/tests/unit/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py index 996f88e7a7d..20e21551a32 100644 --- a/tests/unit/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py +++ b/tests/unit/llms/fireworks_ai/chat/test_fireworks_ai_chat_transformation.py @@ -837,6 +837,7 @@ def _run_transform_response(response_body: dict) -> ModelResponse: {}, {"error": {"message": "upstream broke"}}, {"choices": None}, + {"choices": "not-a-list"}, {"choices": []}, {"choices": [{}]}, {"choices": [{"message": {}}]}, diff --git a/tests/unit/llms/ollama/test_ollama_completion_transformation.py b/tests/unit/llms/ollama/test_ollama_completion_transformation.py index f8c493cc244..26ce84fc14e 100644 --- a/tests/unit/llms/ollama/test_ollama_completion_transformation.py +++ b/tests/unit/llms/ollama/test_ollama_completion_transformation.py @@ -21,7 +21,14 @@ from litellm.types.utils import Message, ModelResponse, ModelResponseStream class TestOllamaConfig: - @pytest.mark.parametrize("body", [{}, {"error": {"message": "upstream broke"}}]) + @pytest.mark.parametrize( + "body", + [ + {}, + {"error": {"message": "upstream broke"}}, + {"response": "", "error": {"message": "upstream broke"}}, + ], + ) def test_transform_response_rejects_payload_without_completion(self, body): raw_response = MagicMock() raw_response.json.return_value = body @@ -620,7 +627,10 @@ class TestOllamaConfig: @pytest.mark.parametrize( "response_body", - [pytest.param({}, id="missing-response"), pytest.param({"error": {"message": "upstream broke"}}, id="error")], + [ + pytest.param({}, id="missing-response"), + pytest.param({"response": "", "error": {"message": "upstream broke"}}, id="error"), + ], ) def test_completion_with_invalid_success_reply_raises_api_connection_error( respx_mock: respx.MockRouter, response_body: dict[str, object]