Skip to content

Commit 4c41d09

Browse files
committed
fix(apply): keep fresh-head label restore out of close proposals
The fresh-head allowance now also requires the report not be a close proposal, so a PR the bot proposes to close never regains review labels through that path and falls back to the comment-recency window. Also broadens the fresh-head regression to cover merge-risk label sync, the patched durable comment justifications, and the apply report record. Refs #394
1 parent f28fdac commit 4c41d09

2 files changed

Lines changed: 197 additions & 0 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17567,6 +17567,7 @@ async function applyDecisionsCommand(args: Args): Promise<void> {
1756717567
if (!storedUpdatedAt) return false;
1756817568
if (!updatedSinceReview || reviewCommentOnlyUpdate) return true;
1756917569
const completeFreshHeadReview =
17570+
!isCloseProposal &&
1757017571
item.kind === "pull_request" &&
1757117572
frontMatterValue(markdown, "review_status") === "complete" &&
1757217573
freshPullRequestReviewHead(markdown, currentItemContext());

‎test/apply-label-sync.test.ts‎

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ test("apply-decisions syncs fresh-head PR review labels when bot activity bumps
474474
item_updated_at: "2026-07-03T21:42:48Z",
475475
reviewed_at: "2026-07-03T21:42:48Z",
476476
pull_head_sha: "bc60b889",
477+
merge_risk_labels: JSON.stringify(["merge-risk: 🚨 session-state"]),
477478
})}
478479
479480
## Summary
@@ -614,6 +615,24 @@ if (args[0] === "api" && /\\/issues\\/74482$/.test(path)) {
614615
args.includes("proof: sufficient"),
615616
),
616617
);
618+
assert(
619+
calls.some(
620+
(args) =>
621+
args[0] === "issue" &&
622+
args[1] === "edit" &&
623+
args.includes("--add-label") &&
624+
args.includes("merge-risk: 🚨 session-state"),
625+
),
626+
);
627+
const patchedBody = calls.find((args) => args[0] === "patched-review-body")?.[1] ?? "";
628+
assert.match(patchedBody, /Label justifications:/);
629+
assert.deepEqual(JSON.parse(readFileSync(reportPath, "utf8")), [
630+
{
631+
number: 74482,
632+
action: "review_comment_synced",
633+
reason: "updated durable Codex review comment",
634+
},
635+
]);
617636
} finally {
618637
rmSync(root, { recursive: true, force: true });
619638
}
@@ -782,6 +801,183 @@ if (args[0] === "api" && /\\/issues\\/74483$/.test(path)) {
782801
}
783802
});
784803

