From 8af57a0873a9985be5762a43c65fc0138212f4b7 Mon Sep 17 00:00:00 2001 From: Yuneng Jiang Date: Tue, 19 May 2026 21:21:00 -0700 Subject: [PATCH] test(proxy_behavior): scaffold session-scoped async ASGI client + liveness smoke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Slice 2 of the management-endpoints behavior-pinning effort. New top-level dir tests/proxy_behavior/management/ outside every existing pytest glob. conftest.py initialises the proxy app once per session against the DATABASE_URL the harness boots Postgres at, wraps it in httpx.AsyncClient via in-process ASGITransport. The one smoke test asserts /health/liveliness returns 200, which exercises the full FastAPI middleware stack against a real app — no mocks. Plan: https://www.notion.so/36643b8acdab8128a581ced0f6a4744d --- tests/proxy_behavior/__init__.py | 0 tests/proxy_behavior/management/__init__.py | 0 tests/proxy_behavior/management/conftest.py | 55 +++++++++++++++++++ tests/proxy_behavior/management/test_smoke.py | 6 ++ 4 files changed, 61 insertions(+) create mode 100644 tests/proxy_behavior/__init__.py create mode 100644 tests/proxy_behavior/management/__init__.py create mode 100644 tests/proxy_behavior/management/conftest.py create mode 100644 tests/proxy_behavior/management/test_smoke.py diff --git a/tests/proxy_behavior/__init__.py b/tests/proxy_behavior/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/proxy_behavior/management/__init__.py b/tests/proxy_behavior/management/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/tests/proxy_behavior/management/conftest.py b/tests/proxy_behavior/management/conftest.py new file mode 100644 index 00000000000..be89d6a9dc9 --- /dev/null +++ b/tests/proxy_behavior/management/conftest.py @@ -0,0 +1,55 @@ +"""Session-scoped async ASGI client for behavior-pinning tests. + +The proxy app is initialised once per pytest session against the real Postgres +pointed at by ``DATABASE_URL``. No mocks: auth runs, prisma runs, integrations +run. Tests assert at the HTTP boundary. +""" + +import os +import tempfile +from typing import AsyncIterator + +import httpx +import pytest_asyncio +import yaml + + +MASTER_KEY = "sk-1234" + + +def _write_minimal_proxy_config() -> str: + config = { + "general_settings": {"master_key": MASTER_KEY}, + "litellm_settings": {}, + } + database_url = os.environ.get("DATABASE_URL") + if database_url: + config["general_settings"]["database_url"] = database_url + + f = tempfile.NamedTemporaryFile(mode="w", suffix=".yaml", delete=False) + yaml.dump(config, f) + f.close() + return f.name + + +@pytest_asyncio.fixture(scope="session") +async def proxy_app(): + from litellm.proxy.proxy_server import ( + app, + cleanup_router_config_variables, + initialize, + ) + + cleanup_router_config_variables() + config_path = _write_minimal_proxy_config() + await initialize(config=config_path) + yield app + + +@pytest_asyncio.fixture(scope="session") +async def proxy_client(proxy_app) -> AsyncIterator[httpx.AsyncClient]: + transport = httpx.ASGITransport(app=proxy_app) + async with httpx.AsyncClient( + transport=transport, base_url="http://testserver" + ) as client: + yield client diff --git a/tests/proxy_behavior/management/test_smoke.py b/tests/proxy_behavior/management/test_smoke.py new file mode 100644 index 00000000000..0481bf74f98 --- /dev/null +++ b/tests/proxy_behavior/management/test_smoke.py @@ -0,0 +1,6 @@ +"""Smoke tests proving the harness boots and talks to the proxy app.""" + + +async def test_liveliness(proxy_client): + resp = await proxy_client.get("/health/liveliness") + assert resp.status_code == 200