mirror of
https://github.com/tiennm99/litellm.git
synced 2026-08-23 08:24:15 +00:00
address greptile review feedback (greploop iteration 1)
Add os.path.exists check before serving custom local logo so that a non-existent UI_LOGO_PATH gracefully falls through to the cache/default instead of causing a FileResponse error. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
a8026154ab
commit
145efe2267
@@ -10699,7 +10699,9 @@ async def get_image():
|
||||
|
||||
# If UI_LOGO_PATH points to a local file, serve it directly (skip cache)
|
||||
if logo_path != default_logo and not logo_path.startswith(("http://", "https://")):
|
||||
return FileResponse(logo_path, media_type="image/jpeg")
|
||||
if os.path.exists(logo_path):
|
||||
return FileResponse(logo_path, media_type="image/jpeg")
|
||||
# Fall through to cache or default if custom path doesn't exist
|
||||
|
||||
# [OPTIMIZATION] For HTTP URLs and default logo, check if the cached image exists
|
||||
if os.path.exists(cache_path):
|
||||
|
||||
@@ -3224,6 +3224,48 @@ async def test_get_image_default_logo_still_uses_cache(monkeypatch):
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_image_custom_logo_missing_falls_through_to_default(monkeypatch):
|
||||
"""
|
||||
Test that when UI_LOGO_PATH points to a non-existent local file,
|
||||
get_image falls through to the cache/default logo instead of failing.
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
|
||||
from litellm.proxy.proxy_server import get_image
|
||||
|
||||
monkeypatch.setenv("UI_LOGO_PATH", "/app/nonexistent_logo.jpg")
|
||||
monkeypatch.delenv("LITELLM_NON_ROOT", raising=False)
|
||||
monkeypatch.delenv("LITELLM_ASSETS_PATH", raising=False)
|
||||
|
||||
calls_to_file_response = []
|
||||
|
||||
def fake_file_response(path, **kwargs):
|
||||
calls_to_file_response.append(path)
|
||||
return MagicMock()
|
||||
|
||||
def exists_side_effect(path):
|
||||
# The custom logo does NOT exist; cache and default DO exist
|
||||
if path == "/app/nonexistent_logo.jpg":
|
||||
return False
|
||||
return True
|
||||
|
||||
with patch("litellm.proxy.proxy_server.os.path.exists", side_effect=exists_side_effect), \
|
||||
patch("litellm.proxy.proxy_server.os.access", return_value=True), \
|
||||
patch("litellm.proxy.proxy_server.FileResponse", side_effect=fake_file_response):
|
||||
|
||||
await get_image()
|
||||
|
||||
assert len(calls_to_file_response) == 1, "FileResponse should be called exactly once"
|
||||
served_path = calls_to_file_response[0]
|
||||
assert served_path != "/app/nonexistent_logo.jpg", (
|
||||
"Should not attempt to serve a non-existent custom logo"
|
||||
)
|
||||
assert served_path.endswith("cached_logo.jpg"), (
|
||||
f"Expected fallback to cached_logo.jpg, got {served_path}"
|
||||
)
|
||||
|
||||
|
||||
def test_get_config_normalizes_string_callbacks(monkeypatch):
|
||||
"""
|
||||
Test that /get/config/callbacks normalizes string callbacks to lists.
|
||||
|
||||
Reference in New Issue
Block a user