@@ -62,8 +62,8 @@ function write(file: string, body: string, mode?: number): void {
6262}
6363
6464/** A shim that must never run: under cmd.exe it prints SHELL-USED. */
65- function cmdShim ( name : string ) : void {
66- write ( path . join ( bin , `${ name } .cmd` ) , '@echo SHELL-USED %*\r\n' ) ;
65+ function cmdShim ( name : string , dir = bin ) : void {
66+ write ( path . join ( dir , `${ name } .cmd` ) , '@echo SHELL-USED %*\r\n' ) ;
6767}
6868
6969function run ( args : string [ ] , env : Record < string , string > = { } ) {
@@ -112,6 +112,53 @@ describe('the launcher passes argv through unchanged', () => {
112112 expect ( parsed ( run ( HOSTILE , { SQUAD_ALLOW_NPX : '1' } ) ) ) . toEqual ( [ '-y' , `${ PKG . join ( '/' ) } @2.0.0` , ...HOSTILE ] ) ;
113113 } ) ;
114114
115+ describe ( 'when a .cmd shim has no JavaScript entry beside it' , ( ) => {
116+ it . runIf ( win ) ( 'resolves a workspace .bin shim to its sibling package without a shell' , ( ) => {
117+ const modules = path . join ( root , 'workspace' , 'node_modules' ) ;
118+ const workspaceBin = path . join ( modules , '.bin' ) ;
119+ cmdShim ( 'squad' , workspaceBin ) ;
120+ const pkg = path . join ( modules , ...PKG ) ;
121+ write ( path . join ( pkg , 'package.json' ) , JSON . stringify ( { name : PKG . join ( '/' ) , version : '2.0.0' } ) ) ;
122+ write ( path . join ( pkg , 'dist' , 'cli-entry.js' ) , ECHO ) ;
123+ expect ( parsed ( run ( HOSTILE , { PATH : [ workspaceBin , path . dirname ( process . execPath ) ] . join ( path . delimiter ) } ) ) ) . toEqual ( HOSTILE ) ;
124+ } ) ;
125+
126+ it . runIf ( win ) ( 'resolves an explicitly configured workspace .bin shim' , ( ) => {
127+ const modules = path . join ( root , 'workspace' , 'node_modules' ) ;
128+ const workspaceBin = path . join ( modules , '.bin' ) ;
129+ cmdShim ( 'squad' , workspaceBin ) ;
130+ write ( path . join ( modules , ...PKG , 'dist' , 'cli-entry.js' ) , ECHO ) ;
131+ expect ( parsed ( run ( HOSTILE , { SQUAD_CLI : path . join ( workspaceBin , 'squad.cmd' ) } ) ) ) . toEqual ( HOSTILE ) ;
132+ } ) ;
133+
134+ it . runIf ( win ) ( 'skips an outdated workspace .bin shim in favor of a recorded CLI' , ( ) => {
135+ const modules = path . join ( root , 'workspace' , 'node_modules' ) ;
136+ const workspaceBin = path . join ( modules , '.bin' ) ;
137+ cmdShim ( 'squad' , workspaceBin ) ;
138+ const pkg = path . join ( modules , ...PKG ) ;
139+ write ( path . join ( pkg , 'package.json' ) , JSON . stringify ( { name : PKG . join ( '/' ) , version : '1.0.0' } ) ) ;
140+ write ( path . join ( pkg , 'dist' , 'cli-entry.js' ) , "throw new Error('outdated CLI selected');\n" ) ;
141+ const recorded = path . join ( root , 'recorded' , 'node_modules' , ...PKG ) ;
142+ const entry = path . join ( recorded , 'dist' , 'cli-entry.js' ) ;
143+ write ( path . join ( recorded , 'package.json' ) , JSON . stringify ( { name : PKG . join ( '/' ) , version : '2.0.0' } ) ) ;
144+ write ( entry , ECHO ) ;
145+ write ( path . join ( root , 'squad-home' , 'cli.json' ) , JSON . stringify ( { entry } ) ) ;
146+ expect ( parsed ( run ( HOSTILE , { PATH : [ workspaceBin , path . dirname ( process . execPath ) ] . join ( path . delimiter ) } ) ) ) . toEqual ( HOSTILE ) ;
147+ } ) ;
148+
149+ it . runIf ( win ) ( 'resolves a workspace npx .bin shim without a shell' , ( ) => {
150+ const modules = path . join ( root , 'workspace' , 'node_modules' ) ;
151+ const workspaceBin = path . join ( modules , '.bin' ) ;
152+ cmdShim ( 'npx' , workspaceBin ) ;
153+ write ( path . join ( modules , 'npm' , 'bin' , 'npx-cli.js' ) , ECHO ) ;
154+ const out = run ( HOSTILE , {
155+ PATH : [ workspaceBin , path . dirname ( process . execPath ) ] . join ( path . delimiter ) ,
156+ SQUAD_ALLOW_NPX : '1' ,
157+ } ) ;
158+ expect ( parsed ( out ) ) . toEqual ( [ '-y' , `${ PKG . join ( '/' ) } @2.0.0` , ...HOSTILE ] ) ;
159+ } ) ;
160+ } ) ;
161+
115162 it ( 'to SQUAD_CLI given as a script' , ( ) => {
116163 const entry = path . join ( root , 'cli dir' , 'cli-entry.js' ) ;
117164 write ( entry , ECHO ) ;
@@ -127,6 +174,7 @@ describe('the launcher passes argv through unchanged', () => {
127174
128175 it . runIf ( win ) ( 'fails closed when a .cmd shim has no JavaScript entry beside it' , ( ) => {
129176 cmdShim ( 'squad' ) ;
177+ write ( path . join ( bin , 'node_modules' , ...PKG , 'package.json' ) , JSON . stringify ( { name : PKG . join ( '/' ) , version : '2.0.0' } ) ) ;
130178 const out = run ( [ 'state-mcp' ] ) ;
131179 expect ( out . status ) . toBe ( 1 ) ;
132180 expect ( out . stdout ) . not . toContain ( 'SHELL-USED' ) ;
0 commit comments