Add /spend/logs/v2 and /spend/logs/ui/{request_id} to spend_tracking_routes

These routes share their handler with /spend/logs/ui (already in
spend_tracking_routes), so they must be reachable by INTERNAL_USER and
INTERNAL_USER_VIEW_ONLY for parity. Per-user data filtering is still
enforced inside the endpoint by _can_user_view_spend_log.
This commit is contained in:
kimsehwan96 2026-04-27 17:20:29 +09:00
parent 2855e33b4f
commit 1c8901ff71
2 changed files with 53 additions and 0 deletions

View file

@ -586,7 +586,9 @@ class LiteLLMRoutes(enum.Enum):
"/spend/calculate",
"/spend/logs",
"/spend/logs/ui",
"/spend/logs/v2",
"/spend/logs/session/ui",
"/spend/logs/ui/{request_id}",
"/cost/estimate",
]

View file

@ -1246,6 +1246,57 @@ def test_proxy_admin_viewer_can_access_spend_logs(route):
)
@pytest.mark.parametrize(
"user_role",
[
LitellmUserRoles.INTERNAL_USER.value,
LitellmUserRoles.INTERNAL_USER_VIEW_ONLY.value,
],
)
@pytest.mark.parametrize(
"route",
["/spend/logs/v2", "/spend/logs/ui/some-request-id"],
)
def test_internal_user_can_access_v2_spend_logs(route, user_role):
"""
Test that INTERNAL_USER and INTERNAL_USER_VIEW_ONLY can pass the route
check for /spend/logs/v2 and /spend/logs/ui/{request_id}.
These routes share their handler with /spend/logs/ui (already in
spend_tracking_routes), so they must be reachable by the same roles for
parity. Per-user data filtering is enforced separately by
_can_user_view_spend_log inside the endpoint.
"""
user_obj = LiteLLM_UserTable(
user_id="internal_user",
user_email="internal@example.com",
user_role=user_role,
)
valid_token = UserAPIKeyAuth(
user_id="internal_user",
user_role=user_role,
)
request = MagicMock(spec=Request)
request.query_params = {}
try:
RouteChecks.non_proxy_admin_allowed_routes_check(
user_obj=user_obj,
_user_role=user_role,
route=route,
request=request,
valid_token=valid_token,
request_data={},
)
except Exception as e:
pytest.fail(
f"{user_role} should be able to access {route} route. Got error: {str(e)}"
)
class TestModelsRouteExemptFromDisableLLMEndpoints:
"""
Test that /models and /v1/models are exempt from DISABLE_LLM_API_ENDPOINTS.