From 980d7a1f5e5253451a0b4ade1cbc6e6617b78e9e Mon Sep 17 00:00:00 2001 From: Pigbibi <20649888+Pigbibi@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:45:53 -0800 Subject: [PATCH] fix(review-core): list oversized deleted files instead of truncating A removed file adds no code. When its deletion patch alone exceeds the batch budget, it is listed by name and line count, and coverage stays complete. Oversized added or modified files still mark coverage partial. Co-Authored-By: Claude Opus 5.5 --- packages/review-core/policy.mjs | 5 +++++ tests/review-core.test.mjs | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/packages/review-core/policy.mjs b/packages/review-core/policy.mjs index 341c391..24b504f 100644 --- a/packages/review-core/policy.mjs +++ b/packages/review-core/policy.mjs @@ -531,6 +531,11 @@ export function buildReviewBatches(files, { maxChars = 80000, maxBatches = 10 } let section; if (file.patch) { section = formatDiffSection(file); + // A deleted file adds no code. When its deletion alone exceeds the batch budget, + // list it instead of truncating, so a large removal does not make coverage partial. + if (file.status === 'removed' && section.length > maxChars) { + section = `\n### ${filename} (removed, +0/-${deletions})\n[deleted file; removed lines not shown]\n`; + } } else { const header = `\n### ${filename} (${file.status}, +${additions}/-${deletions})\n`; if (file.status === 'removed' || hasExplicitZeroCounts) { diff --git a/tests/review-core.test.mjs b/tests/review-core.test.mjs index d285728..4662af0 100644 --- a/tests/review-core.test.mjs +++ b/tests/review-core.test.mjs @@ -2542,3 +2542,21 @@ test('buildReviewBatches/Diff surface skipped lockfiles and buildReviewMessages assert.doesNotMatch(msgsWithoutSkipped.user, /### Skipped Lockfiles \/ Generated Files/); }); + +test('buildReviewBatches lists an oversized deleted file without marking coverage partial', () => { + const big = '-'.repeat(200) + '\n'; + const files = [ + { filename: 'src/old.mjs', status: 'removed', additions: 0, deletions: 900, patch: big.repeat(900) }, + { filename: 'src/new.mjs', status: 'added', additions: 3, deletions: 0, patch: '+a\n+b\n+c' }, + ]; + const { batches, truncated } = buildReviewBatches(files, { maxChars: 20000 }); + assert.equal(truncated, false); + const text = batches.map(b => b.diffText).join(''); + assert.match(text, /### src\/old\.mjs \(removed, \+0\/-900\)\n\[deleted file; removed lines not shown\]/); + assert.match(text, /\+a\n\+b\n\+c/); +}); + +test('buildReviewBatches still truncates an oversized modified file', () => { + const files = [{ filename: 'src/big.mjs', status: 'modified', additions: 900, deletions: 0, patch: ('+' + 'x'.repeat(200) + '\n').repeat(900) }]; + assert.equal(buildReviewBatches(files, { maxChars: 20000 }).truncated, true); +});