From 182ea16dc86b1d6ebf09b5490a8a0b284fc92179 Mon Sep 17 00:00:00 2001 From: coconinja2 Date: Tue, 22 Sep 2026 11:03:39 -0500 Subject: [PATCH] test(proxy): cover Oso image model precedence --- .../proxy/auth/test_oso_authorization.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/test_litellm/proxy/auth/test_oso_authorization.py b/tests/test_litellm/proxy/auth/test_oso_authorization.py index 7a6fe5b2804..a37965c447d 100644 --- a/tests/test_litellm/proxy/auth/test_oso_authorization.py +++ b/tests/test_litellm/proxy/auth/test_oso_authorization.py @@ -1,4 +1,5 @@ from collections.abc import Mapping +from types import MappingProxyType from typing import Final from unittest.mock import patch @@ -415,6 +416,53 @@ async def test_oso_image_query_model_takes_precedence_over_image_default() -> No assert tuple(decision.resource_id for decision in authorizer.requests) == ("query-model",) +@pytest.mark.asyncio +@pytest.mark.parametrize( + ("route", "settings", "expected_model"), + ( + ( + "/v1/images/generations", + MappingProxyType({"image_generation_model": "server-image-model"}), + "cli-model", + ), + ( + "/v1/images/edits", + MappingProxyType( + {"completion_model": "server-completion-model", "image_generation_model": "server-image-model"} + ), + "server-completion-model", + ), + ), +) +async def test_oso_image_model_precedence_matches_final_dispatch( + route: str, + settings: Mapping[str, str], + expected_model: str, +) -> None: + authorizer: Final = RecordingAuthorizer() + request: Final = Request( + scope={ + "type": "http", + "method": "POST", + "path": route, + "headers": (), + "query_string": b"model=query-model", + } + ) + with patch.object(litellm.proxy.proxy_server, "user_model", "cli-model"): + await _enforce_configured_oso_authorization( + user_api_key_auth_obj=UserAPIKeyAuth(user_id="user-alice"), + request=request, + request_data={"model": "body-model"}, + route=route, + general_settings={**_enabled_settings(), **settings}, + llm_router=None, + oso_authorizer=authorizer, + ) + + assert tuple(decision.resource_id for decision in authorizer.requests) == (expected_model,) + + @pytest.mark.asyncio async def test_oso_speech_authorizes_cli_model_without_undispatched_key_alias() -> None: authorizer: Final = RecordingAuthorizer()