Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/intent/inlineChatIntent.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 fs from 'fs';
7
import { join } from 'path';
8
import { Intent } from '../../src/extension/common/constants';
9
import { EditCodeIntent } from '../../src/extension/intents/node/editCodeIntent';
10
import { GenerateCodeIntent } from '../../src/extension/intents/node/generateCodeIntent';
11
import { ChatLocation } from '../../src/platform/chat/common/commonTypes';
12
import { ssuite, stest } from '../base/stest';
13
import { simulateInlineChat } from '../simulation/inlineChatSimulator';
14
import { fromFixture } from '../simulation/stestUtil';
15
import { generateIntentTest } from './intentTest';
16
17
ssuite({ title: 'intent', location: 'inline' }, () => {
18
generateIntentTest({
19
location: ChatLocation.Editor,
20
name: 'convert',
21
query: 'convert private property to lowercase',
22
expectedIntent: EditCodeIntent.ID,
23
});
24
25
generateIntentTest({
26
location: ChatLocation.Editor,
27
name: 'log to console',
28
query: 'log to console in case the action is missing',
29
// Actually gives Explain
30
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
31
});
32
33
generateIntentTest({
34
location: ChatLocation.Editor,
35
name: 'add a cat',
36
query: 'Add a cat to this comment',
37
// Actually gives Unknown
38
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
39
});
40
41
generateIntentTest({
42
location: ChatLocation.Editor,
43
name: 'make simpler',
44
query: 'make simpler',
45
expectedIntent: [EditCodeIntent.ID, Intent.Fix],
46
});
47
48
generateIntentTest({
49
location: ChatLocation.Editor,
50
name: 'generate',
51
query: 'generate a nodejs server that responds with "Hello World"',
52
expectedIntent: GenerateCodeIntent.ID,
53
});
54
55
generateIntentTest({
56
location: ChatLocation.Editor,
57
name: 'rewrite',
58
query: 'Rewrite the selection to use async/await',
59
expectedIntent: EditCodeIntent.ID,
60
});
61
62
generateIntentTest({
63
location: ChatLocation.Editor,
64
name: 'print',
65
query: 'print seconds in a week',
66
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
67
});
68
69
generateIntentTest({
70
location: ChatLocation.Editor,
71
name: 'add a column to dataframe',
72
query: 'add a new column called adjusted to the dataframe and set it to the value of the activity column minus 2',
73
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
74
});
75
76
generateIntentTest({
77
location: ChatLocation.Editor,
78
name: 'plot dataframe',
79
query: 'plot the data frame',
80
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
81
});
82
83
generateIntentTest({
84
location: ChatLocation.Editor,
85
name: 'add test',
86
query: 'add another test for containsUppercaseCharacter with other non latin chars',
87
expectedIntent: 'tests',
88
});
89
90
generateIntentTest({
91
location: ChatLocation.Editor,
92
name: 'add types',
93
query: 'Add types to `reviewRequiredCheck`',
94
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
95
});
96
97
generateIntentTest({
98
location: ChatLocation.Editor,
99
name: 'issue #1126: expand comments',
100
query: 'Expand comments to a full paragraph`',
101
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
102
});
103
104
generateIntentTest({
105
location: ChatLocation.Editor,
106
name: 'issue #1126: change to GDPR',
107
query: 'change to GDPR documentation`',
108
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
109
});
110
111
generateIntentTest({
112
location: ChatLocation.Editor,
113
name: `create a vscode launch task`,
114
query: `create a launch task that invokes MOCHA_GREP='Edit Generation' make test-extension`,
115
expectedIntent: [EditCodeIntent.ID, GenerateCodeIntent.ID],
116
});
117
118
generateIntentTest({
119
location: ChatLocation.Editor,
120
name: 'create basic jest config',
121
query: 'create basic jest config',
122
expectedIntent: [GenerateCodeIntent.ID],
123
});
124
125
const additionalCases = JSON.parse(fs.readFileSync(join(__dirname, '../test/intent/inline-chat.json'), { encoding: 'utf8' }));
126
if (additionalCases && Array.isArray(additionalCases)) {
127
additionalCases.forEach((testCase: any) => {
128
if (typeof testCase === 'object' && !!testCase && testCase['Location'] === 'inline') {
129
const query: string = testCase['Request'];
130
generateIntentTest({ location: ChatLocation.Editor, name: query.split('\n')[0], query, expectedIntent: testCase['Intent'] });
131
}
132
});
133
}
134
135
stest('/tests cannot be intent-detected', (testingServiceCollection) => {
136
return simulateInlineChat(testingServiceCollection, {
137
files: [fromFixture('notebook/fibonacci.ipynb')],
138
queries: [
139
{
140
file: 'fibonacci.ipynb',
141
activeCell: 0,
142
selection: [0, 9],
143
query: 'generate tests',
144
expectedIntent: 'generate',
145
validate: async (outcome, workspace, accessor) => {
146
// @ulugbekna: left empty on purpose
147
}
148
}
149
]
150
});
151
});
152
153
});
154
155