Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/contrib/chat/test/browser/languageModelsConfiguration.test.ts
4780 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 assert from 'assert';
7
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js';
8
import { createTextModel } from '../../../../../editor/test/common/testTextModel.js';
9
import { parseLanguageModelsProviderGroups } from '../../browser/languageModelsConfigurationService.js';
10
11
suite('LanguageModelsConfiguration', () => {
12
const testDisposables = ensureNoDisposablesAreLeakedInTestSuite();
13
14
test('parseLanguageModelsConfiguration - empty', () => {
15
const model = testDisposables.add(createTextModel('[]'));
16
const result = parseLanguageModelsProviderGroups(model);
17
assert.deepStrictEqual(result, []);
18
});
19
20
test('parseLanguageModelsConfiguration - simple', () => {
21
const content = JSON.stringify([{
22
vendor: 'vendor',
23
name: 'group',
24
configurations: []
25
}], null, '\t');
26
const model = testDisposables.add(createTextModel(content));
27
const result = parseLanguageModelsProviderGroups(model);
28
29
assert.strictEqual(result.length, 1);
30
assert.strictEqual(result[0].name, 'group');
31
assert.strictEqual(result[0].vendor, 'vendor');
32
assert.ok(result[0].range);
33
});
34
35
test('parseLanguageModelsConfiguration - with configuration range', () => {
36
const content = `[
37
{
38
"vendor": "vendor",
39
"name": "group",
40
"configurations": [
41
{
42
"configuration": {
43
"foo": "bar"
44
}
45
}
46
]
47
}
48
]`;
49
const model = testDisposables.add(createTextModel(content));
50
const result = parseLanguageModelsProviderGroups(model);
51
52
const configurations = result[0].configurations as { configuration: Record<string, unknown> }[];
53
const config = configurations[0].configuration;
54
assert.deepStrictEqual(config, { foo: 'bar' });
55
});
56
57
test('parseLanguageModelsConfiguration - multiple vendors and groups', () => {
58
const content = `[
59
{ "vendor": "vendor1", "name": "g1", "configurations": [] },
60
{ "vendor": "vendor1", "name": "g2", "configurations": [] },
61
{ "vendor": "vendor2", "name": "g3", "configurations": [] }
62
]`;
63
const model = testDisposables.add(createTextModel(content));
64
const result = parseLanguageModelsProviderGroups(model);
65
66
assert.strictEqual(result.length, 3);
67
assert.strictEqual(result[0].name, 'g1');
68
assert.strictEqual(result[0].vendor, 'vendor1');
69
assert.strictEqual(result[1].name, 'g2');
70
assert.strictEqual(result[1].vendor, 'vendor1');
71
assert.strictEqual(result[2].name, 'g3');
72
assert.strictEqual(result[2].vendor, 'vendor2');
73
});
74
75
test('parseLanguageModelsConfiguration - complex configuration values', () => {
76
const content = `[
77
{
78
"vendor": "vendor",
79
"name": "group",
80
"configurations": [
81
{
82
"configuration": {
83
"str": "value",
84
"num": 123,
85
"bool": true,
86
"null": null,
87
"arr": [1, 2],
88
"obj": { "nested": "val" }
89
}
90
}
91
]
92
}
93
]`;
94
const model = testDisposables.add(createTextModel(content));
95
const result = parseLanguageModelsProviderGroups(model);
96
97
const configurations = result[0]?.configurations as { configuration: Record<string, unknown> }[];
98
const config = configurations[0].configuration;
99
assert.strictEqual(config.str, 'value');
100
assert.strictEqual(config.num, 123);
101
assert.strictEqual(config.bool, true);
102
assert.strictEqual(config.null, null);
103
assert.deepStrictEqual(config.arr, [1, 2]);
104
assert.deepStrictEqual(config.obj, { nested: 'val' });
105
});
106
107
test('parseLanguageModelsConfiguration - with comments', () => {
108
const content = `[
109
// This is a comment
110
/* Block comment */
111
{
112
"vendor": "vendor",
113
"name": "group",
114
"configurations": []
115
}
116
]`;
117
const model = testDisposables.add(createTextModel(content));
118
const result = parseLanguageModelsProviderGroups(model);
119
120
assert.strictEqual(result.length, 1);
121
assert.strictEqual(result[0].name, 'group');
122
assert.strictEqual(result[0].vendor, 'vendor');
123
});
124
125
test('parseLanguageModelsConfiguration - ranges', () => {
126
const content = `[
127
{
128
"vendor": "vendor",
129
"name": "g1",
130
"configurations": []
131
},
132
{
133
"vendor": "vendor",
134
"name": "g2",
135
"configurations": []
136
}
137
]`;
138
const model = testDisposables.add(createTextModel(content));
139
const result = parseLanguageModelsProviderGroups(model);
140
141
const g1 = result[0];
142
const g2 = result[1];
143
144
assert.ok(g1.range);
145
assert.ok(g2.range);
146
assert.strictEqual(g1.range.startLineNumber, 2);
147
assert.strictEqual(g1.range.endLineNumber, 6);
148
assert.strictEqual(g2.range.startLineNumber, 7);
149
assert.strictEqual(g2.range.endLineNumber, 11);
150
});
151
});
152
153