Skip to content

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]

test(ci): reject coverage-allowlist entries that no longer match a file (#37608)

yuneng-jiangcde134488c88
diff --git a/.github/scripts/assert_ci_coverage.py b/.github/scripts/assert_ci_coverage.py
index 86a6b7d4e72..c8572d9f6ef 100644
--- a/.github/scripts/assert_ci_coverage.py
+++ b/.github/scripts/assert_ci_coverage.py
@@ -1,11 +1,12 @@
from __future__ import annotations
import ast
+import operator
import pathlib
import re
import sys
import warnings
-from collections.abc import Iterable, Mapping, Sequence
+from collections.abc import Callable, Iterable, Mapping, Sequence
from dataclasses import dataclass
from typing import Final
@@ -56,6 +57,14 @@ class Allowlist:
return any(relative_path == path for entry in self.dockerfiles for path in entry.paths)
+@dataclass(frozen=True, slots=True)
+class Section:
+ name: str
+ entries: tuple[AllowEntry, ...]
+ candidates: tuple[str, ...]
+ matches: Callable[[str, str], bool]
+
+
@dataclass(frozen=True, slots=True)
class Scalar:
key: str
@@ -368,6 +377,25 @@ def _uncovered_dockerfiles(allowlist: Allowlist, tokens: frozenset[str]) -> tupl
)
+def _stale_allowlist_paths(
+ allowlist: Allowlist,
+ *,
+ test_files: tuple[str, ...],
+ dockerfiles: tuple[str, ...],
+) -> tuple[Finding, ...]:
+ sections: Final[tuple[Section, ...]] = (
+ Section("test_paths", allowlist.test_paths, test_files, _token_covers),
+ Section("dockerfiles", allowlist.dockerfiles, dockerfiles, operator.eq),
+ )
+ return tuple(
+ Finding(subject=path, detail=f"listed under '{section.name}' but matches no file the census looks at")
+ for section in sections
+ for entry in section.entries
+ for path in entry.paths
+ if not any(section.matches(path, candidate) for candidate in section.candidates)
+ )
+
+
def _parse_entry(item: object, section: str) -> AllowEntry:
if not isinstance(item, dict):
raise SystemExit(f"{ALLOWLIST_FILE.name}: '{section}' entries must be mappings")
@@ -465,7 +493,14 @@ def main() -> int:
test_findings = _uncovered_tests(allowlist, _invoked_test_tokens(scalars))
dockerfile_findings = _uncovered_dockerfiles(allowlist, _built_dockerfile_tokens(scalars))
+ stale_findings = _stale_allowlist_paths(allowlist, test_files=_test_files(), dockerfiles=_dockerfiles())
+ if stale_findings:
+ _report(
+ "allowlist entries that exempt nothing",
+ stale_findings,
+ "Delete each from .github/ci-coverage-allowlist.yml; the file it named is gone or was renamed.",
+ )
if test_findings:
_report(
"test files that no CI job invokes",
@@ -478,7 +513,7 @@ def main() -> int:
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:
+ if stale_findings or test_findings or dockerfile_findings:
return 1
_write(
diff --git a/tests/test_litellm/test_assert_ci_coverage.py b/tests/test_litellm/test_assert_ci_coverage.py
index 59cfff52992..4c8f4cc2984 100644
--- a/tests/test_litellm/test_assert_ci_coverage.py
+++ b/tests/test_litellm/test_assert_ci_coverage.py
@@ -209,3 +209,74 @@ def test_character_class_globs_match_the_letter_shards_circleci_uses():
def test_the_repo_as_it_stands_has_no_unrecorded_slice_gap():
findings = coverage._deselected_everywhere(coverage._load_allowlist())
assert [f.subject for f in findings] == []
+
+
+def _allowlist(*, tests: tuple[str, ...] = (), dockerfiles: tuple[str, ...] = ()):
+ return coverage.Allowlist(
+ test_paths=(coverage.AllowEntry(paths=tests, reason="r"),) if tests else (),
+ dockerfiles=(coverage.AllowEntry(paths=dockerfiles, reason="r"),) if dockerfiles else (),
+ )
+
+
+def test_an_allowlist_path_whose_file_is_gone_is_reported():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(tests=("tests/gone/test_a.py",)),
+ test_files=("tests/live/test_b.py",),
+ dockerfiles=(),
+ )
+ assert [f.subject for f in findings] == ["tests/gone/test_a.py"]
+ assert "test_paths" in findings[0].detail
+
+
+def test_an_allowlist_path_that_still_matches_a_file_is_left_alone():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(tests=("tests/live/test_b.py",)),
+ test_files=("tests/live/test_b.py",),
+ dockerfiles=(),
+ )
+ assert findings == ()
+
+
+def test_a_directory_entry_survives_while_any_file_below_it_remains():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(tests=("tests/live",)),
+ test_files=("tests/live/nested/test_b.py",),
+ dockerfiles=(),
+ )
+ assert findings == ()
+
+
+def test_a_glob_entry_matching_nothing_is_reported_like_any_other():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(tests=("tests/live/test_z*.py",)),
+ test_files=("tests/live/test_b.py",),
+ dockerfiles=(),
+ )
+ assert [f.subject for f in findings] == ["tests/live/test_z*.py"]
+
+
+def test_a_stale_dockerfile_entry_is_named_under_its_own_section():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(dockerfiles=("docker/Dockerfile.gone",)),
+ test_files=(),
+ dockerfiles=("docker/Dockerfile.database",),
+ )
+ assert [(f.subject, "dockerfiles" in f.detail) for f in findings] == [("docker/Dockerfile.gone", True)]
+
+
+def test_the_repo_as_it_stands_has_no_stale_allowlist_entry():
+ findings = coverage._stale_allowlist_paths(
+ coverage._load_allowlist(),
+ test_files=coverage._test_files(),
+ dockerfiles=coverage._dockerfiles(),
+ )
+ assert [f.subject for f in findings] == []
+
+
+def test_a_dockerfile_directory_entry_is_stale_because_only_an_exact_path_exempts_one():
+ findings = coverage._stale_allowlist_paths(
+ _allowlist(dockerfiles=("docker",)),
+ test_files=(),
+ dockerfiles=("docker/Dockerfile.database",),
+ )
+ assert [f.subject for f in findings] == ["docker"]