mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* test(unit): reset module state only when a test changed it The proxy conftest deep-copied every snapshotted litellm attribute before each test, and the copy of litellm.model_cost alone was a median 0.12 s for each of 56,031 proxy tests on the runner. The reset now copies an attribute back only when it no longer equals the snapshot. The enterprise and MCP server conftests reloaded litellm before every test, 3.27 s and 0.21 s per test. They now use the same reset. * test(unit): remove six flaky tests They failed on main without a code change behind them between 2026-11-05 and 2026-11-14: the vector store hook SDK fallback, the concurrent user config TPM count, three Prometheus metrics server port tests and the OpenCode list cost billing test. * ci: run four heavy unit shards on 16-core runners and keep two smoke jobs off pull requests proxy-feature-endpoints, proxy-endpoints, root and llms-providers ran 1.9 to 2.2 times faster with 8 workers on a 16-core runner in a benchmark run. windows-sdk and proxy-build-from-pip still run on pushes to main and manual runs. proxy-build-from-pip installs a published release and never runs the pull request's code. * test: move 109 tests that start a process or open a socket into tests/integration tests/unit is in-process by its own rules, and these tests spawn a Python interpreter, a shell or a local TCP or HTTP server. They took 921 s of unit shard time per run, 396 s of it in the MCP client transport tests. Each one now lives in a *_real_io.py file under the integration directory for its domain and runs with that directory's group. The tests themselves are unchanged apart from one repository-root path in the CLI test. * test(unit): copy back only the dict entries a test changed A test module that registers models at import leaves litellm.model_cost four entries larger than the snapshot before every test in its directory, so the reset still deep-copied the whole price map for each of them. It now rebuilds a changed dict from the live entries that still match and copies only the rest. * ci(smoke): keep the two jobs that skip on pull requests out of the smoke gate A skipped job passing the gate is what test_unit_passed_gate guards against, so the gate goes back to requiring success from every job it needs and windows-sdk and proxy-build-from-pip stop being part of it. They still run and report on pushes to main and manual runs.
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
import json
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
from typing import Final
|
|
|
|
import pytest
|
|
import yaml
|
|
|
|
_WORKFLOWS_DIR: Final = Path(__file__).resolve().parents[2] / ".github" / "workflows"
|
|
_TIERS: Final = (
|
|
("test-linting.yml", "lint-passed", frozenset()),
|
|
("test-unit.yml", "unit-passed", frozenset({"coverage"})),
|
|
("test-merge-smoke.yml", "smoke-passed", frozenset({"windows-sdk", "proxy-build-from-pip"})),
|
|
)
|
|
_Tier = tuple[str, str, frozenset[str]]
|
|
|
|
|
|
def _jobs(tier: _Tier) -> dict[str, dict[str, object]]:
|
|
workflow: Final = yaml.safe_load((_WORKFLOWS_DIR / tier[0]).read_text())
|
|
return workflow["jobs"]
|
|
|
|
|
|
def _gate_script(tier: _Tier) -> str:
|
|
steps: Final = _jobs(tier)[tier[1]]["steps"]
|
|
assert isinstance(steps, list) and len(steps) == 1
|
|
return steps[0]["run"]
|
|
|
|
|
|
def _run_gate(tier: _Tier, results: dict[str, str]) -> subprocess.CompletedProcess[str]:
|
|
needs: Final = {job: {"result": result, "outputs": {}} for job, result in results.items()}
|
|
return subprocess.run(
|
|
("bash", "--noprofile", "--norc", "-eo", "pipefail", "-c", _gate_script(tier)),
|
|
env={**os.environ, "NEEDS": json.dumps(needs)},
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=30,
|
|
check=False,
|
|
)
|
|
|
|
|
|
def _needed_jobs(tier: _Tier) -> tuple[str, ...]:
|
|
needs: Final = _jobs(tier)[tier[1]]["needs"]
|
|
assert isinstance(needs, list)
|
|
return tuple(needs)
|
|
|
|
|
|
@pytest.mark.parametrize("tier", _TIERS, ids=("lint", "unit", "smoke"))
|
|
def test_the_gate_passes_when_every_needed_job_succeeded(tier: _Tier) -> None:
|
|
jobs: Final = _needed_jobs(tier)
|
|
assert jobs
|
|
|
|
result: Final = _run_gate(tier, {job: "success" for job in jobs})
|
|
|
|
assert result.returncode == 0, result.stdout + result.stderr
|
|
assert all(f"{job}: success" in result.stdout for job in jobs), result.stdout
|
|
|
|
|
|
@pytest.mark.parametrize("outcome", ("failure", "cancelled", "skipped"))
|
|
@pytest.mark.parametrize("tier", _TIERS, ids=("lint", "unit", "smoke"))
|
|
def test_the_gate_fails_when_any_needed_job_did_not_succeed(tier: _Tier, outcome: str) -> None:
|
|
jobs: Final = _needed_jobs(tier)
|
|
assert len(jobs) > 1
|
|
|
|
result: Final = _run_gate(tier, {**{job: "success" for job in jobs}, jobs[-1]: outcome})
|
|
|
|
assert result.returncode != 0
|
|
assert f"{jobs[-1]}: {outcome}" in result.stdout, result.stdout
|
|
|
|
|
|
@pytest.mark.parametrize("tier", _TIERS, ids=("lint", "unit", "smoke"))
|
|
def test_the_gate_waits_for_every_other_job_and_reports_even_when_they_fail(tier: _Tier) -> None:
|
|
jobs: Final = _jobs(tier)
|
|
gate: Final = jobs[tier[1]]
|
|
|
|
assert set(_needed_jobs(tier)) == set(jobs) - {tier[1]} - set(tier[2])
|
|
assert gate["if"] == "always()"
|
|
assert gate["permissions"] == {}
|