@theia/ai-copilot 1.76.0-next.4 → 1.76.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +86 -14
- package/lib/browser/copilot-auth-dialog.d.ts.map +1 -1
- package/lib/browser/copilot-auth-dialog.js +12 -4
- package/lib/browser/copilot-auth-dialog.js.map +1 -1
- package/lib/browser/copilot-frontend-application-contribution.d.ts +15 -1
- package/lib/browser/copilot-frontend-application-contribution.d.ts.map +1 -1
- package/lib/browser/copilot-frontend-application-contribution.js +52 -24
- package/lib/browser/copilot-frontend-application-contribution.js.map +1 -1
- package/lib/common/copilot-auth-service.d.ts +27 -24
- package/lib/common/copilot-auth-service.d.ts.map +1 -1
- package/lib/common/copilot-language-models-manager.d.ts +3 -21
- package/lib/common/copilot-language-models-manager.d.ts.map +1 -1
- package/lib/common/copilot-language-models-manager.js +1 -13
- package/lib/common/copilot-language-models-manager.js.map +1 -1
- package/lib/common/copilot-preferences.d.ts +1 -0
- package/lib/common/copilot-preferences.d.ts.map +1 -1
- package/lib/common/copilot-preferences.js +24 -6
- package/lib/common/copilot-preferences.js.map +1 -1
- package/lib/common/index.d.ts +0 -1
- package/lib/common/index.d.ts.map +1 -1
- package/lib/common/index.js +0 -1
- package/lib/common/index.js.map +1 -1
- package/lib/node/copilot-auth-service-impl.d.ts +25 -16
- package/lib/node/copilot-auth-service-impl.d.ts.map +1 -1
- package/lib/node/copilot-auth-service-impl.js +67 -183
- package/lib/node/copilot-auth-service-impl.js.map +1 -1
- package/lib/node/copilot-auth-service-impl.spec.js +104 -168
- package/lib/node/copilot-auth-service-impl.spec.js.map +1 -1
- package/lib/node/copilot-backend-module.d.ts.map +1 -1
- package/lib/node/copilot-backend-module.js +10 -2
- package/lib/node/copilot-backend-module.js.map +1 -1
- package/lib/node/copilot-cli-auth-provider.d.ts +146 -0
- package/lib/node/copilot-cli-auth-provider.d.ts.map +1 -0
- package/lib/node/copilot-cli-auth-provider.js +430 -0
- package/lib/node/copilot-cli-auth-provider.js.map +1 -0
- package/lib/node/copilot-cli-auth-provider.spec.d.ts +2 -0
- package/lib/node/copilot-cli-auth-provider.spec.d.ts.map +1 -0
- package/lib/node/copilot-cli-auth-provider.spec.js +249 -0
- package/lib/node/copilot-cli-auth-provider.spec.js.map +1 -0
- package/lib/node/copilot-cli-locator.d.ts +120 -0
- package/lib/node/copilot-cli-locator.d.ts.map +1 -0
- package/lib/node/copilot-cli-locator.js +348 -0
- package/lib/node/copilot-cli-locator.js.map +1 -0
- package/lib/node/copilot-cli-locator.spec.d.ts +2 -0
- package/lib/node/copilot-cli-locator.spec.d.ts.map +1 -0
- package/lib/node/copilot-cli-locator.spec.js +327 -0
- package/lib/node/copilot-cli-locator.spec.js.map +1 -0
- package/lib/node/copilot-credential-store.d.ts +45 -0
- package/lib/node/copilot-credential-store.d.ts.map +1 -0
- package/lib/node/copilot-credential-store.js +96 -0
- package/lib/node/copilot-credential-store.js.map +1 -0
- package/lib/node/copilot-credential-store.spec.d.ts +2 -0
- package/lib/node/copilot-credential-store.spec.d.ts.map +1 -0
- package/lib/node/copilot-credential-store.spec.js +93 -0
- package/lib/node/copilot-credential-store.spec.js.map +1 -0
- package/lib/node/copilot-language-models-manager-impl.d.ts +20 -18
- package/lib/node/copilot-language-models-manager-impl.d.ts.map +1 -1
- package/lib/node/copilot-language-models-manager-impl.js +39 -67
- package/lib/node/copilot-language-models-manager-impl.js.map +1 -1
- package/lib/node/copilot-language-models-manager-impl.spec.d.ts +2 -0
- package/lib/node/copilot-language-models-manager-impl.spec.d.ts.map +1 -0
- package/lib/node/copilot-language-models-manager-impl.spec.js +119 -0
- package/lib/node/copilot-language-models-manager-impl.spec.js.map +1 -0
- package/lib/node/copilot-runtime-env.d.ts +20 -0
- package/lib/node/copilot-runtime-env.d.ts.map +1 -0
- package/lib/node/copilot-runtime-env.js +49 -0
- package/lib/node/copilot-runtime-env.js.map +1 -0
- package/lib/node/copilot-sdk-client-provider.d.ts +103 -0
- package/lib/node/copilot-sdk-client-provider.d.ts.map +1 -0
- package/lib/node/copilot-sdk-client-provider.js +247 -0
- package/lib/node/copilot-sdk-client-provider.js.map +1 -0
- package/lib/node/copilot-sdk-client-provider.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-client-provider.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-client-provider.spec.js +215 -0
- package/lib/node/copilot-sdk-client-provider.spec.js.map +1 -0
- package/lib/node/copilot-sdk-language-model.d.ts +85 -0
- package/lib/node/copilot-sdk-language-model.d.ts.map +1 -0
- package/lib/node/copilot-sdk-language-model.js +301 -0
- package/lib/node/copilot-sdk-language-model.js.map +1 -0
- package/lib/node/copilot-sdk-language-model.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-language-model.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-language-model.spec.js +302 -0
- package/lib/node/copilot-sdk-language-model.spec.js.map +1 -0
- package/lib/node/copilot-sdk-loader.d.ts +57 -0
- package/lib/node/copilot-sdk-loader.d.ts.map +1 -0
- package/lib/node/copilot-sdk-loader.js +133 -0
- package/lib/node/copilot-sdk-loader.js.map +1 -0
- package/lib/node/copilot-sdk-loader.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-loader.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-loader.spec.js +113 -0
- package/lib/node/copilot-sdk-loader.spec.js.map +1 -0
- package/lib/node/copilot-sdk-mappers.d.ts +49 -0
- package/lib/node/copilot-sdk-mappers.d.ts.map +1 -0
- package/lib/node/copilot-sdk-mappers.js +147 -0
- package/lib/node/copilot-sdk-mappers.js.map +1 -0
- package/lib/node/copilot-sdk-mappers.spec.d.ts +2 -0
- package/lib/node/copilot-sdk-mappers.spec.d.ts.map +1 -0
- package/lib/node/copilot-sdk-mappers.spec.js +133 -0
- package/lib/node/copilot-sdk-mappers.spec.js.map +1 -0
- package/lib/node/copilot-sdk-types.d.ts +198 -0
- package/lib/node/copilot-sdk-types.d.ts.map +1 -0
- package/lib/{common/copilot-oauth-config.js → node/copilot-sdk-types.js} +2 -13
- package/lib/node/copilot-sdk-types.js.map +1 -0
- package/lib/node/index.d.ts +9 -1
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +9 -1
- package/lib/node/index.js.map +1 -1
- package/package.json +4 -6
- package/src/browser/copilot-auth-dialog.tsx +12 -8
- package/src/browser/copilot-frontend-application-contribution.ts +62 -29
- package/src/common/copilot-auth-service.ts +28 -24
- package/src/common/copilot-language-models-manager.ts +3 -28
- package/src/common/copilot-preferences.ts +24 -5
- package/src/common/index.ts +0 -1
- package/src/node/copilot-auth-service-impl.spec.ts +122 -207
- package/src/node/copilot-auth-service-impl.ts +63 -218
- package/src/node/copilot-backend-module.ts +11 -2
- package/src/node/copilot-cli-auth-provider.spec.ts +315 -0
- package/src/node/copilot-cli-auth-provider.ts +444 -0
- package/src/node/copilot-cli-locator.spec.ts +386 -0
- package/src/node/copilot-cli-locator.ts +363 -0
- package/src/node/copilot-credential-store.spec.ts +106 -0
- package/src/node/copilot-credential-store.ts +99 -0
- package/src/node/copilot-language-models-manager-impl.spec.ts +137 -0
- package/src/node/copilot-language-models-manager-impl.ts +51 -85
- package/src/node/copilot-runtime-env.ts +46 -0
- package/src/node/copilot-sdk-client-provider.spec.ts +253 -0
- package/src/node/copilot-sdk-client-provider.ts +241 -0
- package/src/node/copilot-sdk-language-model.spec.ts +363 -0
- package/src/node/copilot-sdk-language-model.ts +329 -0
- package/src/node/copilot-sdk-loader.spec.ts +126 -0
- package/src/node/copilot-sdk-loader.ts +142 -0
- package/src/node/copilot-sdk-mappers.spec.ts +151 -0
- package/src/node/copilot-sdk-mappers.ts +161 -0
- package/src/node/copilot-sdk-types.ts +276 -0
- package/src/node/index.ts +9 -1
- package/lib/common/copilot-oauth-config.d.ts +0 -33
- package/lib/common/copilot-oauth-config.d.ts.map +0 -1
- package/lib/common/copilot-oauth-config.js.map +0 -1
- package/lib/node/copilot-language-model.d.ts +0 -34
- package/lib/node/copilot-language-model.d.ts.map +0 -1
- package/lib/node/copilot-language-model.js +0 -236
- package/lib/node/copilot-language-model.js.map +0 -1
- package/lib/node/copilot-language-model.spec.d.ts +0 -2
- package/lib/node/copilot-language-model.spec.d.ts.map +0 -1
- package/lib/node/copilot-language-model.spec.js +0 -89
- package/lib/node/copilot-language-model.spec.js.map +0 -1
- package/src/common/copilot-oauth-config.ts +0 -55
- package/src/node/copilot-language-model.spec.ts +0 -106
- package/src/node/copilot-language-model.ts +0 -273
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const chai_1 = require("chai");
|
|
19
|
+
const fs_1 = require("fs");
|
|
20
|
+
const os = require("os");
|
|
21
|
+
const path_1 = require("path");
|
|
22
|
+
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
23
|
+
const copilot_cli_locator_1 = require("./copilot-cli-locator");
|
|
24
|
+
class TestableCopilotCliLocator extends copilot_cli_locator_1.CopilotCliLocator {
|
|
25
|
+
constructor() {
|
|
26
|
+
super();
|
|
27
|
+
// The logger is injected in production, and read-only for everyone else.
|
|
28
|
+
Object.assign(this, { logger: new mock_logger_1.MockLogger() });
|
|
29
|
+
}
|
|
30
|
+
callToPlatformPackageCandidates(base) {
|
|
31
|
+
return this.toPlatformPackageCandidates(base);
|
|
32
|
+
}
|
|
33
|
+
callToCandidatesOnPath(target) {
|
|
34
|
+
return this.toCandidatesOnPath(target);
|
|
35
|
+
}
|
|
36
|
+
callResolvedCandidates(anchor) {
|
|
37
|
+
return this.resolvedCandidates(anchor);
|
|
38
|
+
}
|
|
39
|
+
callGetCliPlatformPackageNames() {
|
|
40
|
+
return this.getCliPlatformPackageNames();
|
|
41
|
+
}
|
|
42
|
+
callGetBinaryName() {
|
|
43
|
+
return this.getBinaryName();
|
|
44
|
+
}
|
|
45
|
+
callEnvironmentCandidates() {
|
|
46
|
+
return this.environmentCandidates();
|
|
47
|
+
}
|
|
48
|
+
callGetCliFileNames() {
|
|
49
|
+
return this.getCliFileNames();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
const names = new TestableCopilotCliLocator();
|
|
53
|
+
const PLATFORM_PACKAGE = names.callGetCliPlatformPackageNames()[0];
|
|
54
|
+
const BINARY_NAME = names.callGetBinaryName();
|
|
55
|
+
/**
|
|
56
|
+
* Creates a temporary directory with its symlinks resolved.
|
|
57
|
+
*
|
|
58
|
+
* The locator reports what it found canonicalized, through `fs.realpath` and through the module
|
|
59
|
+
* resolution of Node.js, while the temporary directory is a symlink on macOS.
|
|
60
|
+
*/
|
|
61
|
+
async function createTempDirectory(prefix) {
|
|
62
|
+
return fs_1.promises.realpath(await fs_1.promises.mkdtemp((0, path_1.join)(os.tmpdir(), prefix)));
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Creates a file that passes the executable check of the locator.
|
|
66
|
+
*/
|
|
67
|
+
async function writeExecutable(path) {
|
|
68
|
+
await fs_1.promises.mkdir((0, path_1.join)(path, '..'), { recursive: true });
|
|
69
|
+
await fs_1.promises.writeFile(path, '', { mode: 0o755 });
|
|
70
|
+
return path;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Writes a platform package that points its main entry at the executable, the way the ones published
|
|
74
|
+
* by GitHub do: `@github/copilot-win32-x64` exports `./copilot.exe`, the others `./copilot`.
|
|
75
|
+
*/
|
|
76
|
+
async function installPlatformPackage(at, packageName = PLATFORM_PACKAGE, binaryName = BINARY_NAME) {
|
|
77
|
+
const directory = (0, path_1.join)(at, ...packageName.split('/'));
|
|
78
|
+
await fs_1.promises.mkdir(directory, { recursive: true });
|
|
79
|
+
await fs_1.promises.writeFile((0, path_1.join)(directory, 'package.json'), JSON.stringify({
|
|
80
|
+
name: packageName,
|
|
81
|
+
version: '1.0.0',
|
|
82
|
+
exports: { '.': `./${binaryName}` }
|
|
83
|
+
}));
|
|
84
|
+
return writeExecutable((0, path_1.join)(directory, binaryName));
|
|
85
|
+
}
|
|
86
|
+
/** A locator that looks for what a Windows host has, so that the lookup can be tested from anywhere. */
|
|
87
|
+
class WindowsLikeCopilotCliLocator extends TestableCopilotCliLocator {
|
|
88
|
+
static { this.PACKAGE = '@github/copilot-win32-x64'; }
|
|
89
|
+
static { this.BINARY = 'copilot.exe'; }
|
|
90
|
+
getBinaryName() {
|
|
91
|
+
return WindowsLikeCopilotCliLocator.BINARY;
|
|
92
|
+
}
|
|
93
|
+
getCliPlatformPackageNames() {
|
|
94
|
+
return [WindowsLikeCopilotCliLocator.PACKAGE];
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
describe('CopilotCliLocator - candidates', () => {
|
|
98
|
+
const locator = new TestableCopilotCliLocator();
|
|
99
|
+
it('should look for the executable of the platform package below a module directory', () => {
|
|
100
|
+
const candidates = locator.callToPlatformPackageCandidates((0, path_1.join)('/app', 'node_modules'));
|
|
101
|
+
(0, chai_1.expect)(candidates).to.not.be.empty;
|
|
102
|
+
for (const candidate of candidates) {
|
|
103
|
+
(0, chai_1.expect)(candidate).to.contain((0, path_1.join)('node_modules', '@github', 'copilot-'));
|
|
104
|
+
(0, chai_1.expect)(candidate.endsWith(locator.callGetBinaryName())).to.be.true;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
it('should consider the glibc and the musl build on Linux', function () {
|
|
108
|
+
if (process.platform !== 'linux') {
|
|
109
|
+
this.skip();
|
|
110
|
+
}
|
|
111
|
+
const candidates = locator.callToPlatformPackageCandidates('/app/node_modules');
|
|
112
|
+
(0, chai_1.expect)(candidates).to.have.lengthOf(2);
|
|
113
|
+
(0, chai_1.expect)(candidates.some(candidate => candidate.includes('copilot-linux-'))).to.be.true;
|
|
114
|
+
(0, chai_1.expect)(candidates.some(candidate => candidate.includes('copilot-linuxmusl-'))).to.be.true;
|
|
115
|
+
});
|
|
116
|
+
it('should return nothing for an empty module directory', () => {
|
|
117
|
+
(0, chai_1.expect)(locator.callToPlatformPackageCandidates('')).to.be.empty;
|
|
118
|
+
});
|
|
119
|
+
it('should map the JavaScript launcher of a global installation to the platform package', () => {
|
|
120
|
+
const launcher = (0, path_1.join)('/usr', 'lib', 'node_modules', '@github', 'copilot', 'npm-loader.js');
|
|
121
|
+
const candidates = locator.callToCandidatesOnPath(launcher);
|
|
122
|
+
(0, chai_1.expect)(candidates).to.not.be.empty;
|
|
123
|
+
for (const candidate of candidates) {
|
|
124
|
+
(0, chai_1.expect)(candidate).to.contain((0, path_1.join)('/usr', 'lib', 'node_modules', '@github', 'copilot-'));
|
|
125
|
+
(0, chai_1.expect)(candidate).to.not.contain('npm-loader.js');
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
it('should map the shim of a global installation to the platform package next to it', () => {
|
|
129
|
+
// What a global npm installation on Windows puts into its prefix, instead of a link.
|
|
130
|
+
const candidates = locator.callToCandidatesOnPath((0, path_1.join)('/prefix', 'copilot.cmd'));
|
|
131
|
+
(0, chai_1.expect)(candidates).to.not.be.empty;
|
|
132
|
+
for (const candidate of candidates) {
|
|
133
|
+
(0, chai_1.expect)(candidate).to.contain((0, path_1.join)('/prefix', 'node_modules', '@github', 'copilot-'));
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
it('should take a native executable on the PATH as it is', () => {
|
|
137
|
+
const executable = (0, path_1.join)('/opt', 'copilot', 'copilot');
|
|
138
|
+
(0, chai_1.expect)(locator.callToCandidatesOnPath(executable)).to.deep.equal([executable]);
|
|
139
|
+
});
|
|
140
|
+
it('should look for the shim of a global installation on Windows, which has no other entry', function () {
|
|
141
|
+
if (process.platform !== 'win32') {
|
|
142
|
+
this.skip();
|
|
143
|
+
}
|
|
144
|
+
(0, chai_1.expect)(locator.callGetCliFileNames()).to.deep.equal(['copilot.exe', 'copilot.cmd']);
|
|
145
|
+
});
|
|
146
|
+
it('should look for the executable only where an installation links to it', function () {
|
|
147
|
+
if (process.platform === 'win32') {
|
|
148
|
+
this.skip();
|
|
149
|
+
}
|
|
150
|
+
(0, chai_1.expect)(locator.callGetCliFileNames()).to.deep.equal(['copilot']);
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
describe('CopilotCliLocator - installed platform package', () => {
|
|
154
|
+
let root;
|
|
155
|
+
let modules;
|
|
156
|
+
const locator = new TestableCopilotCliLocator();
|
|
157
|
+
beforeEach(async () => {
|
|
158
|
+
root = await createTempDirectory('theia-copilot-install-');
|
|
159
|
+
modules = (0, path_1.join)(root, 'node_modules');
|
|
160
|
+
await fs_1.promises.mkdir((0, path_1.join)(modules, '@github', 'copilot'), { recursive: true });
|
|
161
|
+
// The launcher of the CLI is executable, and linked to from the global binary directory.
|
|
162
|
+
await writeExecutable((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js'));
|
|
163
|
+
});
|
|
164
|
+
afterEach(async () => {
|
|
165
|
+
await fs_1.promises.rm(root, { recursive: true, force: true });
|
|
166
|
+
});
|
|
167
|
+
it('should find a package that the installation hoisted next to the launcher', async () => {
|
|
168
|
+
const executable = await installPlatformPackage(modules);
|
|
169
|
+
const launcher = (0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js');
|
|
170
|
+
(0, chai_1.expect)(locator.callResolvedCandidates(launcher)).to.contain(executable);
|
|
171
|
+
(0, chai_1.expect)(locator.callToCandidatesOnPath(launcher)).to.contain(executable);
|
|
172
|
+
});
|
|
173
|
+
it('should find a package that a global installation nested below the launcher', async () => {
|
|
174
|
+
const executable = await installPlatformPackage((0, path_1.join)(modules, '@github', 'copilot', 'node_modules'));
|
|
175
|
+
const launcher = (0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js');
|
|
176
|
+
(0, chai_1.expect)(locator.callResolvedCandidates(launcher)).to.contain(executable);
|
|
177
|
+
(0, chai_1.expect)(locator.callToCandidatesOnPath(launcher)).to.contain(executable);
|
|
178
|
+
});
|
|
179
|
+
it('should return nothing when no platform package is installed', () => {
|
|
180
|
+
(0, chai_1.expect)(locator.callResolvedCandidates((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js'))).to.be.empty;
|
|
181
|
+
});
|
|
182
|
+
it('should find the package of a global installation from the shim next to its module directory', async () => {
|
|
183
|
+
const executable = await installPlatformPackage((0, path_1.join)(modules, '@github', 'copilot', 'node_modules'));
|
|
184
|
+
(0, chai_1.expect)(locator.callToCandidatesOnPath((0, path_1.join)(root, 'copilot.cmd'))).to.contain(executable);
|
|
185
|
+
});
|
|
186
|
+
it('should reject a configured shim that leads nowhere, since it cannot be spawned', async () => {
|
|
187
|
+
const shim = await writeExecutable((0, path_1.join)(root, 'copilot.cmd'));
|
|
188
|
+
const configured = new TestableCopilotCliLocator();
|
|
189
|
+
configured.setConfiguredPath(shim);
|
|
190
|
+
try {
|
|
191
|
+
await configured.resolve();
|
|
192
|
+
chai_1.expect.fail('should have rejected');
|
|
193
|
+
}
|
|
194
|
+
catch (error) {
|
|
195
|
+
(0, chai_1.expect)(String(error)).to.contain(shim);
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
it('should follow a configured launcher to the executable it would start', async function () {
|
|
199
|
+
if (process.platform === 'win32') {
|
|
200
|
+
// A global installation writes a shim rather than a link there.
|
|
201
|
+
this.skip();
|
|
202
|
+
}
|
|
203
|
+
const executable = await installPlatformPackage((0, path_1.join)(modules, '@github', 'copilot', 'node_modules'));
|
|
204
|
+
const launcher = (0, path_1.join)(root, 'bin', 'copilot');
|
|
205
|
+
await fs_1.promises.mkdir((0, path_1.join)(root, 'bin'), { recursive: true });
|
|
206
|
+
await fs_1.promises.symlink((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js'), launcher);
|
|
207
|
+
const configured = new TestableCopilotCliLocator();
|
|
208
|
+
configured.setConfiguredPath(launcher);
|
|
209
|
+
(0, chai_1.expect)(await configured.resolve()).to.equal(executable);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('CopilotCliLocator - environment', () => {
|
|
213
|
+
const locator = new TestableCopilotCliLocator();
|
|
214
|
+
const previous = process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV];
|
|
215
|
+
let root;
|
|
216
|
+
beforeEach(async () => {
|
|
217
|
+
root = await createTempDirectory('theia-copilot-env-');
|
|
218
|
+
});
|
|
219
|
+
afterEach(async () => {
|
|
220
|
+
if (previous === undefined) {
|
|
221
|
+
delete process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV];
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = previous;
|
|
225
|
+
}
|
|
226
|
+
await fs_1.promises.rm(root, { recursive: true, force: true });
|
|
227
|
+
});
|
|
228
|
+
it('should honor the location given in the environment', async () => {
|
|
229
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = '/opt/copilot/copilot';
|
|
230
|
+
(0, chai_1.expect)(await locator.callEnvironmentCandidates()).to.deep.equal(['/opt/copilot/copilot']);
|
|
231
|
+
});
|
|
232
|
+
it('should ignore a blank value', async () => {
|
|
233
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = ' ';
|
|
234
|
+
(0, chai_1.expect)(await locator.callEnvironmentCandidates()).to.be.empty;
|
|
235
|
+
});
|
|
236
|
+
it('should follow a launcher given in the environment, the way a configured one is followed', async () => {
|
|
237
|
+
const modules = (0, path_1.join)(root, 'node_modules');
|
|
238
|
+
const executable = await installPlatformPackage(modules);
|
|
239
|
+
const launcher = await writeExecutable((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js'));
|
|
240
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = launcher;
|
|
241
|
+
(0, chai_1.expect)(await locator.callEnvironmentCandidates()).to.deep.equal([executable]);
|
|
242
|
+
});
|
|
243
|
+
it('should accept the directory holding the executable', async () => {
|
|
244
|
+
const executable = await writeExecutable((0, path_1.join)(root, 'bin', BINARY_NAME));
|
|
245
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = (0, path_1.join)(root, 'bin');
|
|
246
|
+
(0, chai_1.expect)(await locator.callEnvironmentCandidates()).to.deep.equal([executable]);
|
|
247
|
+
});
|
|
248
|
+
it('should drop a launcher that leads nowhere instead of offering it for spawning', async () => {
|
|
249
|
+
process.env[copilot_cli_locator_1.COPILOT_CLI_PATH_ENV] = await writeExecutable((0, path_1.join)(root, 'copilot.cmd'));
|
|
250
|
+
(0, chai_1.expect)(await locator.callEnvironmentCandidates()).to.be.empty;
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
describe('CopilotCliLocator - configured path', () => {
|
|
254
|
+
let home;
|
|
255
|
+
let executable;
|
|
256
|
+
beforeEach(async () => {
|
|
257
|
+
home = await createTempDirectory('theia-copilot-locator-');
|
|
258
|
+
executable = await writeExecutable((0, path_1.join)(home, 'bin', process.platform === 'win32' ? 'copilot.exe' : 'copilot'));
|
|
259
|
+
});
|
|
260
|
+
afterEach(async () => {
|
|
261
|
+
await fs_1.promises.rm(home, { recursive: true, force: true });
|
|
262
|
+
});
|
|
263
|
+
it('should use the configured executable', async () => {
|
|
264
|
+
const locator = new TestableCopilotCliLocator();
|
|
265
|
+
locator.setConfiguredPath(executable);
|
|
266
|
+
(0, chai_1.expect)(await locator.resolve()).to.equal(executable);
|
|
267
|
+
});
|
|
268
|
+
it('should accept the directory holding the executable', async () => {
|
|
269
|
+
const locator = new TestableCopilotCliLocator();
|
|
270
|
+
locator.setConfiguredPath((0, path_1.join)(home, 'bin'));
|
|
271
|
+
(0, chai_1.expect)(await locator.resolve()).to.equal(executable);
|
|
272
|
+
});
|
|
273
|
+
it('should report a configured location that does not exist', async () => {
|
|
274
|
+
const locator = new TestableCopilotCliLocator();
|
|
275
|
+
const missing = (0, path_1.join)(home, 'nowhere', 'copilot');
|
|
276
|
+
locator.setConfiguredPath(missing);
|
|
277
|
+
try {
|
|
278
|
+
await locator.resolve();
|
|
279
|
+
chai_1.expect.fail('should have rejected');
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
(0, chai_1.expect)(String(error)).to.contain(missing);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
it('should search again after the configured location changed', async () => {
|
|
286
|
+
const locator = new TestableCopilotCliLocator();
|
|
287
|
+
locator.setConfiguredPath((0, path_1.join)(home, 'nowhere', 'copilot'));
|
|
288
|
+
await locator.resolve().catch(() => { });
|
|
289
|
+
locator.setConfiguredPath(executable);
|
|
290
|
+
(0, chai_1.expect)(await locator.resolve()).to.equal(executable);
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
describe('CopilotCliLocator - a Windows host', () => {
|
|
294
|
+
let root;
|
|
295
|
+
const locator = new WindowsLikeCopilotCliLocator();
|
|
296
|
+
beforeEach(async () => {
|
|
297
|
+
root = await createTempDirectory('theia-copilot-windows-');
|
|
298
|
+
});
|
|
299
|
+
afterEach(async () => {
|
|
300
|
+
await fs_1.promises.rm(root, { recursive: true, force: true });
|
|
301
|
+
});
|
|
302
|
+
/**
|
|
303
|
+
* Writes what a global npm installation leaves on Windows: a `copilot.cmd` shim in the prefix, and
|
|
304
|
+
* the platform package nested below the launcher, exporting its executable under the `.exe` name.
|
|
305
|
+
*/
|
|
306
|
+
async function installGlobally() {
|
|
307
|
+
const modules = (0, path_1.join)(root, 'node_modules');
|
|
308
|
+
await writeExecutable((0, path_1.join)(modules, '@github', 'copilot', 'npm-loader.js'));
|
|
309
|
+
const executable = await installPlatformPackage((0, path_1.join)(modules, '@github', 'copilot', 'node_modules'), WindowsLikeCopilotCliLocator.PACKAGE, WindowsLikeCopilotCliLocator.BINARY);
|
|
310
|
+
return { shim: await writeExecutable((0, path_1.join)(root, 'copilot.cmd')), executable };
|
|
311
|
+
}
|
|
312
|
+
it('should follow the shim of a global installation to the executable', async () => {
|
|
313
|
+
const { shim, executable } = await installGlobally();
|
|
314
|
+
(0, chai_1.expect)(locator.callToCandidatesOnPath(shim)).to.contain(executable);
|
|
315
|
+
});
|
|
316
|
+
it('should follow a configured shim to the executable, which is what can be spawned', async () => {
|
|
317
|
+
const { shim, executable } = await installGlobally();
|
|
318
|
+
locator.setConfiguredPath(shim);
|
|
319
|
+
try {
|
|
320
|
+
(0, chai_1.expect)(await locator.resolve()).to.equal(executable);
|
|
321
|
+
}
|
|
322
|
+
finally {
|
|
323
|
+
locator.setConfiguredPath(undefined);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
//# sourceMappingURL=copilot-cli-locator.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-cli-locator.spec.js","sourceRoot":"","sources":["../../src/node/copilot-cli-locator.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,+BAA8B;AAC9B,2BAAoC;AACpC,yBAAyB;AACzB,+BAA4B;AAC5B,yEAAqE;AACrE,+DAA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CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ILogger } from '@theia/core';
|
|
2
|
+
import { KeyStoreService } from '@theia/core/lib/common/key-store';
|
|
3
|
+
/**
|
|
4
|
+
* The credentials of the GitHub Copilot sign-in, as stored by {@link CopilotCredentialStore}.
|
|
5
|
+
*/
|
|
6
|
+
export interface CopilotCredentials {
|
|
7
|
+
/** The GitHub token the Copilot CLI is given for its requests. */
|
|
8
|
+
token: string;
|
|
9
|
+
/** The GitHub login the token belongs to, for display purposes. */
|
|
10
|
+
accountLabel?: string;
|
|
11
|
+
/** The GitHub Enterprise domain the sign-in was performed against, if any. */
|
|
12
|
+
enterpriseUrl?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Where the Copilot credentials of this application are kept.
|
|
16
|
+
*
|
|
17
|
+
* The credentials are held by the application rather than by the Copilot CLI, so that signing out
|
|
18
|
+
* only has to remove this entry and never has to touch credentials of the user's machine, such as
|
|
19
|
+
* their system keyring entries or their GitHub CLI sign-in.
|
|
20
|
+
*/
|
|
21
|
+
export declare class CopilotCredentialStore {
|
|
22
|
+
/** The keystore service name the credentials are stored under. */
|
|
23
|
+
static readonly SERVICE = "theia-copilot";
|
|
24
|
+
/** The keystore account name the credentials are stored under. */
|
|
25
|
+
static readonly ACCOUNT = "github-copilot";
|
|
26
|
+
/**
|
|
27
|
+
* The keystore service name the previous integration stored its OAuth token under.
|
|
28
|
+
*
|
|
29
|
+
* That token belonged to an OAuth application that is no longer used, so it is useless, and the
|
|
30
|
+
* code that could remove it is gone. It is therefore cleaned up once, rather than left behind on
|
|
31
|
+
* the machine of the user.
|
|
32
|
+
*/
|
|
33
|
+
static readonly LEGACY_SERVICE = "theia-copilot-auth";
|
|
34
|
+
protected readonly keyStoreService: KeyStoreService;
|
|
35
|
+
protected readonly logger: ILogger;
|
|
36
|
+
get(): Promise<CopilotCredentials | undefined>;
|
|
37
|
+
set(credentials: CopilotCredentials): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Removes the credentials of the previous integration, if any are still present.
|
|
40
|
+
* @returns whether something was removed, so that the user can be told why they are signed out
|
|
41
|
+
*/
|
|
42
|
+
deleteLegacy(): Promise<boolean>;
|
|
43
|
+
delete(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=copilot-credential-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-credential-store.d.ts","sourceRoot":"","sources":["../../src/node/copilot-credential-store.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAEnE;;GAEG;AACH,MAAM,WAAW,kBAAkB;IAC/B,kEAAkE;IAClE,KAAK,EAAE,MAAM,CAAC;IACd,mEAAmE;IACnE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,qBACa,sBAAsB;IAE/B,kEAAkE;IAClE,MAAM,CAAC,QAAQ,CAAC,OAAO,mBAAmB;IAC1C,kEAAkE;IAClE,MAAM,CAAC,QAAQ,CAAC,OAAO,oBAAoB;IAC3C;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CAAC,cAAc,wBAAwB;IAGtD,SAAS,CAAC,QAAQ,CAAC,eAAe,EAAE,eAAe,CAAC;IAGpD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;IAE7B,GAAG,IAAI,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAa9C,GAAG,CAAC,WAAW,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAIzD;;;OAGG;IACG,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;IAShC,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;CAOhC"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
var CopilotCredentialStore_1;
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.CopilotCredentialStore = void 0;
|
|
20
|
+
const tslib_1 = require("tslib");
|
|
21
|
+
const inversify_1 = require("@theia/core/shared/inversify");
|
|
22
|
+
const core_1 = require("@theia/core");
|
|
23
|
+
const key_store_1 = require("@theia/core/lib/common/key-store");
|
|
24
|
+
/**
|
|
25
|
+
* Where the Copilot credentials of this application are kept.
|
|
26
|
+
*
|
|
27
|
+
* The credentials are held by the application rather than by the Copilot CLI, so that signing out
|
|
28
|
+
* only has to remove this entry and never has to touch credentials of the user's machine, such as
|
|
29
|
+
* their system keyring entries or their GitHub CLI sign-in.
|
|
30
|
+
*/
|
|
31
|
+
let CopilotCredentialStore = class CopilotCredentialStore {
|
|
32
|
+
static { CopilotCredentialStore_1 = this; }
|
|
33
|
+
/** The keystore service name the credentials are stored under. */
|
|
34
|
+
static { this.SERVICE = 'theia-copilot'; }
|
|
35
|
+
/** The keystore account name the credentials are stored under. */
|
|
36
|
+
static { this.ACCOUNT = 'github-copilot'; }
|
|
37
|
+
/**
|
|
38
|
+
* The keystore service name the previous integration stored its OAuth token under.
|
|
39
|
+
*
|
|
40
|
+
* That token belonged to an OAuth application that is no longer used, so it is useless, and the
|
|
41
|
+
* code that could remove it is gone. It is therefore cleaned up once, rather than left behind on
|
|
42
|
+
* the machine of the user.
|
|
43
|
+
*/
|
|
44
|
+
static { this.LEGACY_SERVICE = 'theia-copilot-auth'; }
|
|
45
|
+
async get() {
|
|
46
|
+
try {
|
|
47
|
+
const stored = await this.keyStoreService.getPassword(CopilotCredentialStore_1.SERVICE, CopilotCredentialStore_1.ACCOUNT);
|
|
48
|
+
if (stored) {
|
|
49
|
+
const credentials = JSON.parse(stored);
|
|
50
|
+
return credentials.token ? credentials : undefined;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
this.logger.warn('Copilot: failed to read the stored credentials:', error);
|
|
55
|
+
}
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
async set(credentials) {
|
|
59
|
+
await this.keyStoreService.setPassword(CopilotCredentialStore_1.SERVICE, CopilotCredentialStore_1.ACCOUNT, JSON.stringify(credentials));
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Removes the credentials of the previous integration, if any are still present.
|
|
63
|
+
* @returns whether something was removed, so that the user can be told why they are signed out
|
|
64
|
+
*/
|
|
65
|
+
async deleteLegacy() {
|
|
66
|
+
try {
|
|
67
|
+
return await this.keyStoreService.deletePassword(CopilotCredentialStore_1.LEGACY_SERVICE, CopilotCredentialStore_1.ACCOUNT);
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.logger.warn('Copilot: failed to delete the credentials of the previous integration:', error);
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async delete() {
|
|
75
|
+
try {
|
|
76
|
+
await this.keyStoreService.deletePassword(CopilotCredentialStore_1.SERVICE, CopilotCredentialStore_1.ACCOUNT);
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
this.logger.warn('Copilot: failed to delete the stored credentials:', error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
exports.CopilotCredentialStore = CopilotCredentialStore;
|
|
84
|
+
tslib_1.__decorate([
|
|
85
|
+
(0, inversify_1.inject)(key_store_1.KeyStoreService),
|
|
86
|
+
tslib_1.__metadata("design:type", Object)
|
|
87
|
+
], CopilotCredentialStore.prototype, "keyStoreService", void 0);
|
|
88
|
+
tslib_1.__decorate([
|
|
89
|
+
(0, inversify_1.inject)(core_1.ILogger),
|
|
90
|
+
(0, inversify_1.named)('ai-copilot:CopilotCredentialStore'),
|
|
91
|
+
tslib_1.__metadata("design:type", Object)
|
|
92
|
+
], CopilotCredentialStore.prototype, "logger", void 0);
|
|
93
|
+
exports.CopilotCredentialStore = CopilotCredentialStore = CopilotCredentialStore_1 = tslib_1.__decorate([
|
|
94
|
+
(0, inversify_1.injectable)()
|
|
95
|
+
], CopilotCredentialStore);
|
|
96
|
+
//# sourceMappingURL=copilot-credential-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-credential-store.js","sourceRoot":"","sources":["../../src/node/copilot-credential-store.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;;;;AAEhF,4DAAyE;AACzE,sCAAsC;AACtC,gEAAmE;AAcnE;;;;;;GAMG;AAEI,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;;IAE/B,kEAAkE;aAClD,YAAO,GAAG,eAAe,AAAlB,CAAmB;IAC1C,kEAAkE;aAClD,YAAO,GAAG,gBAAgB,AAAnB,CAAoB;IAC3C;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AAO,CAAC,CAAC;QAC9G,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,mDAAmD,EAAE,KAAK,CAAC,CAAC;QACjF,CAAC;IACL,CAAC;;AAzDQ,wDAAsB;AAgBZ;IADlB,IAAA,kBAAM,EAAC,2BAAe,CAAC;;+DAC4B;AAGjC;IADlB,IAAA,kBAAM,EAAC,cAAO,CAAC;IAAE,IAAA,iBAAK,EAAC,mCAAmC,CAAC;;sDACzB;iCAnB1B,sBAAsB;IADlC,IAAA,sBAAU,GAAE;GACA,sBAAsB,CA0DlC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-credential-store.spec.d.ts","sourceRoot":"","sources":["../../src/node/copilot-credential-store.spec.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// *****************************************************************************
|
|
3
|
+
// Copyright (C) 2026 EclipseSource GmbH and others.
|
|
4
|
+
//
|
|
5
|
+
// This program and the accompanying materials are made available under the
|
|
6
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
7
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
8
|
+
//
|
|
9
|
+
// This Source Code may also be made available under the following Secondary
|
|
10
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
11
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
12
|
+
// with the GNU Classpath Exception which is available at
|
|
13
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
14
|
+
//
|
|
15
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
16
|
+
// *****************************************************************************
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const chai_1 = require("chai");
|
|
19
|
+
const mock_logger_1 = require("@theia/core/lib/common/test/mock-logger");
|
|
20
|
+
const copilot_credential_store_1 = require("./copilot-credential-store");
|
|
21
|
+
/** A keystore that records what was asked of it, keyed the way the real one is. */
|
|
22
|
+
class FakeKeyStore {
|
|
23
|
+
constructor() {
|
|
24
|
+
this.entries = new Map();
|
|
25
|
+
this.failing = false;
|
|
26
|
+
}
|
|
27
|
+
async getPassword(service, account) {
|
|
28
|
+
this.check();
|
|
29
|
+
return this.entries.get(`${service}/${account}`);
|
|
30
|
+
}
|
|
31
|
+
async setPassword(service, account, password) {
|
|
32
|
+
this.check();
|
|
33
|
+
this.entries.set(`${service}/${account}`, password);
|
|
34
|
+
}
|
|
35
|
+
async deletePassword(service, account) {
|
|
36
|
+
this.check();
|
|
37
|
+
return this.entries.delete(`${service}/${account}`);
|
|
38
|
+
}
|
|
39
|
+
check() {
|
|
40
|
+
if (this.failing) {
|
|
41
|
+
throw new Error('keychain unavailable');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function store(keyStore) {
|
|
46
|
+
const credentialStore = new copilot_credential_store_1.CopilotCredentialStore();
|
|
47
|
+
Object.assign(credentialStore, { keyStoreService: keyStore, logger: new mock_logger_1.MockLogger() });
|
|
48
|
+
return credentialStore;
|
|
49
|
+
}
|
|
50
|
+
describe('CopilotCredentialStore', () => {
|
|
51
|
+
const ours = `${copilot_credential_store_1.CopilotCredentialStore.SERVICE}/${copilot_credential_store_1.CopilotCredentialStore.ACCOUNT}`;
|
|
52
|
+
const legacy = `${copilot_credential_store_1.CopilotCredentialStore.LEGACY_SERVICE}/${copilot_credential_store_1.CopilotCredentialStore.ACCOUNT}`;
|
|
53
|
+
it('should keep the token together with the account it belongs to', async () => {
|
|
54
|
+
const keyStore = new FakeKeyStore();
|
|
55
|
+
await store(keyStore).set({ token: 'gho_token', accountLabel: 'octocat', enterpriseUrl: 'company.ghe.com' });
|
|
56
|
+
(0, chai_1.expect)(await store(keyStore).get()).to.deep.equal({ token: 'gho_token', accountLabel: 'octocat', enterpriseUrl: 'company.ghe.com' });
|
|
57
|
+
});
|
|
58
|
+
it('should report nothing when the application never signed in', async () => {
|
|
59
|
+
(0, chai_1.expect)(await store(new FakeKeyStore()).get()).to.be.undefined;
|
|
60
|
+
});
|
|
61
|
+
it('should report nothing for an entry without a token', async () => {
|
|
62
|
+
const keyStore = new FakeKeyStore();
|
|
63
|
+
keyStore.entries.set(ours, JSON.stringify({ accountLabel: 'octocat' }));
|
|
64
|
+
(0, chai_1.expect)(await store(keyStore).get()).to.be.undefined;
|
|
65
|
+
});
|
|
66
|
+
it('should report nothing for an entry that is not readable', async () => {
|
|
67
|
+
const keyStore = new FakeKeyStore();
|
|
68
|
+
keyStore.entries.set(ours, 'not json');
|
|
69
|
+
(0, chai_1.expect)(await store(keyStore).get()).to.be.undefined;
|
|
70
|
+
});
|
|
71
|
+
it('should report nothing rather than fail when the keychain is unavailable', async () => {
|
|
72
|
+
const keyStore = new FakeKeyStore();
|
|
73
|
+
keyStore.failing = true;
|
|
74
|
+
(0, chai_1.expect)(await store(keyStore).get()).to.be.undefined;
|
|
75
|
+
});
|
|
76
|
+
it('should remove only the entry of this application when signing out', async () => {
|
|
77
|
+
const keyStore = new FakeKeyStore();
|
|
78
|
+
keyStore.entries.set(ours, JSON.stringify({ token: 'gho_token' }));
|
|
79
|
+
keyStore.entries.set('some-other-tool/github', 'not ours');
|
|
80
|
+
await store(keyStore).delete();
|
|
81
|
+
(0, chai_1.expect)([...keyStore.entries.keys()]).to.deep.equal(['some-other-tool/github']);
|
|
82
|
+
});
|
|
83
|
+
it('should discard the sign-in of the previous integration and report that it did', async () => {
|
|
84
|
+
const keyStore = new FakeKeyStore();
|
|
85
|
+
keyStore.entries.set(legacy, JSON.stringify({ accessToken: 'gho_legacy' }));
|
|
86
|
+
(0, chai_1.expect)(await store(keyStore).deleteLegacy()).to.be.true;
|
|
87
|
+
(0, chai_1.expect)(keyStore.entries.has(legacy)).to.be.false;
|
|
88
|
+
});
|
|
89
|
+
it('should report that there was no previous sign-in to discard', async () => {
|
|
90
|
+
(0, chai_1.expect)(await store(new FakeKeyStore()).deleteLegacy()).to.be.false;
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
//# sourceMappingURL=copilot-credential-store.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"copilot-credential-store.spec.js","sourceRoot":"","sources":["../../src/node/copilot-credential-store.spec.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,oDAAoD;AACpD,EAAE;AACF,2EAA2E;AAC3E,mEAAmE;AACnE,wCAAwC;AACxC,EAAE;AACF,4EAA4E;AAC5E,8EAA8E;AAC9E,6EAA6E;AAC7E,yDAAyD;AACzD,uDAAuD;AACvD,EAAE;AACF,gFAAgF;AAChF,gFAAgF;;AAEhF,+BAA8B;AAC9B,yEAAqE;AACrE,yEAAoE;AAEpE,mFAAmF;AACnF,MAAM,YAAY;IAAlB;QAEa,YAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,YAAO,GAAG,KAAK,CAAC;IAsBpB,CAAC;IApBG,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,OAAe;QAC9C,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,IAAI,OAAO,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAAe,EAAE,OAAe,EAAE,QAAgB;QAChE,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,OAAO,IAAI,OAAO,EAAE,EAAE,QAAQ,CAAC,CAAC;IACxD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,OAAe;QACjD,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,OAAO,IAAI,OAAO,EAAE,CAAC,CAAC;IACxD,CAAC;IAES,KAAK;QACX,IAAI,IAAI,CAAC,OAA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