File size: 20,395 Bytes
52efc7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import {
  GlobTool,
  sortFileEntries,
  type GlobToolParams,
  type GlobPath,
} from './glob.js';
import { partListUnionToString } from '../core/geminiRequest.js';
import path from 'node:path';
import { isSubpath } from '../utils/paths.js';
import fs from 'node:fs/promises';
import os from 'node:os';
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest';
import { FileDiscoveryService } from '../services/fileDiscoveryService.js';
import type { Config } from '../config/config.js';
import { createMockWorkspaceContext } from '../test-utils/mockWorkspaceContext.js';
import { ToolErrorType } from './tool-error.js';
import * as glob from 'glob';
import { createMockMessageBus } from '../test-utils/mock-message-bus.js';
import {
  DEFAULT_FILE_FILTERING_OPTIONS,
  GEMINI_IGNORE_FILE_NAME,
} from '../config/constants.js';

vi.mock('glob', { spy: true });

describe('GlobTool', () => {
  let tempRootDir: string; // This will be the rootDirectory for the GlobTool instance
  let globTool: GlobTool;
  const abortSignal = new AbortController().signal;
  let mockConfig: Config;

  beforeEach(async () => {
    // Create a unique root directory for each test run
    const rawTempRootDir = await fs.mkdtemp(
      path.join(os.tmpdir(), 'glob-tool-root-'),
    );
    tempRootDir = await fs.realpath(rawTempRootDir);
    await fs.writeFile(path.join(tempRootDir, '.git'), ''); // Fake git repo

    const rootDir = tempRootDir;
    const workspaceContext = createMockWorkspaceContext(rootDir);
    const fileDiscovery = new FileDiscoveryService(rootDir);

    const mockStorage = {
      getProjectTempDir: vi.fn().mockReturnValue('/tmp/project'),
    };

    mockConfig = {
      getTargetDir: () => rootDir,
      getWorkspaceContext: () => workspaceContext,
      getFileService: () => fileDiscovery,
      getFileFilteringOptions: () => DEFAULT_FILE_FILTERING_OPTIONS,
      getFileExclusions: () => ({ getGlobExcludes: () => [] }),
      storage: mockStorage,
      isPathAllowed(this: Config, absolutePath: string): boolean {
        const workspaceContext = this.getWorkspaceContext();
        if (workspaceContext.isPathWithinWorkspace(absolutePath)) {
          return true;
        }

        const projectTempDir = this.storage.getProjectTempDir();
        return isSubpath(path.resolve(projectTempDir), absolutePath);
      },
      validatePathAccess(this: Config, absolutePath: string): string | null {
        if (this.isPathAllowed(absolutePath)) {
          return null;
        }

        const workspaceDirs = this.getWorkspaceContext().getDirectories();
        const projectTempDir = this.storage.getProjectTempDir();
        return `Path not in workspace: Attempted path "${absolutePath}" resolves outside the allowed workspace directories: ${workspaceDirs.join(', ')} or the project temp directory: ${projectTempDir}`;
      },
    } as unknown as Config;

    globTool = new GlobTool(mockConfig, createMockMessageBus());

    // Create some test files and directories within this root
    // Top-level files
    await fs.writeFile(path.join(tempRootDir, 'fileA.txt'), 'contentA');
    await fs.writeFile(path.join(tempRootDir, 'FileB.TXT'), 'contentB'); // Different case for testing

    // Subdirectory and files within it
    await fs.mkdir(path.join(tempRootDir, 'sub'));
    await fs.writeFile(path.join(tempRootDir, 'sub', 'fileC.md'), 'contentC');
    await fs.writeFile(path.join(tempRootDir, 'sub', 'FileD.MD'), 'contentD'); // Different case

    // Deeper subdirectory
    await fs.mkdir(path.join(tempRootDir, 'sub', 'deep'));
    await fs.writeFile(
      path.join(tempRootDir, 'sub', 'deep', 'fileE.log'),
      'contentE',
    );

    // Files for mtime sorting test
    await fs.writeFile(path.join(tempRootDir, 'older.sortme'), 'older_content');
    // Ensure a noticeable difference in modification time
    await new Promise((resolve) => setTimeout(resolve, 50));
    await fs.writeFile(path.join(tempRootDir, 'newer.sortme'), 'newer_content');
  });

  afterEach(async () => {
    // Clean up the temporary root directory
    await fs.rm(tempRootDir, { recursive: true, force: true });
    vi.resetAllMocks();
  });

  describe('execute', () => {
    it('should find files matching a simple pattern in the root', async () => {
      const params: GlobToolParams = { pattern: '*.txt' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 2 file(s)');
      expect(result.llmContent).toContain(path.join(tempRootDir, 'fileA.txt'));
      expect(result.llmContent).toContain(path.join(tempRootDir, 'FileB.TXT'));
      expect(result.returnDisplay).toBe('Found 2 matching file(s)');
    }, 30000);

    it('should find files case-sensitively when case_sensitive is true', async () => {
      const params: GlobToolParams = { pattern: '*.txt', case_sensitive: true };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain(path.join(tempRootDir, 'fileA.txt'));
      expect(result.llmContent).not.toContain(
        path.join(tempRootDir, 'FileB.TXT'),
      );
    }, 30000);

    it('should find files case-insensitively by default (pattern: *.TXT)', async () => {
      const params: GlobToolParams = { pattern: '*.TXT' };
      const invocation = globTool.build(params);

      const result = await invocation.execute({ abortSignal });

      expect(result.llmContent).toContain('fileA.txt');
      expect(result.llmContent).toContain('FileB.TXT');
    }, 30000);

    it('should find files case-insensitively when case_sensitive is false (pattern: *.TXT)', async () => {
      const params: GlobToolParams = {
        pattern: '*.TXT',
        case_sensitive: false,
      };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 2 file(s)');
      expect(result.llmContent).toContain(path.join(tempRootDir, 'fileA.txt'));
      expect(result.llmContent).toContain(path.join(tempRootDir, 'FileB.TXT'));
    }, 30000);

    it('should find files using a pattern that includes a subdirectory', async () => {
      const params: GlobToolParams = { pattern: 'sub/*.md' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 2 file(s)');
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'sub', 'fileC.md'),
      );
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'sub', 'FileD.MD'),
      );
    }, 30000);

    it('should find files in a specified relative path (relative to rootDir)', async () => {
      const params: GlobToolParams = { pattern: '*.md', dir_path: 'sub' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 2 file(s)');
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'sub', 'fileC.md'),
      );
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'sub', 'FileD.MD'),
      );
    }, 30000);

    it('should find files using a deep globstar pattern (e.g., **/*.log)', async () => {
      const params: GlobToolParams = { pattern: '**/*.log' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'sub', 'deep', 'fileE.log'),
      );
    }, 30000);

    it('should return "No files found" message when pattern matches nothing', async () => {
      const params: GlobToolParams = { pattern: '*.nonexistent' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain(
        'No files found matching pattern "*.nonexistent"',
      );
      expect(result.returnDisplay).toBe('No files found');
    }, 30000);

    it('should find files with special characters in the name', async () => {
      await fs.writeFile(path.join(tempRootDir, 'file[1].txt'), 'content');
      const params: GlobToolParams = { pattern: 'file[1].txt' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain(
        path.join(tempRootDir, 'file[1].txt'),
      );
    }, 30000);

    it('should find files with special characters like [] and () in the path', async () => {
      const filePath = path.join(
        tempRootDir,
        'src/app/[test]/(dashboard)/testing/components/code.tsx',
      );
      await fs.mkdir(path.dirname(filePath), { recursive: true });
      await fs.writeFile(filePath, 'content');

      const params: GlobToolParams = {
        pattern: 'src/app/[test]/(dashboard)/testing/components/code.tsx',
      };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain(filePath);
    }, 30000);

    it('should correctly sort files by modification time (newest first)', async () => {
      const params: GlobToolParams = { pattern: '*.sortme' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      const llmContent = partListUnionToString(result.llmContent);
      const newerIndex = llmContent.indexOf('newer.sortme');
      const olderIndex = llmContent.indexOf('older.sortme');
      expect(newerIndex).toBeLessThan(olderIndex);
    }, 30000);

    it('should return a PATH_NOT_IN_WORKSPACE error if path is outside workspace', async () => {
      const params: GlobToolParams = { pattern: '*', dir_path: '/etc' };
      expect(() => globTool.build(params)).toThrow(/Path not in workspace/);
    });

    it('should return a GLOB_EXECUTION_ERROR on glob failure', async () => {
      vi.mocked(glob.glob).mockRejectedValue(new Error('Glob failed'));
      const params: GlobToolParams = { pattern: '*' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });
      expect(result.error?.type).toBe(ToolErrorType.GLOB_EXECUTION_ERROR);
    }, 30000);
  });

  describe('validateToolParams', () => {
    it('should return null for valid parameters', () => {
      const params: GlobToolParams = { pattern: '*.txt' };
      expect(globTool.validateToolParams(params)).toBeNull();
    });

    it('should return null for valid parameters with dir_path', () => {
      const params: GlobToolParams = { pattern: '*.txt', dir_path: 'sub' };
      expect(globTool.validateToolParams(params)).toBeNull();
    });

    it('should return null for valid parameters with absolute dir_path within workspace', async () => {
      const params: GlobToolParams = {
        pattern: '*.txt',
        dir_path: tempRootDir,
      };
      expect(globTool.validateToolParams(params)).toBeNull();
    });

    it('should return error if pattern is missing', () => {
      const params = {} as unknown as GlobToolParams;
      expect(globTool.validateToolParams(params)).toContain(
        "params must have required property 'pattern'",
      );
    });

    it('should return error if pattern is an empty string', () => {
      const params: GlobToolParams = { pattern: '' };
      expect(globTool.validateToolParams(params)).toContain(
        "The 'pattern' parameter cannot be empty",
      );
    });

    it('should return error if pattern is only whitespace', () => {
      const params: GlobToolParams = { pattern: '   ' };
      expect(globTool.validateToolParams(params)).toContain(
        "The 'pattern' parameter cannot be empty",
      );
    });

    it('should return error if dir_path is not a string', () => {
      const params = {
        pattern: '*',
        dir_path: 123,
      } as unknown as GlobToolParams;
      expect(globTool.validateToolParams(params)).toContain(
        'params/dir_path must be string',
      );
    });

    it('should return error if case_sensitive is not a boolean', () => {
      const params = {
        pattern: '*',
        case_sensitive: 'true',
      } as unknown as GlobToolParams;
      expect(globTool.validateToolParams(params)).toContain(
        'params/case_sensitive must be boolean',
      );
    });

    it('should return error if search path resolves outside workspace', () => {
      const params: GlobToolParams = { pattern: '*', dir_path: '../' };
      expect(globTool.validateToolParams(params)).toContain(
        'resolves outside the allowed workspace directories',
      );
    });

    it('should return error if specified search path does not exist', () => {
      const params: GlobToolParams = {
        pattern: '*',
        dir_path: 'non-existent',
      };
      expect(globTool.validateToolParams(params)).toContain(
        'Search path does not exist',
      );
    });

    it('should return error if specified search path is not a directory', async () => {
      await fs.writeFile(path.join(tempRootDir, 'not-a-dir'), 'content');
      const params: GlobToolParams = { pattern: '*', dir_path: 'not-a-dir' };
      expect(globTool.validateToolParams(params)).toContain(
        'Search path is not a directory',
      );
    });
  });

  describe('workspace boundary validation', () => {
    it('should validate search paths are within workspace boundaries', () => {
      expect(globTool.validateToolParams({ pattern: '*' })).toBeNull();
      expect(
        globTool.validateToolParams({ pattern: '*', dir_path: '.' }),
      ).toBeNull();
      expect(
        globTool.validateToolParams({ pattern: '*', dir_path: tempRootDir }),
      ).toBeNull();

      expect(
        globTool.validateToolParams({ pattern: '*', dir_path: '..' }),
      ).toContain('resolves outside the allowed workspace directories');
      expect(
        globTool.validateToolParams({ pattern: '*', dir_path: '/' }),
      ).toContain('resolves outside the allowed workspace directories');
    });

    it('should provide clear error messages when path is outside workspace', () => {
      const result = globTool.validateToolParams({
        pattern: '*',
        dir_path: '/tmp/outside',
      });
      expect(result).toContain(
        'resolves outside the allowed workspace directories',
      );
    });

    it('should work with paths in workspace subdirectories', async () => {
      const subDir = path.join(tempRootDir, 'allowed-sub');
      await fs.mkdir(subDir);
      expect(
        globTool.validateToolParams({ pattern: '*', dir_path: 'allowed-sub' }),
      ).toBeNull();
    });
  });

  describe('ignore file handling', () => {
    it('should respect .gitignore files by default', async () => {
      await fs.writeFile(
        path.join(tempRootDir, '.gitignore'),
        'ignored_test.txt',
      );
      await fs.writeFile(path.join(tempRootDir, 'ignored_test.txt'), 'content');
      await fs.writeFile(path.join(tempRootDir, 'visible_test.txt'), 'content');

      const params: GlobToolParams = { pattern: '*_test.txt' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });

      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain('visible_test.txt');
      expect(result.llmContent).not.toContain('ignored_test.txt');
    }, 30000);

    it('should respect .geminiignore files by default', async () => {
      await fs.writeFile(
        path.join(tempRootDir, GEMINI_IGNORE_FILE_NAME),
        'gemini-ignored_test.txt',
      );
      await fs.writeFile(
        path.join(tempRootDir, 'gemini-ignored_test.txt'),
        'content',
      );
      await fs.writeFile(path.join(tempRootDir, 'visible_test.txt'), 'content');

      const params: GlobToolParams = { pattern: 'visible_test.txt' };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });

      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain('visible_test.txt');
      expect(result.llmContent).not.toContain('gemini-ignored_test.txt');
    }, 30000);

    it('should not respect .gitignore when respect_git_ignore is false', async () => {
      await fs.writeFile(
        path.join(tempRootDir, '.gitignore'),
        'ignored_test.txt',
      );
      await fs.writeFile(path.join(tempRootDir, 'ignored_test.txt'), 'content');

      const params: GlobToolParams = {
        pattern: 'ignored_test.txt',
        respect_git_ignore: false,
      };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });

      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain('ignored_test.txt');
    }, 30000);

    it('should not respect .geminiignore when respect_gemini_ignore is false', async () => {
      await fs.writeFile(
        path.join(tempRootDir, GEMINI_IGNORE_FILE_NAME),
        'gemini-ignored_test.txt',
      );
      await fs.writeFile(
        path.join(tempRootDir, 'gemini-ignored_test.txt'),
        'content',
      );

      const params: GlobToolParams = {
        pattern: 'gemini-ignored_test.txt',
        respect_gemini_ignore: false,
      };
      const invocation = globTool.build(params);
      const result = await invocation.execute({ abortSignal });

      expect(result.llmContent).toContain('Found 1 file(s)');
      expect(result.llmContent).toContain('gemini-ignored_test.txt');
    }, 30000);
  });
});

