@@ -53,18 +53,30 @@ function runGit(cwd: string, args: string[]): string {
5353 } ) . trim ( ) ;
5454}
5555
56- function createDispatchFixture ( options : { workflowSource ?: string } = { } ) {
56+ function createDispatchFixture (
57+ options : {
58+ parentRunStates ?: Array < { conclusion : string | null ; status : string } > ;
59+ workflowSource ?: string ;
60+ } = { } ,
61+ ) {
5762 const root = mkdtempSync ( join ( tmpdir ( ) , "openclaw-release-dispatch-" ) ) ;
5863 const origin = join ( root , "origin.git" ) ;
5964 const checkout = join ( root , "checkout" ) ;
6065 const binDir = join ( root , "bin" ) ;
6166 const gitCallsPath = join ( root , "git-calls.jsonl" ) ;
6267 const ghCallsPath = join ( root , "gh-calls.jsonl" ) ;
68+ const parentRunIndexPath = join ( root , "parent-run-index.txt" ) ;
69+ const preloadPath = join ( root , "immediate-poll.mjs" ) ;
6370 const releaseRef = "release/2026.8.1" ;
6471 mkdirSync ( checkout ) ;
6572 mkdirSync ( binDir ) ;
6673 writeFileSync ( gitCallsPath , "" ) ;
6774 writeFileSync ( ghCallsPath , "" ) ;
75+ writeFileSync ( parentRunIndexPath , "0" ) ;
76+ writeFileSync (
77+ preloadPath ,
78+ 'const wait = Atomics.wait; Atomics.wait = (array, index, value, timeout) => timeout === undefined ? wait(array, index, value) : "timed-out";\n' ,
79+ ) ;
6880
6981 execFileSync ( "git" , [ "init" , "--bare" , origin ] , { stdio : "ignore" } ) ;
7082 execFileSync ( "git" , [ "init" , "-b" , "main" ] , { cwd : checkout , stdio : "ignore" } ) ;
@@ -149,6 +161,8 @@ process.exit(result.status ?? 1);
149161const fs = require("node:fs");
150162const args = process.argv.slice(2);
151163fs.appendFileSync(process.env.MOCK_GH_CALLS, JSON.stringify(args) + "\\n");
164+ const parentRunStates = ${ JSON . stringify ( options . parentRunStates ?? [ { conclusion : "success" , status : "completed" } ] ) } ;
165+ const parentRunIndexPath = ${ JSON . stringify ( parentRunIndexPath ) } ;
152166if (args[0] === "workflow" && args[1] === "run") {
153167 const declaredInputs = new Set(JSON.parse(process.env.MOCK_WORKFLOW_INPUTS));
154168 for (let index = 0; index < args.length; index += 1) {
@@ -163,9 +177,13 @@ if (args[0] === "workflow" && args[1] === "run") {
163177 }
164178 console.log("https://github.com/openclaw/openclaw/actions/runs/123");
165179} else if (args[0] === "api" && args.at(-1).endsWith("/actions/runs/123")) {
166- console.log(JSON.stringify({ status: "completed", conclusion: "success", head_sha: process.env.MOCK_WORKFLOW_SHA, run_attempt: 1 }));
180+ const index = Number(fs.readFileSync(parentRunIndexPath, "utf8"));
181+ const state = parentRunStates[Math.min(index, parentRunStates.length - 1)];
182+ fs.writeFileSync(parentRunIndexPath, String(index + 1));
183+ console.log(JSON.stringify({ ...state, head_sha: process.env.MOCK_WORKFLOW_SHA, run_attempt: 1 }));
167184} else if (args[0] === "run" && args[1] === "download") {
168- console.error("no valid artifacts found");
185+ const index = Number(fs.readFileSync(parentRunIndexPath, "utf8")) - 1;
186+ console.error(parentRunStates[index]?.status === "queued" ? "no artifact matches any of the names or patterns provided" : "no valid artifacts found");
169187 process.exit(1);
170188} else {
171189 console.error("unexpected gh call: " + args.join(" "));
@@ -189,6 +207,13 @@ if (args[0] === "workflow" && args[1] === "run") {
189207 encoding : "utf8" ,
190208 env : {
191209 ...process . env ,
210+ ...( options . parentRunStates
211+ ? {
212+ NODE_OPTIONS : [ process . env . NODE_OPTIONS , "--import" , preloadPath ]
213+ . filter ( Boolean )
214+ . join ( " " ) ,
215+ }
216+ : { } ) ,
192217 MOCK_GH_CALLS : ghCallsPath ,
193218 MOCK_GIT_CALLS : gitCallsPath ,
194219 MOCK_REAL_PATH : process . env . PATH ,
@@ -573,7 +598,7 @@ describe("full-release-validation-at-sha", () => {
573598 expect ( source ) . not . toContain ( "attempt < 480" ) ;
574599 } ) ;
575600
576- it ( "binds early release decisions to the exact parent attempt and tooling SHA" , ( ) => {
601+ it ( "binds release decisions to the exact parent attempt and tooling SHA" , ( ) => {
577602 const payload = {
578603 kind : "openclaw.full-release-decision" ,
579604 mode : "decision" ,
@@ -827,6 +852,61 @@ describe("full-release-validation-at-sha", () => {
827852 }
828853 } ) ;
829854
855+ it ( "retries an absent decision artifact through a parent status regression" , ( ) => {
856+ const fixture = createDispatchFixture ( {
857+ parentRunStates : [
858+ { conclusion : null , status : "in_progress" } ,
859+ { conclusion : null , status : "queued" } ,
860+ { conclusion : null , status : "in_progress" } ,
861+ { conclusion : "success" , status : "completed" } ,
862+ ] ,
863+ } ) ;
864+ try {
865+ const result = fixture . run ( [ "--workflow-sha" , fixture . workflowSha ] ) ;
866+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
867+ const calls = fixture . readCalls ( fixture . ghCallsPath ) ;
868+ const parentPolls = calls
869+ . map ( ( args , index ) => ( { args, index } ) )
870+ . filter ( ( { args } ) => args [ 0 ] === "api" && args [ 1 ] ?. endsWith ( "/actions/runs/123" ) ) ;
871+ const artifactDownloads = calls
872+ . map ( ( args , index ) => ( { args, index } ) )
873+ . filter ( ( { args } ) => args [ 0 ] === "run" && args [ 1 ] === "download" ) ;
874+ expect ( parentPolls ) . toHaveLength ( 4 ) ;
875+ expect ( artifactDownloads ) . toHaveLength ( 4 ) ;
876+ expect ( artifactDownloads [ 1 ] ?. index ) . toBeGreaterThan ( parentPolls [ 1 ] ?. index ?? Infinity ) ;
877+ expect ( artifactDownloads [ 1 ] ?. index ) . toBeLessThan ( parentPolls [ 2 ] ?. index ?? - Infinity ) ;
878+ expect ( result . stdout ) . toContain ( "Parent run status: queued/pending" ) ;
879+ expect ( runGit ( fixture . origin , [ "for-each-ref" , "--format=%(refname)" , "refs/heads" ] ) ) . toBe (
880+ "refs/heads/main\nrefs/heads/release/2026.8.1" ,
881+ ) ;
882+ } finally {
883+ fixture . cleanup ( ) ;
884+ }
885+ } ) ;
886+
887+ it ( "waits for a terminal conclusion across every nonterminal parent state" , ( ) => {
888+ const fixture = createDispatchFixture ( {
889+ parentRunStates : [
890+ { conclusion : null , status : "requested" } ,
891+ { conclusion : null , status : "waiting" } ,
892+ { conclusion : null , status : "pending" } ,
893+ { conclusion : null , status : "completed" } ,
894+ { conclusion : "success" , status : "completed" } ,
895+ ] ,
896+ } ) ;
897+ try {
898+ const result = fixture . run ( [ "--workflow-sha" , fixture . workflowSha ] ) ;
899+ expect ( result . status , result . stderr ) . toBe ( 0 ) ;
900+ const calls = fixture . readCalls ( fixture . ghCallsPath ) ;
901+ expect (
902+ calls . filter ( ( args ) => args [ 0 ] === "api" && args [ 1 ] ?. endsWith ( "/actions/runs/123" ) ) ,
903+ ) . toHaveLength ( 5 ) ;
904+ expect ( calls . filter ( ( args ) => args [ 0 ] === "run" && args [ 1 ] === "download" ) ) . toHaveLength ( 5 ) ;
905+ } finally {
906+ fixture . cleanup ( ) ;
907+ }
908+ } ) ;
909+
830910 it ( "dispatches non-main tooling only when its exact protected tag is supplied" , ( ) => {
831911 const fixture = createDispatchFixture ( ) ;
832912 try {
0 commit comments