@@ -9,7 +9,6 @@ const os = require('node:os');
99const path = require ( 'node:path' ) ;
1010const { test } = require ( 'node:test' ) ;
1111const {
12- normalizeTriageOutput,
1312 validateTriageOutput,
1413 validateTriageOutputFile,
1514} = require ( '../validate-triage-output.cjs' ) ;
@@ -33,15 +32,8 @@ Cancellation leaves the operation running. Investigate the async cancellation pa
3332- Ask the author for their SQL Server version.
3433` ;
3534
36- const waitingLabel = 'Auto-Triage: Waiting for Author' ;
3735const output = ( body ) => ( {
38- items : [
39- { type : 'add_comment' , body } ,
40- ...( ! body . includes ( 'Triage Summary (on-demand re-triage)' ) ? [ {
41- type : / \| E n v i r o n m e n t \| (?: M i s s i n g : | .* P a r t i a l : ) / . test ( body ) ? 'add_labels' : 'remove_labels' ,
42- labels : [ waitingLabel ] ,
43- } ] : [ ] ) ,
44- ] ,
36+ items : [ { type : 'add_comment' , body } ] ,
4537 errors : [ ] ,
4638} ) ;
4739
@@ -52,115 +44,41 @@ test('accepts initial, follow-up, and on-demand summaries with multiline content
5244 validateTriageOutput ( output ( summary . replaceAll ( '\n' , '\r\n' ) ) ) ;
5345} ) ;
5446
55- test ( 'accepts a summary followed by an allowed label operation' , ( ) => {
56- for ( const type of [ 'add_labels' , 'remove_labels' ] ) {
57- const body = type === 'add_labels' ? summary :
58- summary . replace ( 'Missing: SQL Server version' , 'All required environment details provided' ) ;
59- const value = output ( body ) ;
60- validateTriageOutput ( value ) ;
61- }
62- } ) ;
63-
64- test ( 'rejects label operations before the summary' , ( ) => {
65- for ( const type of [ 'add_labels' , 'remove_labels' ] ) {
66- const value = output ( summary ) ;
67- value . items . unshift ( { type, labels : [ 'Auto-Triage: Waiting for Author' ] } ) ;
68- assert . throws ( ( ) => validateTriageOutput ( value ) , / b e f o r e / ) ;
69- }
70- } ) ;
71-
72- // The agent queued its label change first in the failed runs for #4855, #4879, #4904, #4940,
73- // #4953, #4965, and #4969, so the gate rejected otherwise complete summaries.
74- const labelFirst = ( type ) => {
75- const body = type === 'add_labels' ? summary :
76- summary . replace ( 'Missing: SQL Server version' , 'All required environment details provided' ) ;
77- return {
78- items : [ { type, labels : [ waitingLabel ] } , { type : 'add_comment' , body } ] ,
79- errors : [ ] ,
80- } ;
81- } ;
82-
83- test ( 'queues a label operation recorded before the summary after it' , ( ) => {
84- for ( const type of [ 'add_labels' , 'remove_labels' ] ) {
85- // Arrange
86- const value = labelFirst ( type ) ;
87- const queued = structuredClone ( value ) ;
88-
89- // Act
90- const normalized = normalizeTriageOutput ( value ) ;
91-
92- // Assert
93- // The summary is published first, and the reordered batch passes the gate.
94- assert . deepEqual ( normalized . items , [ queued . items [ 1 ] , queued . items [ 0 ] ] ) ;
95- assert . deepEqual ( normalized . errors , [ ] ) ;
96- validateTriageOutput ( normalized ) ;
97- // The queued batch is not mutated.
98- assert . deepEqual ( value , queued ) ;
99- }
100- } ) ;
101-
102- test ( 'leaves batches without one summary or an early label operation unchanged' , ( ) => {
103- const label = { type : 'add_labels' , labels : [ waitingLabel ] } ;
104- const comment = output ( summary ) . items [ 0 ] ;
105- for ( const value of [
106- null ,
107- { } ,
108- { items : null } ,
109- { items : [ null , comment ] } ,
110- output ( summary ) ,
111- { items : [ { type : 'noop' , reason : 'No new information' } ] } ,
112- { items : [ label ] } ,
113- { items : [ label , comment , comment ] } ,
114- ] ) {
115- // Act
116- const normalized = normalizeTriageOutput ( value ) ;
117-
118- // Assert
119- assert . equal ( normalized , value ) ;
120- }
121- } ) ;
122-
123- test ( 'still rejects invalid batches after queueing labels after the summary' , ( ) => {
124- const label = { type : 'add_labels' , labels : [ waitingLabel ] } ;
47+ test ( 'rejects label operations before or after a summary and without one' , ( ) => {
48+ // Arrange
12549 const comment = output ( summary ) . items [ 0 ] ;
126- for ( const [ items , message ] of [
127- [ [ label , label , comment ] , / e x a c t l y o n e / ] ,
128- [ [ label , { type : 'add_comment' , body : 'test simple body' } ] , / T r i a g e S u m m a r y / ] ,
129- [ [ { type : 'remove_labels' , labels : [ waitingLabel ] } , comment ] , / a d d _ l a b e l s / ] ,
130- [ [ { ...label , labels : [ 'Unrelated label' ] } , comment ] , / l a b e l / i] ,
131- ] ) {
132- // Act and Assert
133- assert . throws ( ( ) => validateTriageOutput ( normalizeTriageOutput ( { items } ) ) , message ) ;
50+ for ( const type of [ 'add_labels' , 'remove_labels' ] ) {
51+ const label = { type, labels : [ 'Any label' ] } ;
52+ for ( const items of [
53+ [ label , comment ] ,
54+ [ comment , label ] ,
55+ [ label ] ,
56+ [ { type : 'noop' , reason : 'No new information' } , label ] ,
57+ [ { type : 'report_incomplete' , reason : 'Context unavailable' } , label ] ,
58+ ] ) {
59+ // Act and Assert
60+ assert . throws ( ( ) => validateTriageOutput ( { items } ) , / c a n n o t c h a n g e i s s u e l a b e l s / ) ;
61+ }
13462 }
13563} ) ;
13664
137- test ( 'rewrites the queued batch file only after a reordered batch passes validation ' , ( ) => {
65+ test ( 'validates the queued batch without rewriting its file ' , ( ) => {
13866 // Arrange
13967 const directory = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'triage-output-' ) ) ;
14068 const filename = path . join ( directory , 'agent_output.json' ) ;
14169 try {
142- for ( const type of [ 'add_labels' , 'remove_labels' ] ) {
143- // Act
144- const value = labelFirst ( type ) ;
145- fs . writeFileSync ( filename , JSON . stringify ( value ) ) ;
146- const reordered = validateTriageOutputFile ( filename ) ;
147-
148- // Assert
149- assert . equal ( reordered , true ) ;
150- assert . deepEqual ( JSON . parse ( fs . readFileSync ( filename , 'utf8' ) ) . items ,
151- [ value . items [ 1 ] , value . items [ 0 ] ] ) ;
152- }
70+ const queued = JSON . stringify ( output ( summary ) , null , 2 ) ;
71+ fs . writeFileSync ( filename , queued ) ;
15372
154- // An already ordered batch is validated without rewriting the file.
155- const ordered = JSON . stringify ( output ( summary ) , null , 2 ) ;
156- fs . writeFileSync ( filename , ordered ) ;
157- assert . equal ( validateTriageOutputFile ( filename ) , false ) ;
158- assert . equal ( fs . readFileSync ( filename , 'utf8' ) , ordered ) ;
73+ // Act
74+ validateTriageOutputFile ( filename ) ;
75+
76+ // Assert
77+ assert . equal ( fs . readFileSync ( filename , 'utf8' ) , queued ) ;
15978
16079 // A rejected batch leaves the queued file unchanged.
16180 const invalid = JSON . stringify ( {
162- items : [ { type : 'add_labels' , labels : [ waitingLabel ] } ,
163- { type : 'add_comment' , body : 'test simple body' } ] ,
81+ items : [ { type : 'add_comment' , body : 'test simple body' } ] ,
16482 } ) ;
16583 fs . writeFileSync ( filename , invalid ) ;
16684 assert . throws ( ( ) => validateTriageOutputFile ( filename ) , / T r i a g e S u m m a r y / ) ;
@@ -171,12 +89,12 @@ test('rewrites the queued batch file only after a reordered batch passes validat
17189 }
17290} ) ;
17391
174- test ( 'command line validation rewrites the batch that safe outputs publish ' , ( ) => {
92+ test ( 'command line validation accepts a comment-only batch without rewriting it ' , ( ) => {
17593 // Arrange
17694 const directory = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'triage-output-' ) ) ;
17795 const filename = path . join ( directory , 'agent_output.json' ) ;
178- const value = labelFirst ( 'add_labels' ) ;
179- fs . writeFileSync ( filename , JSON . stringify ( value ) ) ;
96+ const queued = JSON . stringify ( output ( summary ) , null , 2 ) ;
97+ fs . writeFileSync ( filename , queued ) ;
18098 try {
18199 // Act
182100 const result = spawnSync ( process . execPath ,
@@ -185,28 +103,28 @@ test('command line validation rewrites the batch that safe outputs publish', ()
185103
186104 // Assert
187105 assert . equal ( result . status , 0 , result . stderr ) ;
188- assert . match ( result . stdout , / Q u e u e d l a b e l c h a n g e s a f t e r t h e t r i a g e s u m m a r y / ) ;
189- assert . deepEqual ( JSON . parse ( fs . readFileSync ( filename , 'utf8' ) ) . items ,
190- [ value . items [ 1 ] , value . items [ 0 ] ] ) ;
106+ assert . match ( result . stdout , / T r i a g e o u t p u t v a l i d a t e d b e f o r e s a f e - o u t p u t p u b l i c a t i o n / ) ;
107+ assert . equal ( fs . readFileSync ( filename , 'utf8' ) , queued ) ;
191108 } finally {
192109 // Cleanup
193110 fs . rmSync ( directory , { recursive : true , force : true } ) ;
194111 }
195112} ) ;
196113
197- test ( 'the compiled workflow validates and rewrites the batch before publishing it ' , ( ) => {
114+ test ( 'the compiled workflow validates the batch before publishing without label tools ' , ( ) => {
198115 // Arrange
199116 const workflow = fs . readFileSync (
200117 path . join ( __dirname , '..' , '..' , 'workflows' , 'issue-triage.lock.yml' ) , 'utf8' ) ;
201118
202119 // Act
203120 const validate = workflow . indexOf ( 'name: Validate triage output before publishing' ) ;
204- const rewrite = workflow . indexOf ( 'validateTriageOutputFile(filename)' , validate ) ;
121+ const validationCall = workflow . indexOf ( 'validateTriageOutputFile(filename)' , validate ) ;
205122 const publish = workflow . indexOf ( 'name: Process Safe Outputs' , validate ) ;
206123
207124 // Assert
208- assert . ok ( validate >= 0 && rewrite > validate && publish > rewrite ) ;
125+ assert . ok ( validate >= 0 && validationCall > validate && publish > validationCall ) ;
209126 assert . doesNotMatch ( workflow . slice ( validate , publish ) , / v a l i d a t e T r i a g e O u t p u t \( J S O N \. p a r s e / ) ;
127+ assert . doesNotMatch ( workflow , / a d d _ l a b e l s | r e m o v e _ l a b e l s | A u t o - T r i a g e : W a i t i n g f o r A u t h o r / ) ;
210128} ) ;
211129
212130test ( 'preserves explicit no-op and failure reporting without a comment' , ( ) => {
@@ -215,7 +133,7 @@ test('preserves explicit no-op and failure reporting without a comment', () => {
215133 }
216134} ) ;
217135
218- test ( 'enforces label state for initial, follow-up, and on-demand summaries ' , ( ) => {
136+ test ( 'accepts all environment states without labels for each triage scenario ' , ( ) => {
219137 for ( const suffix of [ '' , ' (updated after author response)' , ' (on-demand re-triage)' ] ) {
220138 for ( const environment of [
221139 'Missing: SQL Server version' ,
@@ -225,25 +143,9 @@ test('enforces label state for initial, follow-up, and on-demand summaries', ()
225143 ] ) {
226144 const body = summary . replace ( 'Triage Summary' , `Triage Summary${ suffix } ` )
227145 . replace ( 'Missing: SQL Server version' , environment ) ;
228- const onDemand = suffix . includes ( 'on-demand' ) ;
229- const expected = / M i s s i n g : | P a r t i a l : / . test ( environment ) ? 'add_labels' : 'remove_labels' ;
230- const comment = { type : 'add_comment' , body } ;
231- const label = { type : expected , labels : [ waitingLabel ] } ;
232- validateTriageOutput ( { items : onDemand ? [ comment ] : [ comment , label ] } ) ;
233- const invalid = onDemand ? [
234- [ comment , label ] ,
235- [ comment , { ...label , type : expected === 'add_labels' ? 'remove_labels' : 'add_labels' } ] ,
236- ] : [
237- [ comment ] ,
238- [ comment , { ...label , type : expected === 'add_labels' ? 'remove_labels' : 'add_labels' } ] ,
239- [ comment , label , label ] ,
240- [ comment , { ...label , labels : [ ] } ] ,
241- [ comment , { ...label , labels : [ 'Unrelated label' ] } ] ,
242- [ comment , { ...label , labels : [ waitingLabel , 'Unrelated label' ] } ] ,
243- ] ;
244- for ( const items of invalid ) {
245- assert . throws ( ( ) => validateTriageOutput ( { items } ) , / l a b e l / i) ;
246- }
146+
147+ // Act and Assert
148+ assert . doesNotThrow ( ( ) => validateTriageOutput ( output ( body ) ) ) ;
247149 }
248150 }
249151} ) ;
@@ -502,8 +404,7 @@ test('rejects multiple comments and mixed success/incomplete outcomes', () => {
502404
503405test ( 'rejects output errors even when a complete summary is queued' , ( ) => {
504406 const value = output ( summary ) ;
505- value . items . push ( { type : 'add_labels' , labels : [ 'Auto-Triage: Waiting for Author' ] } ) ;
506- value . errors . push ( { type : 'remove_labels' , message : 'Label operation exceeded quota' } ) ;
407+ value . errors . push ( { type : 'add_comment' , message : 'Comment operation exceeded quota' } ) ;
507408 assert . throws ( ( ) => validateTriageOutput ( value ) , / e r r o r s / ) ;
508409 assert . throws ( ( ) => validateTriageOutput ( {
509410 items : [ { type : 'noop' , reason : 'No new information' } ] ,
@@ -517,6 +418,6 @@ test('rejects missing output, empty results, and label-only results', () => {
517418 assert . throws ( ( ) => validateTriageOutput ( value ) , / o u t p u t | r e s u l t / ) ;
518419 }
519420 assert . throws ( ( ) => validateTriageOutput ( {
520- items : [ { type : 'add_labels' , labels : [ 'Auto-Triage: Waiting for Author ' ] } ] ,
521- } ) , / s u m m a r y / ) ;
421+ items : [ { type : 'add_labels' , labels : [ 'Any label ' ] } ] ,
422+ } ) , / c a n n o t c h a n g e i s s u e l a b e l s / ) ;
522423} ) ;
0 commit comments