@@ -29,51 +29,40 @@ function fileItem(relativePath: string): FileItem {
2929 } ;
3030}
3131
32- it . effect ( "recovers missed watcher changes on reads without rescanning every read " , ( ) =>
32+ it . effect ( "reads never rescan after the former recovery interval " , ( ) =>
3333 Effect . scoped (
3434 Effect . gen ( function * ( ) {
35- let indexed = "old.ts" ;
36- let onDisk = indexed ;
37- const scanFiles = vi . fn ( ( ) => {
38- indexed = onDisk ;
39- return { ok : true as const , value : undefined } ;
40- } ) ;
35+ const scanFiles = vi . fn ( ( ) => ( { ok : true as const , value : undefined } ) ) ;
4136 const finder = {
4237 destroy : vi . fn ( ) ,
4338 waitForIndexReady : vi . fn ( async ( ) => ( { ok : true as const , value : true } ) ) ,
4439 scanFiles,
40+ mixedSearch : ( ) => ( { ok : true as const , value : { items : [ ] , totalMatched : 0 } } ) ,
4541 fileSearch : ( ) => ( {
4642 ok : true as const ,
47- value : { items : [ fileItem ( indexed ) ] , scores : [ ] , totalMatched : 1 , totalFiles : 1 } ,
43+ value : { items : [ fileItem ( "watched.ts" ) ] , scores : [ ] , totalMatched : 1 , totalFiles : 1 } ,
4844 } ) ,
45+ grep : ( ) => ( { ok : true as const , value : { items : [ ] , nextCursor : null } } ) ,
4946 } as unknown as FileFinder ;
5047 vi . spyOn ( FileFinder , "create" ) . mockReturnValueOnce ( { ok : true , value : finder } ) ;
5148 const index = yield * WorkspaceSearchIndex . make ( "/workspace/project" ) ;
52- onDisk = "new.ts" ;
49+ yield * TestClock . adjust ( "10 minutes" ) ;
50+ expect ( yield * index . list ( ) ) . toEqual ( { entries : [ ] , truncated : false } ) ;
5351 expect ( ( yield * index . search ( "" , 10 , "file" ) ) . entries ) . toEqual ( [
54- { path : "old .ts" , kind : "file" } ,
52+ { path : "watched .ts" , kind : "file" } ,
5553 ] ) ;
54+ expect (
55+ yield * index . searchContents ( {
56+ query : "needle" ,
57+ limit : 1 ,
58+ caseSensitive : true ,
59+ wholeWord : false ,
60+ useRegex : false ,
61+ } ) ,
62+ ) . toEqual ( { matches : [ ] , truncated : false } ) ;
5663 expect ( scanFiles ) . not . toHaveBeenCalled ( ) ;
57- yield * TestClock . adjust ( "5 minutes" ) ;
58- const results = yield * Effect . all (
59- [ index . search ( "" , 10 , "file" ) , index . search ( "" , 10 , "file" ) ] ,
60- { concurrency : "unbounded" } ,
61- ) ;
62- for ( const result of results ) {
63- expect ( result . entries ) . toEqual ( [ { path : "new.ts" , kind : "file" } ] ) ;
64- }
65- expect ( scanFiles ) . toHaveBeenCalledTimes ( 1 ) ;
66- yield * index . search ( "" , 10 , "file" ) ;
64+ yield * index . refresh ( ) ;
6765 expect ( scanFiles ) . toHaveBeenCalledTimes ( 1 ) ;
68- scanFiles . mockImplementationOnce ( ( ) => {
69- throw new Error ( "scan unavailable" ) ;
70- } ) ;
71- yield * TestClock . adjust ( "5 minutes" ) ;
72- expect ( ( yield * index . search ( "" , 10 , "file" ) ) . entries ) . toEqual ( [
73- { path : "new.ts" , kind : "file" } ,
74- ] ) ;
75- yield * index . search ( "" , 10 , "file" ) ;
76- expect ( scanFiles ) . toHaveBeenCalledTimes ( 2 ) ;
7766 } ) ,
7867 ) ,
7968) ;
@@ -157,20 +146,14 @@ it.effect("continues whole-word searches after a filtered grep page", () =>
157146 value : grepResult ( "needleSuffix" , [ [ 0 , 6 ] ] , nextCursor ) ,
158147 } ,
159148 ) ;
160- using now = vi . spyOn ( performance , "now" ) . mockReturnValue ( 0 ) ;
161149 const finder = {
162150 destroy : vi . fn ( ) ,
163151 waitForIndexReady : vi . fn ( async ( ) => ( { ok : true as const , value : true } ) ) ,
164- scanFiles : ( ) => {
165- now . mockReturnValue ( 1_000 ) ;
166- return { ok : true as const , value : undefined } ;
167- } ,
168152 grep,
169153 } as unknown as FileFinder ;
170154 vi . spyOn ( FileFinder , "create" ) . mockReturnValueOnce ( { ok : true , value : finder } ) ;
171155
172156 const searchIndex = yield * WorkspaceSearchIndex . make ( "/workspace/project" , "content" ) ;
173- yield * TestClock . adjust ( "5 minutes" ) ;
174157 const result = yield * searchIndex . searchContents ( {
175158 query : "needle" ,
176159 limit : 1 ,
0 commit comments