Merge pull request #28039 from BerriAI/litellm_/nostalgic-johnson-eeb7c3

test(gemini): de-flake test_gemini_image_size_limit_exceeded
This commit is contained in:
yuneng-jiang 2026-05-15 23:18:56 -07:00 • committed by GitHub
commit ec2f3aadb8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1594,13 +1594,49 @@ 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),
},
# Empty body: the Content-Length header check in
# _process_image_response rejects the image before the body
# is ever streamed, so there's no need to allocate 100MB.
content=b"",
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 +1644,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",
},
],
}