@@ -1020,6 +1020,14 @@ describe("read_file tool XML output structure", () => {
10201020 } )
10211021
10221022 it ( "should handle errors in multiple file entries independently" , async ( ) => {
1023+ // Helper function to normalize paths for cross-platform compatibility
1024+ const normalizePath = ( filePath : string ) : string => {
1025+ const normalized = filePath . replace ( / \\ / g, "/" )
1026+ // Extract the relative path part (e.g., "test/valid.txt" from any absolute path)
1027+ const match = normalized . match ( / t e s t \/ ( v a l i d | i n v a l i d ) \. t x t $ / )
1028+ return match ? `test/${ match [ 1 ] } .txt` : normalized
1029+ }
1030+
10231031 // Setup
10241032 const validPath = "test/valid.txt"
10251033 const invalidPath = "test/invalid.txt"
@@ -1030,8 +1038,9 @@ describe("read_file tool XML output structure", () => {
10301038 const normalizedInvalidPath = "/test/invalid.txt"
10311039
10321040 mockedPathResolve . mockImplementation ( ( _ : string , filePath : string ) => {
1033- if ( filePath === validPath ) return normalizedValidPath
1034- if ( filePath === invalidPath ) return normalizedInvalidPath
1041+ const normalizedInput = normalizePath ( filePath )
1042+ if ( normalizedInput === validPath ) return normalizedValidPath
1043+ if ( normalizedInput === invalidPath ) return normalizedInvalidPath
10351044 return filePath
10361045 } )
10371046
@@ -1059,28 +1068,26 @@ describe("read_file tool XML output structure", () => {
10591068
10601069 // Mock file operations to track operation order
10611070 mockedCountFileLines . mockImplementation ( ( filePath : string ) => {
1062- const normalizedPath = filePath . replace ( / \\ / g, "/" )
1063- const relPath = normalizedPath === normalizedValidPath ? validPath : invalidPath
1064- validationOrder . push ( `countLines:${ relPath } ` )
1065- if ( normalizedPath === normalizedValidPath || normalizedPath . endsWith ( validPath ) ) {
1071+ const normalizedInput = normalizePath ( filePath )
1072+ validationOrder . push ( `countLines:${ normalizedInput } ` )
1073+ if ( normalizedInput === validPath ) {
10661074 return Promise . resolve ( 1 )
10671075 }
10681076 throw new Error ( "File not found" )
10691077 } )
10701078
10711079 mockedIsBinaryFile . mockImplementation ( ( filePath : string ) => {
1072- const normalizedPath = filePath . replace ( / \\ / g, "/" )
1073- const relPath = normalizedPath === normalizedValidPath ? validPath : invalidPath
1074- validationOrder . push ( `isBinary:${ relPath } ` )
1075- if ( normalizedPath === normalizedValidPath || normalizedPath . endsWith ( validPath ) ) {
1080+ const normalizedInput = normalizePath ( filePath )
1081+ validationOrder . push ( `isBinary:${ normalizedInput } ` )
1082+ if ( normalizedInput === validPath ) {
10761083 return Promise . resolve ( false )
10771084 }
10781085 throw new Error ( "File not found" )
10791086 } )
10801087
10811088 mockedExtractTextFromFile . mockImplementation ( ( filePath : string ) => {
1082- const normalizedPath = filePath . replace ( / \\ / g , "/" )
1083- if ( normalizedPath === normalizedValidPath || normalizedPath . endsWith ( validPath ) ) {
1089+ const normalizedInput = normalizePath ( filePath )
1090+ if ( normalizedInput === validPath ) {
10841091 validationOrder . push ( `extract:${ validPath } ` )
10851092 return Promise . resolve ( numberedContent )
10861093 }
0 commit comments