@@ -37,15 +37,19 @@ import { createTestWorkspace } from '../../../helpers/workspace-helper.mts'
3737
3838const PACKAGE_JSON = 'package.json'
3939
40+ // Hoisted mocks for better CI reliability.
41+ const mockWhichRealSync = vi . hoisted ( ( ) => vi . fn ( ) )
42+ const mockResolveBinPathSync = vi . hoisted ( ( ) => vi . fn ( ( p : string ) => p ) )
43+
4044// Mock dependencies for new tests.
4145vi . mock ( '@socketsecurity/lib/bin' , async ( ) => {
4246 const actual = await vi . importActual <
4347 typeof import ( '@socketsecurity/lib/bin' )
4448 > ( '@socketsecurity/lib/bin' )
4549 return {
4650 ...actual ,
47- resolveBinPathSync : vi . fn ( p => p ) ,
48- whichRealSync : vi . fn ( ) ,
51+ resolveBinPathSync : mockResolveBinPathSync ,
52+ whichRealSync : mockWhichRealSync ,
4953 }
5054} )
5155
@@ -382,11 +386,8 @@ describe('Path Resolve', () => {
382386 vi . clearAllMocks ( )
383387 } )
384388
385- it ( 'finds bin path when available' , async ( ) => {
386- const { whichRealSync } = vi . mocked (
387- await import ( '@socketsecurity/lib/bin' ) ,
388- )
389- whichRealSync . mockReturnValue ( [ '/usr/local/bin/npm' ] )
389+ it ( 'finds bin path when available' , ( ) => {
390+ mockWhichRealSync . mockReturnValue ( [ '/usr/local/bin/npm' ] )
390391
391392 const result = findBinPathDetailsSync ( 'npm' )
392393
@@ -400,10 +401,7 @@ describe('Path Resolve', () => {
400401 it ( 'handles shadowed bin paths' , async ( ) => {
401402 const constants = await import ( '../../../../src/constants.mts' )
402403 const shadowBinPath = constants . default . shadowBinPath
403- const { whichRealSync } = vi . mocked (
404- await import ( '@socketsecurity/lib/bin' ) ,
405- )
406- whichRealSync . mockReturnValue ( [
404+ mockWhichRealSync . mockReturnValue ( [
407405 `${ shadowBinPath } /npm` ,
408406 '/usr/local/bin/npm' ,
409407 ] )
@@ -417,11 +415,8 @@ describe('Path Resolve', () => {
417415 } )
418416 } )
419417
420- it ( 'handles no bin path found' , async ( ) => {
421- const { whichRealSync } = vi . mocked (
422- await import ( '@socketsecurity/lib/bin' ) ,
423- )
424- whichRealSync . mockReturnValue ( null )
418+ it ( 'handles no bin path found' , ( ) => {
419+ mockWhichRealSync . mockReturnValue ( null )
425420
426421 const result = findBinPathDetailsSync ( 'nonexistent' )
427422
@@ -432,11 +427,8 @@ describe('Path Resolve', () => {
432427 } )
433428 } )
434429
435- it ( 'handles empty array result' , async ( ) => {
436- const { whichRealSync } = vi . mocked (
437- await import ( '@socketsecurity/lib/bin' ) ,
438- )
439- whichRealSync . mockReturnValue ( [ ] )
430+ it ( 'handles empty array result' , ( ) => {
431+ mockWhichRealSync . mockReturnValue ( [ ] )
440432
441433 const result = findBinPathDetailsSync ( 'npm' )
442434
@@ -447,11 +439,8 @@ describe('Path Resolve', () => {
447439 } )
448440 } )
449441
450- it ( 'handles single string result' , async ( ) => {
451- const { whichRealSync } = vi . mocked (
452- await import ( '@socketsecurity/lib/bin' ) ,
453- )
454- whichRealSync . mockReturnValue ( '/usr/local/bin/npm' as any )
442+ it ( 'handles single string result' , ( ) => {
443+ mockWhichRealSync . mockReturnValue ( '/usr/local/bin/npm' as any )
455444
456445 const result = findBinPathDetailsSync ( 'npm' )
457446
@@ -465,10 +454,7 @@ describe('Path Resolve', () => {
465454 it ( 'handles only shadow bin in path' , async ( ) => {
466455 const constants = await import ( '../../../../src/constants.mts' )
467456 const shadowBinPath = constants . default . shadowBinPath
468- const { whichRealSync } = vi . mocked (
469- await import ( '@socketsecurity/lib/bin' ) ,
470- )
471- whichRealSync . mockReturnValue ( [ `${ shadowBinPath } /npm` ] )
457+ mockWhichRealSync . mockReturnValue ( [ `${ shadowBinPath } /npm` ] )
472458
473459 const result = findBinPathDetailsSync ( 'npm' )
474460
0 commit comments