test(managed_agents): conftest.py from swarm

This commit is contained in:
Ishaan Jaffer 2026-05-06 18:02:41 -07:00
parent 229dbb19f0
commit 5f85c4e83d
No known key found for this signature in database

View file

@ -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()