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: avoid duplicate default branch fetches
Yuneng Jiang15ba07f20d3a
diff --git a/Makefile b/Makefileindex 50d431a7c98..ab11220821f 100644--- a/Makefile+++ b/Makefile@@ -70,7 +70,7 @@ GATE_SLOT_LOCK := python3 scripts/gate_slot_lock.pyLINT_DEP_INSTALL ?= install-devLINT_E2E_DEP_INSTALL ?= lint-install-LINT_DEP_BASE ?= lint-fetch-base+LINT_DEP_BASE ?=LINT_JOBS := $(shell sysctl -n hw.ncpu 2>/dev/null || nproc 2>/dev/null || echo 4)LINT_OUTPUT_SYNC := $(if $(filter output-sync,$(.FEATURES)),--output-sync=target,)@@ -133,8 +133,6 @@ format: install-devformat-check: install-devcd litellm && $(UV_RUN) ruff format --check --exclude '/enterprise/' . && cd ..-# Single fetch of the PR base so the delta-based gates below share one network round-# trip instead of each re-fetching when chained from `lint`.lint-fetch-base:@$(RESOLVE_BASE)@@ -222,7 +220,7 @@ lint-test-quality: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE)# --update lowers each limit by what this branch fixed since its branch point, so# it needs the base ref fetched to resolve the merge-base.-lint-basedpyright-budget-update: install-dev lint-fetch-base+lint-basedpyright-budget-update: install-dev$(UV_RUN) python scripts/type_check_gate.py --update --base "$(BASE_REF)"lint-format: format-check@@ -235,13 +233,13 @@ lint-ruff-budget: install-devlint-gate: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE)$(UV_RUN) python scripts/ruff_strict_gate.py --base "$(BASE_REF)"-lint-ruff-budget-update: install-dev lint-fetch-base+lint-ruff-budget-update: install-dev$(UV_RUN) python scripts/ruff_strict_gate.py --update --base "$(BASE_REF)"-lint-type-discipline-budget-update: install-dev lint-fetch-base+lint-type-discipline-budget-update: install-dev$(UV_RUN) python scripts/type_discipline_gate.py --update --base "$(BASE_REF)"-lint-test-quality-budget-update: install-dev lint-fetch-base+lint-test-quality-budget-update: install-dev$(UV_RUN) python scripts/test_quality_gate.py --update --base "$(BASE_REF)"# Ratchet all budgets in one shot (ruff strict + type-discipline + test quality + basedpyright)diff --git a/tests/test_litellm/test_default_branch.py b/tests/test_litellm/test_default_branch.pyindex ac673894067..a1b2a8c5c91 100644--- a/tests/test_litellm/test_default_branch.py+++ b/tests/test_litellm/test_default_branch.py@@ -1,3 +1,4 @@+import jsonimport osimport shutilimport subprocess@@ -210,3 +211,30 @@ def test_each_gate_refuses_an_unverifiable_default(remote_and_clone: tuple[Path,)assert result.returncode != 0assert "Cannot verify the base branch against origin" in result.stderr+++ "target", ["lint-format-check-changed", "lint-test-quality", "lint-test-quality-budget-update"]+)+def test_direct_make_target_fetches_default_once(remote_and_clone: tuple[Path, Path], target: str) -> None:+ _, repo = remote_and_clone+ trace: Final = repo.parent / "git-trace.jsonl"+ shutil.copyfile(ROOT / "scripts" / "check_test_quality.py", repo / "scripts" / "check_test_quality.py")+ shutil.copyfile(ROOT / "test-quality-budget.json", repo / "test-quality-budget.json")+ (repo / "tests").mkdir()+ result: Final = subprocess.run(+ ["make", "-o", "install-dev", target, "LINT_DEP_INSTALL=", "UV_RUN=env"],+ cwd=repo,+ capture_output=True,+ text=True,+ check=False,+ env={**{key: value for key, value in os.environ.items() if key != "BASE_REF"}, "GIT_TRACE2_EVENT": str(trace)},+ )+ assert result.returncode == 0, result.stdout + result.stderr+ commands: Final = tuple(+ event["argv"][1:]+ for line in trace.read_text().splitlines()+ if (event := json.loads(line)).get("event") == "start"+ )+ assert sum(command[0] == "ls-remote" for command in commands) == 1+ assert sum(command[0] == "fetch" for command in commands) == 1diff --git a/tests/test_litellm/test_gate_slot_lock.py b/tests/test_litellm/test_gate_slot_lock.pyindex 17fa8547ce7..c80e876700b 100644--- a/tests/test_litellm/test_gate_slot_lock.py+++ b/tests/test_litellm/test_gate_slot_lock.py@@ -1,6 +1,8 @@import fcntlimport importlib.util+import jsonimport os+import shleximport signalimport subprocessimport sys@@ -301,33 +303,47 @@ def test_held_slot_context_manager_releases_on_exit(tmp_path: Path, monkeypatch:fcntl.flock(probe, fcntl.LOCK_UN)-def _make_rule(target: str) -> tuple[list[str], list[str]]:- database = subprocess.run(- ["make", "--dry-run", "--print-data-base", "info"],- cwd=ROOT,- capture_output=True,- text=True,- check=True,- ).stdout- lines = database.splitlines()- for index, line in enumerate(lines):- if line != f"{target}:" and not line.startswith(f"{target}: "):- continue- recipe: list[str] = []- for follower in lines[index + 1 :]:- if follower.startswith("#"):- continue- if not follower.startswith("\t"):- break- recipe.append(follower.strip())- return line.split(":", 1)[1].split(), recipe- raise AssertionError(f"target {target} not found in make database")---def test_direct_make_lint_takes_a_slot_before_any_setup() -> None:- lint_prerequisites, lint_recipe = _make_rule("lint")- assert lint_prerequisites == []- assert any("$(GATE_SLOT_LOCK)" in line for line in lint_recipe)- inner_prerequisites, _ = _make_rule("lint-inner")- assert "lint-install" in inner_prerequisites- assert "lint-fetch-base" in inner_prerequisites+def test_direct_make_lint_takes_a_slot_before_any_setup(tmp_path: Path) -> None:+ lock_dir = tmp_path / "locks"+ lock_dir.mkdir()+ events_file = tmp_path / "setup.jsonl"+ stderr_file = tmp_path / "make.stderr"+ probe = tmp_path / "probe.py"+ probe.write_text(+ "import fcntl, json, os, pathlib, sys\n"+ "with (pathlib.Path(os.environ['LITELLM_GATE_SLOT_DIR']) / 'slot-0.lock').open('wb') as slot:\n"+ " try:\n"+ " fcntl.flock(slot, fcntl.LOCK_EX | fcntl.LOCK_NB)\n"+ " locked = False\n"+ " except BlockingIOError:\n"+ " locked = True\n"+ "with open(os.environ['EVENTS_FILE'], 'a') as events:\n"+ " events.write(json.dumps({'phase': sys.argv[1], 'locked': locked}) + '\\n')\n"+ "if sys.argv[1] == 'base':\n"+ " print('HEAD')\n"+ )+ (tmp_path / "Makefile").write_text((ROOT / "Makefile").read_text())+ command = [+ "make", "-o", "lint-checks", "lint", "MAKE=make -o lint-checks",+ f"GATE_SLOT_LOCK={shlex.join([sys.executable, str(HELPER)])}",+ f"UV={shlex.join([sys.executable, str(probe), 'setup'])}",+ f"UV_RUN={shlex.join([sys.executable, str(probe), 'setup'])}",+ f"RESOLVE_BASE={shlex.join([sys.executable, str(probe), 'base'])}",+ ]+ with (lock_dir / "slot-0.lock").open("wb") as held, stderr_file.open("wb") as stderr:+ fcntl.flock(held, fcntl.LOCK_EX)+ process = subprocess.Popen(+ command, cwd=tmp_path, stdout=subprocess.DEVNULL, stderr=stderr,+ env={**_env(lock_dir, "1"), "EVENTS_FILE": str(events_file)},+ )+ try:+ assert _wait_until(lambda: "queueing" in stderr_file.read_text(), 10)+ assert not events_file.exists()+ fcntl.flock(held, fcntl.LOCK_UN)+ assert process.wait(timeout=30) == 0, stderr_file.read_text()+ finally:+ fcntl.flock(held, fcntl.LOCK_UN)+ _reap(process)+ events = tuple(json.loads(line) for line in events_file.read_text().splitlines())+ assert {event["phase"] for event in events} == {"setup", "base"}+ assert all(event["locked"] for event in events)