From 2c5e1303642453a29d7f782de0845a330a7d3584 Mon Sep 17 00:00:00 2001 From: Kyle Sexton <153232337+kyle-sexton@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:36:06 -0500 Subject: [PATCH] fix(pr-review-cli): classify binary files by content, not the head's .gitattributes The full-diff step's numstat read the checked-out head's .gitattributes, so a text lockfile the consumer marks -diff was listed as binary and a real binary marked diff was not. Read attributes from the empty tree in all three legs so content alone decides, warn when the list fails, and say so in the README. The binary list also lowers the read-evidence bar to a file's header lines, so the attribute could no longer weaken that check either. Refs: #1109 Co-Authored-By: Claude Opus 5.5 --- .github/scripts/pr-review-cli.test.cjs | 22 ++++++++++--- .github/scripts/publish-review.test.cjs | 14 +++++++++ .github/workflows/pr-review-cli.yml | 42 ++++++++++++++++++------- README.md | 5 ++- 4 files changed, 66 insertions(+), 17 deletions(-) diff --git a/.github/scripts/pr-review-cli.test.cjs b/.github/scripts/pr-review-cli.test.cjs index 919add23..484aa4c1 100644 --- a/.github/scripts/pr-review-cli.test.cjs +++ b/.github/scripts/pr-review-cli.test.cjs @@ -6018,7 +6018,10 @@ test("the extract step names the data files the job left out, and a count its li // Binary files (claude-code-plugins#13097's fixtures.tar.gz archives): the // full-diff step names the files in scope numstat counts no lines for, and // the extract step records them in the coverage without changing a count. -test("the full-diff step names the binary files in scope, in every leg", () => { +// Content alone decides: the head's .gitattributes neither turns a text +// lockfile it marks -diff into a binary file (ci-workflows#1109) nor hides +// a binary file it marks diff, whatever the path is named. +test("the full-diff step names the binary files in scope by content, not the head's .gitattributes, in every leg", () => { const { spawnSync } = require("node:child_process"); const git = (cwd, ...args) => { const result = spawnSync("git", args, { cwd, encoding: "utf8" }); @@ -6039,6 +6042,7 @@ test("the full-diff step names the binary files in scope, in every leg", () => { write("a/fixtures.tar.gz", gz(1)); write("gone.bin", gz(9)); write("src/a.js", "a1\n"); + write("pkg/package-lock.json", '{"lockfileVersion":3}\n'); git(origin, "add", "-A"); git(origin, "commit", "--quiet", "-m", "base"); const base = git(origin, "rev-parse", "HEAD"); @@ -6046,6 +6050,14 @@ test("the full-diff step names the binary files in scope, in every leg", () => { write("b/fixtures.tar.gz", gz(3)); write("odd name.bin", gz(4)); write("src/a.js", "a2\n"); + write( + ".gitattributes", + "package-lock.json -diff\n*.lock -diff\nforced.png diff\nnotes.txt -diff\n", + ); + write("pkg/package-lock.json", '{"lockfileVersion":3,"packages":{}}\n'); + write("notes.txt", "plain text the head marks -diff\n"); + write("x/yarn.lock", gz(5)); + write("forced.png", gz(6)); fs.rmSync(path.join(origin, "gone.bin")); git(origin, "add", "-A"); git(origin, "commit", "--quiet", "-m", "head"); @@ -6079,11 +6091,13 @@ test("the full-diff step names the binary files in scope, in every leg", () => { const out = fs.readFileSync(output, "utf8"); // Every file stays in scope; the deleted one is on no list, and the // binary with a space in its name is counted in scope but not named. - assert.match(out, /^files=4$/mu, job.name); - assert.match(out, /^binary=2$/mu, job.name); + // The -diff lockfile and text file are text; the binary named like a + // lockfile and the binary marked diff are named. + assert.match(out, /^files=9$/mu, job.name); + assert.match(out, /^binary=4$/mu, job.name); assert.equal( fs.readFileSync(path.join(work, ".claude-lane/binary-files.txt"), "utf8"), - "a/fixtures.tar.gz\nb/fixtures.tar.gz\n", + "a/fixtures.tar.gz\nb/fixtures.tar.gz\nforced.png\nx/yarn.lock\n", job.name, ); assert.equal( diff --git a/.github/scripts/publish-review.test.cjs b/.github/scripts/publish-review.test.cjs index 19ac7695..904f60e9 100644 --- a/.github/scripts/publish-review.test.cjs +++ b/.github/scripts/publish-review.test.cjs @@ -760,6 +760,20 @@ test("a partial review still posts the findings it made inline", async () => { ); }); +// A binary file on the list never makes a review partial by itself: only a +// read count short of the scope does (ci-workflows#1109). +test("a review that read every file is complete with a binary file in scope", async () => { + const coverage = { read: 2, changed: 2, binary_files: ["img/logo.png"] }; + const { writes, log } = await publish({ + KEY_REVIEW: JSON.stringify({ ...REVIEW, coverage }), + }); + assert.deepEqual(log.failed, []); + assert.equal( + writes[1][1].body.split("\n")[2], + `**claude-review** reviewed \`${HEAD}\`: read 2 of 2 changed file(s); 1 finding(s), 1 as inline comments.`, + ); +}); + // A generated data file the job left out of the scope is named in the // coverage, so the complete review and the shadow report both say which file // no one reviewed; the completion notice, which merge gates parse, is unchanged. diff --git a/.github/workflows/pr-review-cli.yml b/.github/workflows/pr-review-cli.yml index e0373a97..8397bc2d 100644 --- a/.github/workflows/pr-review-cli.yml +++ b/.github/workflows/pr-review-cli.yml @@ -1501,12 +1501,18 @@ jobs: files="$(git diff --name-only --find-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | tee "$FILE_LIST" | wc -l | tr -d ' ')" # Binary files in scope: those numstat counts no lines for (`--`; # no --text here), named in $binary_list for the review summary. The - # diff above holds them as text no review reads. Only plain paths - # are named, and a failure names none. + # diff above holds them as text no review reads. Attributes come from + # the empty tree, so content alone decides: the head's .gitattributes + # can neither make a text file it marks -diff (a lockfile) binary nor + # hide a binary file it marks diff. Only plain paths are named, and a + # failure names none. binary_list=.claude-lane/binary-files.txt - binary="$(git diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | + binary="$(git --attr-source="$(git hash-object -t tree /dev/null)" diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | awk -F '\t' 'NF == 3 && $1 == "-" && $2 == "-" && $3 ~ /^[A-Za-z0-9._\/@+-]+$/ && length($3) <= 500 { print $3 }' | - tee "$binary_list" | wc -l | tr -d ' ')" || binary=0 + tee "$binary_list" | wc -l | tr -d ' ')" || { + echo "::warning::The binary-file list failed; no binary file is named." + binary=0 + } left="" if [ "${#data[@]}" -gt 0 ]; then left=" ${#data[@]} generated data file(s) the base branch declares are in neither the diff nor the list; do not review them." @@ -4193,12 +4199,18 @@ jobs: files="$(git diff --name-only --find-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | tee "$FILE_LIST" | wc -l | tr -d ' ')" # Binary files in scope: those numstat counts no lines for (`--`; # no --text here), named in $binary_list for the review summary. The - # diff above holds them as text no review reads. Only plain paths - # are named, and a failure names none. + # diff above holds them as text no review reads. Attributes come from + # the empty tree, so content alone decides: the head's .gitattributes + # can neither make a text file it marks -diff (a lockfile) binary nor + # hide a binary file it marks diff. Only plain paths are named, and a + # failure names none. binary_list=.claude-lane/binary-files.txt - binary="$(git diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | + binary="$(git --attr-source="$(git hash-object -t tree /dev/null)" diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | awk -F '\t' 'NF == 3 && $1 == "-" && $2 == "-" && $3 ~ /^[A-Za-z0-9._\/@+-]+$/ && length($3) <= 500 { print $3 }' | - tee "$binary_list" | wc -l | tr -d ' ')" || binary=0 + tee "$binary_list" | wc -l | tr -d ' ')" || { + echo "::warning::The binary-file list failed; no binary file is named." + binary=0 + } left="" if [ "${#data[@]}" -gt 0 ]; then left=" ${#data[@]} generated data file(s) the base branch declares are in neither the diff nor the list; do not review them." @@ -6858,12 +6870,18 @@ jobs: files="$(git diff --name-only --find-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | tee "$FILE_LIST" | wc -l | tr -d ' ')" # Binary files in scope: those numstat counts no lines for (`--`; # no --text here), named in $binary_list for the review summary. The - # diff above holds them as text no review reads. Only plain paths - # are named, and a failure names none. + # diff above holds them as text no review reads. Attributes come from + # the empty tree, so content alone decides: the head's .gitattributes + # can neither make a text file it marks -diff (a lockfile) binary nor + # hide a binary file it marks diff. Only plain paths are named, and a + # failure names none. binary_list=.claude-lane/binary-files.txt - binary="$(git diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | + binary="$(git --attr-source="$(git hash-object -t tree /dev/null)" diff --numstat --no-renames --diff-filter=d "$base" "$HEAD_SHA" "${only[@]}" | awk -F '\t' 'NF == 3 && $1 == "-" && $2 == "-" && $3 ~ /^[A-Za-z0-9._\/@+-]+$/ && length($3) <= 500 { print $3 }' | - tee "$binary_list" | wc -l | tr -d ' ')" || binary=0 + tee "$binary_list" | wc -l | tr -d ' ')" || { + echo "::warning::The binary-file list failed; no binary file is named." + binary=0 + } left="" if [ "${#data[@]}" -gt 0 ]; then left=" ${#data[@]} generated data file(s) the base branch declares are in neither the diff nor the list; do not review them." diff --git a/README.md b/README.md index ed88f9c8..c5ef649f 100644 --- a/README.md +++ b/README.md @@ -1796,7 +1796,10 @@ with: **Binary files.** A whole review names the files in scope that `git diff --numstat` counts no lines for (`--`), at a path of letters, -digits and `._/@+-`, as `binary_files` in its coverage. They stay in the diff, +digits and `._/@+-`, as `binary_files` in its coverage. Content alone decides: +the job reads attributes from the empty tree, so the head's `.gitattributes` +neither lists a text file it marks `-diff` (a lockfile) nor hides a binary file +it marks `diff`. They stay in the diff, the file list and the file total, so a review that leaves them unread is still `partial`; its reason names the first 10 (`; binary file(s) not reviewable as text: , ... and more`).