Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/e2e/explain.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 * as path from 'path';
7
import { getLanguage } from '../../src/util/common/languages';
8
import { ssuite, stest } from '../base/stest';
9
import { validate } from '../base/validate';
10
import { fetchConversationScenarios } from './scenarioLoader';
11
import { generateScenarioTestRunner } from './scenarioTest';
12
13
ssuite({ title: 'explain', subtitle: 'expanded context', location: 'panel' }, (inputPath) => {
14
15
const scenarioFolder = inputPath ?? path.join(__dirname, '..', 'test/scenarios/test-explain');
16
const scenarios = fetchConversationScenarios(scenarioFolder);
17
18
for (const scenario of scenarios) {
19
const language = scenario[0].getState?.().activeTextEditor?.document.languageId;
20
stest({ description: scenario[0].json.description ?? scenario[0].question.replace('/explain', ''), language: language ? getLanguage(language).languageId : undefined }, generateScenarioTestRunner(
21
scenario,
22
async (accessor, question, answer) => {
23
// Answers should not contain speculation
24
const containsSpeculation = validate(answer, [{ not: [{ anyOf: ['presumably', 'unclear'] }] }]);
25
if (containsSpeculation) {
26
return { success: false, errorMessage: 'Answer contained speculation about current selection' };
27
}
28
29
if (scenario[0].json.keywords !== undefined) {
30
const err = validate(answer, scenario[0].json.keywords);
31
if (err) {
32
return { success: false, errorMessage: err };
33
}
34
35
return { success: true, errorMessage: answer };
36
}
37
38
return { success: true, errorMessage: 'No requirements set for test.' };
39
}
40
));
41
}
42
});
43
44