diff --git a/tests/test_openai_source.py b/tests/test_openai_source.py index 2b361da7e..428ef1566 100644 --- a/tests/test_openai_source.py +++ b/tests/test_openai_source.py @@ -273,6 +273,36 @@ async def test_groq_payload_drops_reasoning_content_from_assistant_history(): await provider.terminate() +@pytest.mark.asyncio +async def test_openai_payload_handles_none_think_content(): + """Test that _finally_convert_payload handles think content being None.""" + provider = _make_provider() + try: + # Test case where think content might be None + payloads = { + "messages": [ + { + "role": "assistant", + "content": [ + {"type": "think", "think": None}, # type: ignore + {"type": "text", "text": "final answer"}, + ], + } + ] + } + + # Should not raise TypeError: unsupported operand type(s) for +=: 'NoneType' and 'str' + provider._finally_convert_payload(payloads) + + assistant_message = payloads["messages"][0] + assert assistant_message["content"] == [ + {"type": "text", "text": "final answer"} + ] + finally: + await provider.terminate() + + + @pytest.mark.asyncio async def test_handle_api_error_content_moderated_without_images_raises(): provider = _make_provider(