Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test(mcp): satisfy test quality gate

yassin540e528d2190
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
index 4ae1b105dbf..33b71f8d50f 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py
@@ -7851,15 +7851,15 @@ async def test_token_exchange_refresh_passes_presented_refresh_ownership():
enforce = AsyncMock()
with (
- patch(
+ patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators
"litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client",
return_value=client,
),
- patch(
+ patch( # test-quality-ok: no injection seam exists for request identity extraction
"litellm.proxy._experimental.mcp_server.discoverable_endpoints._extract_user_id_from_request",
new=AsyncMock(return_value="user-a"),
),
- patch(
+ patch( # test-quality-ok: captures the ownership value at the exchange boundary
"litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding",
new=enforce,
),
@@ -7915,20 +7915,20 @@ async def test_token_exchange_authorization_code_passes_no_refresh_ownership():
enforce = AsyncMock()
with (
- patch(
+ patch( # test-quality-ok: no injection seam exists for the exchange's HTTP and identity collaborators
"litellm.proxy._experimental.mcp_server.discoverable_endpoints.get_async_httpx_client",
return_value=client,
),
- patch(
+ patch( # test-quality-ok: no injection seam exists for request identity extraction
"litellm.proxy._experimental.mcp_server.discoverable_endpoints._extract_user_id_from_request",
new=AsyncMock(return_value="user-a"),
),
- patch(
+ patch( # test-quality-ok: captures the ownership value at the exchange boundary
"litellm.proxy._experimental.mcp_server.discoverable_endpoints.enforce_oauth_identity_binding",
new=enforce,
),
):
- await exchange_token_with_server(
+ result = await exchange_token_with_server(
request=request,
mcp_server=server,
grant_type="authorization_code",
@@ -7939,6 +7939,8 @@ async def test_token_exchange_authorization_code_passes_no_refresh_ownership():
code_verifier=None,
)
+ assert result.status_code == 200
+ assert json.loads(result.body)["access_token"] == "at"
assert enforce.await_args.kwargs["refresh_ownership"] is None
diff --git a/tests/test_litellm/proxy/_experimental/mcp_server/test_oauth_identity_binding.py b/tests/test_litellm/proxy/_experimental/mcp_server/test_oauth_identity_binding.py
index c2662f9f298..36364c32ae5 100644
--- a/tests/test_litellm/proxy/_experimental/mcp_server/test_oauth_identity_binding.py
+++ b/tests/test_litellm/proxy/_experimental/mcp_server/test_oauth_identity_binding.py
@@ -95,7 +95,7 @@ async def test_fetch_issuer_jwks_fetches_and_caches_keys():
client: Final = MagicMock()
client.get = AsyncMock(return_value=response)
- with patch(
+ with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching
"litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client",
return_value=client,
):
@@ -115,7 +115,7 @@ async def test_fetch_issuer_jwks_rejects_malformed_document():
client: Final = MagicMock()
client.get = AsyncMock(return_value=response)
- with patch(
+ with patch( # test-quality-ok: no HTTP dependency injection seam exists for JWKS fetching
"litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client",
return_value=client,
):
@@ -130,7 +130,7 @@ async def test_discover_jwks_url_returns_provider_uri():
client: Final = MagicMock()
client.get = AsyncMock(return_value=response)
- with patch(
+ with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery
"litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client",
return_value=client,
):
@@ -147,7 +147,7 @@ async def test_discover_jwks_url_rejects_missing_provider_uri():
client: Final = MagicMock()
client.get = AsyncMock(return_value=response)
- with patch(
+ with patch( # test-quality-ok: no HTTP dependency injection seam exists for OIDC discovery
"litellm.proxy._experimental.mcp_server.oauth_identity_binding.get_async_httpx_client",
return_value=client,
):
@@ -171,7 +171,7 @@ async def test_load_caller_principal_supports_user_id_and_database_email():
assert user_id_binding is not None
assert await _load_caller_principal("user-a", user_id_binding) == "user-a"
- with patch(
+ with patch( # test-quality-ok: caller loading is a lazy database boundary without injection
"litellm.proxy._experimental.mcp_server.bridge_token_flow.load_active_user_by_id",
new=AsyncMock(side_effect=["no_active_key", SimpleNamespace(user_email="[email protected]")]),
):
@@ -183,18 +183,18 @@ async def test_load_caller_principal_supports_user_id_and_database_email():
async def test_load_stored_refresh_token_returns_credential_and_fails_closed():
get_credential: Final = AsyncMock(return_value={"refresh_token": "rt-1"})
with (
- patch(
+ patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection
"litellm.proxy._experimental.mcp_server.db.get_user_oauth_credential",
new=get_credential,
),
- patch(
+ patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection
"litellm.proxy.utils.get_prisma_client_or_throw",
return_value="prisma",
),
):
assert await _load_stored_refresh_token("user-a", "srv-1") == "rt-1"
- with patch(
+ with patch( # test-quality-ok: stored-token loading is a lazy database boundary without injection
"litellm.proxy.utils.get_prisma_client_or_throw",
side_effect=RuntimeError("database unavailable"),
):