diff --git a/src/lib/commands/ls.test.ts b/src/lib/commands/ls.test.ts index 32923391..c082f4af 100644 --- a/src/lib/commands/ls.test.ts +++ b/src/lib/commands/ls.test.ts @@ -131,10 +131,19 @@ describe('LsCommand', () => { expect(result.stderr).toContain('No such file or directory'); }); - it('should reject absolute paths', async () => { + it('should handle absolute paths', async () => { + vi.mocked(mockFS.stat).mockResolvedValue({ + isDirectory: () => true, + isFile: () => false, + }); + vi.mocked(mockFS.readdir).mockResolvedValue([ + { name: 'file1.txt', isDirectory: () => false, isFile: () => true }, + ]); + const result = await lsCommand.execute(['/absolute/path'], testCwd); - expect(result.exitCode).toBe(1); - expect(result.stderr).toContain('absolute paths are not supported'); + expect(result.exitCode).toBe(0); + expect(mockFS.stat).toHaveBeenCalledWith('/absolute/path'); + expect(result.stdout).toContain('file1.txt'); }); }); \ No newline at end of file diff --git a/src/lib/commands/ls.ts b/src/lib/commands/ls.ts index 58bff599..162d499c 100644 --- a/src/lib/commands/ls.ts +++ b/src/lib/commands/ls.ts @@ -28,12 +28,10 @@ export class LsCommand implements ShellCommand { for (const path of targetPaths) { try { - // Handle absolute paths - if (path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path)) { - return createErrorResult(`${this.name}: absolute paths are not supported: ${path}`); - } - - const absolutePath = join(cwd, path); + // Determine the absolute path + const absolutePath = path.startsWith('/') || path.startsWith('\\') || /^[A-Za-z]:[\\/]/.test(path) + ? path // Already absolute + : join(cwd, path); // Make relative path absolute const stats = await this.fs.stat(absolutePath); if (stats.isFile()) {