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