litellm/tests/unit/proxy/common_utils/test_codex_version.py
ryan-crabbe-berri 87be092af7
fix(proxy): send the whole Codex model catalog to Codex 0.166.0-alpha.1 and newer (#50736)
* fix(proxy): send the whole Codex model catalog to Codex 0.166.0-alpha.1 and newer

Codex removed its 1 MiB limit on model_catalog_url responses in openai/codex#56525,
first shipped in 0.166.0-alpha.1 (0.165.0 stable was cut without it). Older or unknown
Codex versions still get the catalog cut to 1 MiB, since they drop a larger one.

* fix(proxy): order patched Codex alphas like 0.166.0-alpha.5.1 when gating the catalog

Codex tags patch releases of an alpha as X.Y.Z-alpha.N.M, which PEP 440 rejects, so those
clients counted as too old for the uncut catalog, their custom reasoning levels and stock
entries. Map them to aN.postM so they sort between alpha.N and alpha.N+1 as semver does.

* test(proxy): type the Codex catalog byte-limit test

* refactor(proxy): gate the uncut Codex catalog on the 0.166 release line

Read only the major and minor numbers of client_version instead of a shared
semver comparison, and leave the reasoning level and stock entry version
checks as they are on main.

* refactor(proxy): read every Codex client_version with one helper

Codex sends semver tags such as 0.166.0-alpha.5.1 that the generic version
parser rejects. The catalog byte limit, the per-model minimum version and the
custom reasoning level checks now share one reader for Codex's format, which
also bounds digit counts so an absurd version can't fail the listing.
2026-11-10 07:10:30 +00:00

39 lines
1.4 KiB
Python

from __future__ import annotations
import pytest
from litellm.proxy.common_utils.codex_version import codex_version_at_least
@pytest.mark.parametrize(
("client_version", "first", "at_least"),
[
("0.166.0", "0.166.0", True),
("0.166.1", "0.166.0", True),
("0.167.0", "0.166.9", True),
("1.0.0", "0.999.0", True),
("0.165.9", "0.166.0", False),
("0.166.0-alpha.1", "0.166.0", False),
("0.166.0", "0.166.0-alpha.9", True),
("0.166.0-alpha.2", "0.166.0-alpha.1", True),
("0.166.0-alpha.10", "0.166.0-alpha.9", True),
("0.166.0-alpha.5.1", "0.166.0-alpha.5", True),
("0.166.0-alpha.5.1", "0.166.0-alpha.6", False),
("0.166.0-alpha.5.2", "0.166.0-alpha.5.1", True),
("0.165.0", "0.165.0-alpha.2", True),
("0.165.0-alpha.1.2", "0.166.0-alpha.1", False),
],
)
def test_codex_versions_order_as_semver(client_version: str, first: str, at_least: bool) -> None:
assert codex_version_at_least(client_version, first) is at_least
@pytest.mark.parametrize(
"client_version", [None, "", "dev", "0.166", "v0.166.0", "0.166.0-beta.1", "9" * 5000 + ".0.0"]
)
def test_a_missing_or_unreadable_version_counts_as_older(client_version: str | None) -> None:
assert codex_version_at_least(client_version, "0.0.0") is False
def test_an_unreadable_threshold_admits_no_version() -> None:
assert codex_version_at_least("0.166.0", "latest") is False