diff --git a/adapters/cloudflare-workflow/worker.mjs b/adapters/cloudflare-workflow/worker.mjs index 06121d7..dfabb72 100644 --- a/adapters/cloudflare-workflow/worker.mjs +++ b/adapters/cloudflare-workflow/worker.mjs @@ -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 = []; @@ -130,6 +130,7 @@ async function checkReviewQuorum({ relatedFiles, batches, allReviewableFiles, + skippedFiles, truncated, previousReview: incremental?.previousReview || null, incrementalDiffText: incremental?.incrementalDiffText || '', @@ -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 : '', }); diff --git a/adapters/local-cli/review-pr.mjs b/adapters/local-cli/review-pr.mjs index 1938574..963991e 100644 --- a/adapters/local-cli/review-pr.mjs +++ b/adapters/local-cli/review-pr.mjs @@ -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) { @@ -246,6 +246,7 @@ async function main() { agentsMd: ctx.agentsMd, relatedFiles, allFiles: includedFiles, + skippedFiles, previousReview: incremental?.previousReview || null, incrementalDiffText: incremental?.incrementalDiffText || '', }); diff --git a/packages/review-core/policy.mjs b/packages/review-core/policy.mjs index f027fda..341c391 100644 --- a/packages/review-core/policy.mjs +++ b/packages/review-core/policy.mjs @@ -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; @@ -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; @@ -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, }; } diff --git a/packages/review-core/provider.mjs b/packages/review-core/provider.mjs index fd966f4..f07e377 100644 --- a/packages/review-core/provider.mjs +++ b/packages/review-core/provider.mjs @@ -67,6 +67,7 @@ export function buildReviewMessages({ batchIndex = 0, totalBatches = 1, allFiles = [], + skippedFiles = [], previousReview = null, incrementalDiffText = '', }) { @@ -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); @@ -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}`, @@ -181,6 +201,7 @@ export function buildReviewMessages({ architectureChecklistSection, docsCalibrationSection, multiBatchCalibrationSection, + skippedFilesCalibrationSection, reReviewCalibrationSection, untrustedPrContent, ].filter(Boolean).join('\n'); diff --git a/tests/review-core.test.mjs b/tests/review-core.test.mjs index 448631a..d285728 100644 --- a/tests/review-core.test.mjs +++ b/tests/review-core.test.mjs @@ -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/); +}); +