Skip to content

Commit ff05bfd

Browse files
author
Peter Steinberger
committed
fix: finalize synthetic autofix receipts and avoid fragile partial checkouts
1 parent e6c782f commit ff05bfd

5 files changed

Lines changed: 98 additions & 44 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,6 @@ jobs:
2727
timeout-minutes: 15
2828
steps:
2929
- uses: actions/checkout@v7
30-
with:
31-
sparse-checkout: |
32-
.github
33-
config
34-
dashboard
35-
docs
36-
instructions
37-
prompts
38-
schema
39-
scripts
40-
src
41-
test
42-
.oxfmtrc.json
43-
AGENTS.md
44-
README.md
45-
package.json
46-
pnpm-lock.yaml
47-
pnpm-workspace.yaml
48-
tsconfig.dashboard.json
49-
tsconfig.json
50-
tsconfig.repair.json
51-
sparse-checkout-cone-mode: false
5230

5331
- name: Validate workflow semantics
5432
env:

‎.github/workflows/codeql.yml‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,18 +37,6 @@ jobs:
3737
- javascript-typescript
3838
steps:
3939
- uses: actions/checkout@v7
40-
with:
41-
sparse-checkout: |
42-
.github
43-
dashboard
44-
scripts
45-
src
46-
package.json
47-
pnpm-lock.yaml
48-
tsconfig.dashboard.json
49-
tsconfig.json
50-
tsconfig.repair.json
51-
sparse-checkout-cone-mode: false
5240

5341
- uses: github/codeql-action/init@v4
5442
with:

‎src/repair/update-command-status.ts‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ export function verifiedTerminalStatusReceipt(
508508
: commandCommentIds.length === 0 &&
509509
!hasCommandAckMarker(comment.body) &&
510510
(options.statusCommentId === null || completionCommentId === options.statusCommentId)
511-
? legacyCommandCommentId(comment.body, options.marker)
511+
? legacyCommandCommentId(comment.body, options.marker, completionCommentId)
512512
: null;
513513
return commandCommentId === null ? null : { commandCommentId, completionCommentId };
514514
}
@@ -555,8 +555,12 @@ function hasCommandAckMarker(body: JsonValue) {
555555
return /<!--\s*clawsweeper-command-ack:[^>]*-->/.test(String(body ?? ""));
556556
}
557557

