@@ -195,6 +195,46 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
195195 } ) ,
196196 ) ;
197197
198+ it . effect ( "resolves a folder of many symlinks in bounded batches" , ( ) =>
199+ Effect . gen ( function * ( ) {
200+ const platform = yield * HostProcess . Platform ;
201+ if ( platform === "win32" ) return ;
202+ const cwd = yield * makeTempDir ( ) ;
203+ const fileSystem = yield * FileSystem . FileSystem ;
204+ const path = yield * Path . Path ;
205+ // Shaped like a pnpm `node_modules`: one link per package into `.pnpm`.
206+ const packages = Array . from ( { length : 200 } , ( _ , index ) => `pkg-${ index } ` ) ;
207+ yield * Effect . forEach (
208+ packages ,
209+ ( name ) =>
210+ Effect . gen ( function * ( ) {
211+ yield * writeTextFile ( cwd , `node_modules/.pnpm/${ name } /index.js` ) ;
212+ yield * fileSystem . symlink ( `.pnpm/${ name } ` , path . join ( cwd , "node_modules" , name ) ) ;
213+ } ) ,
214+ { concurrency : 32 , discard : true } ,
215+ ) ;
216+ const realpath = NodeFSP . realpath ;
217+ let inFlight = 0 ;
218+ let maxInFlight = 0 ;
219+ vi . spyOn ( NodeFSP , "realpath" ) . mockImplementation ( ( async ( target : string ) => {
220+ maxInFlight = Math . max ( maxInFlight , ++ inFlight ) ;
221+ try {
222+ return await realpath ( target ) ;
223+ } finally {
224+ inFlight -- ;
225+ }
226+ } ) as typeof NodeFSP . realpath ) ;
227+
228+ const workspaceEntries = yield * WorkspaceEntries . WorkspaceEntries ;
229+ const { entries } = yield * workspaceEntries . list ( { cwd, directoryPath : "node_modules" } ) ;
230+ expect ( entries . map ( ( entry ) => entry . path ) . toSorted ( ) ) . toEqual (
231+ [ "node_modules/.pnpm" , ...packages . map ( ( name ) => `node_modules/${ name } ` ) ] . toSorted ( ) ,
232+ ) ;
233+ expect ( entries . every ( ( entry ) => entry . kind === "directory" ) ) . toBe ( true ) ;
234+ expect ( maxInFlight ) . toBeLessThanOrEqual ( 64 ) ;
235+ } ) ,
236+ ) ;
237+
198238 it . effect ( "labels the children of wide folders exactly as git does for each child" , ( ) =>
199239 Effect . gen ( function * ( ) {
200240 // Above 1,000 children, listing first asks whether the whole folder is ignored.
0 commit comments