Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/filesystem/__tests__/structured-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,29 @@ describe('structuredContent schema compliance', () => {
// The content should contain success message
expect(structuredContent.content).toContain('Successfully moved');
});

it('should reject an existing destination without replacing it', async () => {
const sourcePath = path.join(testDir, 'source.txt');
const destPath = path.join(testDir, 'existing.txt');
await fs.writeFile(sourcePath, 'source content');
await fs.writeFile(destPath, 'existing content');

const result = await client.callTool({
name: 'move_file',
arguments: {
source: sourcePath,
destination: destPath
}
});

expect(result.isError).toBe(true);
expect(result.content[0]).toMatchObject({ type: 'text' });
expect((result.content[0] as { text: string }).text).toContain(
'Destination already exists'
);
await expect(fs.readFile(sourcePath, 'utf8')).resolves.toBe('source content');
await expect(fs.readFile(destPath, 'utf8')).resolves.toBe('existing content');
});
});

describe('list_directory (control - already working)', () => {
Expand Down
10 changes: 10 additions & 0 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,16 @@ server.registerTool(
async (args: z.infer<typeof MoveFileArgsSchema>) => {
const validSourcePath = await validatePath(args.source);
const validDestPath = await validatePath(args.destination);

try {
await fs.lstat(validDestPath);
throw new Error(`Destination already exists: ${args.destination}`);
} catch (error) {
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
throw error;
}
}

await fs.rename(validSourcePath, validDestPath);
const text = `Successfully moved ${args.source} to ${args.destination}`;
const contentBlock = { type: "text" as const, text };
Expand Down
Loading