File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -403,8 +403,16 @@ export class Editor implements OpenAIEeditor {
403403 }
404404
405405 private resolve ( relativePath : string ) : string {
406+ // If the path already starts with the root, strip it to get the relative part
407+ let pathToProcess = relativePath ;
408+ if ( relativePath . startsWith ( this . root ) ) {
409+ pathToProcess = relativePath . slice ( this . root . length ) ;
410+ // Remove leading slash if present after stripping root
411+ pathToProcess = pathToProcess . replace ( / ^ \/ / , '' ) ;
412+ }
413+
406414 // Remove leading ./ or / if present, then join with root
407- const normalized = relativePath . replace ( / ^ \. \/ / , '' ) . replace ( / ^ \/ / , '' ) ;
415+ const normalized = pathToProcess . replace ( / ^ \. \/ / , '' ) . replace ( / ^ \/ / , '' ) ;
408416 const resolved = normalized ? `${ this . root } /${ normalized } ` : this . root ;
409417
410418 // Normalize path separators first
Original file line number Diff line number Diff line change @@ -403,5 +403,32 @@ describe('Editor', () => {
403403 ) ;
404404 expect ( mockSandbox . writeFile ) . not . toHaveBeenCalled ( ) ;
405405 } ) ;
406+
407+ it ( 'should handle absolute paths within workspace' , async ( ) => {
408+ applyDiffMock . mockReturnValueOnce ( 'content' ) ;
409+
410+ const mockSandbox : MockSandbox = {
411+ mkdir : vi . fn ( ) . mockResolvedValue ( undefined ) ,
412+ writeFile : vi . fn ( ) . mockResolvedValue ( undefined )
413+ } ;
414+
415+ const editor = new Editor (
416+ mockSandbox as unknown as Sandbox ,
417+ '/workspace'
418+ ) ;
419+ const operation = {
420+ type : 'create_file' ,
421+ path : '/workspace/file.txt' ,
422+ diff : 'content'
423+ } as Extract < ApplyPatchOperation , { type : 'create_file' } > ;
424+
425+ await editor . createFile ( operation ) ;
426+
427+ expect ( mockSandbox . writeFile ) . toHaveBeenCalledWith (
428+ '/workspace/file.txt' , // Not /workspace/workspace/file.txt
429+ 'content' ,
430+ { encoding : 'utf-8' }
431+ ) ;
432+ } ) ;
406433 } ) ;
407434} ) ;
You can’t perform that action at this time.
0 commit comments