@@ -3,8 +3,11 @@ import { getValidRootDirectories } from '../roots-utils.js';
33import { mkdtempSync , rmSync , mkdirSync , writeFileSync , realpathSync , symlinkSync } from 'fs' ;
44import { tmpdir } from 'os' ;
55import { join } from 'path' ;
6+ import { pathToFileURL } from 'url' ;
67import type { Root } from '@modelcontextprotocol/sdk/types.js' ;
78
9+ const toFileUri = ( filePath : string ) => pathToFileURL ( filePath ) . href ;
10+
811describe ( 'getValidRootDirectories' , ( ) => {
912 let testDir1 : string ;
1013 let testDir2 : string ;
@@ -32,7 +35,7 @@ describe('getValidRootDirectories', () => {
3235 describe ( 'valid directory processing' , ( ) => {
3336 it ( 'should process all URI formats and edge cases' , async ( ) => {
3437 const roots = [
35- { uri : `file:// ${ testDir1 } ` , name : 'File URI' } ,
38+ { uri : toFileUri ( testDir1 ) , name : 'File URI' } ,
3639 { uri : testDir2 , name : 'Plain path' } ,
3740 { uri : testDir3 } // Plain path without name property
3841 ] ;
@@ -50,7 +53,7 @@ describe('getValidRootDirectories', () => {
5053 mkdirSync ( subDir ) ;
5154
5255 const roots = [
53- { uri : `file:// ${ testDir1 } /./subdir/../subdir` , name : 'Complex Path' }
56+ { uri : `${ toFileUri ( testDir1 ) } /./subdir/../subdir` , name : 'Complex Path' }
5457 ] ;
5558
5659 const result = await getValidRootDirectories ( roots ) ;
@@ -59,7 +62,7 @@ describe('getValidRootDirectories', () => {
5962 expect ( result [ 0 ] ) . toBe ( subDir ) ;
6063 } ) ;
6164
62- it ( 'keeps both original and resolved forms for roots that resolve differently' , async ( ) => {
65+ it ( 'keeps both original and resolved forms for roots that resolve differently' , async ( context ) => {
6366 const realDir = join ( testDir1 , 'real-root' ) ;
6467 const aliasDir = join ( testDir1 , 'alias-root' ) ;
6568 mkdirSync ( realDir ) ;
@@ -68,13 +71,14 @@ describe('getValidRootDirectories', () => {
6871 symlinkSync ( realDir , aliasDir ) ;
6972 } catch ( error ) {
7073 if ( ( error as NodeJS . ErrnoException ) . code === 'EPERM' ) {
74+ context . skip ( 'symlink creation is not permitted in this environment' ) ;
7175 return ;
7276 }
7377 throw error ;
7478 }
7579
7680 const roots : Root [ ] = [
77- { uri : `file:// ${ aliasDir } ` , name : 'Symlink Root' }
81+ { uri : toFileUri ( aliasDir ) , name : 'Symlink Root' }
7882 ] ;
7983
8084 const result = await getValidRootDirectories ( roots ) ;
@@ -92,9 +96,9 @@ describe('getValidRootDirectories', () => {
9296 const nonExistentDir = join ( tmpdir ( ) , 'non-existent-directory-12345' ) ;
9397 const invalidPath = '\0invalid\0path' ; // Null bytes cause different error types
9498 const roots = [
95- { uri : `file:// ${ testDir1 } ` , name : 'Valid Dir' } ,
96- { uri : `file:// ${ nonExistentDir } ` , name : 'Non-existent Dir' } ,
97- { uri : `file:// ${ testFile } ` , name : 'File Not Dir' } ,
99+ { uri : toFileUri ( testDir1 ) , name : 'Valid Dir' } ,
100+ { uri : toFileUri ( nonExistentDir ) , name : 'Non-existent Dir' } ,
101+ { uri : toFileUri ( testFile ) , name : 'File Not Dir' } ,
98102 { uri : `file://${ invalidPath } ` , name : 'Invalid Path' }
99103 ] ;
100104
0 commit comments