From 863d07011fe78212e84a9f701d71bc9682962bca Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Sat, 28 Feb 2026 23:24:25 +0000 Subject: [PATCH] fix(ci): resolve 4 CI test failures 1. Add CURSOR_API_BASE to environment variables reference in config_settings.md 2. Fix test_sse_mcp_handler_mock by mocking extract_mcp_auth_context and set_auth_context so the handler reaches sse_session_manager.handle_request 3. Change test_async_increment_tokens_with_ttl_preservation flaky decorator from reruns=3 to retries=3,delay=2 for better intermittent failure handling 4. Add app.dependency_overrides for user_api_key_auth in test_mock_create_audio_file to bypass authentication (same pattern as test_target_storage_invokes_storage_backend) Co-authored-by: Ishaan Jaff --- docs/my-website/docs/proxy/config_settings.md | 1 + tests/mcp_tests/test_mcp_server.py | 15 +++ .../hooks/test_parallel_request_limiter_v3.py | 2 +- .../test_files_endpoint.py | 94 +++++++++++-------- 4 files changed, 70 insertions(+), 42 deletions(-) diff --git a/docs/my-website/docs/proxy/config_settings.md b/docs/my-website/docs/proxy/config_settings.md index 66a63d33046..302259179c3 100644 --- a/docs/my-website/docs/proxy/config_settings.md +++ b/docs/my-website/docs/proxy/config_settings.md @@ -488,6 +488,7 @@ router_settings: | CONFIDENT_API_KEY | API key for Confident AI (Deepeval) Logging service | COHERE_API_BASE | Base URL for Cohere API. Default is https://api.cohere.com | COMPETITOR_LLM_TEMPERATURE | Temperature setting for the LLM used in competitor discovery. Default is 0.3 +| CURSOR_API_BASE | API base URL for Cursor AI provider integration. Default is https://api.cursor.com | DATABASE_HOST | Hostname for the database server | DATABASE_NAME | Name of the database | DATABASE_PASSWORD | Password for the database user diff --git a/tests/mcp_tests/test_mcp_server.py b/tests/mcp_tests/test_mcp_server.py index a81702d0db3..d3ec7863504 100644 --- a/tests/mcp_tests/test_mcp_server.py +++ b/tests/mcp_tests/test_mcp_server.py @@ -437,6 +437,7 @@ async def test_streamable_http_mcp_handler_mock(): @pytest.mark.asyncio async def test_sse_mcp_handler_mock(): """Test the SSE MCP handler functionality""" + from litellm.proxy._types import UserAPIKeyAuth # Mock the SSE session manager and its methods mock_sse_session_manager = AsyncMock() @@ -455,12 +456,26 @@ async def test_sse_mcp_handler_mock(): mock_receive = AsyncMock() mock_send = AsyncMock() + mock_auth_result = ( + UserAPIKeyAuth(), + None, + None, + {}, + {}, + [], + ) + with patch( "litellm.proxy._experimental.mcp_server.server._SESSION_MANAGERS_INITIALIZED", True, ), patch( "litellm.proxy._experimental.mcp_server.server.sse_session_manager", mock_sse_session_manager, + ), patch( + "litellm.proxy._experimental.mcp_server.server.extract_mcp_auth_context", + new=AsyncMock(return_value=mock_auth_result), + ), patch( + "litellm.proxy._experimental.mcp_server.server.set_auth_context", ): from litellm.proxy._experimental.mcp_server.server import handle_sse_mcp diff --git a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py index 87494368a89..d92e152d89a 100644 --- a/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py +++ b/tests/test_litellm/proxy/hooks/test_parallel_request_limiter_v3.py @@ -1116,7 +1116,7 @@ async def test_dynamic_rate_limiting_v3(): ), "RPM limit should be enforced when dynamic mode and failures detected" -@pytest.mark.flaky(reruns=3) +@pytest.mark.flaky(retries=3, delay=2) @pytest.mark.asyncio async def test_async_increment_tokens_with_ttl_preservation(): """ diff --git a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py index 709ec684266..fb063ef8ee7 100644 --- a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py +++ b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py @@ -107,8 +107,13 @@ def test_mock_create_audio_file(mocker: MockerFixture, monkeypatch, llm_router: """ import litellm from litellm import Router + from litellm.proxy._types import LitellmUserRoles + import litellm.proxy.proxy_server as ps from litellm.proxy.utils import ProxyLogging + monkeypatch.setattr("litellm.proxy.proxy_server.master_key", None) + monkeypatch.setattr("litellm.proxy.proxy_server.prisma_client", None) + # Mock create_file as an async function mock_create_file = mocker.patch("litellm.files.main.create_file", new=mocker.AsyncMock()) @@ -178,52 +183,59 @@ def test_mock_create_audio_file(mocker: MockerFixture, monkeypatch, llm_router: "litellm.proxy.proxy_server.proxy_logging_obj", proxy_logging_obj ) - # Create a simple test file content - test_file_content = b"test audio content" - test_file = ("test.wav", test_file_content, "audio/wav") - - response = client.post( - "/v1/files", - files={"file": test_file}, - data={ - "purpose": "user_data", - "target_model_names": "azure-gpt-3-5-turbo, gpt-3.5-turbo", - }, - headers={"Authorization": "Bearer test-key"}, + app.dependency_overrides[ps.user_api_key_auth] = lambda: UserAPIKeyAuth( + user_role=LitellmUserRoles.PROXY_ADMIN, user_id="test-user" ) - assert response.status_code == 200 + try: + # Create a simple test file content + test_file_content = b"test audio content" + test_file = ("test.wav", test_file_content, "audio/wav") - # Get all calls made to create_file - calls = mock_create_file.call_args_list + response = client.post( + "/v1/files", + files={"file": test_file}, + data={ + "purpose": "user_data", + "target_model_names": "azure-gpt-3-5-turbo, gpt-3.5-turbo", + }, + headers={"Authorization": "Bearer test-key"}, + ) - # Check for Azure call - azure_call_found = False - for call in calls: - kwargs = call.kwargs - if ( - kwargs.get("custom_llm_provider") == "azure" - and kwargs.get("model") == "azure/chatgpt-v-2" - and kwargs.get("api_key") == "azure_api_key" - ): - azure_call_found = True - break - assert ( - azure_call_found - ), f"Azure call not found with expected parameters. Calls: {calls}" + assert response.status_code == 200 - # Check for OpenAI call - openai_call_found = False - for call in calls: - kwargs = call.kwargs - if ( - kwargs.get("custom_llm_provider") == "openai" - and kwargs.get("model") == "openai/gpt-3.5-turbo" - and kwargs.get("api_key") == "openai_api_key" - ): - openai_call_found = True - break - assert openai_call_found, "OpenAI call not found with expected parameters" + # Get all calls made to create_file + calls = mock_create_file.call_args_list + + # Check for Azure call + azure_call_found = False + for call in calls: + kwargs = call.kwargs + if ( + kwargs.get("custom_llm_provider") == "azure" + and kwargs.get("model") == "azure/chatgpt-v-2" + and kwargs.get("api_key") == "azure_api_key" + ): + azure_call_found = True + break + assert ( + azure_call_found + ), f"Azure call not found with expected parameters. Calls: {calls}" + + # Check for OpenAI call + openai_call_found = False + for call in calls: + kwargs = call.kwargs + if ( + kwargs.get("custom_llm_provider") == "openai" + and kwargs.get("model") == "openai/gpt-3.5-turbo" + and kwargs.get("api_key") == "openai_api_key" + ): + openai_call_found = True + break + assert openai_call_found, "OpenAI call not found with expected parameters" + finally: + app.dependency_overrides.pop(ps.user_api_key_auth, None) @pytest.mark.flaky(retries=3, delay=2)