Path: blob/main/extensions/copilot/test/e2e/findFilesTool.stest.ts
13388 views
/*---------------------------------------------------------------------------------------------1* Copyright (c) Microsoft Corporation. All rights reserved.2* Licensed under the MIT License. See License.txt in the project root for license information.3*--------------------------------------------------------------------------------------------*/45import assert from 'assert';6import path from 'path';7import { ToolName } from '../../src/extension/tools/common/toolNames';8import { IFindFilesToolParams } from '../../src/extension/tools/node/findFilesTool';9import { deserializeWorkbenchState } from '../../src/platform/test/node/promptContextModel';10import { ssuite, stest } from '../base/stest';11import { generateToolTestRunner } from './toolSimTest';12import { shouldSkipAgentTests } from './tools.stest';1314ssuite.optional(shouldSkipAgentTests, { title: 'findFilesTool', subtitle: 'toolCalling', location: 'panel' }, () => {15const scenarioFolder = path.join(__dirname, '..', 'test/scenarios/test-tools');16const getState = () => deserializeWorkbenchState(scenarioFolder, path.join(scenarioFolder, 'tools.state.json'));1718stest('proper glob patterns', generateToolTestRunner({19question: 'which folder are my tsx and jsx files in?',20scenarioFolderPath: '',21getState,22expectedToolCalls: ToolName.FindFiles,23tools: {24[ToolName.FindFiles]: true,25[ToolName.FindTextInFiles]: true,26[ToolName.ReadFile]: true,27[ToolName.EditFile]: true,28[ToolName.Codebase]: true,29[ToolName.ListDirectory]: true,30[ToolName.SearchWorkspaceSymbols]: true,31},32}, {33allowParallelToolCalls: true,34toolCallValidators: {35[ToolName.FindFiles]: async (toolCalls) => {36if (toolCalls.length === 1) {37const input = toolCalls[0].input as IFindFilesToolParams;38assert.ok(input.query.includes('**/'), 'should match **/');39assert.ok(input.query.includes('tsx') && input.query.includes('jsx'), 'should match *.tsx and *.jsx');40} else if (toolCalls.length === 2) {41const input1 = toolCalls[0].input as IFindFilesToolParams;42const input2 = toolCalls[1].input as IFindFilesToolParams;43const queries = `${input1.query}, ${input2.query}`;44assert.ok(queries.includes('**/'), 'should match **/');45assert.ok(queries.includes('.tsx') && queries.includes('.jsx'), 'should match *.tsx and *.jsx');46} else {47throw new Error('Too many tool calls');48}49}50}51}));52});535455