Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/sessions/test/e2e/extensions/sessions-e2e-mock/extension.js
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
// @ts-check
7
8
/// <reference types="vscode" />
9
10
/**
11
* Mock extension for Sessions E2E testing.
12
*
13
* Provides:
14
* - A fake GitHub authentication provider (skips sign-in)
15
* - Mock command handlers for Code Review, Create PR, Open PR, and Merge
16
*
17
* The mock-fs:// FileSystemProvider and chat agents are registered
18
* directly in the workbench (web.test.ts), not here.
19
*/
20
21
// ---------------------------------------------------------------------------
22
// Activation
23
// ---------------------------------------------------------------------------
24
25
/**
26
* @param {import('vscode').ExtensionContext} context
27
*/
28
function activate(context) {
29
const vscode = require('vscode');
30
31
console.log('[sessions-e2e-mock] Activating mock extension');
32
33
// 1. Mock GitHub Authentication Provider
34
context.subscriptions.push(registerMockAuth(vscode));
35
36
// 2. Mock command handlers for Code Review and PR actions
37
context.subscriptions.push(...registerMockCommands(vscode));
38
39
// Note: The mock-fs:// FileSystemProvider is registered directly in the
40
// workbench (web.test.ts → registerMockFileSystemProvider) so it is
41
// available before any service tries to resolve workspace files.
42
// Do NOT register it here — it would cause a duplicate provider error.
43
44
console.log('[sessions-e2e-mock] All mocks registered');
45
}
46
47
// ---------------------------------------------------------------------------
48
// Mock Authentication Provider
49
// ---------------------------------------------------------------------------
50
51
/**
52
* @param {typeof import('vscode')} vscode
53
* @returns {import('vscode').Disposable}
54
*/
55
function registerMockAuth(vscode) {
56
const sessionChangeEmitter = new vscode.EventEmitter();
57
58
/** @type {import('vscode').AuthenticationSession} */
59
const mockSession = {
60
id: 'mock-session-1',
61
accessToken: 'gho_mock_e2e_test_token_00000000000000000000',
62
account: {
63
id: 'e2e-test-user',
64
label: 'E2E Test User',
65
},
66
scopes: ['read:user', 'repo', 'workflow'],
67
};
68
69
/** @type {import('vscode').AuthenticationProvider} */
70
const provider = {
71
onDidChangeSessions: sessionChangeEmitter.event,
72
async getSessions(_scopes, _options) {
73
return [mockSession];
74
},
75
async createSession(_scopes, _options) {
76
sessionChangeEmitter.fire({ added: [mockSession], removed: [], changed: [] });
77
return mockSession;
78
},
79
async removeSession(_sessionId) {
80
sessionChangeEmitter.fire({ added: [], removed: [mockSession], changed: [] });
81
},
82
};
83
84
console.log('[sessions-e2e-mock] Registering mock GitHub auth provider');
85
return vscode.authentication.registerAuthenticationProvider('github', 'GitHub (Mock)', provider, {
86
supportsMultipleAccounts: false,
87
});
88
}
89
90
// ---------------------------------------------------------------------------
91
// Mock Command Handlers (Code Review + PR Actions)
92
// ---------------------------------------------------------------------------
93
94
/**
95
* Registers mock command handlers that stand in for the real GitHub Copilot
96
* extension commands. These allow the Code Review and Create PR buttons to
97
* function in the e2e test environment.
98
*
99
* @param {typeof import('vscode')} vscode
100
* @returns {import('vscode').Disposable[]}
101
*/
102
function registerMockCommands(vscode) {
103
const disposables = [];
104
105
// Mock create PR — simulates successful PR creation
106
disposables.push(vscode.commands.registerCommand(
107
'github.copilot.chat.createPullRequestCopilotCLIAgentSession.createPR',
108
() => {
109
console.log('[sessions-e2e-mock] Mock Create PR invoked');
110
vscode.window.showInformationMessage('Mock: Pull request created successfully');
111
}
112
));
113
114
// Mock open PR — simulates opening a PR URL
115
disposables.push(vscode.commands.registerCommand(
116
'github.copilot.chat.openPullRequestCopilotCLIAgentSession.openPR',
117
() => {
118
console.log('[sessions-e2e-mock] Mock Open PR invoked');
119
vscode.window.showInformationMessage('Mock: Opening pull request');
120
}
121
));
122
123
// Mock merge — simulates merging changes
124
disposables.push(vscode.commands.registerCommand(
125
'github.copilot.chat.mergeCopilotCLIAgentSessionChanges.merge',
126
() => {
127
console.log('[sessions-e2e-mock] Mock Merge invoked');
128
vscode.window.showInformationMessage('Mock: Changes merged successfully');
129
}
130
));
131
132
// Mock merge and sync — simulates merging and syncing
133
disposables.push(vscode.commands.registerCommand(
134
'github.copilot.chat.mergeCopilotCLIAgentSessionChanges.mergeAndSync',
135
() => {
136
console.log('[sessions-e2e-mock] Mock Merge and Sync invoked');
137
vscode.window.showInformationMessage('Mock: Changes merged and synced successfully');
138
}
139
));
140
141
// Mock apply changes — simulates applying session changes
142
disposables.push(vscode.commands.registerCommand(
143
'github.copilot.chat.applyCopilotCLIAgentSessionChanges.apply',
144
() => {
145
console.log('[sessions-e2e-mock] Mock Apply Changes invoked');
146
vscode.window.showInformationMessage('Mock: Changes applied successfully');
147
}
148
));
149
150
// Mock checkout PR reroute — simulates checkout PR flow
151
disposables.push(vscode.commands.registerCommand(
152
'github.copilot.chat.checkoutPullRequestReroute',
153
() => {
154
console.log('[sessions-e2e-mock] Mock Checkout PR Reroute invoked');
155
vscode.window.showInformationMessage('Mock: Checking out pull request');
156
}
157
));
158
159
// Mock update changes — simulates updating session changes
160
disposables.push(vscode.commands.registerCommand(
161
'github.copilot.chat.updateCopilotCLIAgentSessionChanges.update',
162
() => {
163
console.log('[sessions-e2e-mock] Mock Update Changes invoked');
164
vscode.window.showInformationMessage('Mock: Changes updated successfully',);
165
}
166
));
167
168
console.log('[sessions-e2e-mock] Registered mock Code Review and PR command handlers');
169
return disposables;
170
}
171
172
// ---------------------------------------------------------------------------
173
// Exports
174
// ---------------------------------------------------------------------------
175
176
module.exports = { activate };
177
178