@@ -214,4 +214,41 @@ suite('Pip Utils - getProjectInstallable', () => {
214214 const progressOptions = withProgressStub . firstCall . args [ 0 ] as ProgressOptions ;
215215 assert . strictEqual ( progressOptions . cancellable , true , 'Progress should be cancellable' ) ;
216216 } ) ;
217+
218+ test ( 'should handle cancellation during file search' , async ( ) => {
219+ // Arrange: Create a cancellation token that is already cancelled
220+ const cancelledToken : CancellationToken = {
221+ isCancellationRequested : true ,
222+ onCancellationRequested : ( ) => ( { dispose : ( ) => { } } ) ,
223+ } ;
224+
225+ // Mock withProgress to immediately call the callback with the cancelled token
226+ withProgressStub . callsFake (
227+ async (
228+ _options : ProgressOptions ,
229+ callback : (
230+ progress : Progress < { message ?: string ; increment ?: number } > ,
231+ token : CancellationToken ,
232+ ) => Thenable < unknown > ,
233+ ) => {
234+ return await callback ( { } as Progress < { message ?: string ; increment ?: number } > , cancelledToken ) ;
235+ } ,
236+ ) ;
237+
238+ // Mock findFiles to check that token is passed
239+ findFilesStub . callsFake ( ( _pattern : string , _exclude : string , _maxResults : number , token : CancellationToken ) => {
240+ // Verify the cancellation token is passed to findFiles
241+ assert . strictEqual ( token , cancelledToken , 'Cancellation token should be passed to findFiles' ) ;
242+ return Promise . resolve ( [ ] ) ;
243+ } ) ;
244+
245+ // Act: Call getProjectInstallable
246+ const workspacePath = Uri . file ( '/test/path/root' ) . fsPath ;
247+ const projects = [ { name : 'workspace' , uri : Uri . file ( workspacePath ) } ] ;
248+ await getProjectInstallable ( mockApi as PythonEnvironmentApi , projects ) ;
249+
250+ // Assert: Verify findFiles was called with the cancellation token
251+ assert . ok ( findFilesStub . called , 'findFiles should be called' ) ;
252+ assert . strictEqual ( findFilesStub . callCount , 4 , 'Should call findFiles 4 times for different patterns' ) ;
253+ } ) ;
217254} ) ;
0 commit comments