litellm/tests/e2e/codex/test_reasoning_effort_e2e.py
izzybn 0a72066fa8
test(e2e): add a Codex compatibility table, a Vertex AI column and five rows to tests/e2e/codex (#54065)
* test(e2e): add a Codex compatibility matrix suite

Add tests/e2e/client_apps, a compatibility matrix for coding-agent CLIs
other than Claude Code, starting with Codex 0.164.0 pinned through npm.
Each of the 36 cells drives the real codex exec against the proxy for one
feature and provider column, records a pass or fail per model, and the
typed matrix builder turns the results into a matrix and flags cells that
went from green to red. The harness parts are covered in
tests/e2e_harness/client_apps

* test(e2e): mark known proxy gaps in the Codex matrix as strict xfails

The codex manifest gets a known_gaps list of feature, provider and reason. The
client_apps conftest marks each listed cell xfail(strict=True) at collection,
so the shared e2e lane stays green while a known gap lasts and goes red when
the cell starts passing. The results file still records what the cell did,
including crashes under the xfail and a passing strict XPASS. An entry naming a
feature or provider the manifest lacks, or a cell listed twice, fails loudly.

Web search is listed for all four columns with the proxy behavior behind each
failure.

* test(e2e): let a Codex known gap be non-strict for intermittent cells

A known_gaps entry can now set strict: false (a real bool, default true). That
entry marks its cell xfail(strict=False), so the e2e lane stays green whether
the cell passes or fails, while the results file still records what happened.

Vertex structured output gets a non-strict entry, since gemini-3.8-flash
sometimes loops on shell calls or stalls under an output schema and times out.

* test(e2e): drop gemini-3.8-flash from the Codex Vertex column and fail vision on shell reads

Flash timed out at random on structured output and file edit, and once named the vision color by reading the PNG with PIL. Vertex now runs gemini-4-argon alone, so the non-strict known gap option goes away, and the vision cell fails when the model ran any shell command.

* test(e2e): settle the Codex claude_bedrock caching and reasoning cells and skip Mantle web search without the IAM grant

* test(e2e): tighten codex known gaps and effort checks, rerun cells once, record the Codex version

The reasoning effort row now checks that every logged request asked for high effort and every logged response echoes it or nothing. Known gaps expect only an AssertionError, so a setup error, crash or timeout still fails. Each codex cell reruns once on an AssertionError, and the table keeps the last attempt. The table builder takes --codex-version, refuses a missing table, reports a dropped pass cell as missing, and keeps acronyms in row names

* test(e2e): wait for the codex MCP server, turn off pytest-retry, and give codex harness tests unique names

Codex sent a turn's first request before the local MCP server was up, so
on a resumed turn the model called the vault tool before Codex registered
it and the MCP row failed on Claude, Gemini and OpenAI. The harness now
marks the server required, so Codex waits for it.

pytest-retry, a ci-group plugin, reads the same flaky marker as
pytest-rerunfailures and retried crashes too, so tests/e2e/pytest.ini
turns it off and the rerun test runs with the real pytest.ini.

The new codex harness test files collided with the claude_code ones of
the same name at collection, so they take the folder's test_codex_ prefix.

* test(e2e): turn off pytest-retry in the codex harness test instead of tests/e2e/pytest.ini

A change to tests/e2e/pytest.ini makes CI's e2e picker run every e2e suite on this PR, and the e2e runners do not install pytest-retry, so the line only mattered locally. The codex conftest harness test now passes -p no:pytest-retry itself, and AGENTS.md tells a local run to do the same

* test(e2e): expect only a missing feature in codex known gaps and match whole color names in the vision row

A strict xfail on a codex setup now expects MissingFeature, which a row raises
through require_feature on the check of the feature itself, so a setup error,
a Codex crash or any other failed assertion in a known-gap cell still fails.
The vision row matches whole color names, so "colored" no longer reads as red.

* test(e2e): record the failed first attempt on a codex cell that passed on its rerun

The OpenAI and Azure web search xfail reason now names Codex's bundled entry as the cause, served by LiteLLM's model list.

* test(e2e): keep a codex known gap's failed first attempt and document the Claude and Gemini real-name check

A known gap after a failed attempt now carries first_attempt_error like a pass does. The docs say the real-name row checks that the gateway adds no tool mode for models no Codex catalog lists, the run.py docstring names the lockfile pin, and pytest.ini drops a duplicate meta marker

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-24 01:14:11 -08:00

71 lines
2.7 KiB
Python

from __future__ import annotations
from collections.abc import Iterable
from typing import Final
import pytest
from codex.harness import CodexHarness
from codex.setups import SETUPS, ModelSetup
from e2e_config import unique_marker
from models import SpendLogRow
from proxy_client import ProxyClient
from pydantic import BaseModel, ConfigDict, JsonValue
pytestmark = pytest.mark.e2e
EFFORT: Final = "high"
HIGH_EFFORT: Final = ("--config", f'model_reasoning_effort="{EFFORT}"')
MIN_TURN_REQUESTS: Final = 2
class _Reasoning(BaseModel):
model_config = ConfigDict(frozen=True)
effort: str | None = None
class _WithReasoning(BaseModel):
model_config = ConfigDict(frozen=True)
reasoning: _Reasoning | None = None
def _requested_efforts(rows: list[SpendLogRow]) -> tuple[str | None, ...]:
assert all(row.proxy_server_request for row in rows), (
"the gateway logged no request body, so this test needs store_prompts_in_spend_logs on",
rows,
)
return _efforts(row.proxy_server_request for row in rows)
def _efforts(bodies: Iterable[JsonValue]) -> tuple[str | None, ...]:
parsed: Final = tuple(_WithReasoning.model_validate(body) for body in bodies)
return tuple(body.reasoning.effort if body.reasoning else None for body in parsed)
@pytest.mark.parametrize("deployment", SETUPS)
class TestCodexReasoningEffort:
def test_reasons_at_high_effort_over_numbers_it_read_through_the_gateway(
self, codex: CodexHarness, setup: ModelSetup, proxy: ProxyClient
) -> None:
numbers: Final = tuple(100 + int(unique_marker()[:4], 16) % 900 for _ in range(3))
workspace: Final = codex.new_workspace(files={"numbers.txt": "\n".join(map(str, numbers)) + "\n"})
run: Final = codex.exec_with_flags(
"Run `cat numbers.txt` and no other command, then work out the sum of the squares of the numbers it"
" printed yourself. Reply with that sum as digits only.",
model=setup.model,
cwd=workspace,
flags=HIGH_EFFORT,
)
assert run.exit_code == 0, run
assert str(sum(number * number for number in numbers)) in run.answer, run
assert run.usage is not None and run.usage.reasoning_output_tokens > 0, run
rows: Final = proxy.poll_logs_for_key(setup.api_key, min_rows=MIN_TURN_REQUESTS)
assert len(rows) >= MIN_TURN_REQUESTS, (
"the gateway logged fewer requests than one command round trip makes",
rows,
)
requested: Final = _requested_efforts(rows)
assert all(effort == EFFORT for effort in requested), requested
applied: Final = _efforts(row.response for row in rows)
assert all(effort in (EFFORT, None) for effort in applied), applied