From 349e8b93583d5517d0855504b3ff67a857e592dc Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Thu, 17 Sep 2026 18:19:42 -0700 Subject: [PATCH] test(proxy): forward each method through the typesafe route to a mocked upstream The route test only resolved route names. It now sends every method through the proxy with a virtual key and asserts the upstream receives that method, the proxy's TypeSafe key and the caller's body --- .../test_llm_pass_through_endpoints.py | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py index 07936e7a9e9..9394a13fee4 100644 --- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py +++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py @@ -6149,9 +6149,41 @@ class TestTypeSafePassthroughRoute: request.json = AsyncMock(return_value=body) return request - @pytest.mark.parametrize("method", ["GET", "POST", "PUT", "DELETE", "PATCH"]) - def test_route_serves_every_method(self, method: str): - assert _resolve_route_name(method, "/typesafe/v1/systemone") == "typesafe_proxy_route" + @pytest.fixture + def client(self, monkeypatch: pytest.MonkeyPatch) -> Iterator[TestClient]: + from litellm.proxy.proxy_server import app + + monkeypatch.setenv("TYPESAFE_API_KEY", "typesafe-test-key") + monkeypatch.setenv("TYPESAFE_API_BASE", "https://typesafe.example/base") + monkeypatch.delenv("SERVER_ROOT_PATH", raising=False) + monkeypatch.setattr(litellm, "disable_aiohttp_transport", True) + litellm.in_memory_llm_clients_cache.flush_cache() + monkeypatch.setitem(app.dependency_overrides, user_api_key_auth, lambda: UserAPIKeyAuth(api_key="sk-virtual")) + yield TestClient(app) + + @pytest.mark.parametrize( + "method, body", + [ + ("GET", None), + ("POST", {"state": "x"}), + ("PUT", {"state": "x"}), + ("DELETE", None), + ("PATCH", {"state": "x"}), + ], + ) + def test_forwards_every_method_and_body_upstream( + self, client: TestClient, method: str, body: dict[str, str] | None + ) -> None: + with respx.mock(assert_all_called=True) as upstream: + route = upstream.request(method, "https://typesafe.example/base/v1/systemone").mock( + return_value=httpx.Response(200, json={"id": "upstream_123"}) + ) + response = client.request(method, "/typesafe/v1/systemone", json=body) + + assert (response.status_code, response.json()) == (200, {"id": "upstream_123"}) + sent: Final = route.calls.last.request + assert sent.headers["authorization"] == "Bearer typesafe-test-key" + assert json.loads(sent.content or b"{}") == (body or {}) @pytest.mark.asyncio async def test_forwards_target_auth_headers_provider_and_query(self, monkeypatch):