Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/test/simulation/fixtures/edit/issue-2988/pseudoStartStopConversationCallback.test.ts
13405 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation and GitHub. All rights reserved.
3
*--------------------------------------------------------------------------------------------*/
4
5
import assert from 'assert';
6
import type { ChatAgentContent, ChatAgentExtendedProgress, ChatAgentVulnerability } from 'vscode';
7
import { IResponseDelta } from '../../openai/fetch';
8
import { PseudoStopStartConversationCallback } from '../pseudoStartStopConversationCallback';
9
import sinon = require('sinon');
10
11
suite('Post Report Conversation Callback', () => {
12
const postReportFn = (deltas: IResponseDelta[]) => {
13
return ['<processed>', ...deltas.map(d => d.text), '</processed>'];
14
};
15
const annotations = [{ id: 123, details: { type: 'type', description: 'description' } }, { id: 456, details: { type: 'type2', description: 'description2' } }];
16
17
test('Simple post-report', async () => {
18
const progress: ChatAgentExtendedProgress[] = [];
19
const testObj = new PseudoStopStartConversationCallback(
20
[{
21
start: 'end',
22
stop: 'start'
23
}],
24
{ report: p => progress.push(p) },
25
postReportFn
26
);
27
28
testObj.apply('', { text: 'one' });
29
testObj.apply('', { text: ' start ' });
30
testObj.apply('', { text: 'two' });
31
testObj.apply('', { text: ' end' });
32
33
assert.strictEqual(await testObj.appliedText, 'one start two end');
34
35
assert.deepStrictEqual(
36
progress.map(p => (p as ChatAgentContent).content),
37
['one', ' ', '<processed>', ' ', 'two', ' ', '</processed>']);
38
});
39
40
test('Partial stop word with extra text before', async () => {
41
const progress: ChatAgentExtendedProgress[] = [];
42
const testObj = new PseudoStopStartConversationCallback(
43
[{
44
start: 'end',
45
stop: 'start'
46
}],
47
{ report: p => progress.push(p) },
48
postReportFn
49
);
50
51
testObj.apply('', { text: 'one sta' });
52
testObj.apply('', { text: 'rt' });
53
testObj.apply('', { text: ' two end' });
54
55
assert.deepStrictEqual(
56
progress.map(p => (p as ChatAgentContent).content),
57
['one ', '<processed>', ' two ', '</processed>']
58
);
59
assert.strictEqual(await testObj.appliedText, 'one start two end');
60
});
61
62
test('Partial stop word with extra text after', async () => {
63
const progress: ChatAgentExtendedProgress[] = [];
64
const testObj = new PseudoStopStartConversationCallback(
65
[{
66
start: 'end',
67
stop: 'start'
68
}],
69
{ report: p => progress.push(p) },
70
postReportFn
71
);
72
73
testObj.apply('', { text: 'one ', annotations });
74
testObj.apply('', { text: 'sta' });
75
testObj.apply('', { text: 'rt two' });
76
testObj.apply('', { text: ' end' });
77
78
assert.strictEqual(await testObj.appliedText, 'one start two end');
79
assert.deepStrictEqual((progress[0] as ChatAgentContent).vulnerabilities, annotations.map(a => ({ title: a.details.type, description: a.details.description } satisfies ChatAgentVulnerability)));
80
81
assert.deepStrictEqual(
82
progress.map(p => (p as ChatAgentContent).content),
83
['one ', '<processed>', ' two', ' ', '</processed>']);
84
});
85
86
test('no second stop word', async () => {
87
const progress: ChatAgentExtendedProgress[] = [];
88
const testObj = new PseudoStopStartConversationCallback(
89
[{
90
start: 'end',
91
stop: 'start'
92
}],
93
{ report: p => progress.push(p) },
94
postReportFn
95
);
96
97
testObj.apply('', { text: 'one' });
98
testObj.apply('', { text: ' start ' });
99
testObj.apply('', { text: 'two' });
100
testObj.apply('', { text: ' ' });
101
102
assert.strictEqual(await testObj.appliedText, 'one start two ');
103
assert.deepStrictEqual(
104
progress.map(p => (p as ChatAgentContent).content),
105
['one', ' ']);
106
});
107
108
test('Text on same line as start', async () => {
109
const progress: ChatAgentExtendedProgress[] = [];
110
const testObj = new PseudoStopStartConversationCallback(
111
[{
112
start: 'end',
113
stop: 'start'
114
}],
115
{ report: p => progress.push(p) },
116
postReportFn
117
);
118
119
testObj.apply('', { text: 'this is test text\n\n' });
120
testObj.apply('', { text: 'eeep start\n\n' });
121
testObj.apply('', { text: 'test test test test 123456' });
122
testObj.apply('', { text: 'end\n\nhello' });
123
124
assert.strictEqual(await testObj.appliedText, 'this is test text\n\neeep start\n\ntest test test test 123456end\n\nhello');
125
126
assert.deepStrictEqual((progress[0] as ChatAgentContent).content, 'this is test text\n\n');
127
assert.deepStrictEqual((progress[1] as ChatAgentContent).content, 'eeep ');
128
assert.deepStrictEqual((progress[2] as ChatAgentContent).content, '<processed>');
129
assert.deepStrictEqual((progress[3] as ChatAgentContent).content, '\n\n');
130
assert.deepStrictEqual((progress[4] as ChatAgentContent).content, 'test test test test 123456');
131
assert.deepStrictEqual((progress[5] as ChatAgentContent).content, '</processed>');
132
assert.deepStrictEqual((progress[6] as ChatAgentContent).content, '\n\nhello');
133
});
134
135
136
test('Start word without a stop word', () => {
137
const progress: ChatAgentExtendedProgress[] = [];
138
const testObj = new PseudoStopStartConversationCallback(
139
[{
140
start: '[RESPONSE END]',
141
stop: '[RESPONSE START]'
142
}],
143
{ report: p => progress.push(p) },
144
postReportFn
145
);
146
147
testObj.apply('', { text: `I'm sorry, but as an AI programming assistant, I'm here to provide assistance with software development topics, specifically related to Visual Studio Code. I'm not equipped to provide a definition of a computer. [RESPONSE END]` });
148
149
assert.strictEqual((progress[0] as ChatAgentContent).content, `I'm sorry, but as an AI programming assistant, I'm here to provide assistance with software development topics, specifically related to Visual Studio Code. I'm not equipped to provide a definition of a computer. [RESPONSE END]`);
150
});
151
152
teardown(() => sinon.restore());
153
});
154
155