describe('sortFileEntries', () => {
  const now = 1000000;
  const threshold = 10000;

  it('should sort a mix of recent and older files correctly', () => {
    const entries: GlobPath[] = [
      { fullpath: () => 'older-b.txt', mtimeMs: now - 20000 },
      { fullpath: () => 'recent-b.txt', mtimeMs: now - 1000 },
      { fullpath: () => 'recent-a.txt', mtimeMs: now - 500 },
      { fullpath: () => 'older-a.txt', mtimeMs: now - 30000 },
    ];

    const sorted = sortFileEntries(entries, now, threshold);
    expect(sorted.map((e) => e.fullpath())).toEqual([
      'recent-a.txt', // Recent, newest first
      'recent-b.txt',
      'older-a.txt', // Older, alphabetical
      'older-b.txt',
    ]);
  });

  it('should sort only recent files by mtime descending', () => {
    const entries: GlobPath[] = [
      { fullpath: () => 'a.txt', mtimeMs: now - 2000 },
      { fullpath: () => 'b.txt', mtimeMs: now - 1000 },
    ];
    const sorted = sortFileEntries(entries, now, threshold);
    expect(sorted.map((e) => e.fullpath())).toEqual(['b.txt', 'a.txt']);
  });

  it('should sort only older files alphabetically', () => {
    const entries: GlobPath[] = [
      { fullpath: () => 'b.txt', mtimeMs: now - 20000 },
      { fullpath: () => 'a.txt', mtimeMs: now - 30000 },
    ];
    const sorted = sortFileEntries(entries, now, threshold);
    expect(sorted.map((e) => e.fullpath())).toEqual(['a.txt', 'b.txt']);
  });

  it('should handle an empty array', () => {
    expect(sortFileEntries([], now, threshold)).toEqual([]);
  });

  it('should correctly sort files when mtimeMs is missing', () => {
    const entries: GlobPath[] = [
      { fullpath: () => 'b.txt' },
      { fullpath: () => 'a.txt' },
    ];
    const sorted = sortFileEntries(entries, now, threshold);
    expect(sorted.map((e) => e.fullpath())).toEqual(['a.txt', 'b.txt']);
  });

  it('should use recencyThresholdMs parameter', () => {
    const customThreshold = 5000;
    const entries: GlobPath[] = [
      { fullpath: () => 'old.txt', mtimeMs: now - 8000 },
      { fullpath: () => 'new.txt', mtimeMs: now - 3000 },
    ];
    const sorted = sortFileEntries(entries, now, customThreshold);
    expect(sorted.map((e) => e.fullpath())).toEqual(['new.txt', 'old.txt']);
  });
});