Skip to content

Commit a297b52

Browse files
committed
fix(apply): distinguish item and repository misses
1 parent 4c9f268 commit a297b52

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17559,6 +17559,21 @@ async function applyDecisionsCommand(args: Args): Promise<void> {
1755917559
liveItem = fetchItem(number);
1756017560
} catch (error) {
1756117561
if (!isGitHubNotFoundError(error)) throw error;
17562+
// A repository lookup can return the same 404 when the repo is missing or
17563+
// inaccessible. Confirm repo access before treating this as an item miss.
17564+
ghJson<unknown>(["api", `repos/${targetRepo()}`]);
17565+
if (syncCommentsOnly) {
17566+
markApplyChecked();
17567+
results.push({
17568+
number,
17569+
action: "skipped_already_closed",
17570+
reason: "item not found on GitHub",
17571+
});
17572+
processedCount += 1;
17573+
maybeLogProgress(`skipped comment sync #${number}: item not found on GitHub`);
17574+
if (processedCount >= processedLimit) break;
17575+
continue;
17576+
}
1756217577
// Items can be deleted after review but before apply. Treat that terminal
1756317578
// state like an already-closed item instead of failing the whole apply run.
1756417579
markdown = replaceFrontMatterValue(markdown, "action_taken", "skipped_already_closed");

‎test/apply-live-state.test.ts‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
3434
console.error("gh: Not Found (HTTP 404)");
3535
process.exit(1);
3636
}
37+
if (args[0] === "api" && path === "repos/openclaw/clawsweeper") {
38+
console.log(JSON.stringify({ full_name: "openclaw/clawsweeper" }));
39+
process.exit(0);
40+
}
3741
console.error("unexpected gh args", JSON.stringify(args));
3842
process.exit(1);
3943
`;
@@ -55,3 +59,91 @@ process.exit(1);
5559
rmSync(root, { recursive: true, force: true });
5660
}
5761
});
62+
63+
test("apply-decisions keeps missing records queued during comment-only sync", () => {
64+
const root = mkdtempSync(tmpPrefix);
65+
try {
66+
const itemsDir = join(root, "items");
67+
const closedDir = join(root, "closed");
68+
const plansDir = join(root, "plans");
69+
const reportPath = join(root, "apply-report.json");
70+
mkdirSync(itemsDir, { recursive: true });
71+
mkdirSync(plansDir, { recursive: true });
72+
writeFileSync(join(itemsDir, "321.md"), implementedCloseReport(), "utf8");
73+
74+
const ghMock = `
75+
const rawArgs = process.argv.slice(2);
76+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
77+
const path = args[1] || "";
78+
if (args[0] === "api" && /\\/issues\\/321$/.test(path)) {
79+
console.error("gh: Not Found (HTTP 404)");
80+
process.exit(1);
81+
}
82+
if (args[0] === "api" && path === "repos/openclaw/clawsweeper") {
83+
console.log(JSON.stringify({ full_name: "openclaw/clawsweeper" }));
84+
process.exit(0);
85+
}
86+
console.error("unexpected gh args", JSON.stringify(args));
87+
process.exit(1);
88+
`;
89+
withMockGh(root, ghMock, () => {
90+
runApplyDecisionsForTest({
91+
itemsDir,
92+
closedDir,
93+
plansDir,
94+
reportPath,
95+
extraArgs: ["--sync-comments-only"],
96+
});
97+
});
98+
99+
assert.ok(existsSync(join(itemsDir, "321.md")));
100+
assert.equal(existsSync(join(closedDir, "321.md")), false);
101+
assert.match(readText(join(itemsDir, "321.md")), /^action_taken: proposed_close$/m);
102+
assert.deepEqual(JSON.parse(readText(reportPath)), [
103+
{
104+
number: 321,
105+
action: "skipped_already_closed",
106+
reason: "item not found on GitHub",
107+
},
108+
]);
109+
} finally {
110+
rmSync(root, { recursive: true, force: true });
111+
}
112+
});
113+
114+
test("apply-decisions fails safely when a missing repository also returns 404", () => {
115+
const root = mkdtempSync(tmpPrefix);
116+
try {
117+
const itemsDir = join(root, "items");
118+
const closedDir = join(root, "closed");
119+
const plansDir = join(root, "plans");
120+
const reportPath = join(root, "apply-report.json");
121+
mkdirSync(itemsDir, { recursive: true });
122+
mkdirSync(plansDir, { recursive: true });
123+
writeFileSync(join(itemsDir, "321.md"), implementedCloseReport(), "utf8");
124+
125+
const ghMock = `
126+
const rawArgs = process.argv.slice(2);
127+
const args = rawArgs[0] === "--repo" ? rawArgs.slice(2) : rawArgs;
128+
const path = args[1] || "";
129+
if (args[0] === "api" && (/\\/issues\\/321$/.test(path) || path === "repos/openclaw/clawsweeper")) {
130+
console.error("gh: Not Found (HTTP 404)");
131+
process.exit(1);
132+
}
133+
console.error("unexpected gh args", JSON.stringify(args));
134+
process.exit(1);
135+
`;
136+
assert.throws(
137+
() =>
138+
withMockGh(root, ghMock, () => {
139+
runApplyDecisionsForTest({ itemsDir, closedDir, plansDir, reportPath });
140+
}),
141+
/Not Found/,
142+
);
143+
144+
assert.ok(existsSync(join(itemsDir, "321.md")));
145+
assert.equal(existsSync(join(closedDir, "321.md")), false);
146+
} finally {
147+
rmSync(root, { recursive: true, force: true });
148+
}
149+
});

0 commit comments

Comments
 (0)