@@ -10,20 +10,7 @@ vi.mock("../../../utils/fs", () => ({
1010 fileExistsAtPath : vi . fn ( ) ,
1111} ) )
1212
13- vi . mock ( "fs" , ( ) => ( {
14- existsSync : vi . fn ( ) ,
15- } ) )
16-
17- vi . mock ( "module" , ( ) => ( {
18- createRequire : vi . fn ( ) ,
19- } ) )
20-
21- import * as fs from "fs"
22- import { createRequire } from "module"
23-
2413const mockFileExists = vi . mocked ( fileExistsAtPath )
25- const mockExistsSync = vi . mocked ( fs . existsSync )
26- const mockCreateRequire = vi . mocked ( createRequire )
2714
2815describe ( "Ripgrep line truncation" , ( ) => {
2916 // The default MAX_LINE_LENGTH is 500 in the implementation
@@ -80,9 +67,6 @@ describe("getBinPath", () => {
8067 beforeEach ( ( ) => {
8168 mockFileExists . mockReset ( )
8269 mockFileExists . mockResolvedValue ( false )
83- mockExistsSync . mockReset ( )
84- mockExistsSync . mockReturnValue ( false )
85- mockCreateRequire . mockReset ( )
8670 } )
8771
8872 it ( "resolves ripgrep from the classic @vscode/ripgrep layout" , async ( ) => {
@@ -112,58 +96,43 @@ describe("getBinPath", () => {
11296 expect ( await getBinPath ( appRoot ) ) . toBeUndefined ( )
11397 } )
11498
115- it ( "returns undefined when platform-package resolution fails" , async ( ) => {
116- mockFileExists . mockResolvedValue ( false )
117- mockExistsSync . mockReturnValue ( true )
118- mockCreateRequire . mockReturnValue ( {
119- resolve : vi . fn ( ( ) => {
120- throw new Error ( "module not found" )
121- } ) ,
122- } as unknown as NodeRequire )
123-
124- await expect ( getBinPath ( appRoot ) ) . resolves . toBeUndefined ( )
125- } )
126-
12799 // Regression test for https://github.com/Zoo-Code-Org/Zoo-Code/issues/1024
128100 // VS Code 1.130+ ships @vscode/ripgrep >=1.18, where the binary lives in a
129- // platform-specific optional package resolved via the wrapper's package.json.
130- // None of the six hardcoded candidate paths match this layout, so getBinPath
131- // returns undefined on affected Windows installs, causing every task to hang.
132- it ( "resolves ripgrep via the @vscode/ripgrep >=1.18 platform-package layout" , async ( ) => {
133- const platformBin = `/vscode/ripgrep-${ process . platform } -${ process . arch } /bin/${ binName } `
101+ // platform-specific optional package (e.g. @vscode/ripgrep-win32-x64).
102+ // None of the previous candidate paths matched this layout.
103+ it ( "resolves ripgrep from the @vscode/ripgrep >=1.18 platform-package layout" , async ( ) => {
104+ const arch = process . env . npm_config_arch || process . arch
105+ const rg = path . join ( appRoot , `node_modules/@vscode/ripgrep-${ process . platform } -${ arch } /bin` , binName )
106+ mockFileExists . mockImplementation ( async ( p : string ) => p === rg )
134107
135- mockFileExists . mockResolvedValue ( false )
136- mockExistsSync . mockReturnValue ( true )
137- const mockRequireFromWrapper = { resolve : vi . fn ( ) . mockReturnValue ( platformBin ) }
138- const mockRequireFromApp = { resolve : vi . fn ( ) . mockReturnValue ( "/vscode/ripgrep/index.js" ) }
139- mockCreateRequire
140- . mockReturnValueOnce ( mockRequireFromApp as unknown as NodeRequire )
141- . mockReturnValueOnce ( mockRequireFromWrapper as unknown as NodeRequire )
142- mockFileExists . mockImplementation ( async ( p : string ) => p === platformBin )
143-
144- expect ( await getBinPath ( appRoot ) ) . toBe ( platformBin )
108+ expect ( await getBinPath ( appRoot ) ) . toBe ( rg )
145109 } )
146110
147- it ( "respects npm_config_arch override when resolving platform-package" , async ( ) => {
148- const overrideArch = "x64"
149- const platformBin = `/vscode/ripgrep-${ process . platform } -${ overrideArch } /bin/${ binName } `
111+ it ( "resolves ripgrep from the unpacked @vscode/ripgrep >=1.18 platform-package layout" , async ( ) => {
112+ const arch = process . env . npm_config_arch || process . arch
113+ const rg = path . join (
114+ appRoot ,
115+ `node_modules.asar.unpacked/@vscode/ripgrep-${ process . platform } -${ arch } /bin` ,
116+ binName ,
117+ )
118+ mockFileExists . mockImplementation ( async ( p : string ) => p === rg )
150119
120+ expect ( await getBinPath ( appRoot ) ) . toBe ( rg )
121+ } )
122+
123+ it ( "respects npm_config_arch when selecting the platform package" , async ( ) => {
124+ const overrideArch = "x64"
151125 const original = process . env . npm_config_arch
152126 process . env . npm_config_arch = overrideArch
153127 try {
154- mockFileExists . mockResolvedValue ( false )
155- mockExistsSync . mockReturnValue ( true )
156- const mockRequireFromWrapper = { resolve : vi . fn ( ) . mockReturnValue ( platformBin ) }
157- const mockRequireFromApp = { resolve : vi . fn ( ) . mockReturnValue ( "/vscode/ripgrep/index.js" ) }
158- mockCreateRequire
159- . mockReturnValueOnce ( mockRequireFromApp as unknown as NodeRequire )
160- . mockReturnValueOnce ( mockRequireFromWrapper as unknown as NodeRequire )
161- mockFileExists . mockImplementation ( async ( p : string ) => p === platformBin )
162-
163- expect ( await getBinPath ( appRoot ) ) . toBe ( platformBin )
164- expect ( mockRequireFromWrapper . resolve ) . toHaveBeenCalledWith (
165- `@vscode/ripgrep-${ process . platform } -${ overrideArch } /bin/${ binName } ` ,
128+ const rg = path . join (
129+ appRoot ,
130+ `node_modules/@vscode/ripgrep-${ process . platform } -${ overrideArch } /bin` ,
131+ binName ,
166132 )
133+ mockFileExists . mockImplementation ( async ( p : string ) => p === rg )
134+
135+ expect ( await getBinPath ( appRoot ) ) . toBe ( rg )
167136 } finally {
168137 if ( original === undefined ) {
169138 delete process . env . npm_config_arch
0 commit comments