@@ -199,4 +199,39 @@ suite('Pip Utils - getProjectInstallable', () => {
199199 assert . ok ( firstResult . uri , 'Should have a URI' ) ;
200200 assert . ok ( firstResult . uri . fsPath . startsWith ( workspacePath ) , 'Should be in workspace directory' ) ;
201201 } ) ;
202+
203+ test ( 'should sort shallower files before deeper ones' , async ( ) => {
204+ // Arrange: Use the shared workspacePath from setup() so paths are platform-safe.
205+ const workspacePath = Uri . file ( '/test/path/root' ) . fsPath ;
206+ const rootReqPath = path . join ( workspacePath , 'requirements.txt' ) ;
207+ const subdirReqPath = path . join ( workspacePath , 'subdir' , 'dev-requirements.txt' ) ;
208+ const deepReqPath = path . join ( workspacePath , 'deep' , 'nested' , 'sub' , 'requirements.txt' ) ;
209+
210+ // Return files at different depths, with deeper ones discovered first.
211+ findFilesStub . callsFake ( ( pattern : string ) => {
212+ if ( pattern === '**/*requirements*.txt' ) {
213+ return Promise . resolve ( [ Uri . file ( deepReqPath ) , Uri . file ( subdirReqPath ) ] ) ;
214+ } else if ( pattern === '*requirements*.txt' ) {
215+ return Promise . resolve ( [ Uri . file ( rootReqPath ) ] ) ;
216+ } else if ( pattern === '**/requirements/*.txt' ) {
217+ return Promise . resolve ( [ ] ) ;
218+ } else if ( pattern === '**/pyproject.toml' ) {
219+ return Promise . resolve ( [ ] ) ;
220+ }
221+ return Promise . resolve ( [ ] ) ;
222+ } ) ;
223+
224+ // Act
225+ const projects = [ { name : 'workspace' , uri : Uri . file ( workspacePath ) } ] ;
226+ const result = ( await getProjectInstallable ( mockApi as PythonEnvironmentApi , projects ) ) . installables ;
227+
228+ // Assert: order by fsPath so the two `requirements.txt` files are unambiguous.
229+ assert . strictEqual ( result . length , 3 ) ;
230+ const fsPaths = result . map ( ( r ) => r . uri ! . fsPath ) ;
231+ assert . deepStrictEqual (
232+ fsPaths ,
233+ [ rootReqPath , subdirReqPath , deepReqPath ] ,
234+ 'Files should be ordered by depth relative to the project root' ,
235+ ) ;
236+ } ) ;
202237} ) ;
0 commit comments