@@ -122,6 +122,81 @@ describe('structuredContent schema compliance', () => {
122122 // The content should contain success message
123123 expect ( structuredContent . content ) . toContain ( 'Successfully moved' ) ;
124124 } ) ;
125+
126+ it ( 'should reject an existing destination without replacing it' , async ( ) => {
127+ const sourcePath = path . join ( testDir , 'source.txt' ) ;
128+ const destPath = path . join ( testDir , 'existing.txt' ) ;
129+ await fs . writeFile ( sourcePath , 'source content' ) ;
130+ await fs . writeFile ( destPath , 'existing content' ) ;
131+
132+ const result = await client . callTool ( {
133+ name : 'move_file' ,
134+ arguments : {
135+ source : sourcePath ,
136+ destination : destPath
137+ }
138+ } ) ;
139+
140+ expect ( result . isError ) . toBe ( true ) ;
141+ expect ( result . content [ 0 ] ) . toMatchObject ( { type : 'text' } ) ;
142+ expect ( ( result . content [ 0 ] as { text : string } ) . text ) . toContain (
143+ 'Destination already exists'
144+ ) ;
145+ await expect ( fs . readFile ( sourcePath , 'utf8' ) ) . resolves . toBe ( 'source content' ) ;
146+ await expect ( fs . readFile ( destPath , 'utf8' ) ) . resolves . toBe ( 'existing content' ) ;
147+ } ) ;
148+
149+ it ( 'should move directories recursively without replacing an existing tree' , async ( ) => {
150+ const sourcePath = path . join ( testDir , 'source-dir' ) ;
151+ const destPath = path . join ( testDir , 'moved-dir' ) ;
152+ await fs . mkdir ( path . join ( sourcePath , 'nested' ) , { recursive : true } ) ;
153+ await fs . writeFile ( path . join ( sourcePath , 'nested' , 'file.txt' ) , 'source content' ) ;
154+
155+ const result = await client . callTool ( {
156+ name : 'move_file' ,
157+ arguments : {
158+ source : sourcePath ,
159+ destination : destPath
160+ }
161+ } ) ;
162+
163+ expect ( result . isError ) . not . toBe ( true ) ;
164+ await expect ( fs . stat ( sourcePath ) ) . rejects . toMatchObject ( { code : 'ENOENT' } ) ;
165+ await expect (
166+ fs . readFile ( path . join ( destPath , 'nested' , 'file.txt' ) , 'utf8' )
167+ ) . resolves . toBe ( 'source content' ) ;
168+ } ) ;
169+
170+ it ( 'should reject an existing directory destination without merging trees' , async ( ) => {
171+ const sourcePath = path . join ( testDir , 'source-dir' ) ;
172+ const destPath = path . join ( testDir , 'existing-dir' ) ;
173+ await fs . mkdir ( sourcePath ) ;
174+ await fs . mkdir ( destPath ) ;
175+ await fs . writeFile ( path . join ( sourcePath , 'source.txt' ) , 'source content' ) ;
176+ await fs . writeFile ( path . join ( destPath , 'existing.txt' ) , 'existing content' ) ;
177+
178+ const result = await client . callTool ( {
179+ name : 'move_file' ,
180+ arguments : {
181+ source : sourcePath ,
182+ destination : destPath
183+ }
184+ } ) ;
185+
186+ expect ( result . isError ) . toBe ( true ) ;
187+ expect ( ( result . content [ 0 ] as { text : string } ) . text ) . toContain (
188+ 'Destination already exists'
189+ ) ;
190+ await expect (
191+ fs . readFile ( path . join ( sourcePath , 'source.txt' ) , 'utf8' )
192+ ) . resolves . toBe ( 'source content' ) ;
193+ await expect (
194+ fs . readFile ( path . join ( destPath , 'existing.txt' ) , 'utf8' )
195+ ) . resolves . toBe ( 'existing content' ) ;
196+ await expect ( fs . stat ( path . join ( destPath , 'source.txt' ) ) ) . rejects . toMatchObject ( {
197+ code : 'ENOENT'
198+ } ) ;
199+ } ) ;
125200 } ) ;
126201
127202 describe ( 'list_directory (control - already working)' , ( ) => {
0 commit comments