Skip to content

Commit d446fc9

Browse files
committed
Merge origin/main into matt/be-8253-workflow-pins-unparsed-ref
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).
2 parents f438b1b + b92f1df commit d446fc9

3 files changed

Lines changed: 213 additions & 6 deletions

File tree

‎.github/workflows/ci-cursor-review.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ jobs:
3333
permissions:
3434
contents: read
3535
pull-requests: write
36-
uses: Comfy-Org/github-workflows/.github/workflows/cursor-review.yml@f8eec04e7923f4719d5b7dbc342e5c15580e22ba # github-workflows main (f8eec04)
36+
uses: Comfy-Org/github-workflows/.github/workflows/cursor-review.yml@00b0eef5fe3e85422bdb525024bf4b2a3ec92b7d # github-workflows main (00b0eef)
3737
with:
3838
# Keep the assets ref in lock-step with the `uses:` ref above.
39-
workflows_ref: f8eec04e7923f4719d5b7dbc342e5c15580e22ba
39+
workflows_ref: 00b0eef5fe3e85422bdb525024bf4b2a3ec92b7d
4040
# No vendored/generated content in this repo; defensive excludes only.
4141
# These live in extra_generated_globs, not diff_excludes: since BE-7633
4242
# diff_excludes leaves the reviewed diff but is still COUNTED against

