@@ -53,76 +53,65 @@ test('supports deterministic as-of week selection from the CLI', () => {
5353 assert . throws ( ( ) => childProcess . execFileSync ( process . execPath , [ script , '--previous-iso-week' , '--as-of' , 'not-a-date' ] , { encoding : 'utf8' } ) ) ;
5454} ) ;
5555
56- test ( 'links detailed items only through exact known-AIC comment or PR evidence' , ( ) => {
56+ test ( 'projects compact AIC-linked items from exact known-AIC evidence' , ( ) => {
5757 const items = [
58- { repository : 'repo' , number : 1 , type : 'issue' , url : 'https://github.com/org/repo/issues/1' } ,
59- { repository : 'repo' , number : 2 , type : 'pull_request' , url : 'https://github.com/org/repo/pull/2' } ,
58+ { repository : 'repo' , number : 1 , type : 'issue' , url : 'https://github.com/org/repo/issues/1' , updatedAt : 'metadata' } ,
59+ { repository : 'repo' , number : 2 , type : 'pull_request' , url : 'https://github.com/org/repo/pull/2' , title : 'metadata' } ,
6060 { repository : 'repo' , number : 3 , type : 'issue' , url : 'https://github.com/org/repo/issues/3' } ,
6161 ] ;
6262 const run = ( id , aic , pullRequests = [ ] ) => ( { id, repository : 'repo' , kind : 'drafter' , aic, pull_requests : pullRequests } ) ;
6363 const pull = ( number , repository = 'repo' ) => ( { url : `https://api.github.com/repos/org/${ repository } /pulls/${ number } ` } ) ;
64+ const comment = ( runId , itemNumber ) => ( { repository : 'repo' , runId, itemNumber, itemUrl : items . find ( ( item ) => item . number === itemNumber ) . url } ) ;
6465 for ( const scenario of [
65- { name : 'comment' , runs : [ run ( 10 , 1 ) ] , comments : [ { repository : 'repo' , runId : 10 , itemNumber : 1 } ] , expected : [ [ 1 , [ 10 ] ] ] } ,
66- { name : 'pull request' , runs : [ run ( 11 , 2 , [ pull ( 2 ) ] ) ] , comments : [ ] , expected : [ [ 2 , [ 11 ] ] ] } ,
67- { name : 'unrelated evidence' , runs : [ run ( 12 , 3 , [ pull ( 3 , 'other' ) ] ) , run ( 13 , null , [ pull ( 2 ) ] ) ] , comments : [ { repository : 'repo' , runId : 12 , itemNumber : 99 } ] , expected : [ ] } ,
68- { name : 'deduplicates links' , runs : [ run ( 14 , 4 , [ pull ( 2 ) , pull ( 2 ) ] ) ] , comments : [ { repository : 'repo' , runId : 14 , itemNumber : 2 } , { repository : 'repo' , runId : 14 , itemNumber : 2 } ] , expected : [ [ 2 , [ 14 ] ] ] } ,
69- { name : 'keeps multiple comment targets' , runs : [ run ( 16 , 5 ) ] , comments : [ { repository : 'repo' , runId : 16 , itemNumber : 1 } , { repository : 'repo' , runId : 16 , itemNumber : 3 } ] , expected : [ [ 1 , [ 16 ] ] , [ 3 , [ 16 ] ] ] } ,
70- { name : 'retains zero AIC' , runs : [ run ( 15 , 0 ) ] , comments : [ { repository : 'repo' , runId : 15 , itemNumber : 1 } ] , expected : [ [ 1 , [ 15 ] ] ] } ,
71- ] ) {
72- const actual = aicLinkedItems ( items , scenario . runs , scenario . comments , 'org' ) . map ( ( item ) => [ item . number , item . aicRunIds ] ) ;
73- assert . deepEqual ( actual , scenario . expected , scenario . name ) ;
74- }
66+ { name : 'comment' , runs : [ run ( 10 , 1 ) ] , comments : [ comment ( 10 , 1 ) ] , expected : [ { repository : 'repo' , number : 1 , type : 'issue' , aic : 1 , aicRunIds : [ 10 ] } ] } ,
67+ { name : 'pull request' , runs : [ run ( 11 , 2 , [ pull ( 2 ) ] ) ] , comments : [ ] , expected : [ { repository : 'repo' , number : 2 , type : 'pull_request' , aic : 2 , aicRunIds : [ 11 ] } ] } ,
68+ { name : 'unrelated or cross-repository evidence' , runs : [ run ( 12 , 3 , [ pull ( 3 , 'other' ) ] ) , run ( 13 , null , [ pull ( 2 ) ] ) ] , comments : [ { ...comment ( 12 , 1 ) , itemNumber : 99 } ] , expected : [ ] } ,
69+ { name : 'sums multiple runs' , runs : [ run ( 10 , 1.25 ) , run ( 14 , 2.5 ) ] , comments : [ comment ( 10 , 1 ) , comment ( 14 , 1 ) ] , expected : [ { repository : 'repo' , number : 1 , type : 'issue' , aic : 3.75 , aicRunIds : [ 10 , 14 ] } ] } ,
70+ { name : 'deduplicates evidence' , runs : [ run ( 14 , 4 , [ pull ( 2 ) , pull ( 2 ) ] ) ] , comments : [ comment ( 14 , 2 ) , comment ( 14 , 2 ) ] , expected : [ { repository : 'repo' , number : 2 , type : 'pull_request' , aic : 4 , aicRunIds : [ 14 ] } ] } ,
71+ { name : 'attributes one run fully to multiple items' , runs : [ run ( 16 , 5 ) ] , comments : [ comment ( 16 , 1 ) , comment ( 16 , 3 ) ] , expected : [ { repository : 'repo' , number : 1 , type : 'issue' , aic : 5 , aicRunIds : [ 16 ] } , { repository : 'repo' , number : 3 , type : 'issue' , aic : 5 , aicRunIds : [ 16 ] } ] } ,
72+ { name : 'retains zero AIC' , runs : [ run ( 15 , 0 ) ] , comments : [ comment ( 15 , 1 ) ] , expected : [ { repository : 'repo' , number : 1 , type : 'issue' , aic : 0 , aicRunIds : [ 15 ] } ] } ,
73+ ] ) assert . deepEqual ( aicLinkedItems ( items , scenario . runs , scenario . comments , 'org' ) , scenario . expected , scenario . name ) ;
7574} ) ;
7675
7776test ( 'parses comment AIC with transparent same-repository item identity' , ( ) => {
78- const comment = parseCommentAic ( {
79- id : 1 ,
80- issue_url : 'https://api.github.com/repos/org/repo/issues/7' , html_url : 'https://github.com/org/repo/pull/7#issuecomment-9' ,
81- body : '> Generated by [workflow](https://github.com/org/repo/actions/runs/42) · 0 AIC' ,
82- } , 'org' , 'repo' ) ;
83- assert . deepEqual ( { runId : comment . runId , itemNumber : comment . itemNumber , itemUrl : comment . itemUrl , aic : comment . aic } , {
84- runId : 42 , itemNumber : 7 , itemUrl : 'https://github.com/org/repo/pull/7' , aic : 0 ,
85- } ) ;
77+ const comment = parseCommentAic ( { id : 1 , issue_url : 'https://api.github.com/repos/org/repo/issues/7' , html_url : 'https://github.com/org/repo/pull/7#issuecomment-9' , body : '> Generated by [workflow](https://github.com/org/repo/actions/runs/42) · 0 AIC' } , 'org' , 'repo' ) ;
78+ assert . deepEqual ( { runId : comment . runId , itemNumber : comment . itemNumber , itemUrl : comment . itemUrl , aic : comment . aic } , { runId : 42 , itemNumber : 7 , itemUrl : 'https://github.com/org/repo/pull/7' , aic : 0 } ) ;
8679 assert . equal ( parseCommentAic ( { id : 1 , issue_url : 'https://api.github.com/repos/other/repo/issues/7' , html_url : 'https://github.com/other/repo/issues/7#issuecomment-9' , body : '> Generated by [workflow](https://github.com/org/repo/actions/runs/42) · 1 AIC' } , 'org' , 'repo' ) , null ) ;
8780 assert . equal ( parseCommentAic ( { id : 1 , issue_url : 'https://api.github.com/repos/org/repo/issues/7' , html_url : 'https://github.com/org/repo/issues/7#issuecomment-9' , body : '> Generated by [workflow](https://github.com/other/repo/actions/runs/42) · 1 AIC' } , 'org' , 'repo' ) , null ) ;
8881 assert . equal ( parseCommentAic ( { id : 1 , issue_url : 'https://api.github.com/repos/org/repo/issues/7' , html_url : 'https://github.com/org/repo/issues/7#issuecomment-9' , body : '> Generated by [workflow](https://github.com/org/repo/actions/runs/42) · 1 AIC\n<!-- gh-aw-agentic-workflow: id: 42, workflow_id: 1, run: https://github.com/other/repo/actions/runs/42 -->' } , 'org' , 'repo' ) , null ) ;
8982} ) ;
9083
9184test ( 'retains consistent comment evidence for every exact item target' , ( ) => {
92- const records = deduplicateCommentAic ( [
93- { runId : 20 , commentId : 1 , commentUrl : 'one' , agentAic : 1 , detectionAic : null , aic : 1 , repository : 'repo' , itemNumber : 1 } ,
94- { runId : 20 , commentId : 2 , commentUrl : 'two' , agentAic : 1 , detectionAic : null , aic : 1 , repository : 'repo' , itemNumber : 2 } ,
95- ] ) . records ;
96- const items = [ { repository : 'repo' , number : 1 , type : 'issue' } , { repository : 'repo' , number : 2 , type : 'issue' } ] ;
97- assert . deepEqual ( aicLinkedItems ( items , [ { id : 20 , repository : 'repo' , kind : 'drafter' , aic : 1 } ] , records , 'org' ) . map ( ( item ) => [ item . number , item . aicRunIds ] ) , [ [ 1 , [ 20 ] ] , [ 2 , [ 20 ] ] ] ) ;
85+ const records = deduplicateCommentAic ( [ { runId : 20 , commentId : 1 , commentUrl : 'one' , agentAic : 1 , detectionAic : null , aic : 1 , repository : 'repo' , itemNumber : 1 } , { runId : 20 , commentId : 2 , commentUrl : 'two' , agentAic : 1 , detectionAic : null , aic : 1 , repository : 'repo' , itemNumber : 2 } ] ) . records ;
86+ const items = [ { repository : 'repo' , number : 1 , type : 'issue' , url : 'https://github.com/org/repo/issues/1' } , { repository : 'repo' , number : 2 , type : 'issue' , url : 'https://github.com/org/repo/issues/2' } ] ;
87+ for ( const record of records ) record . itemUrl = `https://github.com/org/repo/issues/${ record . itemNumber } ` ;
88+ assert . deepEqual ( aicLinkedItems ( items , [ { id : 20 , repository : 'repo' , kind : 'drafter' , aic : 1 } ] , records , 'org' ) , [ { repository : 'repo' , number : 1 , type : 'issue' , aic : 1 , aicRunIds : [ 20 ] } , { repository : 'repo' , number : 2 , type : 'issue' , aic : 1 , aicRunIds : [ 20 ] } ] ) ;
9889} ) ;
9990
10091test ( 'normalizes only same-repository workflow PR references' , ( ) => {
101- assert . deepEqual ( normalizedPullRequests ( { pull_requests : [
102- { url : 'https://api.github.com/repos/org/repo/pulls/2' } ,
103- { url : 'https://api.github.com/repos/org/repo/pulls/1' } ,
104- { url : 'https://api.github.com/repos/org/repo/pulls/2' } ,
105- { url : 'https://api.github.com/repos/org/other/pulls/3' } ,
106- ] } , 'org' , 'repo' ) , [
107- { number : 1 , url : 'https://github.com/org/repo/pull/1' } ,
108- { number : 2 , url : 'https://github.com/org/repo/pull/2' } ,
109- ] ) ;
92+ assert . deepEqual ( normalizedPullRequests ( { pull_requests : [ { url : 'https://api.github.com/repos/org/repo/pulls/2' } , { url : 'https://api.github.com/repos/org/repo/pulls/1' } , { url : 'https://api.github.com/repos/org/repo/pulls/2' } , { url : 'https://api.github.com/repos/org/other/pulls/3' } ] } , 'org' , 'repo' ) , [ { number : 1 , url : 'https://github.com/org/repo/pull/1' } , { number : 2 , url : 'https://github.com/org/repo/pull/2' } ] ) ;
11093} ) ;
11194
112- test ( 'validates detailed item links have exact serialized evidence' , ( ) => {
113- const issue = { repository : 'repo' , number : 1 , type : 'issue' , url : 'https://github.com/org/repo/issues/1' , aicRunIds : [ 1 ] } ;
114- const pullRequest = { repository : 'repo' , number : 2 , type : 'pull_request' , url : 'https://github.com/org/repo/pull/2' , aicRunIds : [ 2 ] } ;
115- const commentAic = [ { repository : 'repo' , runId : 1 , itemNumber : 1 , itemUrl : issue . url } ] ;
116- const workflowRuns = [
117- { id : 1 , repository : 'repo' , aic : 0 , pullRequests : [ ] } ,
118- { id : 2 , repository : 'repo' , aic : 1 , pullRequests : [ { number : 2 , url : pullRequest . url } ] } ,
119- ] ;
95+ test ( 'validates compact detailed item records and exact serialized evidence' , ( ) => {
96+ const issue = { repository : 'repo' , number : 1 , type : 'issue' , aic : 0 , aicRunIds : [ 1 ] } ;
97+ const pullRequest = { repository : 'repo' , number : 2 , type : 'pull_request' , aic : 1 , aicRunIds : [ 2 ] } ;
98+ const issueUrl = 'https://github.com/org/repo/issues/1' ;
99+ const pullRequestUrl = 'https://github.com/org/repo/pull/2' ;
100+ const commentAic = [ { repository : 'repo' , runId : 1 , itemNumber : 1 , itemUrl : issueUrl } ] ;
101+ const workflowRuns = [ { id : 1 , repository : 'repo' , aic : 0 , pullRequests : [ ] } , { id : 2 , repository : 'repo' , aic : 1 , pullRequests : [ { number : 2 , url : pullRequestUrl } ] } ] ;
120102 assert . doesNotThrow ( ( ) => validateDetailedItems ( [ issue , pullRequest ] , workflowRuns , commentAic , 'org' ) ) ;
121- assert . throws ( ( ) => validateDetailedItems ( [ issue ] , [ { id : 1 , repository : 'repo' , aic : 0 , pullRequests : [ ] } ] , [ ] , 'org' ) ) ;
122- assert . throws ( ( ) => validateDetailedItems ( [ pullRequest ] , [ { id : 2 , repository : 'repo' , aic : 1 , pullRequests : [ { number : 2 , url : issue . url } ] } ] , [ ] , 'org' ) ) ;
123- assert . throws ( ( ) => validateDetailedItems ( [ { ...issue , type : 'pull_request' } ] , workflowRuns , commentAic , 'org' ) ) ;
124- assert . throws ( ( ) => validateDetailedItems ( [ { ...issue , url : 'https://github.com/other/repo/issues/1' } ] , workflowRuns , [ { ...commentAic [ 0 ] , itemUrl : 'https://github.com/other/repo/issues/1' } ] , 'org' ) ) ;
125- assert . throws ( ( ) => validateDetailedItems ( [ { ...issue , aicRunIds : [ 1 , 1 ] } ] , workflowRuns , commentAic , 'org' ) ) ;
126- assert . throws ( ( ) => validateDetailedItems ( [ { ...issue , aicRunIds : [ 2 ] } ] , [ { id : 2 , repository : 'repo' , aic : null , pullRequests : [ ] } ] , commentAic , 'org' ) ) ;
127- assert . throws ( ( ) => validateDetailedItems ( [ { ...issue , aicRunIds : [ 3 ] } ] , [ { id : 3 , repository : 'other' , aic : 1 , pullRequests : [ ] } ] , commentAic , 'org' ) ) ;
103+ for ( const [ name , items , runs , comments ] of [
104+ [ 'missing evidence' , [ issue ] , [ { id : 1 , repository : 'repo' , aic : 0 , pullRequests : [ ] } ] , [ ] ] ,
105+ [ 'wrong PR evidence' , [ pullRequest ] , [ { id : 2 , repository : 'repo' , aic : 1 , pullRequests : [ { number : 2 , url : issueUrl } ] } ] , [ ] ] ,
106+ [ 'wrong type' , [ { ...issue , type : 'pull_request' } ] , workflowRuns , commentAic ] ,
107+ [ 'cross-repository comment URL' , [ issue ] , workflowRuns , [ { ...commentAic [ 0 ] , itemUrl : 'https://github.com/other/repo/issues/1' } ] ] ,
108+ [ 'duplicate run ID' , [ { ...issue , aicRunIds : [ 1 , 1 ] } ] , workflowRuns , commentAic ] ,
109+ [ 'unknown AIC' , [ { ...issue , aicRunIds : [ 2 ] } ] , [ { id : 2 , repository : 'repo' , aic : null , pullRequests : [ ] } ] , commentAic ] ,
110+ [ 'cross-repository run' , [ { ...issue , aicRunIds : [ 3 ] } ] , [ { id : 3 , repository : 'other' , aic : 1 , pullRequests : [ ] } ] , commentAic ] ,
111+ [ 'wrong total' , [ { ...pullRequest , aic : 2 } ] , workflowRuns , commentAic ] ,
112+ [ 'duplicate item identity' , [ issue , { ...issue , type : 'pull_request' } ] , workflowRuns , commentAic ] ,
113+ [ 'unexpected metadata' , [ { ...issue , updatedAt : '2026-09-01T00:00:00Z' } ] , workflowRuns , commentAic ] ,
114+ [ 'non-finite AIC' , [ { ...issue , aic : Number . NaN } ] , workflowRuns , commentAic ] ,
115+ [ 'malformed identity' , [ { ...issue , repository : 'bad/repo' } ] , workflowRuns , commentAic ] ,
116+ ] ) assert . throws ( ( ) => validateDetailedItems ( items , runs , comments , 'org' ) , name ) ;
128117} ) ;
0 commit comments