@@ -272,11 +272,13 @@ if (args[0] === "workflow" && args[1] === "run") {
272272 console.error(env.MOCK_GH_DISPATCH_ERROR);
273273 process.exit(1);
274274 }
275- console.log("Created workflow_dispatch event." );
275+ console.log(env.MOCK_GH_DISPATCH_OUTPUT );
276276} else if (args[0] === "api" && args.some((value) => value.includes("/commits/"))) {
277277 console.log(env.MOCK_GH_CURRENT_SHA);
278278} else if (args[0] === "api" && args.some((value) => value.includes("/actions/workflows/") && value.endsWith("/runs"))) {
279279 console.log(env.MOCK_GH_MATCHES);
280+ } else if (args[0] === "api" && args.some((value) => value.includes("/actions/workflows/"))) {
281+ console.log(env.MOCK_GH_WORKFLOW_ID);
280282} else if (args[0] === "api" && args.some((value) => value.includes("/jobs?"))) {
281283 if (env.MOCK_GH_JOBS_ERROR) {
282284 console.error(env.MOCK_GH_JOBS_ERROR);
@@ -290,9 +292,15 @@ if (args[0] === "workflow" && args[1] === "run") {
290292 }
291293 console.log(JSON.stringify({
292294 conclusion,
295+ display_title: env.MOCK_GH_RUN_TITLE,
296+ event: env.MOCK_GH_RUN_EVENT,
297+ head_branch: env.MOCK_GH_RUN_HEAD_BRANCH,
293298 head_sha: env.MOCK_GH_CHILD_SHA,
294299 html_url: url,
300+ id: Number(env.MOCK_GH_RUN_ID),
301+ path: env.MOCK_GH_RUN_PATH,
295302 status: nextStatus(),
303+ workflow_id: Number(env.MOCK_GH_RUN_WORKFLOW_ID),
296304 }));
297305} else if (args[0] === "run" && args[1] === "view") {
298306 const field = args[args.indexOf("--json") + 1];
@@ -390,10 +398,21 @@ if (args[0] === "workflow" && args[1] === "run") {
390398 MOCK_GH_CHILD_SHA : parentSha ,
391399 MOCK_GH_CONCLUSION : "success" ,
392400 MOCK_GH_CURRENT_SHA : parentSha ,
401+ MOCK_GH_DISPATCH_OUTPUT : "Created workflow_dispatch event." ,
393402 MOCK_GH_JOBS : JSON . stringify ( defaultJobs ) ,
394403 MOCK_GH_MATCHES : "[101]" ,
404+ MOCK_GH_RUN_EVENT : "workflow_dispatch" ,
405+ MOCK_GH_RUN_HEAD_BRANCH :
406+ overrides . MOCK_GH_RUN_HEAD_BRANCH ??
407+ overrides . CHILD_WORKFLOW_REF ??
408+ stepEnv . CHILD_WORKFLOW_REF ,
409+ MOCK_GH_RUN_ID : "101" ,
410+ MOCK_GH_RUN_PATH : `.github/workflows/${ child . workflow } ` ,
411+ MOCK_GH_RUN_TITLE : `${ child . runName } full-release-validation-77-2${ child . nonceSuffix } ` ,
412+ MOCK_GH_RUN_WORKFLOW_ID : "789" ,
395413 MOCK_GH_STATUSES : '["completed"]' ,
396414 MOCK_GH_STATUS_POLLS : statusPath ,
415+ MOCK_GH_WORKFLOW_ID : "789" ,
397416 PATH : `${ workdir } :${ process . env . PATH } ` ,
398417 ...overrides ,
399418 } ,
@@ -1807,7 +1826,7 @@ describe("package acceptance workflow", () => {
18071826 expect ( script . match ( / g h w o r k f l o w r u n / gu) ) . toHaveLength ( 1 ) ;
18081827 expect ( script ) . not . toContain ( "gh_with_retry workflow run" ) ;
18091828 expectTextToIncludeAll ( script , [
1810- "A failed dispatch POST can still create a run. Never retry it " ,
1829+ "The dispatch POST is one-shot " ,
18111830 'encoded_workflow_ref="$(jq -rn --arg value "$CHILD_WORKFLOW_REF"' ,
18121831 'gh_with_retry api "repos/${GITHUB_REPOSITORY}/commits/${encoded_workflow_ref}" --jq .sha' ,
18131832 '"$current_workflow_sha" != "$PARENT_WORKFLOW_SHA"' ,
@@ -1816,6 +1835,8 @@ describe("package acceptance workflow", () => {
18161835 "dispatch_status=$?" ,
18171836 'if [[ "$dispatch_status" -ne 0 && ! "$dispatch_output" =~ $GH_TRANSIENT_SERVER_OR_NETWORK_PATTERN ]]' ,
18181837 "dispatch failed with non-ambiguous status ${dispatch_status}; refusing adoption polling." ,
1838+ 'sed -nE "s#^https://github[.]com/${GITHUB_REPOSITORY}/actions/runs/([0-9]+)\\$#\\1#p"' ,
1839+ 'validate_child_run "$run_id"' ,
18191840 'DISPATCH_RUN_NAME="$dispatch_run_name" CHILD_WORKFLOW_REF="$CHILD_WORKFLOW_REF"' ,
18201841 ".display_title == env.DISPATCH_RUN_NAME and .head_branch == env.CHILD_WORKFLOW_REF" ,
18211842 "Multiple runs matched ${dispatch_run_name}; refusing to guess." ,
@@ -1908,6 +1929,76 @@ describe("package acceptance workflow", () => {
19081929 ) ;
19091930 } ) ;
19101931
1932+ it . each ( FULL_RELEASE_CHILD_DISPATCHES ) (
1933+ "adopts and validates the run URL returned for $jobName without listing runs" ,
1934+ ( child ) => {
1935+ const { calls, result } = runFullReleaseChildDispatch ( child , {
1936+ MOCK_GH_DISPATCH_OUTPUT : "https://github.com/openclaw/openclaw/actions/runs/101" ,
1937+ } ) ;
1938+
1939+ expect ( result . status , `${ result . stdout } \n${ result . stderr } ` ) . toBe ( 0 ) ;
1940+ expect ( calls . filter ( ( { args } ) => args [ 0 ] === "workflow" ) ) . toHaveLength ( 1 ) ;
1941+ expect (
1942+ calls . filter ( ( { args } ) =>
1943+ args . some ( ( value ) => value . includes ( "/actions/workflows/" ) && value . endsWith ( "/runs" ) ) ,
1944+ ) ,
1945+ ) . toHaveLength ( 0 ) ;
1946+ expect (
1947+ calls . some ( ( { args } ) => args . some ( ( value ) => value . endsWith ( "/actions/runs/101" ) ) ) ,
1948+ ) . toBe ( true ) ;
1949+ expect ( calls . filter ( ( { args } ) => args [ 0 ] === "run" && args [ 1 ] === "cancel" ) ) . toHaveLength ( 0 ) ;
1950+ } ,
1951+ ) ;
1952+
1953+ it ( "recovers by exact name when a successful dispatch returns no run URL" , ( ) => {
1954+ const { calls, result } = runFullReleaseChildDispatch ( FULL_RELEASE_CHILD_DISPATCHES [ 0 ] , {
1955+ MOCK_GH_DISPATCH_OUTPUT : "" ,
1956+ } ) ;
1957+
1958+ expect ( result . status , `${ result . stdout } \n${ result . stderr } ` ) . toBe ( 0 ) ;
1959+ expect ( calls . filter ( ( { args } ) => args [ 0 ] === "workflow" ) ) . toHaveLength ( 1 ) ;
1960+ expect (
1961+ calls . filter ( ( { args } ) =>
1962+ args . some ( ( value ) => value . includes ( "/actions/workflows/" ) && value . endsWith ( "/runs" ) ) ,
1963+ ) ,
1964+ ) . toHaveLength ( 1 ) ;
1965+ } ) ;
1966+
1967+ it . each ( [
1968+ [ "workflow" , { MOCK_GH_RUN_WORKFLOW_ID : "790" } ] ,
1969+ [ "title" , { MOCK_GH_RUN_TITLE : "Unrelated workflow run" } ] ,
1970+ [ "head branch" , { MOCK_GH_RUN_HEAD_BRANCH : "other" } ] ,
1971+ [ "event" , { MOCK_GH_RUN_EVENT : "push" } ] ,
1972+ ] as const ) ( "refuses a returned run URL with the wrong %s" , ( _label , overrides ) => {
1973+ const { calls, result } = runFullReleaseChildDispatch ( FULL_RELEASE_CHILD_DISPATCHES [ 0 ] , {
1974+ MOCK_GH_DISPATCH_OUTPUT : "https://github.com/openclaw/openclaw/actions/runs/101" ,
1975+ ...overrides ,
1976+ } ) ;
1977+
1978+ expect ( result . status ) . toBe ( 1 ) ;
1979+ expect ( result . stderr ) . toContain ( "Refusing to adopt unvalidated ci.yml run 101" ) ;
1980+ expect (
1981+ calls . some ( ( { args } ) =>
1982+ args . some ( ( value ) => value . includes ( "/actions/workflows/" ) && value . endsWith ( "/runs" ) ) ,
1983+ ) ,
1984+ ) . toBe ( false ) ;
1985+ expect ( calls . filter ( ( { args } ) => args [ 0 ] === "run" && args [ 1 ] === "cancel" ) ) . toHaveLength ( 0 ) ;
1986+ } ) ;
1987+
1988+ it ( "refuses a nonnumeric exact-name candidate without cancellation ownership" , ( ) => {
1989+ const { calls, result } = runFullReleaseChildDispatch ( FULL_RELEASE_CHILD_DISPATCHES [ 0 ] , {
1990+ MOCK_GH_DISPATCH_OUTPUT : "" ,
1991+ MOCK_GH_MATCHES : '["not-a-run-id"]' ,
1992+ } ) ;
1993+
1994+ expect ( result . status ) . toBe ( 1 ) ;
1995+ expect ( result . stderr ) . toContain ( "Refusing to adopt invalid ci.yml run ID not-a-run-id" ) ;
1996+ expect (
1997+ calls . some ( ( { args } ) => args . some ( ( value ) => value . endsWith ( "/actions/runs/not-a-run-id" ) ) ) ,
1998+ ) . toBe ( false ) ;
1999+ expect ( calls . filter ( ( { args } ) => args [ 0 ] === "run" && args [ 1 ] === "cancel" ) ) . toHaveLength ( 0 ) ;
2000+ } ) ;
2001+
19112002 it . each ( FULL_RELEASE_CHILD_DISPATCHES ) (
19122003 "rejects moved workflow refs before dispatching $jobName" ,
19132004 ( child ) => {
@@ -1980,14 +2071,15 @@ describe("package acceptance workflow", () => {
19802071 ) ;
19812072
19822073 it . each ( FULL_RELEASE_CHILD_DISPATCHES ) (
1983- "cancels exactly the adopted $jobName child when its workflow SHA differs" ,
2074+ "cancels exactly the identified $jobName child when its workflow SHA differs" ,
19842075 ( child ) => {
19852076 const { calls, result } = runFullReleaseChildDispatch ( child , {
19862077 MOCK_GH_CHILD_SHA : "c" . repeat ( 40 ) ,
2078+ MOCK_GH_DISPATCH_OUTPUT : "https://github.com/openclaw/openclaw/actions/runs/101" ,
19872079 } ) ;
19882080
19892081 expect ( result . status ) . toBe ( 1 ) ;
1990- expect ( result . stdout ) . toContain ( "expected parent workflow SHA" ) ;
2082+ expect ( result . stderr ) . toContain ( "expected parent workflow SHA" ) ;
19912083 expect ( calls . filter ( ( { args } ) => args [ 0 ] === "run" && args [ 1 ] === "cancel" ) ) . toEqual ( [
19922084 expect . objectContaining ( { args : [ "run" , "cancel" , "101" ] } ) ,
19932085 ] ) ;
0 commit comments