‎scripts/check-pr-size/main.go‎

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,18 @@ func diffFiles(base, head string) ([]FileChange, error) {
241241
// that file counts raw — a failure can only make the cap STRICTER, never sneak a
242242
// large change under it. Restricts the patch to the counted paths, so a large
243243
// generated diff is never fetched or parsed.
244+
//
245+
// A RENAME contributes BOTH of its paths to that pathspec. Naming only the
246+
// destination hides the deletion side from the filtered diff, so git cannot pair
247+
// the rename and re-emits the destination as a whole-file ADDITION — every
248+
// blank/comment line in the file then counts as a discount, and the `d >
249+
// Changed()` clamp below drives the rename's Counted() to 0. That would silently
250+
// cancel classify()'s both-paths rename guard for any caller running with
251+
// --ignore-comments: `git mv handwritten/big.go gen/big.go` plus a large edit is
252+
// correctly classified non-generated and then discounted back down to nothing.
253+
// Discounts stay keyed by DESTINATION (idx holds f.Path only), matching the
254+
// paired diff's `+++` header; an unpaired old-path section finds no idx entry
255+
// and is skipped, so the file just counts raw.
244256
func annotateDiscounts(files []FileChange, base, head string) {
245257
idx := make(map[string]*FileChange, len(files))
246258
paths := make([]string, 0, len(files))
@@ -250,6 +262,9 @@ func annotateDiscounts(files []FileChange, base, head string) {
250262
continue
251263
}
252264
paths = append(paths, f.Path)
265+
if f.OldPath != "" {
266+
paths = append(paths, f.OldPath)
267+
}
253268
idx[f.Path] = f
254269
}
255270
if len(paths) == 0 {
@@ -319,15 +334,31 @@ func attrTrusted(useSource, attrModified, bypass bool) bool {
319334
// regardless of policy, so the report can show the test total whether or not the
320335
// caller opted to exclude it.
321336
//
322-
// A RENAME is classified on BOTH its old and new path for every exclusion
323-
// bucket this function decides — lockfile, extra-generated glob, and test.
337+
// A RENAME is classified on BOTH its old and new path for every PATH- and
338+
// ATTRIBUTE-based exclusion bucket this function decides — lockfile,
339+
// extra-generated glob, the linguist-generated attribute, and test. (The
340+
// content-marker bucket is destination-only; see contentGenerated for why that
341+
// is not a rename hole.)
324342
// `git diff --numstat` books a rename's deletions against the destination, so
325343
// classifying on the destination alone would let e.g. `git mv src/big.go
326344
// tests/big.go` (or `git mv src/big.go go.sum`) charge removed PRODUCTION
327345
// lines to an excluded bucket, silently slipping the change under the cap.
346+
// The attribute bucket has the same hole with an extra sting: a rename into a
347+
// `linguist-generated` tree hides the moved file from the --reviewed-diff-out
348+
// patch as well as from the count, so an edit made in the same commit reaches
349+
// neither the size verdict nor the review panel.
328350
// Requiring both paths to agree keeps every one of these failures in the safe,
329351
// over-counting direction.
330352
//
353+
// KNOWN LIMIT of the both-paths rule: it can only be as good as git's rename
354+
// pairing, which an adversary with commit access to the base can bias. If the
355+
// generated tree already holds a file byte-identical at base to the one being
356+
// moved in, moving both in one PR lets the exact-rename phase pair the untouched
357+
// destination with the hand-written source, leaving the EDITED destination
358+
// paired with the in-tree generated source — both attribute-carrying, so the
359+
// edit is excluded again. It needs a same-content generated file planted at
360+
// base, so it is a documented residual, not the reported defect.
361+
//
331362
// Binary files are classified by the path- and attribute-based rules too (none
332363
// of those read content), so a binary lockfile or a binary matching an extra
333364
// glob is still excluded from a --reviewed-diff-out consumer's diff; only the
@@ -343,6 +374,13 @@ func classify(files []FileChange, base, head string, attr attrPolicy, extras Ext
343374
paths := make([]string, 0, len(files))
344375
for i := range files {
345376
paths = append(paths, files[i].Path)
377+
// A rename's source path needs its attribute resolved too, or the
378+
// both-paths check below has nothing to read. check-attr resolves
379+
// rules for arbitrary path strings, so batching it is safe whether
380+
// or not the path still exists.
381+
if files[i].OldPath != "" {
382+
paths = append(paths, files[i].OldPath)
383+
}
346384
}
347385
attrGen = attrGeneratedBatch(paths, attr.source, attr.useSource)
348386
}
@@ -353,8 +391,8 @@ func classify(files []FileChange, base, head string, attr attrPolicy, extras Ext
353391
f.Test = IsTestPath(f.Path) && (f.OldPath == "" || IsTestPath(f.OldPath))
354392
lockfile := IsLockfile(f.Path) && (f.OldPath == "" || IsLockfile(f.OldPath))
355393
extraGen := extras.Generated(f.Path) && (f.OldPath == "" || extras.Generated(f.OldPath))
356-
if lockfile || extraGen ||
357-
attrGen[f.Path] ||
394+
attrGenOK := attrGen[f.Path] && (f.OldPath == "" || attrGen[f.OldPath])
395+
if lockfile || extraGen || attrGenOK ||
358396
(!f.Binary && contentGenerated(f.Path, base, head, markerFromBase)) {
359397
f.Generated = true
360398
}
@@ -460,6 +498,18 @@ func isUnknownFlagError(stderr string) bool {
460498
// code by prepending one comment line. Base-only means a file new in the PR
461499
// never matches the marker (it is counted and reviewed — conservative); files
462500
// generated at base stay excluded.
501+
//
502+
// Unlike classify's path/attribute buckets, this one reads the DESTINATION only,
503+
// and deliberately so — a rename grants no evasion here that an in-place edit
504+
// does not already grant. With markerFromBase (what --reviewed-diff-out sets) a
505+
// rename's destination does not exist at base, the show fails, and the bucket
506+
// returns false: it fails CLOSED, counting and reviewing the file. Without it,
507+
// the head read can be self-marked — but `git mv handwritten/big.go gen/big.go`
508+
// plus a pasted marker excludes exactly what pasting the marker into
509+
// handwritten/big.go in place already excludes, so the move adds nothing. That
510+
// residual is the accepted count-only tradeoff described above, not a rename
511+
// hole; the fix for it is --marker-from-base, which every evadability-sensitive
512+
// caller already passes.
463513
func contentGenerated(path, base, head string, markerFromBase bool) bool {
464514
if !strings.HasSuffix(path, ".go") {
465515
return false

‎scripts/check-pr-size/main_test.go‎

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"os"
56
"os/exec"
67
"path/filepath"
@@ -338,6 +339,162 @@ func TestClassifyHonorsLegitBaseGitattributes(t *testing.T) {
338339
}
339340
}
340341

342+
// TestClassifyRenameIntoAttrGeneratedTreeStillCounts is the attribute half of
343+
// the rename anti-gaming guard (the path-based buckets are covered by
344+
// TestRenameIntoExclusionBucketsStillCounts, which cannot reach this one — the
345+
// attribute lookup needs a real repo). Renaming a hand-written file INTO a
346+
// `linguist-generated` tree and editing it in the same commit must not hide the
347+
// edit: classifying on the destination alone excluded it from both the size
348+
// count and the --reviewed-diff-out patch fed to the review panel. A rename
349+
// whose BOTH ends carry the attribute is still excluded, so genuine moves
350+
// inside a generated tree are unaffected.
351+
func TestClassifyRenameIntoAttrGeneratedTreeStillCounts(t *testing.T) {
352+
dir := initTestRepo(t)
353+
// The two base files must NOT be byte-identical: gen/keep2.json below is an
354+
// exact-blob rename of gen/keep.json, and if handwritten/x.json carried the
355+
// same bytes git's exact-rename phase could pair keep2 with the hand-written
356+
// source instead (neither basename matches, so the tie-break is hashmap
357+
// order and varies by git version), inverting both OldPath assertions.
358+
body := strings.Repeat("{\"k\": \"v\"}\n", 40)
359+
keepBody := strings.Repeat("{\"keep\": \"generated\"}\n", 25)
360+
writeFile(t, dir, ".gitattributes", "gen/** linguist-generated=true\n")
361+
writeFile(t, dir, "handwritten/x.json", body)
362+
writeFile(t, dir, "gen/keep.json", keepBody)
363+
base := commitAll(t, dir, "base")
364+
365+
// PR head, touching NOTHING under .gitattributes: a hand-written file moves
366+
// into the generated tree carrying an injected edit, and a genuinely
367+
// generated file moves within that tree.
368+
gitRun(t, dir, "mv", "handwritten/x.json", "gen/x.json")
369+
writeFile(t, dir, "gen/x.json", body+"{\"injected\": \"marker\"}\n")
370+
gitRun(t, dir, "mv", "gen/keep.json", "gen/keep2.json")
371+
head := commitAll(t, dir, "head")
372+
t.Chdir(dir)
373+
374+
// Probe AFTER the chdir: base is a SHA in this throwaway repo, so running it
375+
// from the outer repo would fail for "not a valid object" — which
376+
// checkAttrSourceSupported deliberately reports as supported — and the skip
377+
// could never fire on a runner whose git predates check-attr --source.
378+
if !checkAttrSourceSupported(base) {
379+
t.Skip("git too old for check-attr --source")
380+
}
381+
382+
files, err := diffFiles(base, head)
383+
if err != nil {
384+
t.Fatalf("diffFiles: %v", err)
385+
}
386+
attr := attrPolicy{source: base, useSource: true}
387+
attr.trusted = attrTrusted(attr.useSource, TouchesGitattributes(files), false)
388+
if !attr.trusted {
389+
t.Fatal("attribute path should be trusted (PR does not touch .gitattributes)")
390+
}
391+
classify(files, base, head, attr, Extras{}, false)
392+
393+
byPath := make(map[string]FileChange, len(files))
394+
for _, f := range files {
395+
byPath[f.Path] = f
396+
}
397+
moved, ok := byPath["gen/x.json"]
398+
if !ok {
399+
t.Fatalf("git did not report gen/x.json as changed; got %+v", files)
400+
}
401+
if moved.OldPath != "handwritten/x.json" {
402+
t.Fatalf("gen/x.json OldPath = %q, want handwritten/x.json (rename detection did not fire)", moved.OldPath)
403+
}
404+
if moved.Generated {
405+
t.Error("a hand-written file renamed INTO a linguist-generated tree must not be classified generated — its edit would vanish from both the count and the reviewed diff")
406+
}
407+
kept, ok := byPath["gen/keep2.json"]
408+
if !ok {
409+
t.Fatalf("git did not report gen/keep2.json as changed; got %+v", files)
410+
}
411+
if !kept.Generated {
412+
t.Error("a rename whose source AND destination both carry linguist-generated should stay excluded")
413+
}
414+
415+
res := Evaluate(files, Policy{Max: 1000})
416+
if res.Counted == 0 {
417+
t.Errorf("Counted = %d, want the injected edit counted", res.Counted)
418+
}
419+
420+
// End-to-end on the second symptom: the injected edit must reach the patch
421+
// the review panel reads, while the genuinely generated rename stays out.
422+
out := filepath.Join(t.TempDir(), "pr-diff.patch")
423+
if err := writeReviewedDiff(base, head, nil, files, out); err != nil {
424+
t.Fatalf("writeReviewedDiff: %v", err)
425+
}
426+
patch, err := os.ReadFile(out)
427+
if err != nil {
428+
t.Fatal(err)
429+
}
430+
if !strings.Contains(string(patch), "injected") {
431+
t.Error("the injected edit is missing from the --reviewed-diff-out patch — the review panel would never see it")
432+
}
433+
if strings.Contains(string(patch), "keep2.json") {
434+
t.Error("a rename entirely inside a generated tree should still be dropped from the reviewed diff")
435+
}
436+
}
437+
438+
// TestAnnotateDiscountsPairsRenamesSoTheEditStillCounts guards the downstream
439+
// half of the rename guard. classify() correctly leaves a hand-written file
440+
// renamed out of its tree non-generated, but annotateDiscounts then re-derives a
441+
// patch from git; naming only the DESTINATION in that pathspec hid the deletion
442+
// side, git could not pair the rename, and it re-emitted the file as a
443+
// whole-file ADDITION whose every comment/blank line became a discount. Clamped
444+
// at Changed(), that drove the rename's Counted() to 0 — silently cancelling the
445+
// guard for any caller running with --ignore-comments (cursor-review's
446+
// ignore_comments input feeds exactly that).
447+
func TestAnnotateDiscountsPairsRenamesSoTheEditStillCounts(t *testing.T) {
448+
dir := initTestRepo(t)
449+
// Comment-heavy on purpose: unpaired, the whole-file addition discounts far
450+
// more lines than the rename actually changed, so the clamp zeroes it out.
451+
var sb strings.Builder
452+
sb.WriteString("package hw\n")
453+
for i := 0; i < 200; i++ {
454+
fmt.Fprintf(&sb, "// comment line %d\n\nvar V%d = %d\n", i, i, i)
455+
}
456+
writeFile(t, dir, "handwritten/big.go", sb.String())
457+
base := commitAll(t, dir, "base")
458+
459+
if err := os.MkdirAll(filepath.Join(dir, "moved"), 0o755); err != nil {
460+
t.Fatal(err)
461+
}
462+
gitRun(t, dir, "mv", "handwritten/big.go", "moved/big.go")
463+
writeFile(t, dir, "moved/big.go", sb.String()+"var Injected = 42\n")
464+
head := commitAll(t, dir, "head")
465+
t.Chdir(dir)
466+
467+
files, err := diffFiles(base, head)
468+
if err != nil {
469+
t.Fatalf("diffFiles: %v", err)
470+
}
471+
classify(files, base, head, attrPolicy{}, Extras{}, false)
472+
473+
var moved *FileChange
474+
for i := range files {
475+
if files[i].Path == "moved/big.go" {
476+
moved = &files[i]
477+
}
478+
}
479+
if moved == nil {
480+
t.Fatalf("git did not report moved/big.go as changed; got %+v", files)
481+
}
482+
if moved.OldPath != "handwritten/big.go" {
483+
t.Fatalf("moved/big.go OldPath = %q, want handwritten/big.go (rename detection did not fire)", moved.OldPath)
484+
}
485+
if moved.Generated {
486+
t.Fatal("a plain hand-written rename must not be classified generated")
487+
}
488+
489+
annotateDiscounts(files, base, head)
490+
if moved.Discounted != 0 {
491+
t.Errorf("Discounted = %d, want 0 — the rename was re-read as a whole-file addition", moved.Discounted)
492+
}
493+
if got := Evaluate(files, Policy{Max: 1000}).Counted; got != 1 {
494+
t.Errorf("Counted = %d, want 1 (the injected line); discounting cancelled the rename guard", got)
495+
}
496+
}
497+
341498
// TestWriteReviewedDiff proves the end-to-end --reviewed-diff-out path against
342499
// real git: the emitted patch keeps the hand-written file's section, drops the
343500
// generated file's section entirely, and honors a verbatim exclude pathspec —

0 commit comments

Comments
 (0)