Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/prompts/customInstructions.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 assert from 'assert';
6
import { EditCodeIntent } from '../../src/extension/intents/node/editCodeIntent';
7
import { ConfigKey } from '../../src/platform/configuration/common/configurationService';
8
import { ssuite, stest } from '../base/stest';
9
import { simulateInlineChat } from '../simulation/inlineChatSimulator';
10
import { toFile } from '../simulation/stestUtil';
11
12
ssuite({ title: 'custom instructions', location: 'inline' }, () => {
13
let configurations = [
14
{
15
key: ConfigKey.CodeGenerationInstructions,
16
value: [
17
{ 'text': `Field names should start with the prefix 'f'`, 'language': 'typescript' },
18
{ 'text': `Add a comment: 'Generated by Copilot'` }
19
]
20
}
21
];
22
stest({ description: 'Custom instructions for language', configurations }, (testingServiceCollection) => {
23
return simulateInlineChat(testingServiceCollection, {
24
files: [toFile({ fileName: 'hello.ts', fileContents: '\n\n' })],
25
queries: [
26
{
27
file: 'hello.ts',
28
selection: [0, 0, 0, 0],
29
query: [
30
`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,
31
].join('\n'),
32
expectedIntent: EditCodeIntent.ID,
33
validate: async (outcome, workspace, accessor) => {
34
assert.strictEqual(outcome.type, 'inlineEdit');
35
assert.ok(outcome.fileContents.includes(' fAddress'));
36
assert.ok(outcome.fileContents.includes('Generated by Copilot'));
37
}
38
}
39
]
40
});
41
});
42
configurations = [
43
{
44
key: ConfigKey.CodeGenerationInstructions,
45
value: [
46
{ 'text': `Field names should start with the prefix 'f'`, 'language': 'javascript' },
47
{ 'text': `Add a comment: 'Generated by Copilot'`, 'language': 'java' },
48
]
49
}
50
];
51
stest({ description: 'Custom instructions not applicable to language', configurations }, (testingServiceCollection) => {
52
return simulateInlineChat(testingServiceCollection, {
53
files: [
54
toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),
55
],
56
queries: [
57
{
58
file: 'hello.ts',
59
selection: [0, 0, 0, 0],
60
query: [
61
`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,
62
].join('\n'),
63
expectedIntent: EditCodeIntent.ID,
64
validate: async (outcome, workspace, accessor) => {
65
assert.strictEqual(outcome.type, 'inlineEdit');
66
assert.ok(!outcome.fileContents.includes(' fAddress'));
67
assert.ok(!outcome.fileContents.includes('Generated by Copilot'));
68
}
69
}
70
]
71
});
72
});
73
const configurations2 = [
74
{
75
key: ConfigKey.CodeGenerationInstructions,
76
value: [
77
{ 'file': 'code-guidelines.md' }
78
]
79
}
80
];
81
stest({ description: 'Custom instructions from file', configurations: configurations2 }, (testingServiceCollection) => {
82
return simulateInlineChat(testingServiceCollection, {
83
files: [
84
toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),
85
toFile({ fileName: 'code-guidelines.md', fileContents: `\n\nField names should start with the prefix '__'\n` })
86
],
87
queries: [
88
{
89
file: 'hello.ts',
90
selection: [0, 0, 0, 0],
91
query: [
92
`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,
93
].join('\n'),
94
expectedIntent: EditCodeIntent.ID,
95
validate: async (outcome, workspace, accessor) => {
96
assert.strictEqual(outcome.type, 'inlineEdit');
97
assert.ok(outcome.fileContents.includes(' __address'));
98
}
99
}
100
]
101
});
102
});
103
const configurations3 = [
104
{
105
key: ConfigKey.CodeGenerationInstructions,
106
value: [
107
{ 'file': 'code-guidelines1.md' },
108
{ 'text': `Add a comment: 'Generated by Copilot'`, 'language': 'typescript' },
109
]
110
}
111
];
112
stest({ description: 'Custom instructions with missing file', configurations: configurations3 }, (testingServiceCollection) => {
113
return simulateInlineChat(testingServiceCollection, {
114
files: [
115
toFile({ fileName: 'hello.ts', fileContents: '\n\n' }),
116
toFile({ fileName: 'code-guidelines.md', fileContents: `\n\nField names should start with the prefix '__'\n` })
117
],
118
queries: [
119
{
120
file: 'hello.ts',
121
selection: [0, 0, 0, 0],
122
query: [
123
`/edit add a class named 'Foo' with a field 'address' along with getters and setters`,
124
].join('\n'),
125
expectedIntent: EditCodeIntent.ID,
126
validate: async (outcome, workspace, accessor) => {
127
assert.strictEqual(outcome.type, 'inlineEdit');
128
assert.ok(!outcome.fileContents.includes(' __address'));
129
assert.ok(outcome.fileContents.includes('Generated by Copilot'));
130
}
131
}
132
]
133
});
134
});
135
});
136
137