diff options
| author | matt korwel <[email protected]> | 2025-06-12 17:53:10 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-13 00:53:10 +0000 |
| commit | 9a11567f73b166eb9435f7f98877e7aba3ac4d06 (patch) | |
| tree | fb3064f40598657504bde0504a7d10fb98b4ab47 /packages/core/src/tools/glob.test.ts | |
| parent | 181abde2ffa8f1f68b6c540a5600346116cb5145 (diff) | |
Revert "Make glob tool support abortSignal" (#996)
Diffstat (limited to 'packages/core/src/tools/glob.test.ts')
| -rw-r--r-- | packages/core/src/tools/glob.test.ts | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/packages/core/src/tools/glob.test.ts b/packages/core/src/tools/glob.test.ts index 37738ba7..90fe1a2e 100644 --- a/packages/core/src/tools/glob.test.ts +++ b/packages/core/src/tools/glob.test.ts @@ -4,10 +4,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { GlobTool, GlobToolParams, GlobPath, sortFileEntries } from './glob.js'; +import { + GlobTool, + GlobToolParams, + sortFileEntries, + GlobFileEntry, +} from './glob.js'; import { partListUnionToString } from '../core/geminiRequest.js'; +// import { ToolResult } from './tools.js'; // ToolResult is implicitly used by execute import path from 'path'; import fs from 'fs/promises'; +import { Stats } from 'fs'; import os from 'os'; import { describe, it, expect, beforeEach, afterEach } from 'vitest'; // Removed vi import { FileDiscoveryService } from '../services/fileDiscoveryService.js'; @@ -267,9 +274,9 @@ describe('sortFileEntries', () => { const nowTimestamp = new Date('2024-01-15T12:00:00.000Z').getTime(); const oneDayInMs = 24 * 60 * 60 * 1000; - const createFileEntry = (fullpath: string, mtimeDate: Date): GlobPath => ({ - fullpath: () => fullpath, - mtimeMs: mtimeDate.getTime(), + const createFileEntry = (path: string, mtimeDate: Date): GlobFileEntry => ({ + path, + stats: { mtime: mtimeDate } as Stats, }); it('should sort a mix of recent and older files correctly', () => { @@ -282,7 +289,7 @@ describe('sortFileEntries', () => { nowTimestamp - (oneDayInMs + 2 * 60 * 60 * 1000), ); // 26 hours ago - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('older_zebra.txt', olderTime2), createFileEntry('recent_alpha.txt', recentTime1), createFileEntry('older_apple.txt', olderTime1), @@ -291,7 +298,7 @@ describe('sortFileEntries', () => { ]; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); - const sortedPaths = sorted.map((e) => e.fullpath()); + const sortedPaths = sorted.map((e) => e.path); expect(sortedPaths).toEqual([ 'recent_alpha.txt', // Recent, newest @@ -307,28 +314,24 @@ describe('sortFileEntries', () => { const recentTime2 = new Date(nowTimestamp - 2000); const recentTime3 = new Date(nowTimestamp - 3000); // Oldest recent - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('c.txt', recentTime2), createFileEntry('a.txt', recentTime3), createFileEntry('b.txt', recentTime1), ]; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); - expect(sorted.map((e) => e.fullpath())).toEqual([ - 'b.txt', - 'c.txt', - 'a.txt', - ]); + expect(sorted.map((e) => e.path)).toEqual(['b.txt', 'c.txt', 'a.txt']); }); it('should sort only older files alphabetically by path', () => { const olderTime = new Date(nowTimestamp - 2 * oneDayInMs); // All equally old - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('zebra.txt', olderTime), createFileEntry('apple.txt', olderTime), createFileEntry('banana.txt', olderTime), ]; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); - expect(sorted.map((e) => e.fullpath())).toEqual([ + expect(sorted.map((e) => e.path)).toEqual([ 'apple.txt', 'banana.txt', 'zebra.txt', @@ -336,30 +339,30 @@ describe('sortFileEntries', () => { }); it('should handle an empty array', () => { - const entries: GlobPath[] = []; + const entries: GlobFileEntry[] = []; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); expect(sorted).toEqual([]); }); it('should correctly sort files when mtimes are identical for older files', () => { const olderTime = new Date(nowTimestamp - 2 * oneDayInMs); - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('b.txt', olderTime), createFileEntry('a.txt', olderTime), ]; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); - expect(sorted.map((e) => e.fullpath())).toEqual(['a.txt', 'b.txt']); + expect(sorted.map((e) => e.path)).toEqual(['a.txt', 'b.txt']); }); it('should correctly sort files when mtimes are identical for recent files (maintaining mtime sort)', () => { const recentTime = new Date(nowTimestamp - 1000); - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('b.txt', recentTime), createFileEntry('a.txt', recentTime), ]; const sorted = sortFileEntries(entries, nowTimestamp, oneDayInMs); - expect(sorted.map((e) => e.fullpath())).toContain('a.txt'); - expect(sorted.map((e) => e.fullpath())).toContain('b.txt'); + expect(sorted.map((e) => e.path)).toContain('a.txt'); + expect(sorted.map((e) => e.path)).toContain('b.txt'); expect(sorted.length).toBe(2); }); @@ -368,12 +371,12 @@ describe('sortFileEntries', () => { const justUnderThreshold = new Date(nowTimestamp - (1000 - 1)); // Barely recent const customThresholdMs = 1000; // 1 second - const entries: GlobPath[] = [ + const entries: GlobFileEntry[] = [ createFileEntry('older_file.txt', justOverThreshold), createFileEntry('recent_file.txt', justUnderThreshold), ]; const sorted = sortFileEntries(entries, nowTimestamp, customThresholdMs); - expect(sorted.map((e) => e.fullpath())).toEqual([ + expect(sorted.map((e) => e.path)).toEqual([ 'recent_file.txt', 'older_file.txt', ]); |
