@@ -119,6 +119,13 @@ describe("collect_ndjson_output.cjs", () => {
119119 defaultMax : 1 ,
120120 fields : { tag : { type : "string" , sanitize : ! 0 , maxLength : 256 } , operation : { required : ! 0 , type : "string" , enum : [ "replace" , "append" , "prepend" ] } , body : { required : ! 0 , type : "string" , sanitize : ! 0 , maxLength : 65e3 } } ,
121121 } ,
122+ dispatch_workflow : {
123+ defaultMax : 1 ,
124+ fields : {
125+ workflow_name : { required : ! 0 , type : "string" , sanitize : ! 0 , minLength : 1 , maxLength : 256 , pattern : ".*\\S.*" , patternError : "must not be empty" } ,
126+ inputs : { type : "object" } ,
127+ } ,
128+ } ,
122129 } )
123130 ) ) ;
124131 } ) ,
@@ -195,6 +202,32 @@ describe("collect_ndjson_output.cjs", () => {
195202 const parsedOutput = JSON . parse ( outputCall [ 1 ] ) ;
196203 ( expect ( parsedOutput . items ) . toHaveLength ( 2 ) , expect ( parsedOutput . items [ 0 ] . type ) . toBe ( "create_issue" ) , expect ( parsedOutput . items [ 1 ] . type ) . toBe ( "add_comment" ) , expect ( parsedOutput . errors ) . toHaveLength ( 0 ) ) ;
197204 } ) ,
205+ it ( "should infer dispatch_workflow workflow_name when one workflow is configured" , async ( ) => {
206+ const testFile = "/tmp/gh-aw/test-ndjson-output.txt" ,
207+ ndjsonContent = '{"type": "dispatch_workflow", "inputs": {"message": "hello"}}' ;
208+ ( fs . writeFileSync ( testFile , ndjsonContent ) , ( process . env . GH_AW_SAFE_OUTPUTS = testFile ) ) ;
209+ const __config = '{"dispatch_workflow":{"workflows":["workflow-handler"]}}' ,
210+ configPath = "/tmp/gh-aw/safeoutputs/config.json" ;
211+ ( fs . mkdirSync ( "/tmp/gh-aw/safeoutputs" , { recursive : ! 0 } ) , fs . writeFileSync ( configPath , __config ) , await eval ( `(async () => { ${ collectScript } ; await main(); })()` ) ) ;
212+ const setOutputCalls = mockCore . setOutput . mock . calls ,
213+ outputCall = setOutputCalls . find ( call => "output" === call [ 0 ] ) ;
214+ expect ( outputCall ) . toBeDefined ( ) ;
215+ const parsedOutput = JSON . parse ( outputCall [ 1 ] ) ;
216+ ( expect ( parsedOutput . items ) . toHaveLength ( 1 ) , expect ( parsedOutput . items [ 0 ] . type ) . toBe ( "dispatch_workflow" ) , expect ( parsedOutput . items [ 0 ] . workflow_name ) . toBe ( "workflow-handler" ) , expect ( parsedOutput . errors ) . toHaveLength ( 0 ) ) ;
217+ } ) ,
218+ it ( "should not infer dispatch_workflow workflow_name when multiple workflows are configured" , async ( ) => {
219+ const testFile = "/tmp/gh-aw/test-ndjson-output.txt" ,
220+ ndjsonContent = '{"type": "dispatch_workflow", "inputs": {"message": "hello"}}' ;
221+ ( fs . writeFileSync ( testFile , ndjsonContent ) , ( process . env . GH_AW_SAFE_OUTPUTS = testFile ) ) ;
222+ const __config = '{"dispatch_workflow":{"workflows":["worker", " "]}}' ,
223+ configPath = "/tmp/gh-aw/safeoutputs/config.json" ;
224+ ( fs . mkdirSync ( "/tmp/gh-aw/safeoutputs" , { recursive : ! 0 } ) , fs . writeFileSync ( configPath , __config ) , await eval ( `(async () => { ${ collectScript } ; await main(); })()` ) ) ;
225+ const setOutputCalls = mockCore . setOutput . mock . calls ,
226+ outputCall = setOutputCalls . find ( call => "output" === call [ 0 ] ) ;
227+ expect ( outputCall ) . toBeDefined ( ) ;
228+ const parsedOutput = JSON . parse ( outputCall [ 1 ] ) ;
229+ expect ( parsedOutput . errors ) . toHaveLength ( 1 ) ;
230+ } ) ,
198231 it ( "should preserve Slack mrkdwn links in custom safe-job string inputs" , async ( ) => {
199232 const testFile = "/tmp/gh-aw/test-ndjson-output.txt" ;
200233 const slackText = "Tracking issue: <https://github.com/octo-org/octo-repo/issues/123|Build failure — Build github/gh-aw#456>" ;
0 commit comments