litellm/tests/e2e/codex/setups.py
ryan-crabbe-berri 4012eb6242
test(e2e): run codex in fast mode under the real model name (#49899)
* test(e2e): run codex in fast mode under the real model name as a team model

Each test registers its deployment as a team model named after the real model, on a throwaway team with a
team key, so parallel tests never share one pooled deployment. Fast mode sets service_tier to priority the
way /fast does and must still answer with a value only reachable through the gateway, on every setup

* test(e2e): check codex fast mode really asks the gateway for the fast tier

The Fast mode row only checked the answer, so it passed the same if the fast setting quietly stopped
doing anything. It now reads whether the gateway's Codex catalog offers the priority tier for the model,
and checks the requests the gateway logged for that key carried service_tier priority when it does and
never asked for it when it doesn't

* test(e2e): fail codex fast mode when the gateway logged too few requests

With no spend log rows the tier checks ran over an empty list and passed. The test now requires at least
the two requests a command round trip makes before it checks their tiers
2026-11-21 03:10:15 +00:00

113 lines
3.6 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 dataclasses import dataclass, field
from typing import Final, Literal
import pytest
from _pytest.mark.structures import ParameterSet
from cli_harness.rate_limiter import RateBucket
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}"
_BEDROCK_REGION: Final = "us-east-1"
type SetupId = Literal["bedrock_mantle", "bedrock_runtime", "azure_openai", "openai", "claude_bedrock"]
@dataclass(frozen=True, slots=True)
class Deployment:
litellm_params: LiteLLMParamsBody
rate_bucket: RateBucket
real_model_name: str
@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,
)
)
SETUPS: Final = (
pytest.param(
Deployment(
LiteLLMParamsBody(model=GPT_ON_BEDROCK_MANTLE, aws_region_name=_BEDROCK_REGION),
RateBucket.BEDROCK_MANTLE,
real_model_name=GPT,
),
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,
),
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,
),
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,
),
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,
),
id="claude_bedrock",
marks=_drives(Provider.BEDROCK, CLAUDE_ON_BEDROCK),
),
)
def with_expected_failure(setup_id: SetupId, *, reason: str) -> tuple[ParameterSet, ...]:
return tuple(
pytest.param(*setup.values, id=setup.id, marks=(*setup.marks, pytest.mark.xfail(strict=True, reason=reason)))
if setup.id == setup_id
else setup
for setup in SETUPS
)