@@ -973,4 +973,45 @@ describe("Safe Output Handler Manager", () => {
973973 expect ( result . codePushFailures ) . toHaveLength ( 0 ) ;
974974 } ) ;
975975 } ) ;
976+
977+ describe ( "output emission via emitSafeOutputActionOutputs" , ( ) => {
978+ it ( "processMessages result includes create_issue result with number and url for emission" , async ( ) => {
979+ const messages = [ { type : "create_issue" , title : "My Issue" } ] ;
980+ const mockHandler = vi . fn ( ) . mockResolvedValue ( { number : 42 , url : "https://github.com/owner/repo/issues/42" } ) ;
981+ const handlers = new Map ( [ [ "create_issue" , mockHandler ] ] ) ;
982+
983+ const result = await processMessages ( handlers , messages ) ;
984+
985+ const issueResult = result . results . find ( r => r . type === "create_issue" && r . success ) ;
986+ expect ( issueResult ) . toBeDefined ( ) ;
987+ expect ( issueResult . result . number ) . toBe ( 42 ) ;
988+ expect ( issueResult . result . url ) . toBe ( "https://github.com/owner/repo/issues/42" ) ;
989+ } ) ;
990+
991+ it ( "processMessages result with failed create_issue does not include success result for emission" , async ( ) => {
992+ const messages = [ { type : "create_issue" , title : "Failing Issue" } ] ;
993+ const mockHandler = vi . fn ( ) . mockRejectedValue ( new Error ( "API error" ) ) ;
994+ const handlers = new Map ( [ [ "create_issue" , mockHandler ] ] ) ;
995+
996+ const result = await processMessages ( handlers , messages ) ;
997+
998+ const successfulIssueResult = result . results . find ( r => r . type === "create_issue" && r . success ) ;
999+ expect ( successfulIssueResult ) . toBeUndefined ( ) ;
1000+ } ) ;
1001+
1002+ it ( "core.setOutput is called with created_issue_number when create_issue succeeds" , async ( ) => {
1003+ const messages = [ { type : "create_issue" , title : "My Issue" } ] ;
1004+ const mockHandler = vi . fn ( ) . mockResolvedValue ( { number : 7 , url : "https://github.com/owner/repo/issues/7" } ) ;
1005+ const handlers = new Map ( [ [ "create_issue" , mockHandler ] ] ) ;
1006+
1007+ const result = await processMessages ( handlers , messages ) ;
1008+
1009+ // Simulate what main() does: call emitSafeOutputActionOutputs with the result
1010+ const { emitSafeOutputActionOutputs } = await import ( "./safe_outputs_action_outputs.cjs" ) ;
1011+ emitSafeOutputActionOutputs ( result ) ;
1012+
1013+ expect ( global . core . setOutput ) . toHaveBeenCalledWith ( "created_issue_number" , "7" ) ;
1014+ expect ( global . core . setOutput ) . toHaveBeenCalledWith ( "created_issue_url" , "https://github.com/owner/repo/issues/7" ) ;
1015+ } ) ;
1016+ } ) ;
9761017} ) ;
0 commit comments