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
4 changes: 3 additions & 1 deletion adapters/cloudflare-workflow/worker.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async function checkReviewQuorum({
}
}

const { batches, allReviewableFiles, truncated } = buildReviewBatches(ctx.files);
const { batches, allReviewableFiles, skippedFiles, truncated } = buildReviewBatches(ctx.files);
if (!batches.length) return { skip: true, reason: 'empty_diff' };
const refPaths = extractReferencedPaths(ctx.files, 3);
const relatedFiles = [];
Expand All @@ -130,6 +130,7 @@ async function checkReviewQuorum({
relatedFiles,
batches,
allReviewableFiles,
skippedFiles,
truncated,
previousReview: incremental?.previousReview || null,
incrementalDiffText: incremental?.incrementalDiffText || '',
Expand Down Expand Up @@ -198,6 +199,7 @@ export class PrReviewWorkflow extends WorkflowEntrypoint {
batchIndex: i,
totalBatches,
allFiles: reviewContext.allReviewableFiles,
skippedFiles: reviewContext.skippedFiles || [],
previousReview: i === 0 ? reviewContext.previousReview : null,
incrementalDiffText: i === 0 ? reviewContext.incrementalDiffText : '',
});
Expand Down
3 changes: 2 additions & 1 deletion adapters/local-cli/review-pr.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ async function main() {
return;
}

const { diffText, truncated, includedFiles } = buildReviewDiff(ctx.files);
const { diffText, truncated, includedFiles, skippedFiles } = buildReviewDiff(ctx.files);
const refPaths = extractReferencedPaths(ctx.files, 3);
const relatedFiles = [];
for (const relPath of refPaths) {
Expand Down Expand Up @@ -246,6 +246,7 @@ async function main() {
agentsMd: ctx.agentsMd,
relatedFiles,
allFiles: includedFiles,
skippedFiles,
previousReview: incremental?.previousReview || null,
incrementalDiffText: incremental?.incrementalDiffText || '',
});
Expand Down
16 changes: 13 additions & 3 deletions packages/review-core/policy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ function formatDiffSection(file) {
export function buildReviewBatches(files, { maxChars = 80000, maxBatches = 10 } = {}) {
const batches = [];
const allReviewableFiles = [];
const skippedFiles = [];
let currentText = '';
let currentFiles = [];
let truncated = false;
Expand All @@ -514,7 +515,15 @@ export function buildReviewBatches(files, { maxChars = 80000, maxBatches = 10 }
const filename = file.filename || '';
// Lockfiles, fixtures, and generated asset bundles are intentionally excluded:
// they must not mark coverage partial or consume the per-batch diff budget.
if (SKIP_DIFF_PATH.test(filename) || GENERATED_ASSET_PATH.test(filename)) continue;
if (SKIP_DIFF_PATH.test(filename) || GENERATED_ASSET_PATH.test(filename)) {
skippedFiles.push({
filename,
status: file.status || 'modified',
additions: file.additions ?? 0,
deletions: file.deletions ?? 0,
});
continue;
}

const hasExplicitZeroCounts = file.additions === 0 && file.deletions === 0;
const additions = file.additions ?? 0;
Expand Down Expand Up @@ -573,16 +582,17 @@ export function buildReviewBatches(files, { maxChars = 80000, maxBatches = 10 }
truncated = true;
}

return { batches, allReviewableFiles, truncated };
return { batches, allReviewableFiles, skippedFiles, truncated };
}

export function buildReviewDiff(files, maxChars = 60000) {
const { batches, truncated } = buildReviewBatches(files, { maxChars, maxBatches: 1 });
const { batches, skippedFiles, truncated } = buildReviewBatches(files, { maxChars, maxBatches: 1 });
const first = batches[0];
return {
diffText: first ? first.diffText : '',
truncated,
includedFiles: first ? first.files : [],
skippedFiles,
};
}

Expand Down
21 changes: 21 additions & 0 deletions packages/review-core/provider.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function buildReviewMessages({
batchIndex = 0,
totalBatches = 1,
allFiles = [],
skippedFiles = [],
previousReview = null,
incrementalDiffText = '',
}) {
Expand Down Expand Up @@ -120,6 +121,16 @@ export function buildReviewMessages({
].join('\n')
: '';

const skippedList = Array.isArray(skippedFiles) ? skippedFiles.filter(f => f && f.filename) : [];

const skippedFilesCalibrationSection = skippedList.length
? [
'## Skipped Lockfiles & Generated Files Calibration',
'1. Lockfiles, fixtures, and generated asset bundles listed under "Skipped Lockfiles / Generated Files" ARE modified in this PR at the reviewed head SHA; their patches are omitted only to preserve diff budget.',
'2. Do NOT claim that a listed lockfile or generated bundle is missing, omitted, or un-updated solely because its patch is not shown, and do not emit "high" or "medium" findings on that basis alone — rely on CI lock/asset checks instead.',
].join('\n')
: '';

const incrementalDiff = String(incrementalDiffText || '');
const incrementalDiffTruncated = incrementalDiff.length > INCREMENTAL_DIFF_MAX_CHARS;
const incrementalDiffSlice = incrementalDiff.slice(0, INCREMENTAL_DIFF_MAX_CHARS);
Expand Down Expand Up @@ -157,11 +168,20 @@ export function buildReviewMessages({
? `### Review Batch ${batchIndex + 1}/${totalBatches}\nAll reviewable files (${allFiles.length}): ${allFiles.slice(0, 80).join(', ')}`
: '';

const skippedFilesHeader = skippedList.length
? `### Skipped Lockfiles / Generated Files (patches intentionally omitted, ${skippedList.length} file${skippedList.length === 1 ? '' : 's'})\n` +
skippedList
.slice(0, 40)
.map(f => `- ${f.filename} (${f.status || 'modified'}, +${f.additions ?? 0}/-${f.deletions ?? 0})`)
.join('\n')
: '';

const untrustedPrContent = [
`## BEGIN ${untrustedBoundary}`,
`## PR #${pr.number}: ${pr.title}`,
pr.body ? `### Description\n${pr.body.slice(0, 2000)}\n` : '',
batchHeader,
skippedFilesHeader,
relatedSection,
previousReviewContent,
`## Diff${truncated ? ' (truncated)' : ''}${diffText}`,
Expand All @@ -181,6 +201,7 @@ export function buildReviewMessages({
architectureChecklistSection,
docsCalibrationSection,
multiBatchCalibrationSection,
skippedFilesCalibrationSection,
reReviewCalibrationSection,
untrustedPrContent,
].filter(Boolean).join('\n');
Expand Down
41 changes: 41 additions & 0 deletions tests/review-core.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2501,3 +2501,44 @@ test('executeReviewWithFallback runs dual-model OpenCode cross-review on high-ri
}, mockFetch), /must differ from OPENCODE_MODEL/);
});

test('buildReviewBatches/Diff surface skipped lockfiles and buildReviewMessages isolates calibration vs untrusted summary', () => {
const files = [
{ filename: 'pyproject.toml', status: 'modified', additions: 2, deletions: 0, patch: '+import-linter==2.17' },
{ filename: 'uv.lock', status: 'modified', additions: 149, deletions: 0, patch: '+' + 'z'.repeat(10000) },
];
const batched = buildReviewBatches(files);
assert.equal(batched.truncated, false);
assert.deepEqual(batched.allReviewableFiles, ['pyproject.toml']);
assert.deepEqual(batched.skippedFiles, [
{ filename: 'uv.lock', status: 'modified', additions: 149, deletions: 0 },
]);

const diffed = buildReviewDiff(files);
assert.deepEqual(diffed.skippedFiles, batched.skippedFiles);

const msgsWithSkipped = buildReviewMessages({
pr: { number: 578, title: 'chore(ci): lock import-linter', body: '' },
diffText: batched.batches[0].diffText,
truncated: batched.truncated,
agentsMd: '',
allFiles: batched.allReviewableFiles,
skippedFiles: batched.skippedFiles,
});
const boundaryIdx = msgsWithSkipped.user.indexOf('## BEGIN UNTRUSTED_PR_CONTENT_');
const calibrationIdx = msgsWithSkipped.user.indexOf('## Skipped Lockfiles & Generated Files Calibration');
const summaryIdx = msgsWithSkipped.user.indexOf('### Skipped Lockfiles / Generated Files');
assert.ok(calibrationIdx >= 0 && calibrationIdx < boundaryIdx);
assert.ok(summaryIdx > boundaryIdx);
assert.match(msgsWithSkipped.user, /- uv\.lock \(modified, \+149\/-0\)/);

const msgsWithoutSkipped = buildReviewMessages({
pr: { number: 579, title: 'fix: minor', body: '' },
diffText: batched.batches[0].diffText,
truncated: false,
agentsMd: '',
allFiles: batched.allReviewableFiles,
});
assert.doesNotMatch(msgsWithoutSkipped.user, /Skipped Lockfiles & Generated Files Calibration/);
assert.doesNotMatch(msgsWithoutSkipped.user, /### Skipped Lockfiles \/ Generated Files/);
});

Loading