@@ -42,8 +42,8 @@ vi.mock("@roo-code/telemetry", () => ({
4242} ) )
4343
4444// Mock i18n translator used in orchestrator messages
45- vi . mock ( "../../i18n" , ( ) => ( {
46- t : ( key : string , params ?: any ) => {
45+ vi . mock ( "../../../ i18n" , ( ) => ( {
46+ t : ( key : string , params ?: { errorMessage ?: string } ) => {
4747 if ( key === "embeddings:orchestrator.failedDuringInitialScan" && params ?. errorMessage ) {
4848 return `Failed during initial scan: ${ params . errorMessage } `
4949 }
@@ -259,36 +259,49 @@ describe("CodeIndexOrchestrator - error path cleanup gating", () => {
259259 expect ( calls [ calls . length - 1 ] ) . toBe ( "Error" )
260260 } )
261261
262- it ( "collects batch errors from incremental scan and still completes indexing" , async ( ) => {
263- const batchError = new Error ( "incremental batch failure" )
264- vectorStore . initialize . mockResolvedValue ( false ) // existing collection
265- vectorStore . hasIndexedData . mockResolvedValue ( true ) // force incremental scan path
266- vectorStore . markIndexingIncomplete . mockResolvedValue ( undefined )
267- vectorStore . markIndexingComplete . mockResolvedValue ( undefined )
268-
269- // Incremental scan reports a batch error but returns a result — orchestrator completes normally
270- scanner . scanDirectory . mockImplementation ( async ( _dir : string , onBatchError : ( e : Error ) => void ) => {
271- onBatchError ( batchError )
272- return { stats : { processed : 0 , skipped : 0 } , totalBlockCount : 0 }
273- } )
262+ it . each ( [ 0 , 2 ] ) (
263+ "preserves the existing index on incremental batch failure after %s indexed blocks" ,
264+ async ( indexed ) => {
265+ const batchError = new Error ( "incremental batch failure" )
266+ vectorStore . initialize . mockResolvedValue ( false ) // existing collection
267+ vectorStore . hasIndexedData . mockResolvedValue ( true ) // force incremental scan path
268+ vectorStore . markIndexingIncomplete . mockResolvedValue ( undefined )
269+ vectorStore . markIndexingComplete . mockResolvedValue ( undefined )
270+
271+ scanner . scanDirectory . mockImplementation (
272+ async ( _dir : string , onBatchError : ( e : Error ) => void , onIndexed : ( count : number ) => void ) => {
273+ onIndexed ( indexed )
274+ onBatchError ( batchError )
275+ return { stats : { processed : 1 , skipped : 0 } , totalBlockCount : 3 }
276+ } ,
277+ )
274278
275- const orchestrator = new CodeIndexOrchestrator (
276- configManager ,
277- stateManager ,
278- workspacePath ,
279- cacheManager ,
280- vectorStore ,
281- scanner ,
282- fileWatcher ,
283- )
279+ const orchestrator = new CodeIndexOrchestrator (
280+ configManager ,
281+ stateManager ,
282+ workspacePath ,
283+ cacheManager ,
284+ vectorStore ,
285+ scanner ,
286+ fileWatcher ,
287+ )
284288
285- await orchestrator . startIndexing ( )
289+ await orchestrator . startIndexing ( )
286290
287- // Incremental scan doesn't gate on batch errors — Indexed state is still reached
288- const calls = stateManager . setSystemState . mock . calls . map ( ( c : any [ ] ) => c [ 0 ] )
289- expect ( calls [ calls . length - 1 ] ) . toBe ( "Indexed" )
290- expect ( calls ) . not . toContain ( "Error" )
291- } )
291+ expect ( orchestrator . state ) . toBe ( "Error" )
292+ expect ( stateManager . setSystemState ) . toHaveBeenLastCalledWith (
293+ "Error" ,
294+ expect . stringContaining ( batchError . message ) ,
295+ )
296+ expect ( stateManager . setSystemState ) . not . toHaveBeenCalledWith ( "Indexed" , expect . any ( String ) )
297+ expect ( vectorStore . markIndexingIncomplete ) . toHaveBeenCalledOnce ( )
298+ expect ( vectorStore . markIndexingComplete ) . not . toHaveBeenCalled ( )
299+ expect ( vectorStore . clearCollection ) . not . toHaveBeenCalled ( )
300+ expect ( cacheManager . clearCacheFile ) . not . toHaveBeenCalled ( )
301+ expect ( fileWatcher . initialize ) . not . toHaveBeenCalled ( )
302+ expect ( fileWatcher . dispose ) . toHaveBeenCalledOnce ( )
303+ } ,
304+ )
292305} )
293306
294307describe ( "CodeIndexOrchestrator - stopIndexing" , ( ) => {
0 commit comments