@@ -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+
1437314504test("apply-decisions dry-run computes advisory labels without mutating GitHub labels", () => {
1437414505 const root = mkdtempSync(tmpPrefix);
1437514506 try {
0 commit comments