Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/review-core/policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
18 changes: 18 additions & 0 deletions tests/review-core.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Loading