From 0da5cc9653b5f6340198344f823b88a53a0e1dbd Mon Sep 17 00:00:00 2001 From: mubashir1osmani Date: Thu, 3 Sep 2026 16:47:15 -0400 Subject: [PATCH] test(mcp): explain the premium_user patch and tighten the helper docstring --- litellm/proxy/litellm_pre_call_utils.py | 2 +- tests/test_litellm/proxy/test_proxy_utils.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.py index a9d2dcd9d63..fdce1bd33de 100644 --- a/litellm/proxy/litellm_pre_call_utils.py +++ b/litellm/proxy/litellm_pre_call_utils.py @@ -2870,7 +2870,7 @@ def add_guardrails_from_auth_metadata( data: dict, # mutable-ok: writes guardrails into the live request dict, same contract as the helpers it wraps metadata_variable_name: str, ) -> None: - """Resolve key, team, and project guardrails (direct and via policies) onto ``data[metadata_variable_name]``.""" + """Resolve key, team, and project guardrails, direct and via policies, onto the request metadata.""" _add_guardrails_from_key_or_team_metadata( key_metadata=user_api_key_dict.metadata, team_metadata=user_api_key_dict.team_metadata, diff --git a/tests/test_litellm/proxy/test_proxy_utils.py b/tests/test_litellm/proxy/test_proxy_utils.py index 499181fe0e5..8c4afe32810 100644 --- a/tests/test_litellm/proxy/test_proxy_utils.py +++ b/tests/test_litellm/proxy/test_proxy_utils.py @@ -1900,7 +1900,9 @@ def test_convert_mcp_to_llm_format_carries_key_and_team_guardrails(key_metadata, } request_obj = proxy_logging._create_mcp_request_object_from_kwargs(kwargs) - with patch("litellm.proxy.proxy_server.premium_user", True): + with patch( # test-quality-ok: the key-guardrail premium gate reads this proxy_server module global and has no injection seam + "litellm.proxy.proxy_server.premium_user", True + ): synthetic = proxy_logging._convert_mcp_to_llm_format(request_obj, kwargs) assert guardrail.should_run_guardrail(synthetic, GuardrailEventHooks.pre_mcp_call) is expected_to_run