The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
ci: fail the build when a test file or Dockerfile is invoked by no job (#35991)
Yassin Kortam7a5d6a0548bb
diff --git a/.github/ci-coverage-allowlist.yml b/.github/ci-coverage-allowlist.ymlnew file mode 100644index 00000000000..140f1155e3a--- /dev/null+++ b/.github/ci-coverage-allowlist.yml@@ -0,0 +1,159 @@+description: >-+ Paths deliberately outside CI coverage, each with the reason it is exempt.+ assert_ci_coverage.py fails when a test file or Dockerfile is neither invoked+ by a job nor listed here, so every entry below is a decision on the record.++test_paths:+ - reason: >-+ The end-to-end suite runs against a deployed proxy from its own in-cluster rig rather than+ from a pull request; it needs a live gateway and provider credentials no PR job holds+ paths:+ - tests/e2e+ - reason: >-+ The documentation and code-quality workflows execute four files in this directory by name as+ scripts and pytest never collects the directory, so these six run nowhere; listed individually+ so a seventh cannot inherit the exemption+ paths:+ - tests/documentation_tests/test_exception_types.py+ - tests/documentation_tests/test_general_setting_keys.py+ - tests/documentation_tests/test_optional_params.py+ - tests/documentation_tests/test_readme_providers.py+ - tests/documentation_tests/test_requests_lib_usage.py+ - tests/documentation_tests/test_standard_logging_payload.py+ - reason: >-+ Sibling files here are executed by name from the code-quality workflow; this one is referenced+ by no job+ paths:+ - tests/code_coverage_tests/test_aio_http_image_conversion.py+ - reason: >-+ A second mirror of the package tree living beside tests/test_litellm, which is the mirror the+ repo convention names; only test_no_hardcoded_secrets.py is invoked, from the linting+ workflow, and whether this directory should exist at all is unresolved+ paths:+ - tests/litellm/a2a_protocol/providers/pydantic_ai_agents/test_pydantic_ai_agent_headers.py+ - tests/litellm/a2a_protocol/providers/pydantic_ai_agents/test_pydantic_ai_agent_transformation.py+ - tests/litellm/integrations/helicone/test_helicone_gemini.py+ - tests/litellm/litellm_core_utils/test_json_schema_validation.py+ - tests/litellm/llms/anthropic/test_anthropic_reasoning_effort.py+ - tests/litellm/llms/anthropic/test_anthropic_schema_filter.py+ - tests/litellm/llms/azure/test_azure_embedding.py+ - tests/litellm/llms/bedrock/embed/test_embedding.py+ - tests/litellm/llms/bedrock/test_nova_imported_models.py+ - tests/litellm/llms/deepseek/chat/test_deepseek_chat_transformation.py+ - tests/litellm/llms/gradient_ai/chat/test_gradient_ai_chat_transformation.py+ - tests/litellm/llms/oci/chat/test_oci_chat_transformation.py+ - tests/litellm/llms/openai_like/test_abliteration_provider.py+ - tests/litellm/llms/openai_like/test_assemblyai_provider.py+ - tests/litellm/llms/openai_like/test_empiriolabs_provider.py+ - tests/litellm/llms/vertex_ai/agent_engine/test_transformation.py+ - tests/litellm/llms/vertex_ai/gemini/test_transformation.py+ - tests/litellm/llms/vertex_ai/text_to_speech/test_transformation.py+ - tests/litellm/proxy/_experimental/mcp_server/test_discoverable_endpoints.py+ - tests/litellm/proxy/agent_endpoints/test_agent_rbac.py+ - tests/litellm/proxy/common_utils/test_rbac_utils.py+ - tests/litellm/proxy/management_endpoints/test_common_utils.py+ - tests/litellm/proxy/management_endpoints/test_cost_estimate_endpoint.py+ - tests/litellm/proxy/test_claude_code_marketplace.py+ - tests/litellm/proxy/test_init_litellm_callbacks.py+ - tests/litellm/proxy/test_prisma_engine_watchdog.py+ - tests/litellm/proxy/vector_store_endpoints/test_vector_store_rbac.py+ - tests/litellm/test_bedrock_extended_beta_models.py+ - tests/litellm/test_bedrock_nemotron_super.py+ - tests/litellm/test_proxy_auth.py+ - tests/litellm/test_router_retry_backoff_headers.py+ - tests/litellm/test_sambanova_model_metadata.py+ - tests/litellm/test_stream_chunk_builder_images.py+ - reason: >-+ Legacy proxy suite superseded by the proxy shards; no job invokes it and whether it still+ describes supported behaviour is unresolved+ paths:+ - tests/old_proxy_tests/tests/test_anthropic_context_caching.py+ - tests/old_proxy_tests/tests/test_anthropic_sdk.py+ - tests/old_proxy_tests/tests/test_async.py+ - tests/old_proxy_tests/tests/test_gemini_context_caching.py+ - tests/old_proxy_tests/tests/test_langchain_embedding.py+ - tests/old_proxy_tests/tests/test_langchain_request.py+ - tests/old_proxy_tests/tests/test_llamaindex.py+ - tests/old_proxy_tests/tests/test_mistral_sdk.py+ - tests/old_proxy_tests/tests/test_openai_embedding.py+ - tests/old_proxy_tests/tests/test_openai_exception_request.py+ - tests/old_proxy_tests/tests/test_openai_request.py+ - tests/old_proxy_tests/tests/test_openai_request_with_traceparent.py+ - tests/old_proxy_tests/tests/test_openai_simple_embedding.py+ - tests/old_proxy_tests/tests/test_openai_tts_request.py+ - tests/old_proxy_tests/tests/test_pass_through_langfuse.py+ - tests/old_proxy_tests/tests/test_q.py+ - tests/old_proxy_tests/tests/test_simple_traceparent_openai.py+ - tests/old_proxy_tests/tests/test_vertex_sdk_forward_headers.py+ - tests/old_proxy_tests/tests/test_vtx_embedding.py+ - tests/old_proxy_tests/tests/test_vtx_sdk_embedding.py+ - reason: >-+ No job invokes this suite and its files mix pure transformation tests with ones driving live+ vendor vector stores, so assigning them needs a per-file decision+ paths:+ - tests/vector_store_tests/rag/test_rag_bedrock.py+ - tests/vector_store_tests/rag/test_rag_openai.py+ - tests/vector_store_tests/rag/test_rag_s3_vectors.py+ - tests/vector_store_tests/rag/test_rag_vertex_ai.py+ - tests/vector_store_tests/test_azure_ai_vector_store.py+ - tests/vector_store_tests/test_azure_vector_store.py+ - tests/vector_store_tests/test_bedrock_vector_store.py+ - tests/vector_store_tests/test_gemini_vector_store.py+ - tests/vector_store_tests/test_milvus_vector_store.py+ - tests/vector_store_tests/test_openai_vector_store.py+ - tests/vector_store_tests/test_ragflow_vector_store.py+ - tests/vector_store_tests/test_s3_vectors_vector_store.py+ - tests/vector_store_tests/test_vertex_ai_search_api_vector_store.py+ - tests/vector_store_tests/test_vertex_ai_vector_store.py+ - reason: >-+ Throughput and memory-growth measurements whose runtime and variance make them unsuitable for+ a per-pull-request job+ paths:+ - tests/load_tests/test_datadog_load_test.py+ - tests/load_tests/test_langsmith_load_test.py+ - tests/load_tests/test_linear_memory_growth.py+ - tests/load_tests/test_memory_usage.py+ - tests/load_tests/test_otel_load_test.py+ - tests/load_tests/test_vertex_embeddings_load_test.py+ - tests/load_tests/test_vertex_load_tests.py+ - reason: >-+ Third-party integration tests that skip themselves without OCI configuration or sandbox+ credentials, neither of which a pull request job holds+ paths:+ - tests/integration/sandbox/test_e2b_sandbox.py+ - tests/integration/test_oci_integration.py+ - tests/integration/test_oci_proxy_integration.py+ - reason: >-+ Two prompt-factory tests sitting at the top level of tests/ instead of under the+ tests/test_litellm mirror the shards enumerate; they need moving rather than a shard entry+ paths:+ - tests/litellm_core_utils/test_anthropic_dedup_factory.py+ - tests/litellm_core_utils/test_bedrock_converse_dedup_factory.py+ - reason: >-+ A unit test for the proxy-extras package that no job invokes, while the package's other tests+ live under tests/proxy_migration_tests+ paths:+ - tests/litellm-proxy-extras/test_litellm_proxy_extras_utils.py++dockerfiles:+ - reason: >-+ The componentized images the microservices chart deploys are built by no job; wiring both into+ the scan workflow costs a full image build each and is deferred to a change that prices the+ whole set+ paths:+ - backend/Dockerfile+ - gateway/Dockerfile+ - reason: >-+ The dashboard container is a static Next.js export served by nginx, and the dashboard build+ and lint workflows already exercise that output, so building the image adds no signal about it+ paths:+ - ui/Dockerfile+ - reason: >-+ The Rust gateway ships as its own chart and package with a separate release pipeline, so its+ image is not part of this repo's Python image set+ paths:+ - litellm-rust/crates/ai-gateway/Dockerfile+ - reason: >-+ An example image under cookbook/ that is documentation rather than a shipped artifact+ paths:+ - cookbook/litellm-ollama-docker-image/Dockerfilediff --git a/.github/scripts/assert_ci_coverage.py b/.github/scripts/assert_ci_coverage.pynew file mode 100644index 00000000000..5b7ca9c7275--- /dev/null+++ b/.github/scripts/assert_ci_coverage.py@@ -0,0 +1,262 @@+from __future__ import annotations++import pathlib+import re+import sys+from collections.abc import Iterable, Mapping, Sequence+from dataclasses import dataclass++import yaml++REPO_ROOT = pathlib.Path(__file__).resolve().parents[2]+WORKFLOW_DIR = REPO_ROOT / ".github" / "workflows"+CIRCLECI_CONFIG = REPO_ROOT / ".circleci" / "config.yml"+ALLOWLIST_FILE = REPO_ROOT / ".github" / "ci-coverage-allowlist.yml"+TESTS_ROOT = REPO_ROOT / "tests"++ALLOWLIST_KEYS = frozenset({"description", "test_paths", "dockerfiles"})+PATH_FILTER_KEYS = frozenset({"paths", "paths-ignore"})+TEST_PATH_KEYS = frozenset({"test-path", "test-paths"})+DOCKERFILE_INPUT_KEYS = frozenset({"file", "dockerfile"})+TEST_RUNNER_RE = re.compile(r"\bpytest\b|\bcircleci tests\b|\bhelm unittest\b|\bplaywright test\b|\bpython[0-9.]*\s")+IMAGE_BUILD_RE = re.compile(r"\bdocker\s+(?:buildx\s+)?build\b")+TEST_TOKEN_RE = re.compile(r"tests/[A-Za-z0-9_./*?-]+")+DOCKERFILE_TOKEN_RE = re.compile(r"[A-Za-z0-9_./-]*Dockerfile[A-Za-z0-9_.-]*")+COMMENT_RE = re.compile(r"^\s*#.*$", re.MULTILINE)+GLOB_CHARS = frozenset("*?")+++@dataclass(frozen=True, slots=True)+class AllowEntry:+ paths: tuple[str, ...]+ reason: str+++@dataclass(frozen=True, slots=True)+class Allowlist:+ test_paths: tuple[AllowEntry, ...]+ dockerfiles: tuple[AllowEntry, ...]++ def covers_test(self, relative_path: str) -> bool:+ return any(_token_covers(path, relative_path) for entry in self.test_paths for path in entry.paths)++ def covers_dockerfile(self, relative_path: str) -> bool:+ return any(relative_path == path for entry in self.dockerfiles for path in entry.paths)+++@dataclass(frozen=True, slots=True)+class Scalar:+ key: str+ value: str+++@dataclass(frozen=True, slots=True)+class Finding:+ subject: str+ detail: str+++def _scalars(node: object, key: str) -> tuple[Scalar, ...]:+ if isinstance(node, str):+ return (Scalar(key=key, value=node),)+ if isinstance(node, Mapping):+ return tuple(+ scalar+ for child_key, value in node.items()+ if child_key not in PATH_FILTER_KEYS+ for scalar in _scalars(value, str(child_key))+ )+ if isinstance(node, Sequence):+ return tuple(scalar for item in node for scalar in _scalars(item, key))+ return ()+++def _config_files() -> tuple[pathlib.Path, ...]:+ workflows = tuple(sorted(path for path in WORKFLOW_DIR.iterdir() if path.suffix in (".yml", ".yaml")))+ circleci = (CIRCLECI_CONFIG,) if CIRCLECI_CONFIG.is_file() else ()+ return workflows + circleci+++def _all_scalars() -> tuple[Scalar, ...]:+ return tuple(+ scalar+ for path in _config_files()+ for scalar in _scalars(yaml.safe_load(path.read_text(encoding="utf-8")), path.name)+ )+++def _uncommented(value: str) -> str:+ return COMMENT_RE.sub("", value)+++def _invoked_test_tokens(scalars: Iterable[Scalar]) -> frozenset[str]:+ return frozenset(+ match.group(0).rstrip("/")+ for scalar in scalars+ if scalar.key in TEST_PATH_KEYS or TEST_RUNNER_RE.search(scalar.value)+ for match in TEST_TOKEN_RE.finditer(_uncommented(scalar.value))+ )+++def _built_dockerfile_tokens(scalars: Iterable[Scalar]) -> frozenset[str]:+ return frozenset(+ match.group(0)+ for scalar in scalars+ if scalar.key in DOCKERFILE_INPUT_KEYS or IMAGE_BUILD_RE.search(scalar.value)+ for match in DOCKERFILE_TOKEN_RE.finditer(_uncommented(scalar.value))+ )+++def _glob_to_regex(token: str) -> re.Pattern[str]:+ parts = re.split(r"(\*\*/|\*\*|\*|\?)", token)+ translated = "".join(+ {"**/": r"(?:.*/)?", "**": r".*", "*": r"[^/]*", "?": r"[^/]"}.get(part, re.escape(part)) for part in parts+ )+ return re.compile(rf"{translated}(?:/.*)?$")+++def _token_covers(token: str, relative_path: str) -> bool:+ if GLOB_CHARS & set(token):+ return _glob_to_regex(token).match(relative_path) is not None+ return relative_path == token or relative_path.startswith(f"{token}/")+++def _test_files() -> tuple[str, ...]:+ return tuple(+ sorted(+ path.relative_to(REPO_ROOT).as_posix()+ for path in TESTS_ROOT.rglob("test_*.py")+ if path.is_file() and "node_modules" not in path.parts+ )+ )+++def _dockerfiles() -> tuple[str, ...]:+ return tuple(+ sorted(+ path.relative_to(REPO_ROOT).as_posix()+ for path in REPO_ROOT.rglob("Dockerfile*")+ if path.is_file()+ and ".git" not in path.parts+ and "node_modules" not in path.parts+ and not path.name.endswith(".dockerignore")+ )+ )+++def _uncovered_tests(allowlist: Allowlist, tokens: frozenset[str]) -> tuple[Finding, ...]:+ uncovered = tuple(+ relative_path+ for relative_path in _test_files()+ if not any(_token_covers(token, relative_path) for token in tokens) and not allowlist.covers_test(relative_path)+ )+ directories = tuple(dict.fromkeys(path.rsplit("/", 1)[0] for path in uncovered))+ return tuple(+ Finding(+ subject=directory,+ detail=_describe(tuple(p for p in uncovered if p.rsplit("/", 1)[0] == directory)),+ )+ for directory in directories+ )+++def _describe(paths: tuple[str, ...]) -> str:+ names = ", ".join(path.rsplit("/", 1)[1] for path in paths[:3])+ suffix = f", +{len(paths) - 3} more" if len(paths) > 3 else ""+ return f"{len(paths)} test file(s) invoked by no job: {names}{suffix}"+++def _uncovered_dockerfiles(allowlist: Allowlist, tokens: frozenset[str]) -> tuple[Finding, ...]:+ return tuple(+ Finding(subject=relative_path, detail="built by no job")+ for relative_path in _dockerfiles()+ if relative_path not in tokens and not allowlist.covers_dockerfile(relative_path)+ )+++def _parse_entry(item: object, section: str) -> AllowEntry:+ if not isinstance(item, dict):+ raise SystemExit(f"{ALLOWLIST_FILE.name}: '{section}' entries must be mappings")+ paths = item.get("paths")+ reason = item.get("reason")+ if (+ not isinstance(paths, list)+ or not paths+ or not all(isinstance(path, str) for path in paths)+ or not isinstance(reason, str)+ or not reason.strip()+ ):+ raise SystemExit(+ f"{ALLOWLIST_FILE.name}: every '{section}' entry needs a non-empty 'paths' "+ "list of strings and a non-empty 'reason'"+ )+ return AllowEntry(paths=tuple(paths), reason=reason)+++def _parse_entries(raw: object, section: str) -> tuple[AllowEntry, ...]:+ if not isinstance(raw, list):+ raise SystemExit(f"{ALLOWLIST_FILE.name}: '{section}' must be a list")+ return tuple(_parse_entry(item, section) for item in raw)+++def _load_allowlist() -> Allowlist:+ if not ALLOWLIST_FILE.is_file():+ return Allowlist(test_paths=(), dockerfiles=())+ raw = yaml.safe_load(ALLOWLIST_FILE.read_text(encoding="utf-8")) or {}+ if not isinstance(raw, dict):+ raise SystemExit(f"{ALLOWLIST_FILE.name}: top level must be a mapping")+ unknown = sorted(str(key) for key in raw if key not in ALLOWLIST_KEYS)+ if unknown:+ raise SystemExit(+ f"{ALLOWLIST_FILE.name}: unknown top-level key(s) {unknown}; expected only {sorted(ALLOWLIST_KEYS)}"+ )+ return Allowlist(+ test_paths=_parse_entries(raw.get("test_paths", []), "test_paths"),+ dockerfiles=_parse_entries(raw.get("dockerfiles", []), "dockerfiles"),+ )+++def _write(message: str) -> None:+ sys.stdout.write(f"{message}\n")+++def _report(title: str, findings: tuple[Finding, ...], remedy: str) -> None:+ _write(f"ERROR: {title}")+ for finding in findings:+ _write(f" - {finding.subject}: {finding.detail}")+ _write("")+ _write(remedy)+ _write("")+++def main() -> int:+ allowlist = _load_allowlist()+ scalars = _all_scalars()++ test_findings = _uncovered_tests(allowlist, _invoked_test_tokens(scalars))+ dockerfile_findings = _uncovered_dockerfiles(allowlist, _built_dockerfile_tokens(scalars))++ if test_findings:+ _report(+ "test files that no CI job invokes",+ test_findings,+ "Add each to a job's test path, or list it in .github/ci-coverage-allowlist.yml with a reason.",+ )+ if dockerfile_findings:+ _report(+ "Dockerfiles that no CI job builds",+ dockerfile_findings,+ "Build each in a workflow, or list it in .github/ci-coverage-allowlist.yml with a reason.",+ )+ if test_findings or dockerfile_findings:+ return 1++ _write(+ f"OK: {len(_test_files())} test files and {len(_dockerfiles())} Dockerfiles are each "+ "invoked by at least one job or carry an explicit allowlist entry."+ )+ return 0+++if __name__ == "__main__":+ sys.exit(main())diff --git a/.github/workflows/ci-coverage.yml b/.github/workflows/ci-coverage.ymlnew file mode 100644index 00000000000..c95921297a2--- /dev/null+++ b/.github/workflows/ci-coverage.yml@@ -0,0 +1,42 @@+name: "CI Coverage"++on:+ pull_request:+ branches:+ - main+ - litellm_internal_staging+ - litellm_oss_staging+ - "litellm_**"+ push:+ branches:+ - main+ - litellm_internal_staging++permissions:+ contents: read++concurrency:+ group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}+ cancel-in-progress: ${{ github.event_name == 'pull_request' }}++jobs:+ assert-ci-coverage:+ name: assert-ci-coverage+ runs-on: ubuntu-latest+ timeout-minutes: 5+ permissions:+ contents: read+ steps:+ - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0+ with:+ persist-credentials: false++ - name: Set up Python+ uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0+ with:+ python-version: "3.12"++ - name: Assert every test file and Dockerfile is invoked by a job+ run: |+ python -m pip install "pyyaml==6.0.3"+ python .github/scripts/assert_ci_coverage.pydiff --git a/.github/workflows/image-scan.yml b/.github/workflows/image-scan.ymlindex 4d0acb0b6e5..e0c0bfcedae 100644--- a/.github/workflows/image-scan.yml+++ b/.github/workflows/image-scan.yml@@ -8,6 +8,7 @@ on:- litellm_oss_branch- "litellm_**"paths:+ - Dockerfile- docker/Dockerfile.non_root- migrations/Dockerfile- migrations/run.py@@ -87,6 +88,35 @@ jobs:--fail-on high \--output table+ runtime-image:+ name: runtime-image+ runs-on: ubuntu-latest+ if: >-+ github.event_name != 'pull_request' ||+ github.event.pull_request.head.repo.full_name == github.repository+ timeout-minutes: 30+ permissions:+ contents: read+ steps:+ - uses: actions/checkout@08eba0b27e820071cde6df949e0beb9ba4906955 # v4.3.0+ with:+ persist-credentials: false++ - name: Build runtime image+ run: docker build -f Dockerfile -t litellm-runtime-scan:${{ github.sha }} .++ - name: Set up Python+ uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0+ with:+ python-version: "3.12"++ - name: Verify offline migration as a non-root uid+ env:+ LITELLM_IMAGE: litellm-runtime-scan:${{ github.sha }}+ run: |+ python -m pip install "pytest==9.0.3"+ python -m pytest tests/proxy_migration_tests/test_offline_image_migration.py -v+migrations-image:name: migrations-imageruns-on: ubuntu-latestdiff --git a/.github/workflows/test-unit-misc.yml b/.github/workflows/test-unit-misc.ymlindex 505e22cfed4..123a31e23f7 100644--- a/.github/workflows/test-unit-misc.yml+++ b/.github/workflows/test-unit-misc.yml@@ -40,7 +40,11 @@ jobs:tests/test_litellm/interactionstests/test_litellm/ocrtests/test_litellm/passthrough+ tests/test_litellm/rag+ tests/test_litellm/realtime_api+ tests/test_litellm/rerank_apitests/test_litellm/sandbox+ tests/test_litellm/test_routertests/test_litellm/vector_storestests/test_litellm/videostests/test_litellm/test_*.pydiff --git a/.github/workflows/test-unit-proxy-endpoints.yml b/.github/workflows/test-unit-proxy-endpoints.ymlindex 6a51d2a8578..20b89c72440 100644--- a/.github/workflows/test-unit-proxy-endpoints.yml+++ b/.github/workflows/test-unit-proxy-endpoints.yml@@ -29,7 +29,9 @@ jobs:uses: ./.github/workflows/_test-unit-base.ymlwith:test-path: >-+ tests/test_litellm/proxy/analytics_endpointstests/test_litellm/proxy/management_endpoints+ tests/test_litellm/proxy/memorytests/test_litellm/proxy/guardrailstests/test_litellm/proxy/management_helperstests/test_litellm/proxy/anthropic_endpointsdiff --git a/.github/workflows/test-unit-proxy-infra.yml b/.github/workflows/test-unit-proxy-infra.ymlindex 913653a1711..83d95463cdf 100644--- a/.github/workflows/test-unit-proxy-infra.yml+++ b/.github/workflows/test-unit-proxy-infra.yml@@ -33,6 +33,8 @@ jobs:tests/test_litellm/proxy/_experimentaltests/test_litellm/proxy/experimentaltests/test_litellm/proxy/common_utils+ tests/test_litellm/proxy/enterprise_billing+ tests/test_litellm/proxy/types_utilstests/test_litellm/proxy/logging_endpointstests/test_litellm/proxy/test_*.pyworkers: 2