Skip to content

feat: add lint-gate target and truncation-proof summary to the strict ruff gate#30877

Merged
mateo-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_ruff_gate_dx
Jun 20, 2026
Merged

feat: add lint-gate target and truncation-proof summary to the strict ruff gate#30877
mateo-berri merged 4 commits into
litellm_internal_stagingfrom
litellm_ruff_gate_dx

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

Relevant issues

None; this is developer-experience cleanup for the strict ruff gate that came out of fighting it on a recent PR.

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

  • Branch creation CI run
    Link:
  • CI run for the last commit
    Link:
  • Merge / cherry-pick CI run
    Links:

Screenshots / Proof of Fix

Two pain points with the strict ruff gate and how to see the fix locally.

First, the truncation-proof summary. CI only surfaces the tail of the job log, and the gate printed each breached rule's header before its (potentially long) list of offending files, so on a real failure the rule name and counts scrolled off the top of the captured tail and you could not tell which rule blew the budget. The gate now also prints a single BREACHED RULES: ... line as the very last line, which survives tail truncation. Covered by test_report_emits_breached_rules_as_final_line.

Second, a local entry point that predicts CI. make lint-gate fetches origin/litellm_internal_staging fresh and then runs the gate the same way the lint check does in test-linting.yml (the CI job checks out the PR head sha and counts against the merge-base with the base branch), so a clean local run predicts the CI verdict before you push.

# matches what the lint CI check will conclude, before you push
make lint-gate

Default behavior and the existing make lint-ruff-budget target are unchanged.

Type

🚄 Infrastructure

Changes

scripts/ruff_strict_gate.py always emits a final one-line BREACHED RULES summary so the verdict survives log truncation, and the shared violation-collection logic is factored into collect_violations(root, config) with worktree handling consolidated behind a _temp_worktree context manager that cleans up its temp dir even when git worktree add fails. make lint-gate is a new local entry point that fetches staging fresh and runs the gate exactly as CI does. Tests extend tests/test_litellm/test_ruff_strict_gate.py with a regression for the trailing summary line.


Note

Low Risk
Changes are limited to Makefile targets, the ruff strict gate script, and unit tests—no runtime or proxy behavior.

Overview
Improves strict ruff budget gate developer experience: failures now end with a single BREACHED RULES: line (rule, total/cap, added) so CI log tails still show which rules failed.

Adds make lint-gate, which fetches origin/litellm_internal_staging and runs ruff_strict_gate.py --base the same way contributors expect before push; make lint-ruff-budget is unchanged.

scripts/ruff_strict_gate.py is refactored: shared collect_violations, gather, and a _temp_worktree context manager for base-branch counts; docs note merge-base behavior aligns with CI. A unit test locks in the trailing summary line.

Reviewed by Cursor Bugbot for commit 497447a. Bugbot is set up for automated code reviews on this repo. Configure here.

@codecov

codecov Bot commented Jun 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mateo-berri mateo-berri marked this pull request as ready for review June 20, 2026 17:33
@greptile-apps

greptile-apps Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR improves the developer experience around the strict ruff gate by adding a local make lint-gate target that replicates the CI check exactly and by making failure output survive log tail truncation in CI.

  • scripts/ruff_strict_gate.py: collect_violations is now parameterized for both head and worktree use; _temp_worktree consolidates worktree lifecycle management and switches the finally cleanup to bare subprocess.run so worktree-removal failures can no longer mask the original exception; a new trailing BREACHED RULES: … line is always the last line of failure output so the verdict is visible even when CI surfaces only the tail of a long log.
  • Makefile: adds lint-gate which fetches origin/litellm_internal_staging fresh and passes --base origin/litellm_internal_staging, mirroring the CI invocation exactly.
  • tests/test_litellm/test_ruff_strict_gate.py: adds test_report_emits_breached_rules_as_final_line as a regression guard for the new trailing-summary behaviour.

Confidence Score: 5/5

Safe to merge — changes are confined to the gate script, Makefile, and its tests, with no impact on production code paths.

All three changed files touch developer tooling only (a lint gate script, its Makefile target, and its unit tests). The refactoring is internally consistent: collect_violations is called in both the head and base worktree paths, _temp_worktree correctly suppresses cleanup failures without masking the original error, and the new trailing summary line is directly covered by a regression test. No application logic, request handling, or authentication code is touched.

No files require special attention.

Important Files Changed

Filename Overview
scripts/ruff_strict_gate.py Refactors violation collection into a parameterized collect_violations(root, config), consolidates worktree lifecycle into _temp_worktree context manager that uses bare subprocess.run in the finally to avoid masking original exceptions, factors out gather() and report(), and adds a trailing BREACHED RULES summary line so the verdict survives log tail truncation in CI.
Makefile Adds lint-gate to the .PHONY list, adds its help text, and adds the target itself — fetches origin/litellm_internal_staging then runs the gate with --base origin/litellm_internal_staging to match the CI invocation exactly.
tests/test_litellm/test_ruff_strict_gate.py Adds test_report_emits_breached_rules_as_final_line which captures stdout and asserts the last line is the compact BREACHED RULES summary, directly covering the new trailing-summary behaviour.

Reviews (4): Last reviewed commit: "fix: align lint-gate with CI by dropping..." | Re-trigger Greptile

Comment thread scripts/ruff_strict_gate.py Outdated
Comment thread scripts/ruff_strict_gate.py Outdated
@mateo-berri

