mirror of
https://github.com/BerriAI/litellm.git
synced 2026-12-05 01:59:27 +00:00
* test(e2e): cover a codex thread that resumes while its first deployment is down One model group holds a setup's deployment at order 1 and another provider at order 2. Codex reasons on the first, the first goes down, the thread resumes on the second, then returns once the first is back. The row needs encrypted_content_affinity, which the default e2e stack does not set, so it sits behind an opt-in marker * test(e2e): check each resumed codex turn under its own key and rate bucket
209 lines
7.1 KiB
Python
209 lines
7.1 KiB
Python
"""The credentials are `os.environ/` references the gateway resolves, the same names the Claude Code matrix's
|
|
`test_config.yaml` uses, and Bedrock rides the gateway's default AWS identity."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Mapping
|
|
from dataclasses import dataclass, field, replace
|
|
from typing import Final, Literal
|
|
|
|
import pytest
|
|
from _pytest.mark.structures import ParameterSet
|
|
from cli_harness.rate_limiter import RateBucket
|
|
from codex.harness import CodexCatalog
|
|
from codex.run import CodexRun
|
|
from e2e_metadata import Domain, Mode, Provider, Route, Subject, meta
|
|
from models import LiteLLMParamsBody
|
|
|
|
GPT: Final = "gpt-6.1-sol"
|
|
CLAUDE: Final = "claude-sonnet-5-5"
|
|
GPT_ON_BEDROCK_MANTLE: Final = f"bedrock_mantle/openai.{GPT}"
|
|
GPT_ON_BEDROCK_RUNTIME: Final = f"bedrock/global.openai.{GPT}"
|
|
GPT_ON_AZURE_OPENAI: Final = f"azure/{GPT}"
|
|
GPT_ON_OPENAI: Final = f"openai/{GPT}"
|
|
CLAUDE_ON_BEDROCK: Final = f"bedrock/us.anthropic.{CLAUDE}"
|
|
CLAUDE_OPUS: Final = "claude-opus-5-5"
|
|
CLAUDE_OPUS_ON_AZURE_AI: Final = f"azure_ai/{CLAUDE_OPUS}"
|
|
_BEDROCK_REGION: Final = "us-east-1"
|
|
|
|
type SetupId = Literal[
|
|
"bedrock_mantle", "bedrock_runtime", "azure_openai", "openai", "claude_bedrock", "vertex_ai", "claude_azure_ai"
|
|
]
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class CodexEntry:
|
|
catalog: CodexCatalog
|
|
slug: str
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Deployment:
|
|
litellm_params: LiteLLMParamsBody
|
|
rate_bucket: RateBucket
|
|
real_model_name: str
|
|
codex_entry: CodexEntry
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class ModelSetup:
|
|
model: str
|
|
rate_bucket: RateBucket
|
|
api_key: str = field(repr=False)
|
|
|
|
|
|
def _drives(provider: Provider, model: str) -> pytest.MarkDecorator:
|
|
return meta(
|
|
Subject(
|
|
domain=Domain.LLM_TRANSLATION,
|
|
route=Route.RESPONSES,
|
|
providers=(provider,),
|
|
models=(model,),
|
|
mode=Mode.STREAM,
|
|
)
|
|
)
|
|
|
|
|
|
GEMINI_ON_VERTEX: Final = "vertex_ai/gemini-4-neon"
|
|
_VERTEX_LOCATION: Final = "global"
|
|
|
|
SETUPS: Final = (
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(model=GPT_ON_BEDROCK_MANTLE, aws_region_name=_BEDROCK_REGION),
|
|
RateBucket.BEDROCK_MANTLE,
|
|
real_model_name=GPT,
|
|
codex_entry=CodexEntry("amazon-bedrock", GPT_ON_BEDROCK_MANTLE.removeprefix("bedrock_mantle/")),
|
|
),
|
|
id="bedrock_mantle",
|
|
marks=_drives(Provider.BEDROCK_MANTLE, GPT_ON_BEDROCK_MANTLE),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(model=GPT_ON_BEDROCK_RUNTIME, aws_region_name=_BEDROCK_REGION),
|
|
RateBucket.BEDROCK_CONVERSE,
|
|
real_model_name=GPT,
|
|
codex_entry=CodexEntry("amazon-bedrock-runtime", GPT_ON_BEDROCK_RUNTIME.removeprefix("bedrock/")),
|
|
),
|
|
id="bedrock_runtime",
|
|
marks=(
|
|
_drives(Provider.BEDROCK, GPT_ON_BEDROCK_RUNTIME),
|
|
pytest.mark.skip(reason="Stage IAM lacks bedrock:InvokeModel on the default Bedrock Runtime project"),
|
|
),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(
|
|
model=GPT_ON_AZURE_OPENAI, api_base="os.environ/AZURE_API_BASE", api_key="os.environ/AZURE_API_KEY"
|
|
),
|
|
RateBucket.AZURE_OPENAI,
|
|
real_model_name=GPT,
|
|
codex_entry=CodexEntry("openai", GPT),
|
|
),
|
|
id="azure_openai",
|
|
marks=_drives(Provider.AZURE, GPT_ON_AZURE_OPENAI),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(model=GPT_ON_OPENAI, api_key="os.environ/OPENAI_API_KEY"),
|
|
RateBucket.OPENAI,
|
|
real_model_name=GPT,
|
|
codex_entry=CodexEntry("openai", GPT),
|
|
),
|
|
id="openai",
|
|
marks=_drives(Provider.OPENAI, GPT_ON_OPENAI),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(model=CLAUDE_ON_BEDROCK, aws_region_name=_BEDROCK_REGION),
|
|
RateBucket.BEDROCK_CONVERSE,
|
|
real_model_name=CLAUDE,
|
|
codex_entry=CodexEntry("openai", CLAUDE),
|
|
),
|
|
id="claude_bedrock",
|
|
marks=_drives(Provider.BEDROCK, CLAUDE_ON_BEDROCK),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(
|
|
model=GEMINI_ON_VERTEX,
|
|
vertex_project="os.environ/VERTEXAI_PROJECT",
|
|
vertex_location=_VERTEX_LOCATION,
|
|
vertex_credentials="os.environ/VERTEXAI_CREDENTIALS",
|
|
),
|
|
RateBucket.VERTEX_AI,
|
|
real_model_name=GEMINI_ON_VERTEX.removeprefix("vertex_ai/"),
|
|
codex_entry=CodexEntry("openai", GEMINI_ON_VERTEX.removeprefix("vertex_ai/")),
|
|
),
|
|
id="vertex_ai",
|
|
marks=_drives(Provider.VERTEX_AI, GEMINI_ON_VERTEX),
|
|
),
|
|
pytest.param(
|
|
Deployment(
|
|
LiteLLMParamsBody(
|
|
model=CLAUDE_OPUS_ON_AZURE_AI,
|
|
api_base="os.environ/AZURE_AI_API_BASE",
|
|
api_key="os.environ/AZURE_AI_API_KEY",
|
|
),
|
|
RateBucket.AZURE,
|
|
real_model_name=CLAUDE_OPUS,
|
|
codex_entry=CodexEntry("openai", CLAUDE_OPUS),
|
|
),
|
|
id="claude_azure_ai",
|
|
marks=_drives(Provider.AZURE_AI, CLAUDE_OPUS_ON_AZURE_AI),
|
|
),
|
|
)
|
|
|
|
|
|
class MissingFeature(AssertionError):
|
|
pass
|
|
|
|
|
|
def require_feature(present: bool, run: CodexRun) -> None:
|
|
if not present:
|
|
raise MissingFeature(run)
|
|
|
|
|
|
def with_expected_failures(reasons: Mapping[SetupId, str]) -> tuple[ParameterSet, ...]:
|
|
return tuple(_expected_to_fail(setup, reasons) for setup in SETUPS)
|
|
|
|
|
|
def _expected_to_fail(setup: ParameterSet, reasons: Mapping[SetupId, str]) -> ParameterSet:
|
|
reason: Final = next((reason for setup_id, reason in reasons.items() if setup_id == setup.id), None)
|
|
if reason is None:
|
|
return setup
|
|
expected_failure: Final = pytest.mark.xfail(strict=True, raises=MissingFeature, reason=reason)
|
|
return pytest.param(*setup.values, id=setup.id, marks=(*setup.marks, expected_failure))
|
|
|
|
|
|
def with_fallbacks() -> tuple[ParameterSet, ...]:
|
|
by_id: Final = {setup.id: setup for setup in SETUPS}
|
|
return tuple(_with_fallback(setup, by_id["azure_openai" if setup.id == "openai" else "openai"]) for setup in SETUPS)
|
|
|
|
|
|
def _with_fallback(setup: ParameterSet, fallback: ParameterSet) -> ParameterSet:
|
|
return pytest.param(
|
|
*setup.values,
|
|
*fallback.values,
|
|
id=setup.id,
|
|
marks=tuple(_widened(mark, fallback) for mark in setup.marks),
|
|
)
|
|
|
|
|
|
def _widened(mark: pytest.MarkDecorator | pytest.Mark, fallback: ParameterSet) -> pytest.MarkDecorator | pytest.Mark:
|
|
subject: Final = _subject(mark)
|
|
added: Final = next((found for other in fallback.marks if (found := _subject(other)) is not None), None)
|
|
if subject is None or added is None:
|
|
return mark
|
|
return meta(
|
|
replace(
|
|
subject,
|
|
providers=(*subject.providers, *added.providers),
|
|
models=(*subject.models, *added.models),
|
|
)
|
|
)
|
|
|
|
|
|
def _subject(mark: pytest.MarkDecorator | pytest.Mark) -> Subject | None:
|
|
subject: Final = mark.args[0] if mark.name == "meta" and mark.args else None
|
|
return subject if isinstance(subject, Subject) else None
|