804+
test("apply-decisions withholds fresh-head PR label sync from close proposals", () => {
805+
const root = mkdtempSync(tmpPrefix);
806+
try {
807+
const itemsDir = join(root, "items");
808+
const closedDir = join(root, "closed");
809+
const plansDir = join(root, "plans");
810+
const reportPath = join(root, "apply-report.json");
811+
const logPath = join(root, "gh.log");
812+
const itemPath = join(itemsDir, "74484.md");
813+
mkdirSync(itemsDir, { recursive: true });
814+
mkdirSync(plansDir, { recursive: true });
815+
const sourceReport = `${reportFrontMatter({
816+
repository: "openclaw/openclaw",
817+
type: "pull_request",
818+
number: "74484",
819+
title: "Fresh head close proposal",
820+
url: "https://github.com/openclaw/openclaw/pull/74484",
821+
decision: "close",
822+
close_reason: "low_signal_unmergeable_pr",
823+
confidence: "high",
824+
action_taken: "proposed_close",
825+
review_status: "complete",
826+
local_checkout_access: "verified",
827+
author: "contributor",
828+
author_association: "CONTRIBUTOR",
829+
labels: JSON.stringify([]),
830+
item_snapshot_hash: "snapshot-a",
831+
item_updated_at: "2026-07-03T21:42:48Z",
832+
reviewed_at: "2026-07-03T21:42:48Z",
833+
pull_head_sha: "bc60b889",
834+
})}
835+
836+
## Summary
837+
838+
A close proposal must not regain PR labels through the fresh-head allowance.
839+
840+
${realBehaviorProofReportSection()}
841+
842+
${prRatingReportSection({ overallTier: "F", proofTier: "F", patchTier: "F" })}
843+
844+
## Review Findings
845+
846+
Overall correctness: patch is incorrect
847+
848+
Overall confidence: 0.9
849+
850+
Full review comments:
851+
852+
- none
853+
854+
## Evidence
855+
856+
- **branch shape:** PR diff is mostly unrelated provider churn around a tiny possible useful tweak
857+
858+
## Close Comment
859+
860+
Closing this PR because the branch is not a useful landing base.
861+
`;
862+
const synced = reportWithSyncedReviewComment(sourceReport, 74484, "low_signal_unmergeable_pr");
863+
writeFileSync(itemPath, synced.report, "utf8");
864+
865+
const ghMock = `
866+
const { appendFileSync, readFileSync } = require("fs");
867+
const logPath = ${JSON.stringify(logPath)};
868+
const comment = ${JSON.stringify(synced.comment)};
869+
const rawArgs = process.argv.slice(2);
870+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
871+
appendFileSync(logPath, JSON.stringify(args) + "\\n");
872+
const path = args[1] || "";
873+
if (args[0] === "api" && /\\/issues\\/74484$/.test(path)) {
874+
console.log(JSON.stringify({
875+
number: 74484,
876+
title: "Fresh head close proposal",
877+
html_url: "https://github.com/openclaw/openclaw/pull/74484",
878+
created_at: "2026-07-03T19:00:00Z",
879+
updated_at: "2026-07-03T21:43:45Z",
880+
closed_at: null,
881+
state: "open",
882+
locked: false,
883+
active_lock_reason: null,
884+
author_association: "CONTRIBUTOR",
885+
user: { login: "contributor" },
886+
labels: [],
887+
pull_request: {}
888+
}));
889+
} else if (args[0] === "api" && args[1] === "-i" && /\\/issues\\/74484\\/timeline(?:\\?|$)/.test(args[2] || "")) {
890+
console.log("HTTP/2 200\\n\\n[]");
891+
} else if (args[0] === "api" && /\\/issues\\/74484\\/timeline(?:\\?|$)/.test(path)) {
892+
console.log(JSON.stringify([[]]));
893+
} else if (args[0] === "api" && /\\/pulls\\/74484$/.test(path)) {
894+
console.log(JSON.stringify({
895+
number: 74484,
896+
html_url: "https://github.com/openclaw/openclaw/pull/74484",
897+
state: "open",
898+
changed_files: 1,
899+
commits: 2,
900+
review_comments: 0,
901+
requested_reviewers: [],
902+
requested_teams: [],
903+
head: { sha: "bc60b889", ref: "branch", repo: { full_name: "fork/openclaw" } },
904+
base: { sha: "base-sha", ref: "main", repo: { full_name: "openclaw/openclaw" } },
905+
user: { login: "contributor" }
906+
}));
907+
} else if (args[0] === "api" && /\\/pulls\\/74484\\/reviews(?:\\?|$)/.test(path)) {
908+
console.log(JSON.stringify([[]]));
909+
} else if (args[0] === "api" && /\\/pulls\\/74484\\/(files|commits|comments)(?:\\?|$)/.test(path)) {
910+
console.log(JSON.stringify([[]]));
911+
} else if (args[0] === "api" && /\\/issues\\/74484\\/comments(?:\\?|$)/.test(path)) {
912+
console.log(JSON.stringify([[
913+
{
914+
id: 987486,
915+
html_url: "https://github.com/openclaw/openclaw/pull/74484#issuecomment-987486",
916+
body: comment,
917+
user: { login: "clawsweeper[bot]" },
918+
created_at: "2026-07-03T21:33:21Z",
919+
updated_at: "2026-07-03T21:33:21Z"
920+
},
921+
{
922+
id: 987487,
923+
html_url: "https://github.com/openclaw/openclaw/pull/74484#issuecomment-987487",
924+
body: "Pushed a new head, please take another look.",
925+
user: { login: "contributor" },
926+
author_association: "CONTRIBUTOR",
927+
created_at: "2026-07-03T21:42:28Z",
928+
updated_at: "2026-07-03T21:42:28Z"
929+
}
930+
]]));
931+
} else if (args[0] === "api" && /\\/issues\\/comments\\/987486$/.test(path)) {
932+
const input = args[args.indexOf("--input") + 1];
933+
appendFileSync(logPath, JSON.stringify(["patched-review-body", JSON.parse(readFileSync(input, "utf8")).body]) + "\\n");
934+
console.log(JSON.stringify({
935+
id: 987486,
936+
html_url: "https://github.com/openclaw/openclaw/pull/74484#issuecomment-987486",
937+
updated_at: "2026-07-03T21:48:00Z"
938+
}));
939+
} else if (args[0] === "issue" && args[1] === "edit") {
940+
console.log("");
941+
} else if (args[0] === "label" && args[1] === "create") {
942+
console.log(JSON.stringify({ name: args[2] }));
943+
} else {
944+
console.error("unexpected gh args", JSON.stringify(args));
945+
process.exit(1);
946+
}
947+
`;
948+
withMockGh(root, ghMock, () => {
949+
runApplyDecisionsForTest({
950+
targetRepo: "openclaw/openclaw",
951+
itemsDir,
952+
closedDir,
953+
plansDir,
954+
reportPath,
955+
extraArgs: ["--sync-comments-only", "--item-numbers", "74484"],
956+
});
957+
});
958+
959+
const updatedReport = readFileSync(itemPath, "utf8");
960+
assert.doesNotMatch(updatedReport, /^labels_synced_at: /m);
961+
const calls = readFileSync(logPath, "utf8")
962+
.trim()
963+
.split("\n")
964+
.filter(Boolean)
965+
.map((line) => JSON.parse(line) as string[]);
966+
assert.equal(
967+
calls.some(
968+
(args) => args[0] === "issue" && args[1] === "edit" && args.includes("--add-label"),
969+
),
970+
false,
971+
);
972+
assert.equal(
973+
calls.some((args) => args[0] === "label" && args[1] === "create"),
974+
false,
975+
);
976+
} finally {
977+
rmSync(root, { recursive: true, force: true });
978+
}
979+
});
980+
785981
test("apply-decisions routes parsed security owner acceptance to maintainer review", () => {
786982
const root = mkdtempSync(tmpPrefix);
787983
try {

0 commit comments

Comments
 (0)