Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/copilot/src/extension/conversation/vscode-node/test/conversationFeature.test.ts
13405 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
7
import assert from 'assert';
8
import * as sinon from 'sinon';
9
import * as vscode from 'vscode';
10
import { IAuthenticationService } from '../../../../platform/authentication/common/authentication';
11
import { CopilotToken, createTestExtendedTokenInfo } from '../../../../platform/authentication/common/copilotToken';
12
import { setCopilotToken, StaticGitHubAuthenticationService } from '../../../../platform/authentication/common/staticGitHubAuthenticationService';
13
import { FailingDevContainerConfigurationService, IDevContainerConfigurationService } from '../../../../platform/devcontainer/common/devContainerConfigurationService';
14
import { ICombinedEmbeddingIndex, VSCodeCombinedIndexImpl } from '../../../../platform/embeddings/common/vscodeIndex';
15
import { IVSCodeExtensionContext } from '../../../../platform/extContext/common/extensionContext';
16
import { IGitCommitMessageService, NoopGitCommitMessageService } from '../../../../platform/git/common/gitCommitMessageService';
17
import { ISettingsEditorSearchService, NoopSettingsEditorSearchService } from '../../../../platform/settingsEditor/common/settingsEditorSearchService';
18
import { ITestingServicesAccessor } from '../../../../platform/test/node/services';
19
import { SyncDescriptor } from '../../../../util/vs/platform/instantiation/common/descriptors';
20
import { IInstantiationService } from '../../../../util/vs/platform/instantiation/common/instantiation';
21
import { IMergeConflictService } from '../../../git/common/mergeConflictService';
22
import { TestMergeConflictServiceImpl } from '../../../git/vscode/mergeConflictServiceImpl';
23
import { IIntentService, IntentService } from '../../../intents/node/intentService';
24
import { INewWorkspacePreviewContentManager, NewWorkspacePreviewContentManagerImpl } from '../../../intents/node/newIntent';
25
import { createExtensionTestingServices } from '../../../test/vscode-node/services';
26
import { ConversationFeature } from '../conversationFeature';
27
28
suite('Conversation feature test suite', function () {
29
let accessor: ITestingServicesAccessor;
30
let instaService: IInstantiationService;
31
let sandbox: sinon.SinonSandbox;
32
33
function createAccessor() {
34
const testingServiceCollection = createExtensionTestingServices();
35
testingServiceCollection.define(ICombinedEmbeddingIndex, new SyncDescriptor(VSCodeCombinedIndexImpl, [/*useRemoteCache*/ false]));
36
testingServiceCollection.define(INewWorkspacePreviewContentManager, new SyncDescriptor(NewWorkspacePreviewContentManagerImpl));
37
testingServiceCollection.define(IGitCommitMessageService, new NoopGitCommitMessageService());
38
testingServiceCollection.define(IDevContainerConfigurationService, new FailingDevContainerConfigurationService());
39
testingServiceCollection.define(IIntentService, new SyncDescriptor(IntentService));
40
testingServiceCollection.define(ISettingsEditorSearchService, new SyncDescriptor(NoopSettingsEditorSearchService));
41
testingServiceCollection.define(IMergeConflictService, new SyncDescriptor(TestMergeConflictServiceImpl));
42
// We don't need auth in these tests
43
testingServiceCollection.define(IAuthenticationService, new SyncDescriptor(StaticGitHubAuthenticationService, [() => undefined]));
44
45
accessor = testingServiceCollection.createTestingAccessor();
46
instaService = accessor.get(IInstantiationService);
47
}
48
49
setup(() => {
50
sandbox = sinon.createSandbox();
51
sandbox.stub(vscode.commands, 'registerCommand').returns({ dispose: () => { } });
52
sandbox.stub(vscode.workspace, 'registerFileSystemProvider').returns({ dispose: () => { } });
53
createAccessor();
54
});
55
56
teardown(() => {
57
sandbox.restore();
58
const extensionContext = accessor.get(IVSCodeExtensionContext);
59
extensionContext.subscriptions.forEach(sub => sub.dispose());
60
});
61
62
test.skip(`If the 'interactive' namespace is not available, the feature is not enabled and not activated`, function () {
63
// TODO: The vscode module cannot be stubbed
64
sandbox.stub(vscode, 'interactive').value(undefined);
65
66
const conversationFeature = instaService.createInstance(ConversationFeature);
67
try {
68
assert.deepStrictEqual(conversationFeature.enabled, false);
69
assert.deepStrictEqual(conversationFeature.activated, false);
70
} finally {
71
conversationFeature.dispose();
72
}
73
});
74
75
test(`If the 'interactive' version does not match, the feature is not enabled and not activated`, function () {
76
const conversationFeature = instaService.createInstance(ConversationFeature);
77
try {
78
assert.deepStrictEqual(conversationFeature.enabled, false);
79
assert.deepStrictEqual(conversationFeature.activated, false);
80
} finally {
81
conversationFeature.dispose();
82
}
83
});
84
85
test('The feature is enabled and activated in test mode', function () {
86
const conversationFeature = instaService.createInstance(ConversationFeature);
87
try {
88
const copilotToken = new CopilotToken(createTestExtendedTokenInfo({ token: 'token', username: 'fake', copilot_plan: 'unknown' }));
89
setCopilotToken(accessor.get(IAuthenticationService), copilotToken);
90
91
assert.deepStrictEqual(conversationFeature.enabled, true);
92
assert.deepStrictEqual(conversationFeature.activated, true);
93
} finally {
94
conversationFeature.dispose();
95
}
96
});
97
98
test('If the token envelope setting is set to true, the feature should be enabled', function () {
99
const conversationFeature = instaService.createInstance(ConversationFeature);
100
try {
101
const copilotToken = new CopilotToken(createTestExtendedTokenInfo({ token: 'token', username: 'fake', copilot_plan: 'unknown' }));
102
setCopilotToken(accessor.get(IAuthenticationService), copilotToken);
103
104
assert.deepStrictEqual(conversationFeature.enabled, true);
105
} finally {
106
conversationFeature.dispose();
107
}
108
});
109
110
test('The feature should be activated when it becomes enabled', function () {
111
const conversationFeature = instaService.createInstance(ConversationFeature);
112
try {
113
const copilotToken = new CopilotToken(createTestExtendedTokenInfo({ token: 'token', username: 'fake', copilot_plan: 'unknown' }));
114
setCopilotToken(accessor.get(IAuthenticationService), copilotToken);
115
assert.deepStrictEqual(conversationFeature.enabled, true);
116
assert.deepStrictEqual(conversationFeature.activated, true);
117
} finally {
118
conversationFeature.dispose();
119
}
120
});
121
122
test('The feature should register a chat provider on activation', function () {
123
if (!vscode.chat.createChatParticipant) {
124
this.skip();
125
}
126
127
const conversationFeature = instaService.createInstance(ConversationFeature);
128
try {
129
130
const copilotToken = new CopilotToken(createTestExtendedTokenInfo({ token: 'token', username: 'fake', copilot_plan: 'unknown' }));
131
setCopilotToken(accessor.get(IAuthenticationService), copilotToken);
132
133
assert.deepStrictEqual(conversationFeature.activated, true);
134
} finally {
135
conversationFeature.dispose();
136
}
137
});
138
});
139
140