diff options
| author | joshualitt <[email protected]> | 2025-08-07 10:05:37 -0700 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-08-07 17:05:37 +0000 |
| commit | 8bac9e7d048c7ff97f0942b23edb0167ee6ca83e (patch) | |
| tree | c1a4d73348256a152e7c3dad2bbd89979a2ca30d /packages/core/src/tools/glob.test.ts | |
| parent | 0d65baf9283138da56cdf08b00058ab3cf8cbaf9 (diff) | |
Migrate EditTool, GrepTool, and GlobTool to DeclarativeTool (#5744)
Diffstat (limited to 'packages/core/src/tools/glob.test.ts')
| -rw-r--r-- | packages/core/src/tools/glob.test.ts | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/packages/core/src/tools/glob.test.ts b/packages/core/src/tools/glob.test.ts index 0ee6c0ee..934b7ce7 100644 --- a/packages/core/src/tools/glob.test.ts +++ b/packages/core/src/tools/glob.test.ts @@ -64,7 +64,8 @@ describe('GlobTool', () => { describe('execute', () => { it('should find files matching a simple pattern in the root', async () => { const params: GlobToolParams = { pattern: '*.txt' }; - const result = await globTool.execute(params, abortSignal); + 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')); @@ -73,7 +74,8 @@ describe('GlobTool', () => { it('should find files case-sensitively when case_sensitive is true', async () => { const params: GlobToolParams = { pattern: '*.txt', case_sensitive: true }; - const result = await globTool.execute(params, abortSignal); + 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( @@ -83,7 +85,8 @@ describe('GlobTool', () => { it('should find files case-insensitively by default (pattern: *.TXT)', async () => { const params: GlobToolParams = { pattern: '*.TXT' }; - const result = await globTool.execute(params, abortSignal); + 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')); @@ -94,7 +97,8 @@ describe('GlobTool', () => { pattern: '*.TXT', case_sensitive: false, }; - const result = await globTool.execute(params, abortSignal); + 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')); @@ -102,7 +106,8 @@ describe('GlobTool', () => { it('should find files using a pattern that includes a subdirectory', async () => { const params: GlobToolParams = { pattern: 'sub/*.md' }; - const result = await globTool.execute(params, abortSignal); + 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'), @@ -114,7 +119,8 @@ describe('GlobTool', () => { it('should find files in a specified relative path (relative to rootDir)', async () => { const params: GlobToolParams = { pattern: '*.md', path: 'sub' }; - const result = await globTool.execute(params, abortSignal); + 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'), @@ -126,7 +132,8 @@ describe('GlobTool', () => { it('should find files using a deep globstar pattern (e.g., **/*.log)', async () => { const params: GlobToolParams = { pattern: '**/*.log' }; - const result = await globTool.execute(params, abortSignal); + 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'), @@ -135,7 +142,8 @@ describe('GlobTool', () => { it('should return "No files found" message when pattern matches nothing', async () => { const params: GlobToolParams = { pattern: '*.nonexistent' }; - const result = await globTool.execute(params, abortSignal); + const invocation = globTool.build(params); + const result = await invocation.execute(abortSignal); expect(result.llmContent).toContain( 'No files found matching pattern "*.nonexistent"', ); @@ -144,7 +152,8 @@ describe('GlobTool', () => { it('should correctly sort files by modification time (newest first)', async () => { const params: GlobToolParams = { pattern: '*.sortme' }; - const result = await globTool.execute(params, abortSignal); + const invocation = globTool.build(params); + const result = await invocation.execute(abortSignal); const llmContent = partListUnionToString(result.llmContent); expect(llmContent).toContain('Found 2 file(s)'); @@ -242,8 +251,8 @@ describe('GlobTool', () => { // Let's try to go further up. const paramsOutside: GlobToolParams = { pattern: '*.txt', - path: '../../../../../../../../../../tmp', - }; // Definitely outside + path: '../../../../../../../../../../tmp', // Definitely outside + }; expect(specificGlobTool.validateToolParams(paramsOutside)).toContain( 'resolves outside the allowed workspace directories', ); @@ -290,7 +299,8 @@ describe('GlobTool', () => { it('should work with paths in workspace subdirectories', async () => { const params: GlobToolParams = { pattern: '*.md', path: 'sub' }; - const result = await globTool.execute(params, abortSignal); + const invocation = globTool.build(params); + const result = await invocation.execute(abortSignal); expect(result.llmContent).toContain('Found 2 file(s)'); expect(result.llmContent).toContain('fileC.md'); |
