From 00934e20fd2ea177ff629b2a4e6c9c9d8e6ce6e1 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Sat, 24 Oct 2026 09:32:08 -0700 Subject: [PATCH 1/3] fix(make): skip deleted files in the diff-scoped format check --- Makefile | 5 +++-- tests/unit/test_default_branch.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dec853515b9..4234d299025 100644 --- a/Makefile +++ b/Makefile @@ -147,14 +147,15 @@ lint-install: $(UV_RUN) python scripts/prisma_generate_if_needed.py # Diff-scoped format check, mirroring test-linting.yml's "Check ruff format" step: -# only the litellm Python files changed vs the base are checked, so a pre-existing +# only the litellm Python files changed vs the base and still on disk are checked, so a pre-existing # format issue elsewhere doesn't block an unrelated commit. Git pathspecs match # recursively, so 'litellm/*.py' covers top-level files and nested modules alike, # the same set CI's ':(glob)litellm/**/*.py' selects. lint-format-check-changed: $(LINT_DEP_INSTALL) $(LINT_DEP_BASE) @base_ref=$$($(RESOLVE_BASE)) && \ changed=$$(git diff --name-only --diff-filter=ACMR "$$base_ref...HEAD" -- 'litellm/*.py') && \ - files=$$(printf '%s\n' "$$changed" | grep -v '^litellm/enterprise/' || true) || exit $$?; \ + files=$$(printf '%s\n' "$$changed" | grep -v '^litellm/enterprise/' | \ + while IFS= read -r f; do if [ -f "$$f" ]; then printf '%s\n' "$$f"; fi; done) || exit $$?; \ if [ -z "$$files" ]; then \ echo "No changed litellm Python files to format-check."; \ else \ diff --git a/tests/unit/test_default_branch.py b/tests/unit/test_default_branch.py index bb04ea2a0fa..9759a263cb7 100644 --- a/tests/unit/test_default_branch.py +++ b/tests/unit/test_default_branch.py @@ -119,6 +119,18 @@ def test_explicit_base_works_without_remote_access( assert "No changed litellm Python files" in checked.stdout +def test_format_check_skips_branch_files_deleted_from_the_working_tree(remote_and_clone: tuple[Path, Path]) -> None: + _, repo = remote_and_clone + (repo / "litellm" / "kept.py").write_text("value = 2\n") + (repo / "litellm" / "dropped.py").write_text("value = 3\n") + _commit(repo, "add two modules") + _git(repo, "rm", "-q", "litellm/dropped.py") + checked: Final = _make(repo, "lint-format-check-changed", "BASE_REF=origin/release_branch", "UV_RUN=echo") + assert checked.returncode == 0, checked.stderr + assert "litellm/kept.py" in checked.stdout + assert "litellm/dropped.py" not in checked.stdout + + def _freshness(repo: Path, *args: str) -> subprocess.CompletedProcess[str]: return subprocess.run( [ From 3dcdf03409f06f675770284882a3bcf4fd233c78 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 08:33:19 -0700 Subject: [PATCH 2/3] fix(make): skip deleted paths in the dev diff-scoped lint targets too --- Makefile | 4 ++-- tests/unit/test_default_branch.py | 34 +++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 4234d299025..6e0ba361131 100644 --- a/Makefile +++ b/Makefile @@ -174,7 +174,7 @@ lint-ruff: $(LINT_DEP_INSTALL) # https://github.com/astral-sh/ruff/discussions/4049 lint-format-changed: install-dev @base_ref=$$($(RESOLVE_BASE)) && \ - diff=$$(git diff "$$base_ref" --unified=0 --no-color -- '*.py') && \ + diff=$$(git diff "$$base_ref" --unified=0 --no-color --no-renames --diff-filter=d -- '*.py') && \ printf '%s\n' "$$diff" | \ perl -ne '\ if (/^diff --git a\/(.*) b\//) { $$file = $$1; } \ @@ -200,7 +200,7 @@ lint-ruff-dev: install-dev lint-ruff-FULL-dev: install-dev @base_ref=$$($(RESOLVE_BASE)) && \ - files=$$(git diff --name-only "$$base_ref" -- '*.py') || exit $$?; \ + files=$$(git diff --name-only --diff-filter=d "$$base_ref" -- '*.py') || exit $$?; \ if [ -n "$$files" ]; then echo "$$files" | xargs $(UV_RUN) ruff check; \ else echo "No changed .py files to check."; fi diff --git a/tests/unit/test_default_branch.py b/tests/unit/test_default_branch.py index 9759a263cb7..b780e279482 100644 --- a/tests/unit/test_default_branch.py +++ b/tests/unit/test_default_branch.py @@ -119,16 +119,42 @@ def test_explicit_base_works_without_remote_access( assert "No changed litellm Python files" in checked.stdout -def test_format_check_skips_branch_files_deleted_from_the_working_tree(remote_and_clone: tuple[Path, Path]) -> None: +@pytest.mark.parametrize("target", ["lint-format-check-changed", "lint-format-changed", "lint-ruff-FULL-dev"]) +def test_changed_file_targets_skip_paths_gone_from_the_working_tree( + remote_and_clone: tuple[Path, Path], + target: str, +) -> None: _, repo = remote_and_clone + (repo / "litellm" / "renamed_away.py").write_text("a = 1\nb = 2\nc = 3\nd = 4\n") + _commit(repo, "add a module the branch renames") + base: Final = _git(repo, "rev-parse", "HEAD") (repo / "litellm" / "kept.py").write_text("value = 2\n") (repo / "litellm" / "dropped.py").write_text("value = 3\n") _commit(repo, "add two modules") - _git(repo, "rm", "-q", "litellm/dropped.py") - checked: Final = _make(repo, "lint-format-check-changed", "BASE_REF=origin/release_branch", "UV_RUN=echo") + _git(repo, "rm", "-q", "litellm/dropped.py", "litellm/example.py") + _git(repo, "mv", "litellm/renamed_away.py", "litellm/renamed_to.py") + (repo / "litellm" / "renamed_to.py").write_text("a = 1\nb = 2\nc = 3\nd = 5\n") + checked: Final = _make(repo, target, "-o", "install-dev", f"BASE_REF={base}", "UV_RUN=echo") assert checked.returncode == 0, checked.stderr assert "litellm/kept.py" in checked.stdout - assert "litellm/dropped.py" not in checked.stdout + gone: Final = ("litellm/dropped.py", "litellm/example.py", "litellm/renamed_away.py") + assert [path for path in gone if path in checked.stdout] == [] + + +def test_format_check_skips_a_branch_file_the_merged_base_renamed(remote_and_clone: tuple[Path, Path]) -> None: + _, repo = remote_and_clone + _git(repo, "checkout", "-qb", "upstream") + _git(repo, "mv", "litellm/example.py", "litellm/moved.py") + _commit(repo, "upstream renames the module") + _git(repo, "checkout", "-q", "release_branch") + (repo / "litellm" / "example.py").write_text("value = 5\n") + _commit(repo, "branch edits the module") + _git(repo, "-c", "user.name=Test", "-c", "user.email=test@example.com", "merge", "-q", "--no-commit", "upstream") + assert (repo / "litellm" / "moved.py").read_text() == "value = 5\n" + checked: Final = _make(repo, "lint-format-check-changed", "BASE_REF=upstream", "UV_RUN=echo") + assert checked.returncode == 0, checked.stderr + assert "litellm/example.py" not in checked.stdout + assert "No changed litellm Python files to format-check." in checked.stdout def _freshness(repo: Path, *args: str) -> subprocess.CompletedProcess[str]: From c3f3c0a1895fdffc09493e07aded2e5ca1cbbdd2 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Thu, 29 Oct 2026 10:52:13 -0700 Subject: [PATCH 3/3] fix(make): make lint-format-changed work under GNU make and keep renames line-scoped --- Makefile | 11 ++++------- tests/unit/test_default_branch.py | 6 ++++-- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 72d7c9f6251..d00d8b9f166 100644 --- a/Makefile +++ b/Makefile @@ -174,14 +174,11 @@ lint-ruff: $(LINT_DEP_INSTALL) # https://github.com/astral-sh/ruff/discussions/4049 lint-format-changed: install-dev @base_ref=$$($(RESOLVE_BASE)) && \ - diff=$$(git diff "$$base_ref" --unified=0 --no-color --no-renames --diff-filter=d -- '*.py') && \ + diff=$$(git diff "$$base_ref" --unified=0 --no-color --diff-filter=d -- '*.py') && \ printf '%s\n' "$$diff" | \ - perl -ne '\ - if (/^diff --git a\/(.*) b\//) { $$file = $$1; } \ - if (/^@@ .* \+(\d+)(?:,(\d+))? @@/) { \ - $$start = $$1; $$count = $$2 || 1; $$end = $$start + $$count - 1; \ - print "$$file:$$start:1-$$end:999\n"; \ - }' | \ + perl -ne 'if (/^\+\+\+ b\/(.*)/) { $$file = $$1; }' \ + -e 'if (/^@@ .* \+(\d+)(?:,(\d+))? @@/) { $$start = $$1; $$count = $$2 || 1; $$end = $$start + $$count - 1;' \ + -e 'print "$$file:$$start:1-$$end:999\n"; }' | \ while read range; do \ file="$${range%%:*}"; \ lines="$${range#*:}"; \ diff --git a/tests/unit/test_default_branch.py b/tests/unit/test_default_branch.py index b780e279482..81053b13e8c 100644 --- a/tests/unit/test_default_branch.py +++ b/tests/unit/test_default_branch.py @@ -130,13 +130,15 @@ def test_changed_file_targets_skip_paths_gone_from_the_working_tree( base: Final = _git(repo, "rev-parse", "HEAD") (repo / "litellm" / "kept.py").write_text("value = 2\n") (repo / "litellm" / "dropped.py").write_text("value = 3\n") - _commit(repo, "add two modules") - _git(repo, "rm", "-q", "litellm/dropped.py", "litellm/example.py") _git(repo, "mv", "litellm/renamed_away.py", "litellm/renamed_to.py") (repo / "litellm" / "renamed_to.py").write_text("a = 1\nb = 2\nc = 3\nd = 5\n") + _commit(repo, "add two modules and rename one") + _git(repo, "rm", "-q", "litellm/dropped.py", "litellm/example.py") checked: Final = _make(repo, target, "-o", "install-dev", f"BASE_REF={base}", "UV_RUN=echo") assert checked.returncode == 0, checked.stderr assert "litellm/kept.py" in checked.stdout + assert "litellm/renamed_to.py" in checked.stdout + assert "--range 0:" not in checked.stdout gone: Final = ("litellm/dropped.py", "litellm/example.py", "litellm/renamed_away.py") assert [path for path in gone if path in checked.stdout] == []