Skip to content

Commit 98280ac

Browse files
committed
fix(review): retain completed local history on failure
1 parent 4cd2e4a commit 98280ac

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

‎src/clawsweeper-review-command-workflow.ts‎

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,20 +1468,22 @@ export function createReviewCommandWorkflow(dependencies: CreateReviewCommandWor
14681468
reviewLeaseCommentId: acquiredReviewLease.commentId,
14691469
}
14701470
: {}),
1471-
});
1471+
});
14721472
writeFileSync(reportPath, reportMarkdown, "utf8");
14731473
if (itemLocalReviewHistoryPath) {
1474-
writeFileSync(
1475-
itemLocalReviewHistoryPath,
1476-
renderReviewCommentFromReport(
1477-
reportMarkdown,
1478-
"none",
1479-
previousLocalReviewCommentBody
1480-
? { previousReviewCommentBody: previousLocalReviewCommentBody }
1481-
: undefined,
1482-
),
1483-
"utf8",
1484-
);
1474+
const nextLocalReviewCommentBody =
1475+
frontMatterValue(reportMarkdown, "review_status") === "complete"
1476+
? renderReviewCommentFromReport(
1477+
reportMarkdown,
1478+
"none",
1479+
previousLocalReviewCommentBody
1480+
? { previousReviewCommentBody: previousLocalReviewCommentBody }
1481+
: undefined,
1482+
)
1483+
: previousLocalReviewCommentBody;
1484+
if (nextLocalReviewCommentBody) {
1485+
writeFileSync(itemLocalReviewHistoryPath, nextLocalReviewCommentBody, "utf8");
1486+
}
14851487
}
14861488
recordReviewLogPublication({
14871489
ledger: reviewLedger,

‎test/local-range-review.test.ts‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -502,8 +502,13 @@ const captures = fs.existsSync(process.env.LOCAL_REVIEW_CAPTURE)
502502
captures.push({
503503
hasPreviousReview: prompt.includes('"previousClawSweeperReview"'),
504504
hasPriorFinding: prompt.includes(${JSON.stringify(priorFindingTitle)}),
505+
previousReviewedSha: prompt.match(/"reviewedSha":\\s*"([0-9a-f]{40})"/)?.[1] ?? null,
505506
});
506507
fs.writeFileSync(process.env.LOCAL_REVIEW_CAPTURE, JSON.stringify(captures));
508+
if (process.env.LOCAL_REVIEW_FAIL === "1") {
509+
process.stderr.write("deterministic local review failure\\n");
510+
process.exit(1);
511+
}
507512
fs.writeFileSync(outputPath, fs.readFileSync(process.env.LOCAL_REVIEW_DECISION));
508513
process.stdout.write(JSON.stringify({ type: "turn.completed", usage: { input_tokens: 1 } }) + "\\n");
509514
`,
@@ -516,7 +521,7 @@ process.stdout.write(JSON.stringify({ type: "turn.completed", usage: { input_tok
516521
});
517522
}
518523

519-
function runReview(artifactDir: string, base = "base-ref"): void {
524+
function runReview(artifactDir: string, base = "base-ref", shouldFail = false): void {
520525
const result = spawnSync(
521526
process.execPath,
522527
[
@@ -542,11 +547,16 @@ process.stdout.write(JSON.stringify({ type: "turn.completed", usage: { input_tok
542547
CODEX_BIN: fakeCodex,
543548
LOCAL_REVIEW_CAPTURE: capturePath,
544549
LOCAL_REVIEW_DECISION: decisionPath,
550+
LOCAL_REVIEW_FAIL: shouldFail ? "1" : "0",
545551
},
546552
timeout: 60000,
547553
},
548554
);
549-
assert.equal(result.status, 0, `${result.stderr ?? ""}${result.stdout ?? ""}`);
555+
if (shouldFail) {
556+
assert.notEqual(result.status, 0, "deterministic Codex failure must fail the review run");
557+
} else {
558+
assert.equal(result.status, 0, `${result.stderr ?? ""}${result.stdout ?? ""}`);
559+
}
550560
}
551561

552562
try {
@@ -564,7 +574,9 @@ process.stdout.write(JSON.stringify({ type: "turn.completed", usage: { input_tok
564574
writeFileSync(join(dir, "feature.txt"), "first\nsecond\n");
565575
git(dir, "add", "feature.txt");
566576
git(dir, "commit", "-q", "-m", "fix: follow up on local review");
567-
runReview(join(harness, "run-2"));
577+
const failedHead = git(dir, "rev-parse", "HEAD");
578+
runReview(join(harness, "run-2-failed"), "base-ref", true);
579+
runReview(join(harness, "run-3"));
568580

569581
const historyPath = resolve(
570582
dir,
@@ -576,24 +588,27 @@ process.stdout.write(JSON.stringify({ type: "turn.completed", usage: { input_tok
576588
assert.match(relatedHistory, new RegExp(firstHead));
577589

578590
git(dir, "branch", "alternate-base", firstHead);
579-
runReview(join(harness, "run-3"), "alternate-base");
591+
runReview(join(harness, "run-4"), "alternate-base");
580592

581593
git(dir, "checkout", "-q", "-b", "unrelated", "base-ref");
582594
writeFileSync(join(dir, "unrelated.txt"), "different branch\n");
583595
git(dir, "add", "unrelated.txt");
584596
git(dir, "commit", "-q", "-m", "feat: unrelated local range");
585-
runReview(join(harness, "run-4"));
597+
runReview(join(harness, "run-5"));
586598

587599
const captures = JSON.parse(readFileSync(capturePath, "utf8")) as Array<{
588600
hasPreviousReview: boolean;
589601
hasPriorFinding: boolean;
602+
previousReviewedSha: string | null;
590603
}>;
591604
assert.deepEqual(captures, [
592-
{ hasPreviousReview: false, hasPriorFinding: false },
593-
{ hasPreviousReview: true, hasPriorFinding: true },
594-
{ hasPreviousReview: false, hasPriorFinding: false },
595-
{ hasPreviousReview: false, hasPriorFinding: false },
605+
{ hasPreviousReview: false, hasPriorFinding: false, previousReviewedSha: null },
606+
{ hasPreviousReview: true, hasPriorFinding: true, previousReviewedSha: firstHead },
607+
{ hasPreviousReview: true, hasPriorFinding: true, previousReviewedSha: firstHead },
608+
{ hasPreviousReview: false, hasPriorFinding: false, previousReviewedSha: null },
609+
{ hasPreviousReview: false, hasPriorFinding: false, previousReviewedSha: null },
596610
]);
611+
assert.doesNotMatch(JSON.stringify(captures[2]), new RegExp(failedHead));
597612
assert.doesNotMatch(readFileSync(historyPath, "utf8"), /Review history \(/);
598613
assert.equal(git(dir, "status", "--porcelain"), "");
599614
} finally {

0 commit comments

Comments
 (0)