@@ -57,10 +57,16 @@ describe('findQoderCLIPath', () => {
5757 } ) ;
5858
5959 it ( 'falls back to the official npm cli.js path when the binary is not found' , ( ) => {
60- const cliPath = path . join (
61- os . homedir ( ) , '.npm-global' , 'lib' , 'node_modules' ,
62- '@qoder-ai' , 'qodercli' , 'cli.js'
63- ) ;
60+ // On Windows the source looks under AppData\Roaming\npm instead of ~/.npm-global.
61+ const cliPath = isWindows
62+ ? path . join (
63+ os . homedir ( ) , 'AppData' , 'Roaming' , 'npm' , 'node_modules' ,
64+ '@qoder-ai' , 'qodercli' , 'cli.js'
65+ )
66+ : path . join (
67+ os . homedir ( ) , '.npm-global' , 'lib' , 'node_modules' ,
68+ '@qoder-ai' , 'qodercli' , 'cli.js'
69+ ) ;
6470
6571 jest . spyOn ( fs , 'existsSync' ) . mockImplementation (
6672 p => String ( p ) === cliPath
@@ -74,9 +80,16 @@ describe('findQoderCLIPath', () => {
7480 } ) ;
7581
7682 it ( 'falls back to PATH environment when common and npm paths fail' , ( ) => {
77- const envQoderPath = '/env/specific/bin/qodercli' ;
83+ // Use the platform's PATH delimiter; the expected path keeps the mocked
84+ // Unix-style directory with host separators, mirroring how the source
85+ // joins PATH entries with the binary name.
86+ const sep = isWindows ? ';' : ':' ;
87+ const envBin = '/env/specific/bin' ;
88+ const envQoderPath = isWindows
89+ ? `${ envBin } /qodercli` . replace ( / \/ / g, '\\' )
90+ : `${ envBin } /qodercli` ;
7891 const originalPath = process . env . PATH ;
79- process . env . PATH = `/env/specific/bin: ${ originalPath } ` ;
92+ process . env . PATH = `${ envBin } ${ sep } ${ originalPath } ` ;
8093
8194 jest . spyOn ( fs , 'existsSync' ) . mockImplementation (
8295 p => String ( p ) === envQoderPath
@@ -219,9 +232,12 @@ describe('findQoderCLIPath (platform resolution)', () => {
219232
220233 it ( 'should return first matching Qoder CLI path' , ( ) => {
221234 jest . spyOn ( os , 'homedir' ) . mockReturnValue ( '/home/test' ) ;
222- mockExistingFile ( '/home/test/.local/bin/qodercli' ) ;
235+ // Build the mock path with path.join so it matches the source's
236+ // separator even when this suite runs on a Windows host.
237+ const qoderPath = path . join ( '/home/test' , '.local' , 'bin' , 'qodercli' ) ;
238+ mockExistingFile ( qoderPath ) ;
223239
224- expect ( findQoderCLIPath ( ) ) . toBe ( '/home/test/.local/bin/qodercli' ) ;
240+ expect ( findQoderCLIPath ( ) ) . toBe ( qoderPath ) ;
225241 } ) ;
226242
227243 it ( 'should return null when Qoder CLI is not found' , ( ) => {
@@ -233,24 +249,27 @@ describe('findQoderCLIPath (platform resolution)', () => {
233249
234250 it ( 'should check the official npm package entrypoint as fallback on Unix' , ( ) => {
235251 jest . spyOn ( os , 'homedir' ) . mockReturnValue ( '/home/test' ) ;
236- mockExistingFile ( '/usr/local/lib/node_modules/@qoder-ai/qodercli/cli.js' ) ;
252+ const cliPath = path . join ( '/usr' , 'local' , 'lib' , 'node_modules' , '@qoder-ai' , 'qodercli' , 'cli.js' ) ;
253+ mockExistingFile ( cliPath ) ;
237254
238- expect ( findQoderCLIPath ( ) ) . toBe ( '/usr/local/lib/node_modules/@qoder-ai/qodercli/cli.js' ) ;
255+ expect ( findQoderCLIPath ( ) ) . toBe ( cliPath ) ;
239256 } ) ;
240257
241258 it ( 'should resolve Qoder CLI from custom PATH' , ( ) => {
242- mockExistingFile ( '/custom/bin/qodercli' ) ;
259+ const qoderPath = path . join ( '/custom' , 'bin' , 'qodercli' ) ;
260+ mockExistingFile ( qoderPath ) ;
243261
244262 const customPath = '/custom/bin:/usr/bin' ;
245- expect ( findQoderCLIPath ( customPath ) ) . toBe ( '/custom/bin/qodercli' ) ;
263+ expect ( findQoderCLIPath ( customPath ) ) . toBe ( qoderPath ) ;
246264 } ) ;
247265
248266 it ( 'should expand home directory in custom PATH' , ( ) => {
249267 jest . spyOn ( os , 'homedir' ) . mockReturnValue ( '/home/test' ) ;
250- mockExistingFile ( '/home/test/bin/qodercli' ) ;
268+ const qoderPath = path . join ( '/home/test' , 'bin' , 'qodercli' ) ;
269+ mockExistingFile ( qoderPath ) ;
251270
252271 const customPath = '~/bin:/usr/bin' ;
253- expect ( findQoderCLIPath ( customPath ) ) . toBe ( '/home/test/bin/qodercli' ) ;
272+ expect ( findQoderCLIPath ( customPath ) ) . toBe ( qoderPath ) ;
254273 } ) ;
255274
256275 it ( 'should not return a directory path even if it exists' , ( ) => {
0 commit comments