Skip to content

fix(pr-pipeline): cut a hunk larger than one chunk between its lines - #18705

Merged
kyle-sexton merged 4 commits into
mainfrom
fix/18178-cut-oversize-hunk-at-lines
Nov 24, 2026
Merged

kyle-sexton merged 4 commits into
mainfrom
fix/18178-cut-oversize-hunk-at-lines

Conversation

@kyle-sexton

Copy link
Copy Markdown
Member

Closes #18178
Siblings: #18196

Summary

#18196 cut a file larger than one chunk into pieces at its hunks, but a file whose one hunk is over a chunk (300,000 bytes) with its header still left pr-verify and pr-review-main with no verdict. That was the last part of done-when item 1 and the issue's "A single hunk larger than a chunk is cut at line boundaries."

diff_chunking.py split gains --cut-lines. With it, such a hunk is cut between its lines, and each cut goes under its own @@ header, recounted for the lines it holds, so a reviewer can still place every line. pr-verify and pr-review-main pass the flag. Without the flag the splitter still refuses the hunk, which is what ci-workflows' generate-review-chunks/split.sh relies on, so that caller is unchanged.

Fix

  • .github/scripts/diff-chunking/diff_chunking.py: cut_hunk cuts an oversize hunk between its lines into hunks that fit beside the file's header. Each gets a recounted @@ -a,b +c,d @@ header and keeps the original header's function context. A side with no lines in a cut names the line before it, as git does (-0,0 for a new file). A \ No newline at end of file line stays with the line before it. Only a single line over the chunk with its headers is still too large; it exits 3 with "a file has a line larger than one chunk". MAX_CHUNKS stays the cost guard.
  • .github/scripts/pr-verify/chunk-diff.sh and the three pr-review-main.yml legs call split with --cut-lines.
  • The prompts say a piece can hold part of a hunk: pr-verify's chunk-note.md, the final judge's manifest description in spec-prompt.md, and pr-review-main's chunk note in all three legs.
  • Also updated: the step comments in pr-verify.yml and pr-review-main.yml, pr-review-main's too-large stop message, the chunk-diff.sh header, and docs/conventions/pr-pipeline/README.md. A pr-pipeline changelog fragment is added.
  • split.sh in ci-workflows calls split without the flag, so its refusal and partial review are unchanged. No cross-repo change is needed. Basis: split.sh in melodic-software/ci-workflows, "A file with a hunk over the budget with its header is not cut, so the split refuses it and the review stays partial", and its splitter=(... diff_chunking.py split) call with no flag.

