@@ -38,7 +38,9 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
3838 ] ) ( '%s call site' , ( _name , payload ) => {
3939 it . each ( [
4040 [ '/squad cast' , 'cast' , null ] ,
41+ [ ' /squad cast ' , 'cast' , null ] ,
4142 [ ' /squad cast ' , 'cast' , null ] ,
43+ [ ' /squad cast ' , 'cast' , null ] ,
4244 [ 'Context first.\n\n/squad status ' , 'status' , null ] ,
4345 [ '/squad research Focus only on proposal P1' , 'research' , null ] ,
4446 [ '/squad activate phase 2' , 'activate' , 2 ] ,
@@ -95,6 +97,9 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
9597 [ '````text\n```` trailing-info\n/squad cast\n````' , 'code after a fence with trailing info' ] ,
9698 [ ' /squad cast' , 'four-space-indented code' ] ,
9799 [ '\t/squad cast' , 'tab-indented code' ] ,
100+ [ ' \t/squad cast' , 'one-space-plus-tab-indented code' ] ,
101+ [ ' \t/squad cast' , 'two-spaces-plus-tab-indented code' ] ,
102+ [ ' \t/squad cast' , 'three-spaces-plus-tab-indented code' ] ,
98103 ] ) ( 'ignores %s instead of activating control-plane work' , ( body ) => {
99104 expect ( classifySquadCommand ( payload ( body ) , 'issues' ) ) . toEqual ( {
100105 status : 'none' ,
@@ -285,4 +290,34 @@ describe('gh-aw: shared /squad command contract (#1824)', () => {
285290 rmSync ( root , { recursive : true , force : true } ) ;
286291 }
287292 } ) ;
293+
294+ it ( 'realistic CommonMark tab-indentation mutation exposes hidden commands and is caught' , async ( ) => {
295+ mkdirSync ( TEST_ROOT , { recursive : true } ) ;
296+ const root = mkdtempSync ( join ( TEST_ROOT , 'command-indent-mutant-' ) ) ;
297+ try {
298+ const source = join ( process . cwd ( ) , 'workflows' , 'shared' , 'squad-command-contract.mjs' ) ;
299+ const mutant = join ( root , 'squad-command-contract-mutant.mjs' ) ;
300+ cpSync ( source , mutant ) ;
301+ const original = readFileSync ( mutant , 'utf8' ) ;
302+ const changed = original . replace (
303+ '/^(?: {4}| {0,3}\\t)/' ,
304+ '/^(?: {4}|\\t)/' ,
305+ ) ;
306+ expect ( changed ) . not . toBe ( original ) ;
307+ writeFileSync ( mutant , changed ) ;
308+ const module = await import ( `${ pathToFileURL ( mutant ) . href } ?mutation=${ Date . now ( ) } ` ) ;
309+ for ( const body of [ ' \t/squad cast' , ' \t/squad cast' , ' \t/squad cast' ] ) {
310+ expect ( module . classifySquadCommand ( comment ( body ) , 'issue_comment' ) ) . toMatchObject ( {
311+ status : 'accepted' ,
312+ mode : 'cast' ,
313+ } ) ;
314+ expect ( classifySquadCommand ( comment ( body ) , 'issue_comment' ) ) . toEqual ( {
315+ status : 'none' ,
316+ source : 'comment' ,
317+ } ) ;
318+ }
319+ } finally {
320+ rmSync ( root , { recursive : true , force : true } ) ;
321+ }
322+ } ) ;
288323} ) ;
0 commit comments