Copy link
Copy Markdown
Collaborator Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Collaborator Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Lint gate mismatches CI
    • Dropped the --ci-parity flag from the lint-gate Makefile target (and removed the now-unused gather_ci_parity branch plus the misleading docstring claim about CI), so make lint-gate now invokes ruff_strict_gate.py the same way test-linting.yml does.

You can send follow-ups to the cloud agent here.

Comment thread Makefile Outdated
The lint-gate Makefile target invoked ruff_strict_gate.py with --ci-parity,
which counted violations on a throwaway merge of base into HEAD against base
counts at the base tip. CI in test-linting.yml runs the same script without
--ci-parity on a PR-head checkout, taking the gather_fast path that counts on
the live tree against base counts at the merge-base. A local pass could
therefore disagree with CI.

Drop --ci-parity from the Makefile and remove the now-unused gather_ci_parity
branch and flag so there is one code path that both local and CI exercise.
The docstring claim that CI runs against the synthetic merge ref was also
wrong; the workflow checks out github.event.pull_request.head.sha.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ mateo-berri
❌ cursoragent
You have signed the CLA already but the status is still pending? Let us recheck it.

@yucheng-berri yucheng-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ci-parity mode was dropped and the body no longer matches the code.

@mateo-berri mateo-berri changed the title feat: add CI-parity mode and truncation-proof summary to strict ruff gate feat: add lint-gate target and truncation-proof summary to the strict ruff gate Jun 20, 2026
@mateo-berri

Copy link
Copy Markdown
Collaborator Author

@greptileai


Generated by Claude Code

@mateo-berri

Copy link
Copy Markdown
Collaborator Author

bugbot run


Generated by Claude Code

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 497447a. Configure here.

@mateo-berri mateo-berri merged commit a7b0b0b into litellm_internal_staging Jun 20, 2026
145 of 162 checks passed
@mateo-berri mateo-berri deleted the litellm_ruff_gate_dx branch June 20, 2026 18:46
@Jason-123-cyber

Copy link
Copy Markdown

Ok

@Jason-123-cyber

Copy link
Copy Markdown

Greptile Summary

This PR improves the developer experience around the strict ruff gate by adding a local make lint-gate target that replicates the CI check exactly and by making failure output survive log tail truncation in CI.

  • scripts/ruff_strict_gate.py: collect_violations is now parameterized for both head and worktree use; _temp_worktree consolidates worktree lifecycle management and switches the finally cleanup to bare subprocess.run so worktree-removal failures can no longer mask the original exception; a new trailing BREACHED RULES: … line is always the last line of failure output so the verdict is visible even when CI surfaces only the tail of a long log.
  • Makefile: adds lint-gate which fetches origin/litellm_internal_staging fresh and passes --base origin/litellm_internal_staging, mirroring the CI invocation exactly.
  • tests/test_litellm/test_ruff_strict_gate.py: adds test_report_emits_breached_rules_as_final_line as a regression guard for the new trailing-summary behaviour.

Confidence Score: 5/5

Safe to merge — changes are confined to the gate script, Makefile, and its tests, with no impact on production code paths.

All three changed files touch developer tooling only (a lint gate script, its Makefile target, and its unit tests). The refactoring is internally consistent: collect_violations is called in both the head and base worktree paths, _temp_worktree correctly suppresses cleanup failures without masking the original error, and the new trailing summary line is directly covered by a regression test. No application logic, request handling, or authentication code is touched.

No files require special attention.

Important Files Changed

Filename Overview
scripts/ruff_strict_gate.py Refactors violation collection into a parameterized collect_violations(root, config), consolidates worktree lifecycle into _temp_worktree context manager that uses bare subprocess.run in the finally to avoid masking original exceptions, factors out gather() and report(), and adds a trailing BREACHED RULES summary line so the verdict survives log tail truncation in CI.
Makefile Adds lint-gate to the .PHONY list, adds its help text, and adds the target itself — fetches origin/litellm_internal_staging then runs the gate with --base origin/litellm_internal_staging to match the CI invocation exactly.
tests/test_litellm/test_ruff_strict_gate.py Adds test_report_emits_breached_rules_as_final_line which captures stdout and asserts the last line is the compact BREACHED RULES summary, directly covering the new trailing-summary behaviour.

Reviews (4): Last reviewed commit: "fix: align lint-gate with CI by dropping..." | Re-trigger Greptile

K

fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
… ruff gate (BerriAI#30877)

* feat: add CI-parity mode and truncation-proof summary to strict ruff gate

* refactor: tolerant worktree cleanup and concrete GateInputs types

* fix: clean up temp dir when git worktree add fails

* fix: align lint-gate with CI by dropping unused --ci-parity path

The lint-gate Makefile target invoked ruff_strict_gate.py with --ci-parity,
which counted violations on a throwaway merge of base into HEAD against base
counts at the base tip. CI in test-linting.yml runs the same script without
--ci-parity on a PR-head checkout, taking the gather_fast path that counts on
the live tree against base counts at the merge-base. A local pass could
therefore disagree with CI.

Drop --ci-parity from the Makefile and remove the now-unused gather_ci_parity
branch and flag so there is one code path that both local and CI exercise.
The docstring claim that CI runs against the synthetic merge ref was also
wrong; the workflow checks out github.event.pull_request.head.sha.

---------

Co-authored-by: Cursor Agent <[email protected]>
@Jason-123-cyber

Copy link
Copy Markdown

K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants