Skip to content

Commit 433e985

Browse files
Fix: Guard superseded PR closes against unsafe replacements
1 parent 4e2b0aa commit 433e985

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

‎test/clawsweeper.test.ts‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7998,6 +7998,84 @@ test("apply-decisions promotes PRs superseded by linked pull requests", () => {
79987998
}
79997999
});
80008000

8001+
test("apply-decisions promotes PRs superseded by merged linked pull requests without proof labels", () => {
8002+
const root = mkdtempSync(tmpPrefix);
8003+
try {
8004+
const itemsDir = join(root, "items");
8005+
const closedDir = join(root, "closed");
8006+
const plansDir = join(root, "plans");
8007+
const reportPath = join(root, "apply-report.json");
8008+
mkdirSync(itemsDir, { recursive: true });
8009+
mkdirSync(plansDir, { recursive: true });
8010+
const synced = reportWithSyncedReviewComment(
8011+
stalePullRequestReport({
8012+
number: 333,
8013+
title: "Old merged-replacement PR",
8014+
pr_rating_overall: "D",
8015+
pr_rating_proof: "D",
8016+
work_cluster_refs: JSON.stringify([
8017+
"Superseded by https://github.com/openclaw/openclaw/pull/400",
8018+
]),
8019+
}),
8020+
333,
8021+
"none",
8022+
);
8023+
writeFileSync(join(itemsDir, "333.md"), synced.report, "utf8");
8024+
8025+
withMockGh(
8026+
root,
8027+
promotionGhMock({
8028+
number: 333,
8029+
title: "Old merged-replacement PR",
8030+
comment: synced.comment,
8031+
linkedPulls: {
8032+
400: {
8033+
number: 400,
8034+
title: "Merged canonical PR",
8035+
html_url: "https://github.com/openclaw/openclaw/pull/400",
8036+
state: "closed",
8037+
merged_at: "2026-05-02T00:00:00Z",
8038+
mergeable_state: "dirty",
8039+
labels: ["status: needs proof", "rating: unranked krab"],
8040+
},
8041+
},
8042+
}),
8043+
() => {
8044+
runApplyDecisionsForTest({
8045+
itemsDir,
8046+
closedDir,
8047+
plansDir,
8048+
reportPath,
8049+
extraArgs: [
8050+
"--target-repo",
8051+
"openclaw/openclaw",
8052+
"--dry-run",
8053+
"--apply-kind",
8054+
"all",
8055+
"--processed-limit",
8056+
"3",
8057+
],
8058+
});
8059+
},
8060+
);
8061+
8062+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{
8063+
action: string;
8064+
reason: string;
8065+
}>;
8066+
assert.equal(
8067+
report.some((entry) => entry.action === "closed"),
8068+
true,
8069+
);
8070+
assert.match(
8071+
report.find((entry) => entry.action === "closed")?.reason ?? "",
8072+
/duplicate or superseded/,
8073+
);
8074+
} finally {
8075+
rmSync(root, { recursive: true, force: true });
8076+
}
8077+
});
8078+
80018079
test("apply-decisions does not promote PRs superseded by no-proof linked pull requests", () => {
80028080
const root = mkdtempSync(tmpPrefix);
80038081
try {

0 commit comments

Comments
 (0)