Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/setupTests.stest.ts
13389 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
import * as assert from 'assert';
6
import * as path from 'path';
7
import type { ChatResponseFileTree } from 'vscode';
8
import { createTextDocumentData } from '../../src/util/common/test/shims/textDocument';
9
import { URI } from '../../src/util/vs/base/common/uri';
10
import { rubric } from '../base/rubric';
11
import { ssuite, stest } from '../base/stest';
12
import { validate } from '../base/validate';
13
import { discoverScenarios } from '../e2e/scenarioLoader';
14
import { generateScenarioTestRunner } from '../e2e/scenarioTest';
15
16
ssuite({ title: 'setupTests - recommend', location: 'panel' }, () => {
17
const scenarioFolder = path.join(__dirname, '..', 'test/scenarios/test-setupTestRecommend');
18
const scenarios = discoverScenarios(scenarioFolder);
19
for (const scenario of scenarios) {
20
stest({ description: scenario[0].json.name }, collection => {
21
const runner = generateScenarioTestRunner(
22
scenario.map(tcase => ({
23
...tcase,
24
setupCase(accessor, workspace) {
25
const files = (tcase.json as any).files || [];
26
for (const file of files) {
27
workspace.addDocument(createTextDocumentData(
28
URI.joinPath(workspace.workspaceFolders[0], file),
29
'',
30
''
31
));
32
}
33
},
34
})),
35
async (accessor, question, answer, rawResponse, turn, scenarioIndex, commands, confirmations) => {
36
assert.ok(scenario[0].json.keywords, 'expected test case to have keywords');
37
assert.ok(confirmations.length, 'expected to have a confirmation part');
38
const err = validate(confirmations[0].buttons!.join(' ').toLowerCase(), scenario[0].json.keywords);
39
if (err) {
40
return { success: false, errorMessage: err };
41
}
42
43
return { success: true, errorMessage: answer };
44
}
45
);
46
47
return runner(collection);
48
});
49
}
50
});
51
52
ssuite({ title: 'setupTests - invoke', location: 'panel' }, () => {
53
const scenarioFolder = path.join(__dirname, '..', 'test/scenarios/test-setupTest');
54
const scenarios = discoverScenarios(scenarioFolder);
55
for (const scenario of scenarios) {
56
stest({ description: scenario[0].json.name }, collection => {
57
const runner = generateScenarioTestRunner(
58
scenario.map(tcase => ({
59
...tcase,
60
setupCase(accessor, workspace) {
61
const files = (tcase.json as any).files || [];
62
for (const file of files) {
63
workspace.addDocument(createTextDocumentData(
64
URI.joinPath(workspace.workspaceFolders[0], file),
65
'',
66
''
67
));
68
}
69
},
70
})),
71
async (accessor, question, answer, rawResponse, turn, scenarioIndex, commands, confirmations, fileTree) => {
72
const e: {
73
filePatterns: string[];
74
installCommandPattern: string;
75
runCommandPattern: string;
76
} = (scenario[0].json as any).expectations;
77
78
const files: string[] = [];
79
const serializeFileTree = (node: ChatResponseFileTree, path: string = ''): void => {
80
if (node.children) {
81
node.children.forEach(child => serializeFileTree(child, `${path}${node.name}/`));
82
} else {
83
files.push(path + node.name);
84
}
85
};
86
fileTree[0].value.forEach(v => serializeFileTree(v));
87
88
rubric(accessor,
89
() => {
90
for (const pattern of e.filePatterns) {
91
assert.ok(files.some(f => f.match(pattern)), `expected file to match ${pattern}`);
92
}
93
},
94
() => assert.ok(rawResponse.match(e.installCommandPattern), 'expected to have an install command pattern'),
95
() => assert.ok(rawResponse.match(e.runCommandPattern), 'expected to have a run command pattern'),
96
);
97
98
return { success: true };
99
}
100
);
101
102
return runner(collection);
103
});
104
}
105
});
106
107