Verification

  • node --test --test-concurrency=4:
    • diff-chunking/diff-chunking.test.mjs: 15 passed
    • pr-verify/chunk-diff.test.mjs: 19 passed
    • pr-verify/spec-prompt-text.test.mjs and pr-verify/workflow.test.mjs: 57 passed
    • pr-review-main/workflow.test.mjs: the four diff tests passed after the change. An earlier full run of the suite had 47 passed and 2 failed, and those two are the tests this PR updates.
  • New and changed tests:
    • a hunk cut between its lines, with exact recounted headers (-10,2 +10,1, -11,0 +11,2, -12,2 +13,2) and the manifest's piece <i> of 3
    • the MAX_CHUNKS exit still holding with line cuts
    • a new file's hunk (-0,0 +1,2, -0,0 +3,1), with a no-newline mark kept with its line
    • only a single over-size line still exits 3
    • without the flag, an over-size hunk is still refused
    • chunk-diff.sh judging one 200-line hunk in recounted pieces that hold every line once, in order
    • under pr-verify.yml's real limits, one 334 KB file in a single hunk giving chunks=2 with no ::error::
    • pr-review-main's "Write the diff" step judging a single 618-byte hunk in three chunks with no stop
    • the prompts naming the line cut
  • scripts/run-ruff.sh check and format --check on diff_chunking.py: clean.
  • scripts/check-affected.sh --base HEAD~1: 21 passed, 3 skipped.
  • Not run: applying each cut piece in order with git apply (the local scratch harness was refused by the session's permission classifier), and the full .github suite (per-machine limit; CI runs it). pr-verify and pr-review-main run the cutter from main's checkout (.base), so this PR's own run uses the old cutter; the line cut first runs live after merge.

Related

🤖 Generated with Claude Code

diff_chunking.py split gains --cut-lines: a hunk that with its file's
header is over one chunk is cut between its lines, each cut under an
@@ header recounted for the lines it holds, and a "\ No newline" mark
stays with its line. Only a single line over a chunk is then too large.
pr-verify's chunk-diff.sh and pr-review-main's three legs pass the flag;
the default keeps the refusal ci-workflows' generate-review-chunks
relies on. The chunk prompts, final-judge spec prompt, step comments,
too-large message and pr-pipeline README say a piece can hold part of
a hunk.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton
kyle-sexton marked this pull request as ready for review November 24, 2026 05:41
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T05:48:02.273669Z 99107ea Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-security-review reviewed d1f57deb70ea59fe76354f93b56dd4a1b9b71314: read 1 of 1 changed file(s); 0 finding(s), 0 as inline comments.

Security review: PR #18705, incremental since 31fc89e

I found no security issues. This review was blocking only: the lane already reviewed an earlier head, so it would have reported only CRITICAL and IMPORTANT findings.

Scope

Since 31fc89ee7e5507212e1e43c9753f99ec6bc2a49e, one file changed: .github/scripts/diff-chunking/diff-chunking.test.mjs. I read the whole change. The file matches the trusted-path glob .github/scripts/diff-chunking/**, so it got extra scrutiny.

What I checked

  • The change itself. It is test-only. Before, three --cut-lines tests used hand-written patch fixtures. Now a new gitDiff helper builds them from real git diff output. The helper:

    • makes a temporary directory with mkdtempSync;
    • runs git through spawnSync with an argument array, so no shell is involved and nothing is interpolated into a command string;
    • sets GIT_CONFIG_GLOBAL=/dev/null and GIT_CONFIG_NOSYSTEM=1, which keeps the runner's own git config, including any diff or external-diff drivers, out of the fixture (it also passes --no-ext-diff);
    • removes the directory in a finally block.

    Every input is a constant from the test file. The only value placed into a RegExp is the numeric cap.

  • Production code. Untouched: diff_chunking.py, the prompts, the workflows and the gate logic did not change in this push.

  • Test selection. The file's test-scope comments did not change, so nothing now runs less often or more weakly.

  • Trust controls. None changed: no trusted-actor list, token scope, kill switch or merge-hold script.

  • Plugin manifests. None changed.

Findings from earlier reviews

The earlier reviews at 99107ea and 31fc89e reported no findings, and this push changes nothing they concluded about the cutter or the chunk prompts.

critical-findings: 0

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

claude-review reviewed d1f57deb70ea59fe76354f93b56dd4a1b9b71314: read 1 of 1 changed file(s); 0 finding(s), 0 as inline comments.

Code review (incremental, blocking only): no findings

Scope: this push changes one file since 31fc89e: .github/scripts/diff-chunking/diff-chunking.test.mjs. It adds a gitDiff helper. The helper builds each --cut-lines test's patch from real git diff output in a scratch repository, with global and system config off. Before this push, the tests used hand-written headers.

What I checked (by reading the code; I ran nothing):

  • The fixtures are what git writes. The first test compares 9 lead lines, then a b e 9 against a c d e 9, at -U1. That gives @@ -10,3 +10,4 @@ fn with one context line on each side. fn is the funcname, because git's default funcname rule takes the last line before the hunk that starts with a letter, which is line 9. The second test uses add -N and drops the trailing newline. That gives a new file mode header and @@ -0,0 +1,3 @@ followed by the no-newline mark. The third test's x → 100×y gives @@ -1 +1 @@. Each test asserts the exact hunk text, so if git's output were different the test would fail rather than pass by accident.
  • The caps still force the same cuts. Each cap is the real header length plus the budget the old fixtures used (77, 78 and 67 bytes beside the header). In test 1, the recounted pieces are 63, 63 and 42 bytes, and any two lines plus their neighbour would be 84 bytes, which is over the cap. So the three cuts and the -12,1 +13,1 third header still follow, along with the MAX_CHUNKS exit at 2. In test 2, the pieces are 58 and 65 bytes and together they are over 78. In test 3, the one + line with its header is 114 bytes, which is over 67, so the "line larger than one chunk" exit still holds. The stderr regex now interpolates the cap, which is digits only.
  • The new code uses spawnSync, mkdtempSync, writeFileSync and rmSync, which were already imported. The scratch directory is removed in finally.

The earlier reviews covered the rest of the PR, including closing issue #18178's done-when items; this push leaves them unchanged. This is a blocking-only review, because this lane already reviewed an earlier head. I found no instructions embedded in the PR context.

Loosened checks would be marked: fail. That is the default, because the prompt gave no loosened_check_verdict: or loosened_check_patterns: line; patterns: 0. The prompt gave no loosened_check_decision_record: line, so I did not check the citation requirement. This push loosens no check.

No plugin manifests changed in this push.

Uncovered rules (1)
  • Uncovered rule: a test helper that runs git in a scratch repository should clear inherited GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE, as the repository's .sh tests do (unset GIT_DIR GIT_WORK_TREE GIT_CONFIG GIT_INDEX_FILE). Otherwise a caller that exports them sends the helper's git add into its own repository. Prompted by diff-chunking.test.mjs#L102. This is advisory only: the repository's lefthook hooks run guards and formatters, not this suite.

Verifier dropped 0 of 0 candidates.

Uncovered rules (1)
  • Uncovered rule: A test helper that runs git in a scratch repo should clear inherited GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE (as the repo's .sh tests do), so a caller that exports them can't have the helper's git add write into its own repo (.github/scripts/diff-chunking/diff-chunking.test.mjs:102).

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 99107eaaee

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

kyle-sexton and others added 2 commits November 24, 2026 01:33
…ge_settings.py

Test Selection's strict trace failed on run
https://github.com/melodic-software/claude-code-plugins/actions/runs/45335096019:
the suite reads plugins/source-control/skills/babysit-prs/scripts/babysit_merge_settings.py
without a test-scope line, so a change to that file did not select it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The three --cut-lines tests in diff-chunking.test.mjs now run git diff
in a temp repository (global and system config off) and split its real
output, asserting git's own hunk header before checking the recounted
cuts. This drops the impossible `@@ -1 +1 @@` header over a lone
addition; the long-line case is now a real one-line replacement, and
the new-file case takes git's no-newline mark. Caps are the file
header's length plus a fixed room, so git's index line does not shift
them. All three still fail on the splitter before --cut-lines.

Finding: #18705 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kyle-sexton

Copy link
Copy Markdown
Member Author

pr-review-main claude-review SUGGESTION at d1f57de (diff-chunking.test.mjs:2, an unexplained // test-scope: line), dispositioned without code change. The line is the repository's declaration form for a file a suite reads (the test-scope directive Test Selection parses). It exists because Test Selection failed this PR on that undeclared read of babysit_merge_settings.py (run 45335096019). The comment-lint posture keeps comments to the necessary ones, so the reason lives in the commit (31fc89e) and here rather than beside the directive.

@kyle-sexton
kyle-sexton added this pull request to the merge queue Nov 24, 2026
Merged via the queue into main with commit 3bbf76c Nov 24, 2026
64 checks passed
@kyle-sexton
kyle-sexton deleted the fix/18178-cut-oversize-hunk-at-lines branch November 24, 2026 08:22
@github-actions github-actions Bot added the merge-path: owner-agent Post-merge accounting record (README.md, Merge paths) label Nov 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Post-merge mutation testing

Killed 5, survived 2, timeout 0, no coverage 0, invalid 0, not run 0.
Covered-code score 71%; mutation score 71%.

File Killed Survived Timeout No coverage Invalid Not run
.github/scripts/diff-chunking/diff_chunking.py 4 2 0 0 0 0
.github/scripts/pr-verify/chunk-diff.sh 1 0 0 0 0 0

Surviving mutants

Location Operator Disposition Cause
.github/scripts/diff-chunking/diff_chunking.py:103 ROR productive input-gap
.github/scripts/diff-chunking/diff_chunking.py:146 ROR productive input-gap

The run's summary has the full report.

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

Labels

merge-path: owner-agent Post-merge accounting record (README.md, Merge paths)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pr-verify: split a file larger than one chunk into pieces instead of leaving the head with no verdict

1 participant