@@ -37,6 +37,7 @@ describe("handle_agent_failure", () => {
3737 delete global . context ;
3838 delete process . env . GITHUB_SHA ;
3939 delete process . env . GH_AW_ACTION_FAILURE_ISSUE_EXPIRES_HOURS ;
40+ delete process . env . GH_AW_GROUP_REPORTS ;
4041 } ) ;
4142
4243 describe ( "getActionFailureIssueExpiresHours" , ( ) => {
@@ -421,15 +422,53 @@ describe("handle_agent_failure", () => {
421422
422423 expect ( createCommentMock ) . not . toHaveBeenCalled ( ) ;
423424 expect ( createIssueMock ) . toHaveBeenCalledOnce ( ) ;
424- expect ( createIssueMock ) . toHaveBeenCalledWith (
425- expect . objectContaining ( {
426- headers : { "X-GitHub-Api-Version" : "2022-11-28" } ,
427- } )
428- ) ;
425+ const createCall = createIssueMock . mock . calls [ 0 ] [ 0 ] ;
426+ expect ( createCall . headers ) . toEqual ( { "X-GitHub-Api-Version" : "2022-11-28" } ) ;
429427 expect ( searchMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { q : expect . stringContaining ( '"gh-aw-agentic-workflow:"' ) } ) ) ;
430428 expect ( searchMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { q : expect . stringContaining ( '"workflow_id: test-workflow" in:body' ) } ) ) ;
431429 } ) ;
432430
431+ it ( "creates a parent issue with the API version header when group reports are enabled" , async ( ) => {
432+ const createCommentMock = vi . fn ( ) ;
433+ const createIssueMock = vi . fn ( async ( { title } ) => ( {
434+ data : {
435+ number : title === "[aw] Failed runs" ? 200 : 201 ,
436+ html_url : `https://github.com/owner/repo/issues/${ title === "[aw] Failed runs" ? 200 : 201 } ` ,
437+ node_id : title === "[aw] Failed runs" ? "I_parent" : "I_child" ,
438+ } ,
439+ } ) ) ;
440+ const searchMock = vi . fn ( async ( { q } ) => {
441+ if ( q . includes ( "is:pr" ) ) {
442+ return { data : { total_count : 0 , items : [ ] } } ;
443+ }
444+ return { data : { total_count : 0 , items : [ ] } } ;
445+ } ) ;
446+
447+ process . env . GH_AW_GROUP_REPORTS = "true" ;
448+
449+ global . github = {
450+ rest : {
451+ search : {
452+ issuesAndPullRequests : searchMock ,
453+ } ,
454+ issues : {
455+ create : createIssueMock ,
456+ createComment : createCommentMock ,
457+ } ,
458+ pulls : { get : vi . fn ( ) } ,
459+ } ,
460+ graphql : vi . fn ( ) ,
461+ } ;
462+
463+ await main ( ) ;
464+
465+ const parentCreateCall = createIssueMock . mock . calls . map ( ( [ call ] ) => call ) . find ( call => call . title === "[aw] Failed runs" ) ;
466+ expect ( parentCreateCall ) . toBeDefined ( ) ;
467+ expect ( parentCreateCall . headers ) . toEqual ( { "X-GitHub-Api-Version" : "2022-11-28" } ) ;
468+ expect ( createCommentMock ) . not . toHaveBeenCalled ( ) ;
469+ expect ( searchMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { q : expect . stringContaining ( '"[aw] Failed runs"' ) } ) ) ;
470+ } ) ;
471+
433472 it ( "escapes workflow IDs before searching for legacy XML marker matches" , async ( ) => {
434473 const createCommentMock = vi . fn ( async ( ) => ( { data : { id : 1001 } } ) ) ;
435474 const createIssueMock = vi . fn ( ) ;
@@ -791,7 +830,9 @@ describe("handle_agent_failure", () => {
791830
792831 expect ( global . core . warning ) . toHaveBeenCalledWith ( expect . stringContaining ( "Daily per-category issue cap reached" ) ) ;
793832 expect ( global . core . info ) . toHaveBeenCalledWith ( expect . stringContaining ( "Summarize-and-stop" ) ) ;
794- expect ( createIssueMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { title : "[aw] Daily failure issue cap exceeded" } ) ) ;
833+ const createCall = createIssueMock . mock . calls [ 0 ] [ 0 ] ;
834+ expect ( createCall . title ) . toBe ( "[aw] Daily failure issue cap exceeded" ) ;
835+ expect ( createCall . headers ) . toEqual ( { "X-GitHub-Api-Version" : "2022-11-28" } ) ;
795836 expect ( createCommentMock ) . toHaveBeenCalledOnce ( ) ;
796837 expect ( createCommentMock ) . toHaveBeenCalledWith ( expect . objectContaining ( { issue_number : 999 } ) ) ;
797838 expect ( global . github . rest . search . issuesAndPullRequests ) . toHaveBeenCalledWith ( expect . objectContaining ( { q : expect . stringContaining ( "is:open" ) } ) ) ;
0 commit comments