558-
function legacyCommandCommentId(body: JsonValue, statusMarker: string) {
559-
const status = /^<!--\s*clawsweeper-command-status:\d+:([^:\s>]+):([^:\s>]+)\s*-->$/.exec(
558+
function legacyCommandCommentId(
559+
body: JsonValue,
560+
statusMarker: string,
561+
completionCommentId: number,
562+
) {
563+
const status = /^<!--\s*clawsweeper-command-status:(\d+):([^:\s>]+):([^:\s>]+)\s*-->$/.exec(
560564
statusMarker,
561565
);
562566
if (!status) return null;
@@ -565,11 +569,30 @@ function legacyCommandCommentId(body: JsonValue, statusMarker: string) {
565569
/<!--\s*clawsweeper-command:(\d+):(?:[^>]*:)?([^:\s>]+):([^:\s>]+)\s*-->/g,
566570
),
567571
);
568-
if (commands.length !== 1 || commands[0]![2] !== status[1] || commands[0]![3] !== status[2]) {
572+
if (commands.length === 1 && commands[0]![2] === status[2] && commands[0]![3] === status[3]) {
573+
const commandCommentId = Number(commands[0]![1]);
574+
return Number.isSafeInteger(commandCommentId) && commandCommentId > 0 ? commandCommentId : null;
575+
}
576+
if (commands.length !== 0) return null;
577+
const commandMarkers = Array.from(
578+
String(body ?? "").matchAll(/<!--\s*clawsweeper-command:[^>]+-->/g),
579+
);
580+
if (commandMarkers.length !== 1) return null;
581+
const syntheticCommands = Array.from(
582+
String(body ?? "").matchAll(
583+
/<!--\s*clawsweeper-command:repair-loop-label-sweep:(autofix|automerge):(\d+):(autofix|automerge):([^:\s>]+)\s*-->/g,
584+
),
585+
);
586+
if (
587+
syntheticCommands.length !== 1 ||
588+
syntheticCommands[0]![1] !== status[2] ||
589+
syntheticCommands[0]![2] !== status[1] ||
590+
syntheticCommands[0]![3] !== status[2] ||
591+
syntheticCommands[0]![4] !== status[3]
592+
) {
569593
return null;
570594
}
571-
const commandCommentId = Number(commands[0]![1]);
572-
return Number.isSafeInteger(commandCommentId) && commandCommentId > 0 ? commandCommentId : null;
595+
return completionCommentId;
573596
}
574597

575598
function commandStatusMarkersFromBody(body: JsonValue) {

‎test/repair/update-command-status.test.ts‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,60 @@ test("terminal receipt verification accepts the matching legacy command marker",
353353
}
354354
});
355355

356+
test("terminal receipt verification binds synthetic autofix commands to their status comment", () => {
357+
const marker =
358+
"<!-- clawsweeper-command-status:117443:autofix:59382f10545ffc2955fc88e828be1c649d33f581 -->";
359+
const syntheticMarker =
360+
"<!-- clawsweeper-command:repair-loop-label-sweep:autofix:117443:autofix:59382f10545ffc2955fc88e828be1c649d33f581 -->";
361+
const options = parseOptions([
362+
"--repo",
363+
"openclaw/openclaw",
364+
"--item-number",
365+
"117443",
366+
"--marker",
367+
marker,
368+
"--state",
369+
"Complete",
370+
"--detail",
371+
"The durable review result and its route handoff completed.",
372+
"--verify-terminal-status-receipt",
373+
]);
374+
const comment = {
375+
id: 5151931725,
376+
body: [
377+
marker,
378+
syntheticMarker,
379+
"ClawSweeper autofix is enabled.",
380+
"<!-- clawsweeper-command-progress:start -->",
381+
"Re-review progress:",
382+
"- State: Complete",
383+
"- Detail: The durable review result and its route handoff completed.",
384+
"<!-- clawsweeper-command-progress:end -->",
385+
].join("\n"),
386+
};
387+
388+
assert.deepEqual(verifiedTerminalStatusReceipt(comment, options), {
389+
commandCommentId: 5151931725,
390+
completionCommentId: 5151931725,
391+
});
392+
for (const invalidMarker of [
393+
syntheticMarker.replace(":117443:", ":117444:"),
394+
syntheticMarker.replace(":autofix:117443:", ":automerge:117443:"),
395+
syntheticMarker.replace(":117443:autofix:", ":117443:automerge:"),
396+
syntheticMarker.replace("59382f10545ffc2955fc88e828be1c649d33f581", "mismatched"),
397+
`${syntheticMarker}\n${syntheticMarker}`,
398+
`${syntheticMarker}\n<!-- clawsweeper-command:untrusted-extra -->`,
399+
]) {
400+
assert.equal(
401+
verifiedTerminalStatusReceipt(
402+
{ ...comment, body: comment.body.replace(syntheticMarker, invalidMarker) },
403+
options,
404+
),
405+
null,
406+
);
407+
}
408+
});
409+
356410
test("parseOptions enables the terminal locked-conversation skip only when requested", () => {
357411
const options = parseOptions([
358412
"--repo",

‎test/repair/workflow-sparse-checkout.test.ts‎

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,21 @@ test("state-hydrating sparse repair workflows keep hydration dependencies", () =
147147
}
148148
});
149149

150-
test("sparse CI checkout includes pnpm workspace policy", () => {
151-
const entries = sourceSparseCheckoutEntries(".github/workflows/ci.yml");
152-
153-
assert.ok(entries.includes("pnpm-workspace.yaml"));
150+
test("CI and CodeQL avoid fragile lazy promisor checkouts", () => {
151+
for (const [workflowPath, jobName] of [
152+
[".github/workflows/ci.yml", "check"],
153+
[".github/workflows/codeql.yml", "analyze"],
154+
]) {
155+
const workflow = parse(readText(workflowPath)) as {
156+
jobs: Record<string, { steps: Array<{ uses?: string; with?: Record<string, unknown> }> }>;
157+
};
158+
const checkout = workflow.jobs[jobName]!.steps.find((step) =>
159+
step.uses?.startsWith("actions/checkout@"),
160+
);
161+
assert.ok(checkout, `${workflowPath}:${jobName} must check out its source`);
162+
assert.equal(checkout.with?.["sparse-checkout"], undefined);
163+
assert.equal(checkout.with?.filter, undefined);
164+
}
154165
});
155166

156167
test("repair build emits the bounded Codex process worker", () => {

0 commit comments

Comments
 (0)