@@ -6,15 +6,8 @@ import { fileExistsAtPath } from "../../../utils/fs"
66import { ToolUse , ToolResponse } from "../../../shared/tools"
77import { insertContentTool } from "../insertContentTool"
88
9- // Mock the path module to return consistent Unix-style paths
10- vi . mock ( "path" , async ( ) => {
11- const originalPath = await vi . importActual ( "path" )
12- return {
13- default : originalPath ,
14- ...originalPath ,
15- resolve : vi . fn ( ) . mockImplementation ( ( ...args ) => args . join ( "/" ) ) ,
16- }
17- } )
9+ // Helper to normalize paths to POSIX format for cross-platform testing
10+ const toPosix = ( filePath : string ) => filePath . replace ( / \\ / g, "/" )
1811
1912// Mock external dependencies
2013vi . mock ( "fs/promises" , ( ) => ( {
@@ -71,10 +64,6 @@ describe("insertContentTool", () => {
7164 beforeEach ( ( ) => {
7265 vi . clearAllMocks ( )
7366
74- // Configure path module mocks to return consistent Unix-style paths
75- const mockedPathResolve = vi . mocked ( path . resolve )
76- mockedPathResolve . mockReturnValue ( absoluteFilePath )
77-
7867 mockedFileExistsAtPath . mockResolvedValue ( true ) // Assume file exists by default for insert
7968 mockedFsReadFile . mockResolvedValue ( "" ) // Default empty file content
8069
@@ -192,7 +181,9 @@ describe("insertContentTool", () => {
192181 { fileExists : false , fileContent : "" } ,
193182 )
194183
195- expect ( mockedFileExistsAtPath ) . toHaveBeenCalledWith ( expect . stringContaining ( testFilePath ) )
184+ // Normalize the path that was called with to POSIX format for comparison
185+ const calledPath = mockedFileExistsAtPath . mock . calls [ 0 ] [ 0 ]
186+ expect ( toPosix ( calledPath ) ) . toContain ( testFilePath )
196187 expect ( mockedFsReadFile ) . not . toHaveBeenCalled ( )
197188 expect ( mockCline . diffViewProvider . update ) . toHaveBeenCalledWith ( contentToInsert , true )
198189 expect ( mockCline . diffViewProvider . editType ) . toBe ( "create" )
@@ -202,7 +193,9 @@ describe("insertContentTool", () => {
202193 it ( "creates an empty new file if content is empty string" , async ( ) => {
203194 await executeInsertContentTool ( { line : "1" , content : "" } , { fileExists : false , fileContent : "" } )
204195
205- expect ( mockedFileExistsAtPath ) . toHaveBeenCalledWith ( expect . stringContaining ( testFilePath ) )
196+ // Normalize the path that was called with to POSIX format for comparison
197+ const calledPath = mockedFileExistsAtPath . mock . calls [ 0 ] [ 0 ]
198+ expect ( toPosix ( calledPath ) ) . toContain ( testFilePath )
206199 expect ( mockedFsReadFile ) . not . toHaveBeenCalled ( )
207200 expect ( mockCline . diffViewProvider . update ) . toHaveBeenCalledWith ( "" , true )
208201 expect ( mockCline . diffViewProvider . editType ) . toBe ( "create" )
@@ -216,7 +209,9 @@ describe("insertContentTool", () => {
216209 { fileExists : false , fileContent : "" } ,
217210 )
218211
219- expect ( mockedFileExistsAtPath ) . toHaveBeenCalledWith ( expect . stringContaining ( testFilePath ) )
212+ // Normalize the path that was called with to POSIX format for comparison
213+ const calledPath = mockedFileExistsAtPath . mock . calls [ 0 ] [ 0 ]
214+ expect ( toPosix ( calledPath ) ) . toContain ( testFilePath )
220215 expect ( mockedFsReadFile ) . not . toHaveBeenCalled ( )
221216 expect ( mockCline . consecutiveMistakeCount ) . toBe ( 1 )
222217 expect ( mockCline . recordToolError ) . toHaveBeenCalledWith ( "insert_content" )
0 commit comments