From 5f85c4e83d75301c11f18e865f37f070bb5889b4 Mon Sep 17 00:00:00 2001 From: Ishaan Jaffer Date: Wed, 6 May 2026 18:02:41 -0700 Subject: [PATCH] test(managed_agents): conftest.py from swarm --- tests/test_litellm/managed_agents/conftest.py | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/test_litellm/managed_agents/conftest.py diff --git a/tests/test_litellm/managed_agents/conftest.py b/tests/test_litellm/managed_agents/conftest.py new file mode 100644 index 00000000000..233bfe6db3e --- /dev/null +++ b/tests/test_litellm/managed_agents/conftest.py @@ -0,0 +1,54 @@ +""" +Shared fixtures for ``litellm.managed_agents`` tests. + +Re-uses the in-memory Prisma stand-in from +``tests/test_litellm/proxy/agent_session_endpoints/conftest.py`` so the +managed_agents Python API and the proxy HTTP endpoints exercise the +same fake DB behaviour. Tests don't need to reach into proxy_server's +global state because the managed_agents API talks to the Prisma client +directly via ``self.db``. +""" + +import os +import sys +from pathlib import Path + +import pytest + +# Set a JWT secret BEFORE any module under test (Agent / Session import the +# proxy auth helpers which read this env var at call time). +os.environ.setdefault("LITELLM_AGENT_JWT_SECRET", "test-agent-jwt-secret") +os.environ.setdefault("LITELLM_MASTER_KEY", "sk-1234") + +# Provide ``prisma.Json`` as an identity function for tests. The real symbol +# is generated by ``prisma generate`` from the schema and isn't available +# unless the full prisma codegen has run. The fake DB stores whatever payload +# we hand it, so an identity wrapper is sufficient — the call sites only +# need ``prisma.Json(value)`` to evaluate to ``value`` in tests. +import prisma # noqa: E402 + +if not hasattr(prisma, "Json"): + prisma.Json = lambda value: value # type: ignore[attr-defined] + +# Make the agent_session_endpoints test conftest importable from here. We +# reach across test packages instead of duplicating the FakePrismaClient +# so any future evolution of the fake DB is shared with proxy tests. +_ENDPOINTS_TEST_DIR = ( + Path(__file__).resolve().parent.parent / "proxy" / "agent_session_endpoints" +) +if str(_ENDPOINTS_TEST_DIR) not in sys.path: + sys.path.insert(0, str(_ENDPOINTS_TEST_DIR)) + + +@pytest.fixture +def fake_db(): + """Bare in-memory Prisma client; use this directly via ``client.db``. + + Most managed_agents tests don't need monkeypatching of + ``proxy_server.prisma_client`` because Agent/Session take ``db`` as + a parameter — pass ``fake_db.db`` straight through. + """ + # Local import: see _ENDPOINTS_TEST_DIR sys.path manipulation above. + from conftest import FakePrismaClient # type: ignore # noqa: E402 + + return FakePrismaClient()