diff --git a/tests/llm_translation/test_gemini.py b/tests/llm_translation/test_gemini.py index 97b0aaee86..037b8dad30 100644 --- a/tests/llm_translation/test_gemini.py +++ b/tests/llm_translation/test_gemini.py @@ -1594,13 +1594,46 @@ def test_gemini_31_flash_lite_reasoning_effort_minimal(): ), "gemini-3.1-flash-lite-preview should use thinkingLevel, not thinkingBudget" -def test_gemini_image_size_limit_exceeded(): +def test_gemini_image_size_limit_exceeded(monkeypatch): """ Test that large images exceeding MAX_IMAGE_URL_DOWNLOAD_SIZE_MB are rejected. This validates that the 50MB default limit prevents downloading very large images that could cause memory issues and pod crashes. + + The image fetch is mocked (mirroring the LargeImageClient pattern in + tests/test_litellm/litellm_core_utils/test_image_handling.py) so the test + deterministically exercises the size-limit rejection path without any + external network dependency. """ + from httpx import Request, Response + + from litellm.litellm_core_utils.prompt_templates import image_handling + + class LargeImageClient: + """Returns a response whose Content-Length exceeds the 50MB limit.""" + + def get(self, url, follow_redirects=True): + size_bytes = int(100 * 1024 * 1024) # 100MB > 50MB default limit + return Response( + status_code=200, + headers={ + "Content-Type": "image/jpeg", + "Content-Length": str(size_bytes), + }, + content=b"x" * size_bytes, + request=Request("GET", url), + ) + + # Bypass SSRF validation (which would resolve DNS / hit the network) and + # route straight to our mocked client. + monkeypatch.setattr( + image_handling, + "safe_get", + lambda client, url, **kw: client.get(url, follow_redirects=True), + ) + monkeypatch.setattr(litellm, "module_level_client", LargeImageClient()) + messages = [ { "role": "user", @@ -1608,7 +1641,7 @@ def test_gemini_image_size_limit_exceeded(): {"type": "text", "text": "What is in this image?"}, { "type": "image_url", - "image_url": "https://upload.wikimedia.org/wikipedia/commons/5/51/Blue_Marble_2002.jpg", + "image_url": "https://example.com/large-image.jpg", }, ], }