Repository navigation
fix(pr-size): require a rename's SOURCE to be linguist-generated too (BE-8137) - #196
Conversation
…(BE-8137) classify() excluded a rename on the linguist-generated attribute of the DESTINATION path alone, while the three sibling exclusion buckets on the adjacent lines each also require OldPath to match. Renaming a hand-written file into a linguist-generated tree and editing it in the same commit therefore hid the edit from BOTH the size count and the --reviewed-diff-out patch fed to cursor-review. Feed OldPath into the batched `git check-attr` lookup so its attribute is resolved, then require both ends to carry the attribute — mirroring how IsTestPath / IsLockfile / extras.Generated already treat renames. Strictly conservative: every changed direction moves toward counting and reviewing MORE. The base-ref invariant is unchanged; attributes still come from the base .gitattributes, never the PR head. The omission dates to ab2066a, which extended the both-paths rule to the lockfile and extra-glob buckets but left the attribute one bare.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 17 minutes Limit details: You’ve used the included review currently available. Your 94 included PR review attempts over the past 7 days set your current allowance at 1 review per hour. Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?Wait for the limit to reset, then comment An organization admin can change what happens after included review limits in Billing. How do review limits work?CodeRabbit enforces per-developer PR review limits within each organization. For paid Pro and Pro+ reviews, CodeRabbit uses a developer's included PR review attempts over the past 7 days to set the current hourly allowance. At typical activity levels, the full plan allowance applies. Higher sustained activity can lower the allowance until earlier attempts leave the 7-day window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 5 finding(s).
| Severity | Count |
|---|---|
| 🟠 High | 2 |
| 🟡 Medium | 2 |
| 🟢 Low | 1 |
Panel: 8/8 reviewers contributed findings.
…ncelled (BE-8137) Review round on the both-paths rename guard. annotateDiscounts built its patch with a pathspec naming only the DESTINATION, so git could not pair a rename and re-emitted it as a whole-file ADDITION. Every blank/comment line in the file then counted as a discount and the `d > Changed()` clamp drove Counted() to 0 — silently cancelling the count half of classify()'s rename guard for any caller running with --ignore-comments (cursor-review's ignore_comments input feeds exactly that). Verified end to end: `git mv handwritten/big.go gen/big.go` plus a one-line edit reported `Counted = 0` before, `Counted = 1` after. Feed OldPath as an extra pathspec, mirroring what classify() now does for check-attr. Discounts stay keyed by destination, so an unpaired old-path section simply finds no entry and the file counts raw. Test hardening on the new attribute test: - give the two base files distinct bodies, so gen/keep2.json is an unambiguous exact-rename of gen/keep.json; byte-identical bodies left the pairing to git's hashmap tie-break and could invert both OldPath assertions. - move the `check-attr --source` probe after t.Chdir, so it runs where `base` is a valid object; from the outer repo it failed as "not a valid object", which the helper reports as supported, so the skip could never fire. Documented two residuals raised in review rather than changing behavior: the content-marker bucket is destination-only by design (it fails closed under --marker-from-base, and without that flag a rename grants no evasion an in-place marker paste does not already grant), and the both-paths rule inherits whatever pairing git chooses, which a same-content file planted in the generated tree at base can bias.
This branch already carried a prior merge (f438b1b) combining BE-8253's two-tier step-output reader with BE-8220's scope-gate/with-key fixes, resolved against main's pre-squash commit 1c66f7f. Main has since squash-merged that same work as #202 (b92f1df) — byte-identical content under .github/workflow-pins/, different commit hash — so this merge's conflicts were git failing to recognize already-incorporated content across the squash, not new upstream changes. Resolved by keeping HEAD's already-combined version of the three workflow-pins files (verified: its tree for that directory is unchanged from before this merge, and both BE-8220's and BE-8253's added symbols are present). Also picked up two unrelated, cleanly-auto-merged main changes: the cursor-review SHA bump (#200) and the pr-size rename-discount fix (#196). Verified: full workflow-pins test suite (160 tests) and the lint itself pass; pr-size go tests pass except one pre-existing, pre-merge failure (TestResolveMergeBaseWithAdvancedBaseBranch, environment-dependent, reproduces identically on an unmodified origin/main checkout — unrelated to this merge).
ELI-5
The PR-size checker decides which files are "generated" so they skip both the line count and the review panel's patch. For a renamed file it asked "is the file's NEW path marked
linguist-generated?" and nothing else. So you couldgit mva hand-written file into a generated tree, edit it in the same commit, and the edit became invisible — it counted zero lines and never reached the reviewers. The three exclusion buckets sitting on the lines right next to it already asked about the OLD path too; this one just didn't. Now it does.What changed
classify()inscripts/check-pr-size/main.go, two edits:git check-attrlookup now resolves a rename'sOldPathas well as itsPath, so the source path's attribute is actually available.attrGen[f.Path] && (f.OldPath == "" || attrGen[f.OldPath]), mirroring theIsTestPath/IsLockfile/extras.Generatedconjuncts immediately above it.The
classify()header comment's "a RENAME is classified on BOTH its old and new path for every exclusion bucket" list now names the attribute bucket, and spells out that this bucket's hole costs the reviewed diff as well as the count.Chesterton's Fence
The destination-only form was an omission, not a design choice.
git log -Lon those lines lands onab2066a(fix(pr-size): close the rename bypass on lockfiles too), which introduced thelockfileandextraGenboth-paths conjuncts in exactly thisifand leftattrGen[f.Path]bare on the line between them. The change is also strictly narrowing — every case it newly declines to exclude gets counted and reviewed, never the reverse — so the failure direction stays the safe one. The base-ref invariant is untouched:attrGeneratedBatchstill resolves viagit check-attr -z --stdin --source <base>, which works for arbitrary path strings whether or not they exist at that ref, and a rename's source path does exist there.Test
TestClassifyRenameIntoAttrGeneratedTreeStillCounts(new,main_test.go) builds a throwaway repo whose base carriesgen/** linguist-generated=true, then in one head commit renames a hand-written file intogen/with an injected edit and renames a genuinely generated file withingen/. It asserts, in that order: rename detection actually fired (OldPathis the source), the moved hand-written file is NOTGenerated, the intra-gen/rename still IS,Evaluatecounts the injected line, the injected marker appears in the--reviewed-diff-outpatch, and the generated rename does not.I falsified the test three ways against the unfixed code before trusting it — reverting the
attrGenOKconjunct alone, reverting theOldPathbatch-lookup alone, and reverting both. Each revert fails the assertion it is supposed to guard, and reverting both reproduces the ticket's reported numbers exactly:Counted = 0, everything excluded, zero occurrences of the injected marker in the reviewed diff (0 file section(s) kept, 2 generated section(s) excluded). TheOldPathbatch-lookup edit is load-bearing on its own: without itattrGen[f.OldPath]is always false and legitimate moves inside a generated tree would start counting.Sweep of the buckets this PR does NOT change
classify()makes five rename-sensitive decisions. Four were already sound and I left them alone:f.Test,lockfileandextraGencarry the explicit both-paths conjunct, and the content-marker bucket fails closed on renames by construction. I probed that last one rather than reasoning about it, since it was the only non-obvious case — withmarkerFromBaseset it readsbase:<destination>, which for a true rename does not exist, so it returns false and the file is counted. Review sharpened this: the fail-closed behavior holds only under--marker-from-base, which the sole--reviewed-diff-outcall site (cursor-review.yml:672) does pass. Without the flag the head read can be self-marked — but that reduces to pasting the marker in place, needs no rename, and is the already-documented count-only tradeoff, so the bucket stays destination-only with the reasoning now written down. The adjacent worry (moving a hand-written.goon top of a file that was generated at base) is not a rename at all: git reports it as a separate modify plus delete with an emptyOldPath, so the hand-written deletions stay booked against their own non-generated path and still count. One hole out of five, and it is the one fixed here.Propagation
None by hand.
main.gois inside thescripts/check-pr-size/**path filter of bothbump-cursor-review-callers.ymlandbump-pr-size-callers.yml, so merging fans SHA-bump PRs to the pinned callers automatically. Themain_test.gohalf is stripped by the:(exclude)scripts/check-pr-size/*_test.gonegation, which only strips the paths it matches — the non-test change still triggers the bump. No consumer'sci-cursor-review.ymlpin is touched in this PR.Judgment calls and unexercised artifacts
initTestRepo(main_test.go) does not pin the throwaway repo's initial branch, so it inherits the host'sinit.defaultBranch. On any machine where that ismain,TestResolveMergeBaseWithAdvancedBaseBranchfails withfatal: a branch named 'main' already exists— pre-existing on the base commit, unrelated to this change, and invisible in CI because the runner's git still defaults tomaster. I did not fix it: it means touching an unrelated test, and this diff is scoped to the reported defect. Because it is an unfixed defect on a file the ticket names, the reference below isRefs, notCloses.couldn't find remote ref), so I confirmed the bareattrGen[f.Path] ||form on the currentorigin/maintip instead, where it was still present. The private consumer-repo PR the original reproduction ran against is in another repository and out of bounds for this change; nothing here relies on it, since the repro is reproduced in-repo by the new test. The tracking ticket's own thread and any linked material were not readable from this environment.full-autonomyis deliberately absent: the source ticket does not carry it, and the label does not exist on this repo.Review round
The panel raised 5 findings; 3 were fixed and 2 documented as residuals (76bf67a).
The one that mattered — the fix was being cancelled downstream.
annotateDiscountsbuilt its patch with a pathspec naming only the DESTINATION, so git could not pair a rename and re-emitted it as a whole-file addition. Every blank/comment line then became a discount and thed > Changed()clamp droveCounted()to 0. I reproduced it end to end before touching anything: withPR_SIZE_IGNORE_COMMENTS=1(whichcursor-review'signore_commentsinput feeds),git mv handwritten/big.go gen/big.goplus a one-line edit reportedCounted = 0— i.e. the count half of this PR's guard was fully nullified for that caller. It now passesOldPathas an extra pathspec, mirroring the check-attr change, and the same run reportsCounted = 1. Discounts stay keyed by destination, so an unpaired old-path section finds no entry and the file counts raw.Test hardening. The two base files in the new attribute test were byte-identical, leaving
gen/keep2.json's exact-rename pairing to git's hashmap tie-break — it could have paired with the hand-written source and inverted bothOldPathassertions. They now carry distinct bodies. Separately thecheck-attr --sourceprobe ran beforet.Chdir, wherebaseis not a valid object; the helper reports that class of failure as supported, so the skip could never fire and an old-git runner would have died onkept.Generatedwith a misleading message. Probe moved after the chdir.Documented, not changed. The content-marker bucket is destination-only by design (fails closed under
--marker-from-base; without it a rename grants nothing an in-place marker paste does not). And the both-paths rule inherits whatever pairing git chooses, which a same-content generated file planted at base can bias — aKNOWN LIMITparagraph onclassifynow records it. Neither is reachable as a new defect under any current caller, so neither got a follow-up ticket.Refs BE-8137
Provenance
gofmt -l .clean;go vet ./...clean;cd scripts/check-pr-size && go test ./...— ok, 0 failures (run with a neutralGIT_CONFIG_GLOBAL, see the out-of-scope note above). Falsification: the original fix reverted three ways (each partial revert fails the assertion it guards), and the newTestAnnotateDiscountsPairsRenamesSoTheEditStillCountsre-run against the revertedannotateDiscountschange, which fails withDiscounted = 1, want 0andCounted = 0, want 1. Both the original defect and the discount cancellation were also reproduced end to end through the built binary against a throwaway repo, before and after each fix.classify()edits, the header-comment update, and the test are implemented. The review round then added one behavior fix outside the original plan (annotateDiscountsrename pairing), taken on because it silently cancelled this PR's own fix rather than being adjacent cleanup. Two review findings were answered with documentation rather than code, each with the reasoning on its thread. The unrelatedinitTestRepobranch-name fragility described above remains a deliberate omission.