File size: 1,422 Bytes
94193b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import { describe, it, expect, vi, beforeEach } from 'vitest';

const mockVfs = {
  init: vi.fn(),
  getAllFilesAndDirectories: vi.fn().mockResolvedValue([]),
};

vi.mock('@/lib/vfs', () => ({
  getActiveVFS: () => mockVfs,
  vfs: mockVfs,
}));

vi.mock('@/lib/utils', () => ({
  logger: { debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() },
}));

async function exec(cmd: string[], stdin?: string) {
  const { vfsShell } = await import('../cli-shell');
  return vfsShell.execute('test', cmd, stdin);
}

beforeEach(() => {
  vi.clearAllMocks();
  mockVfs.getAllFilesAndDirectories.mockResolvedValue([
    { path: '/data.json', type: 'file' },
    { path: '/index.html', type: 'file' },
    { path: '/styles', type: 'directory' },
    { path: '/styles/app.css', type: 'file' },
  ]);
});

describe('find with a relative current-directory root', () => {
  it('find . resolves to the project root (not the literal path /.)', async () => {
    const result = await exec(['find', '.', '-type', 'f']);
    expect(result.stdout).toContain('/data.json');
    expect(result.stdout).toContain('/index.html');
    expect(result.stdout).toContain('/styles/app.css');
  });

  it('find ./styles resolves under the root', async () => {
    const result = await exec(['find', './styles', '-type', 'f']);
    expect(result.stdout).toContain('/styles/app.css');
    expect(result.stdout).not.toContain('/data.json');
  });
});