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); +});