diff --git a/docs/REVIEW.md b/docs/REVIEW.md index b913a20..e6c5164 100644 --- a/docs/REVIEW.md +++ b/docs/REVIEW.md @@ -142,7 +142,8 @@ This API option is not inferred from config, environment, issue text, coder output or model response. There is no new CLI flag or implicit image acquisition. The existing `{ receipt }` reviewer option remains supported. `runOnlyReview` also forwards the host backend executor used by offline tests. -For a retry of a run with independent-verification metadata, the caller must +For a retry with independent-verification metadata in the run or its existing +managed review artifact, the caller must explicitly supply fresh approval again; otherwise it refuses before archiving the existing review or invoking a model. Prior review metadata is not an executable plan, and an ordinary `/review --again` cannot silently drop that diff --git a/src/lib/review.mjs b/src/lib/review.mjs index 55d459c..6e7850e 100644 --- a/src/lib/review.mjs +++ b/src/lib/review.mjs @@ -20,13 +20,14 @@ export async function runOnlyReview(run, { if (!run?.worktreePath || !run.result?.resultPath) throw new Error('A completed coder result is required; run or resume a task before /review.'); if (run.planningOnly) throw new Error('Planning-only output is not a completed coder result to review.'); throwIfCancelled(signal); - if (run.review?.independentVerification && !independentVerification) { - throw new Error('Independent verification must be explicitly approved again for a review-only retry; prior review metadata is not execution authority.'); - } const worktree = run.worktreePath; const task = await readPlannerTask(worktree); if (task === null) throw new Error('Review requires TASK.md in the current worktree.'); const previous = await readPreviousReview(worktree); + if (!independentVerification && (run.review?.independentVerification || + /^## Independent verification[ \t]*\r?$/m.test(previous ?? ''))) { + throw new Error('Independent verification must be explicitly approved again for a review-only retry; prior review metadata is not execution authority.'); + } if (previous !== null) { if (!again) throw new Error('REVIEW.md already exists; use /review --again to rerun the current diff.'); const tracked = (await execute('git', ['ls-files', '--', 'REVIEW.md'], { diff --git a/tests/review-command.test.mjs b/tests/review-command.test.mjs index 5361593..c1d4734 100644 --- a/tests/review-command.test.mjs +++ b/tests/review-command.test.mjs @@ -124,6 +124,14 @@ test('review-only retries execute fresh approved observations and retain depende runVerificationCommand: async () => assert.fail('Missing host authority must not execute'), }), /explicitly approved again/); assert.equal(readFileSync(path.join(run.worktreePath, 'REVIEW.md'), 'utf8'), originalReview); + const retainedReview = originalReview.replaceAll('\n', '\r\n'); + writeFileSync(path.join(run.worktreePath, 'REVIEW.md'), retainedReview); + await assert.rejects(runOnlyReview({ ...rejected, review: undefined }, { + ...options, independentVerification: undefined, again: true, + fetchImpl: async () => assert.fail('Stored independent authority must survive missing run metadata'), + runVerificationCommand: async () => assert.fail('Stored metadata is not execution approval'), + }), /explicitly approved again/); + assert.equal(readFileSync(path.join(run.worktreePath, 'REVIEW.md'), 'utf8'), retainedReview); writeFileSync(path.join(run.worktreePath, 'README.md'), '# Approved\n'); const accepted = await runOnlyReview({ ...rejected, result: run.result }, { ...options, again: true }); assert.equal(accepted.review.verdict, 'pass', accepted.review.content);