Skip to content

Commit 0bf7a45

Browse files
committed
fix: allow label sync after review placeholder
1 parent a6ee02e commit 0bf7a45

2 files changed

Lines changed: 145 additions & 4 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16844,9 +16844,19 @@ async function applyDecisionsCommand(args: Args): Promise<void> {
1684416844
}
1684516845
const updatedSinceReview = Boolean(storedUpdatedAt && item.updatedAt !== storedUpdatedAt);
1684616846
const reviewCommentOnlyUpdate = item.updatedAt === commentUpdatedAt(existingReviewComment);
16847-
const unchangedSinceReview = storedUpdatedAt
16848-
? !updatedSinceReview || reviewCommentOnlyUpdate
16849-
: false;
16847+
const labelSyncFreshEnough = (): boolean => {
16848+
if (!storedUpdatedAt) return false;
16849+
if (!updatedSinceReview || reviewCommentOnlyUpdate) return true;
16850+
const existingReviewCommentUpdatedAtMs = timestampMs(commentUpdatedAt(existingReviewComment));
16851+
const itemUpdatedAtMs = timestampMs(item.updatedAt);
16852+
if (existingReviewCommentUpdatedAtMs === null || itemUpdatedAtMs === null) return false;
16853+
if (Math.abs(itemUpdatedAtMs - existingReviewCommentUpdatedAtMs) > 5 * 60 * 1000) {
16854+
return false;
16855+
}
16856+
const storedUpdatedAtMs = timestampMs(storedUpdatedAt);
16857+
if (storedUpdatedAtMs === null) return false;
16858+
return !contextHasNonAutomationActivityAfter(currentItemContext(), storedUpdatedAtMs);
16859+
};
1685016860
const markChangedSinceReview = (options: {
1685116861
reason: string;
1685216862
currentUpdatedAt?: string | undefined;
@@ -17043,7 +17053,7 @@ async function applyDecisionsCommand(args: Args): Promise<void> {
1704317053
}
1704417054
}
1704517055
const isCurrentCompleteReport =
17046-
frontMatterValue(markdown, "review_status") === "complete" && unchangedSinceReview;
17056+
frontMatterValue(markdown, "review_status") === "complete" && labelSyncFreshEnough();
1704717057
if (state === "open" && isCurrentCompleteReport) {
1704817058
try {
1704917059
const syncResult = syncPriorityLabel({

‎test/clawsweeper.test.ts‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14370,6 +14370,137 @@ if (args[0] === "api" && /\\/issues\\/comments\\/\\d+$/.test(path)) {
1437014370
}
1437114371
});
1437214372

14373+
test("apply-decisions syncs labels when first review placeholder advanced issue updated_at", () => {
14374+
const root = mkdtempSync(tmpPrefix);
14375+
try {
14376+
const itemsDir = join(root, "items");
14377+
const closedDir = join(root, "closed");
14378+
const plansDir = join(root, "plans");
14379+
const reportPath = join(root, "apply-report.json");
14380+
const logPath = join(root, "gh.log");
14381+
mkdirSync(itemsDir, { recursive: true });
14382+
mkdirSync(plansDir, { recursive: true });
14383+
14384+
const report = workPlanCandidateReport({
14385+
number: 321,
14386+
reviewed_at: "2026-05-01T00:05:00Z",
14387+
item_snapshot_hash: "reviewed-snapshot-321",
14388+
item_updated_at: "2026-05-01T00:00:00Z",
14389+
triage_priority: "P1",
14390+
impact_labels: JSON.stringify(["impact:message-loss"]),
14391+
reproduction_status: "source_reproducible",
14392+
reproduction_confidence: "high",
14393+
});
14394+
writeFileSync(join(itemsDir, "321.md"), report, "utf8");
14395+
const placeholder = renderReviewStartStatusComment({
14396+
number: 321,
14397+
kind: "issue",
14398+
title: "Render work plans",
14399+
});
14400+
14401+
const ghMock = `
14402+
const { appendFileSync, readFileSync } = require("fs");
14403+
const logPath = ${JSON.stringify(logPath)};
14404+
const placeholder = ${JSON.stringify(placeholder)};
14405+
const rawArgs = process.argv.slice(2);
14406+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
14407+
appendFileSync(logPath, JSON.stringify(args) + "\\n");
14408+
const path = args.includes("-i") ? args[args.indexOf("-i") + 1] : args[1] || "";
14409+
const commentMatch = path.match(/\\/issues\\/(\\d+)\\/comments(?:\\?|$)/);
14410+
const issueMatch = path.match(/\\/issues\\/(\\d+)$/);
14411+
if (args[0] === "api" && /\\/issues\\/comments\\/\\d+$/.test(path)) {
14412+
const inputPath = args[args.indexOf("--input") + 1];
14413+
const body = JSON.parse(readFileSync(inputPath, "utf8")).body;
14414+
appendFileSync(logPath, JSON.stringify(["comment-patch", body]) + "\\n");
14415+
console.log(JSON.stringify({
14416+
id: 9321,
14417+
html_url: "https://github.com/openclaw/clawsweeper/issues/321#issuecomment-9321",
14418+
created_at: "2026-05-01T00:01:00Z",
14419+
updated_at: "2026-05-01T00:06:00Z",
14420+
user: { login: "clawsweeper[bot]" },
14421+
body
14422+
}));
14423+
} else if (args[0] === "api" && commentMatch) {
14424+
console.log(JSON.stringify([[{
14425+
id: 9321,
14426+
html_url: "https://github.com/openclaw/clawsweeper/issues/321#issuecomment-9321",
14427+
created_at: "2026-05-01T00:01:00Z",
14428+
updated_at: "2026-05-01T00:01:00Z",
14429+
user: { login: "clawsweeper[bot]" },
14430+
body: placeholder
14431+
}]]));
14432+
} else if (args[0] === "api" && /\\/issues\\/321\\/timeline/.test(path)) {
14433+
console.log(JSON.stringify([{
14434+
id: 1,
14435+
event: "commented",
14436+
created_at: "2026-05-01T00:01:00Z",
14437+
actor: { login: "clawsweeper[bot]" }
14438+
}]));
14439+
} else if (args[0] === "api" && issueMatch) {
14440+
console.log(JSON.stringify({
14441+
number: 321,
14442+
title: "Render work plans",
14443+
html_url: "https://github.com/openclaw/clawsweeper/issues/321",
14444+
created_at: "2026-05-01T00:00:00Z",
14445+
updated_at: "2026-05-01T00:01:01Z",
14446+
closed_at: null,
14447+
state: "open",
14448+
locked: false,
14449+
active_lock_reason: null,
14450+
author_association: "CONTRIBUTOR",
14451+
user: { login: "reporter" },
14452+
labels: [],
14453+
comments: 1,
14454+
pull_request: null
14455+
}));
14456+
} else if (args[0] === "issue" && args[1] === "view") {
14457+
console.log(JSON.stringify({ closedByPullRequestsReferences: [] }));
14458+
} else if (args[0] === "label" && args[1] === "create") {
14459+
console.log("");
14460+
} else if (args[0] === "issue" && args[1] === "edit") {
14461+
console.log("");
14462+
} else {
14463+
console.error("unexpected gh args", JSON.stringify(args));
14464+
process.exit(1);
14465+
}
14466+
`;
14467+
withMockGh(root, ghMock, () => {
14468+
runApplyDecisionsForTest({ itemsDir, closedDir, plansDir, reportPath });
14469+
});
14470+
14471+
const calls = readFileSync(logPath, "utf8")
14472+
.trim()
14473+
.split("\n")
14474+
.filter(Boolean)
14475+
.map((line) => JSON.parse(line) as string[]);
14476+
const editCalls = calls.filter((args) => args[0] === "issue" && args[1] === "edit");
14477+
assert.ok(editCalls.some((args) => args.includes("--add-label") && args.includes("P1")));
14478+
assert.ok(
14479+
editCalls.some(
14480+
(args) => args.includes("--add-label") && args.includes("impact:message-loss"),
14481+
),
14482+
);
14483+
assert.ok(
14484+
editCalls.some(
14485+
(args) => args.includes("--add-label") && args.includes("clawsweeper:source-repro"),
14486+
),
14487+
);
14488+
assert.deepEqual(JSON.parse(readFileSync(reportPath, "utf8")), [
14489+
{
14490+
number: 321,
14491+
action: "review_comment_synced",
14492+
reason: "updated durable Codex review comment",
14493+
},
14494+
]);
14495+
const updatedReport = readFileSync(join(itemsDir, "321.md"), "utf8");
14496+
assert.match(updatedReport, /^labels: .*"P1"/m);
14497+
assert.match(updatedReport, /^labels: .*"impact:message-loss"/m);
14498+
assert.match(updatedReport, /^labels_synced_at: /m);
14499+
} finally {
14500+
rmSync(root, { recursive: true, force: true });
14501+
}
14502+
});
14503+
1437314504
test("apply-decisions dry-run computes advisory labels without mutating GitHub labels", () => {
1437414505
const root = mkdtempSync(tmpPrefix);
1437514506
try {

0 commit comments

Comments
 (0)