@@ -17,6 +17,7 @@ vi.mock('./exec.ts', async (original) => ({
1717import { readProcessExecutablePaths } from '../process.ts' ;
1818
1919const originalPlatform = Object . getOwnPropertyDescriptor ( process , 'platform' ) ! ;
20+ const host = { env : process . env , cwd : process . cwd ( ) } ;
2021afterEach ( ( ) => {
2122 Object . defineProperty ( process , 'platform' , originalPlatform ) ;
2223 vi . resetAllMocks ( ) ;
@@ -45,7 +46,10 @@ test('Linux reads requested executable links and refuses missing, deleted and in
4546 if ( ! ( name in entries ) ) throw new Error ( 'unavailable' ) ;
4647 return entries [ name ] ;
4748 } ) ;
48- const paths = await readProcessExecutablePaths ( [ 1 , 2 , 3 , 4 , 5 , 6 , 1 , 0 , - 1 , 1.5 , 2147483648 ] ) ;
49+ const paths = await readProcessExecutablePaths (
50+ [ 1 , 2 , 3 , 4 , 5 , 6 , 1 , 0 , - 1 , 1.5 , 2147483648 ] ,
51+ host ,
52+ ) ;
4953 assert . deepEqual ( [ ...paths ] , [ [ 1 , '/opt/应用/my binary' ] ] ) ;
5054 assert . equal ( readlinkMock . mock . calls . length , 6 ) ;
5155 assert . equal ( runCmdMock . mock . calls . length , 0 ) ;
@@ -54,7 +58,7 @@ test('Linux reads requested executable links and refuses missing, deleted and in
5458test ( 'Linux deadline returns unknown when a read does not settle' , async ( ) => {
5559 platform ( 'linux' ) ;
5660 readlinkMock . mockImplementation ( ( ) => new Promise ( ( ) => { } ) ) ;
57- assert . deepEqual ( [ ...( await readProcessExecutablePaths ( [ 1 ] , 1 ) ) ] , [ ] ) ;
61+ assert . deepEqual ( [ ...( await readProcessExecutablePaths ( [ 1 ] , host , 1 ) ) ] , [ ] ) ;
5862} ) ;
5963
6064test . each ( [ 'darwin' , 'win32' ] as const ) (
@@ -76,7 +80,11 @@ test.each(['darwin', 'win32'] as const)(
7680 { pid : 5 , path : valid } ,
7781 ] ) ,
7882 } ) ;
79- const paths = await readProcessExecutablePaths ( [ 1 , 2 , 3 , 4 , 5 , 0 , 1 , - 1 , 1.5 , 2147483648 ] , 20 ) ;
83+ const paths = await readProcessExecutablePaths (
84+ [ 1 , 2 , 3 , 4 , 5 , 0 , 1 , - 1 , 1.5 , 2147483648 ] ,
85+ host ,
86+ 20 ,
87+ ) ;
8088 assert . deepEqual ( [ ...paths ] , [ [ 1 , valid ] ] ) ;
8189 assert . equal ( runCmdMock . mock . calls . length , 1 ) ;
8290 const [ cmd , args , options ] = runCmdMock . mock . calls [ 0 ] ! ;
@@ -117,8 +125,8 @@ test.each(['darwin', 'win32'] as const)(
117125 stderr : '' ,
118126 } ) ;
119127 runCmdMock . mockRejectedValueOnce ( new Error ( 'timeout' ) ) ;
120- for ( let i = 0 ; i < 3 ; i ++ ) assert . equal ( ( await readProcessExecutablePaths ( [ 1 ] ) ) . size , 0 ) ;
121- assert . equal ( ( await readProcessExecutablePaths ( [ 0 , - 1 ] ) ) . size , 0 ) ;
128+ for ( let i = 0 ; i < 3 ; i ++ ) assert . equal ( ( await readProcessExecutablePaths ( [ 1 ] , host ) ) . size , 0 ) ;
129+ assert . equal ( ( await readProcessExecutablePaths ( [ 0 , - 1 ] , host ) ) . size , 0 ) ;
122130 assert . equal ( runCmdMock . mock . calls . length , 3 ) ;
123131 } ,
124132) ;
@@ -128,17 +136,18 @@ test.each([undefined, '', 'Windows', String.raw`C:Windows`, String.raw`\Windows`
128136 async ( root ) => {
129137 platform ( 'win32' ) ;
130138 vi . stubEnv ( 'SystemRoot' , root ) ;
131- assert . equal ( ( await readProcessExecutablePaths ( [ 1 ] ) ) . size , 0 ) ;
139+ assert . equal ( ( await readProcessExecutablePaths ( [ 1 ] , host ) ) . size , 0 ) ;
132140 assert . equal ( runCmdMock . mock . calls . length , 0 ) ;
133141 } ,
134142) ;
135143
136- test ( 'Windows host SystemRoot variable names are case-insensitive' , async ( ) => {
144+ test ( 'Windows uses only its supplied host SystemRoot with case-insensitive names ' , async ( ) => {
137145 platform ( 'win32' ) ;
138- vi . stubEnv ( 'SystemRoot' , undefined ) ;
139- vi . stubEnv ( 'sYsTeMrOoT' , String . raw `E:\Windows` ) ;
140146 runCmdMock . mockResolvedValue ( { stdout : '[]' , stderr : '' , exitCode : 0 } ) ;
141- await readProcessExecutablePaths ( [ 1 ] ) ;
147+ await readProcessExecutablePaths ( [ 1 ] , {
148+ env : { sYsTeMrOoT : String . raw `E:\Windows` } ,
149+ cwd : process . cwd ( ) ,
150+ } ) ;
142151 assert . equal (
143152 runCmdMock . mock . calls [ 0 ] ?. [ 0 ] ,
144153 String . raw `E:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe` ,
0 commit comments