@@ -170,6 +170,39 @@ describe("CodeIndexManager - handleSettingsChange regression", () => {
170170 } )
171171
172172 describe ( "handleSettingsChange" , ( ) => {
173+ it ( "does not remain initialized when disposed during initialization" , async ( ) => {
174+ let finishCreatingServices : ( ( ) => void ) | undefined
175+ const stopIndexing = vi . fn ( )
176+ const loadConfiguration = vi . fn ( ) . mockResolvedValue ( { requiresRestart : false } )
177+ Object . defineProperty ( manager , "_configManager" , {
178+ value : {
179+ loadConfiguration,
180+ isFeatureConfigured : true ,
181+ isFeatureEnabled : true ,
182+ } ,
183+ configurable : true ,
184+ } )
185+ Object . defineProperty ( manager , "_cacheManager" , { value : { } , writable : true } )
186+ Object . defineProperty ( manager , "_recreateServices" , {
187+ value : vi . fn ( async ( ) => {
188+ await new Promise < void > ( ( resolve ) => {
189+ finishCreatingServices = resolve
190+ } )
191+ Object . defineProperty ( manager , "_orchestrator" , { value : { stopIndexing } , writable : true } )
192+ Object . defineProperty ( manager , "_searchService" , { value : { } , writable : true } )
193+ } ) ,
194+ } )
195+ const initialization = manager . initialize ( mockContext )
196+ await Promise . resolve ( )
197+ manager . dispose ( )
198+ finishCreatingServices ?.( )
199+ await initialization
200+
201+ expect ( loadConfiguration ) . toHaveBeenCalledTimes ( 1 )
202+ expect ( stopIndexing ) . toHaveBeenCalledTimes ( 1 )
203+ expect ( manager . isInitialized ) . toBe ( false )
204+ } )
205+
173206 it ( "should log background indexing failures" , async ( ) => {
174207 const indexingError = new Error ( "indexing startup failed" )
175208 const startIndexing = vi . fn ( ) . mockRejectedValue ( indexingError )
0 commit comments