11import { afterAll , describe , expect , it } from 'vitest' ;
2- import { cpSync , mkdirSync , mkdtempSync , readFileSync , readdirSync , rmSync } from 'node:fs' ;
3- import { execFileSync } from 'node:child_process' ;
2+ import { cpSync , mkdirSync , mkdtempSync , readFileSync , readdirSync , rmSync , writeFileSync } from 'node:fs' ;
3+ import { execFileSync , spawnSync } from 'node:child_process' ;
44import { tmpdir } from 'node:os' ;
55import { dirname , resolve } from 'node:path' ;
66import { fileURLToPath } from 'node:url' ;
@@ -209,11 +209,18 @@ describe('gh-aw advisory Squad reviewer', () => {
209209 }
210210 execFileSync ( 'git' , [ 'init' , '--quiet' ] , { cwd : workspace } ) ;
211211 for ( const name of installOrder ) {
212- execFileSync (
212+ const result = spawnSync (
213213 'gh' ,
214214 [ 'aw' , 'compile' , name . slice ( 0 , - 3 ) , '--strict' , '--approve' , '--no-check-update' ] ,
215215 { cwd : workspace , encoding : 'utf8' , stdio : 'pipe' } ,
216216 ) ;
217+ const diagnostics = `${ result . stdout } \n${ result . stderr } ` ;
218+ expect ( result . error , `failed to launch gh aw for ${ name } ` ) . toBeUndefined ( ) ;
219+ expect ( result . status , `strict compile failed for ${ name } :\n${ diagnostics } ` ) . toBe ( 0 ) ;
220+ expect (
221+ diagnostics ,
222+ `${ name } must not emit the workflow_dispatch concurrency warning in a clean consumer install` ,
223+ ) . not . toContain ( 'concurrency.job-discriminator' ) ;
217224 }
218225
219226 const installed = readdirSync ( workflowDir , { withFileTypes : true } )
@@ -232,6 +239,32 @@ describe('gh-aw advisory Squad reviewer', () => {
232239 ] ) ;
233240 } , 30000 ) ;
234241
242+ it ( 'detects a missing workflow_dispatch job discriminator during strict compilation' , ( ) => {
243+ const workspace = mkdtempSync ( resolve ( tmpdir ( ) , 'squad-review-discriminator-mutation-' ) ) ;
244+ compileWorkspaces . push ( workspace ) ;
245+ const workflowDir = resolve ( workspace , '.github' , 'workflows' ) ;
246+ mkdirSync ( workflowDir , { recursive : true } ) ;
247+ cpSync ( resolve ( ROOT , 'workflows' ) , workflowDir , { recursive : true } ) ;
248+
249+ const workerPath = resolve ( workflowDir , 'squad-deps-worker.md' ) ;
250+ const worker = readFileSync ( workerPath , 'utf8' ) . replace ( / \r \n / g, '\n' ) ;
251+ expect ( worker ) . toContain ( ' job-discriminator: ${{ github.run_id }}\n' ) ;
252+ writeFileSync ( workerPath , worker . replace ( ' job-discriminator: ${{ github.run_id }}\n' , '' ) ) ;
253+ execFileSync ( 'git' , [ 'init' , '--quiet' ] , { cwd : workspace } ) ;
254+
255+ const result = spawnSync (
256+ 'gh' ,
257+ [ 'aw' , 'compile' , 'squad-deps-worker' , '--strict' , '--no-check-update' , '--no-emit' ] ,
258+ { cwd : workspace , encoding : 'utf8' , stdio : 'pipe' } ,
259+ ) ;
260+ const diagnostics = `${ result . stdout } \n${ result . stderr } ` ;
261+ expect ( result . error , 'failed to launch gh aw for discriminator mutation' ) . toBeUndefined ( ) ;
262+ expect ( result . status , `mutated workflow must remain compilable:\n${ diagnostics } ` ) . toBe ( 0 ) ;
263+ expect ( diagnostics ) . toContain (
264+ 'workflow_dispatch workflow has no concurrency.job-discriminator' ,
265+ ) ;
266+ } , 20000 ) ;
267+
235268 it ( 'keeps all consumer install surfaces on the coherent four-workflow order' , ( ) => {
236269 for ( const surface of [ GUIDE , README , AGENT_GUIDE , SHARED_BOOTSTRAP ] ) {
237270 const orders = installOrders ( surface ) ;
0 commit comments