@@ -24,6 +24,13 @@ import { FS_CALL_TIMEOUT_MS, MAX_WALK_ENTRIES } from "../lib.js";
2424const realReaddir = fs . readdir . bind ( fs ) ;
2525const realRealpath = fs . realpath . bind ( fs ) ;
2626
27+ // The cap tests walk MAX_WALK_ENTRIES + 1 entries on purpose, so their cost is
28+ // the bound they check and scales with the runner: about 1 s locally, near
29+ // vitest's 5 s default on a loaded Windows runner (#5328). An explicit timeout
30+ // keeps them from failing on load; a retry would hide a real failure, and a
31+ // smaller cap would stop them testing the real bound.
32+ const WALK_CAP = { timeout : 30_000 } ;
33+
2734let dir : string ;
2835let conn : Connected ;
2936let client : Client ;
@@ -143,24 +150,28 @@ describe("search_files", () => {
143150 expect ( textOf ( result ) ) . toContain ( `realpath ${ stalled } ` ) ;
144151 } ) ;
145152
146- it ( `stops with an error after visiting ${ MAX_WALK_ENTRIES } entries` , async ( ) => {
147- vi . spyOn ( fs , "readdir" ) . mockImplementation ( ( ( target : PathLike ) =>
148- target . toString ( ) === dir
149- ? Promise . resolve ( fileEntries ( dir , MAX_WALK_ENTRIES + 1 ) )
150- : realReaddir ( target ) ) as typeof fs . readdir ) ;
151- // The listed names do not exist on disk; resolve them as themselves so
152- // each entry costs a string check rather than a real lookup.
153- vi . spyOn ( fs , "realpath" ) . mockImplementation ( ( ( target : PathLike ) =>
154- Promise . resolve ( target . toString ( ) ) ) as typeof fs . realpath ) ;
155- const result = await call ( client , "search_files" , {
156- path : dir ,
157- pattern : "nothing-matches" ,
158- } ) ;
159- expect ( result . isError ) . toBe ( true ) ;
160- expect ( textOf ( result ) ) . toContain (
161- `search_files stopped after visiting ${ MAX_WALK_ENTRIES } entries under ${ dir } ` ,
162- ) ;
163- } ) ;
153+ it (
154+ `stops with an error after visiting ${ MAX_WALK_ENTRIES } entries` ,
155+ WALK_CAP ,
156+ async ( ) => {
157+ vi . spyOn ( fs , "readdir" ) . mockImplementation ( ( ( target : PathLike ) =>
158+ target . toString ( ) === dir
159+ ? Promise . resolve ( fileEntries ( dir , MAX_WALK_ENTRIES + 1 ) )
160+ : realReaddir ( target ) ) as typeof fs . readdir ) ;
161+ // The listed names do not exist on disk; resolve them as themselves so
162+ // each entry costs a string check rather than a real lookup.
163+ vi . spyOn ( fs , "realpath" ) . mockImplementation ( ( ( target : PathLike ) =>
164+ Promise . resolve ( target . toString ( ) ) ) as typeof fs . realpath ) ;
165+ const result = await call ( client , "search_files" , {
166+ path : dir ,
167+ pattern : "nothing-matches" ,
168+ } ) ;
169+ expect ( result . isError ) . toBe ( true ) ;
170+ expect ( textOf ( result ) ) . toContain (
171+ `search_files stopped after visiting ${ MAX_WALK_ENTRIES } entries under ${ dir } ` ,
172+ ) ;
173+ } ,
174+ ) ;
164175
165176 it ( "still skips an entry that fails for any other reason" , async ( ) => {
166177 const refused = path . join ( dir , "local" , "a.txt" ) ;
@@ -188,19 +199,23 @@ describe("directory_tree", () => {
188199 ) ;
189200 } ) ;
190201
191- it ( `stops with an error after visiting ${ MAX_WALK_ENTRIES } entries` , async ( ) => {
192- vi . spyOn ( fs , "readdir" ) . mockImplementation ( ( ( target : PathLike ) =>
193- target . toString ( ) === dir
194- ? Promise . resolve ( fileEntries ( dir , MAX_WALK_ENTRIES + 1 ) )
195- : realReaddir ( target ) ) as typeof fs . readdir ) ;
196- const result = await call ( client , "directory_tree" , { path : dir } ) ;
197- expect ( result . isError ) . toBe ( true ) ;
198- expect ( textOf ( result ) ) . toContain (
199- `directory_tree stopped after visiting ${ MAX_WALK_ENTRIES } entries under ${ dir } ` ,
200- ) ;
201- } ) ;
202+ it (
203+ `stops with an error after visiting ${ MAX_WALK_ENTRIES } entries` ,
204+ WALK_CAP ,
205+ async ( ) => {
206+ vi . spyOn ( fs , "readdir" ) . mockImplementation ( ( ( target : PathLike ) =>
207+ target . toString ( ) === dir
208+ ? Promise . resolve ( fileEntries ( dir , MAX_WALK_ENTRIES + 1 ) )
209+ : realReaddir ( target ) ) as typeof fs . readdir ) ;
210+ const result = await call ( client , "directory_tree" , { path : dir } ) ;
211+ expect ( result . isError ) . toBe ( true ) ;
212+ expect ( textOf ( result ) ) . toContain (
213+ `directory_tree stopped after visiting ${ MAX_WALK_ENTRIES } entries under ${ dir } ` ,
214+ ) ;
215+ } ,
216+ ) ;
202217
203- it ( "does not count excluded entries toward the cap" , async ( ) => {
218+ it ( "does not count excluded entries toward the cap" , WALK_CAP , async ( ) => {
204219 vi . spyOn ( fs , "readdir" ) . mockImplementation ( ( ( target : PathLike ) =>
205220 target . toString ( ) === dir
206221 ? Promise . resolve ( fileEntries ( dir , MAX_WALK_ENTRIES + 1 ) )
0 commit comments