@theia/core 1.78.0-next.0 → 1.78.0-next.23
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/lib/browser/catalog.json +247 -32
- package/lib/browser/encoding-registry.js +1 -1
- package/lib/browser/encoding-registry.js.map +1 -1
- package/lib/browser/encoding-registry.spec.d.ts +2 -0
- package/lib/browser/encoding-registry.spec.d.ts.map +1 -0
- package/lib/browser/encoding-registry.spec.js +43 -0
- package/lib/browser/encoding-registry.spec.js.map +1 -0
- package/lib/browser/messaging/service-connection-provider.d.ts.map +1 -1
- package/lib/browser/messaging/service-connection-provider.js +9 -1
- package/lib/browser/messaging/service-connection-provider.js.map +1 -1
- package/lib/browser/messaging/service-connection-provider.spec.d.ts +2 -0
- package/lib/browser/messaging/service-connection-provider.spec.d.ts.map +1 -0
- package/lib/browser/messaging/service-connection-provider.spec.js +76 -0
- package/lib/browser/messaging/service-connection-provider.spec.js.map +1 -0
- package/lib/browser/shell/application-shell.d.ts.map +1 -1
- package/lib/browser/shell/application-shell.js +13 -1
- package/lib/browser/shell/application-shell.js.map +1 -1
- package/lib/browser/shell/tab-bars.d.ts +78 -1
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +267 -18
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +401 -1
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/lib/browser/widgets/widget.d.ts.map +1 -1
- package/lib/browser/widgets/widget.js +34 -1
- package/lib/browser/widgets/widget.js.map +1 -1
- package/lib/common/core-preferences.d.ts +2 -0
- package/lib/common/core-preferences.d.ts.map +1 -1
- package/lib/common/core-preferences.js +21 -1
- package/lib/common/core-preferences.js.map +1 -1
- package/lib/common/messaging/handler.d.ts +11 -0
- package/lib/common/messaging/handler.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.d.ts +8 -1
- package/lib/common/messaging/proxy-factory.d.ts.map +1 -1
- package/lib/common/messaging/proxy-factory.js +4 -2
- package/lib/common/messaging/proxy-factory.js.map +1 -1
- package/lib/common/messaging/proxy-factory.spec.js +16 -1
- package/lib/common/messaging/proxy-factory.spec.js.map +1 -1
- package/lib/common/messaging/socket-write-buffer.d.ts +8 -2
- package/lib/common/messaging/socket-write-buffer.d.ts.map +1 -1
- package/lib/common/messaging/socket-write-buffer.js +18 -12
- package/lib/common/messaging/socket-write-buffer.js.map +1 -1
- package/lib/common/messaging/socket-write-buffer.spec.d.ts +2 -0
- package/lib/common/messaging/socket-write-buffer.spec.d.ts.map +1 -0
- package/lib/common/messaging/socket-write-buffer.spec.js +72 -0
- package/lib/common/messaging/socket-write-buffer.spec.js.map +1 -0
- package/lib/common/shell-environment.d.ts +61 -0
- package/lib/common/shell-environment.d.ts.map +1 -0
- package/lib/common/shell-environment.js +29 -0
- package/lib/common/shell-environment.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.d.ts +20 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.js +72 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.d.ts +2 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.js +86 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-contribution.spec.js.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.d.ts +4 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.d.ts.map +1 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.js +26 -0
- package/lib/electron-browser/shell-environment/electron-shell-environment-module.js.map +1 -0
- package/lib/electron-main/electron-main-application.d.ts.map +1 -1
- package/lib/electron-main/electron-main-application.js +12 -4
- package/lib/electron-main/electron-main-application.js.map +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.d.ts.map +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.js +1 -1
- package/lib/electron-node/keyboard/electron-backend-keyboard-module.js.map +1 -1
- package/lib/electron-node/request/electron-backend-request-service.d.ts +4 -1
- package/lib/electron-node/request/electron-backend-request-service.d.ts.map +1 -1
- package/lib/electron-node/request/electron-backend-request-service.js +56 -13
- package/lib/electron-node/request/electron-backend-request-service.js.map +1 -1
- package/lib/node/backend-application-module.d.ts.map +1 -1
- package/lib/node/backend-application-module.js +13 -5
- package/lib/node/backend-application-module.js.map +1 -1
- package/lib/node/env-variables/env-variables-server.d.ts +13 -3
- package/lib/node/env-variables/env-variables-server.d.ts.map +1 -1
- package/lib/node/env-variables/env-variables-server.js +21 -14
- package/lib/node/env-variables/env-variables-server.js.map +1 -1
- package/lib/node/env-variables/env-variables-server.spec.d.ts +2 -0
- package/lib/node/env-variables/env-variables-server.spec.d.ts.map +1 -0
- package/lib/node/env-variables/env-variables-server.spec.js +83 -0
- package/lib/node/env-variables/env-variables-server.spec.js.map +1 -0
- package/lib/node/i18n/i18n-backend-module.js +2 -2
- package/lib/node/i18n/i18n-backend-module.js.map +1 -1
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/logger-backend-module.js +1 -1
- package/lib/node/logger-backend-module.js.map +1 -1
- package/lib/node/messaging/connection-container-module.d.ts +11 -2
- package/lib/node/messaging/connection-container-module.d.ts.map +1 -1
- package/lib/node/messaging/connection-container-module.js +13 -2
- package/lib/node/messaging/connection-container-module.js.map +1 -1
- package/lib/node/messaging/connection-container-module.spec.d.ts +2 -0
- package/lib/node/messaging/connection-container-module.spec.d.ts.map +1 -0
- package/lib/node/messaging/connection-container-module.spec.js +37 -0
- package/lib/node/messaging/connection-container-module.spec.js.map +1 -0
- package/lib/node/messaging/default-messaging-service.d.ts +33 -4
- package/lib/node/messaging/default-messaging-service.d.ts.map +1 -1
- package/lib/node/messaging/default-messaging-service.js +52 -10
- package/lib/node/messaging/default-messaging-service.js.map +1 -1
- package/lib/node/messaging/gated-channel-multiplexer.d.ts +20 -0
- package/lib/node/messaging/gated-channel-multiplexer.d.ts.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.js +50 -0
- package/lib/node/messaging/gated-channel-multiplexer.js.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.d.ts +2 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.d.ts.map +1 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.js +74 -0
- package/lib/node/messaging/gated-channel-multiplexer.spec.js.map +1 -0
- package/lib/node/messaging/index.d.ts +1 -0
- package/lib/node/messaging/index.d.ts.map +1 -1
- package/lib/node/messaging/index.js +1 -0
- package/lib/node/messaging/index.js.map +1 -1
- package/lib/node/messaging/messaging-backend-module.js +1 -1
- package/lib/node/messaging/messaging-backend-module.js.map +1 -1
- package/lib/node/messaging/messaging-service.d.ts +5 -1
- package/lib/node/messaging/messaging-service.d.ts.map +1 -1
- package/lib/node/messaging/messaging-service.js.map +1 -1
- package/lib/node/messaging/test/default-messaging-service.spec.js +82 -2
- package/lib/node/messaging/test/default-messaging-service.spec.js.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.d.ts +1 -0
- package/lib/node/messaging/websocket-frontend-connection-service.d.ts.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.js +8 -0
- package/lib/node/messaging/websocket-frontend-connection-service.js.map +1 -1
- package/lib/node/messaging/websocket-frontend-connection-service.spec.d.ts +2 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.d.ts.map +1 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.js +141 -0
- package/lib/node/messaging/websocket-frontend-connection-service.spec.js.map +1 -0
- package/lib/node/performance/measurement-backend-bindings.js +1 -1
- package/lib/node/performance/measurement-backend-bindings.js.map +1 -1
- package/lib/node/process-utils.d.ts +125 -2
- package/lib/node/process-utils.d.ts.map +1 -1
- package/lib/node/process-utils.js +297 -25
- package/lib/node/process-utils.js.map +1 -1
- package/lib/node/process-utils.slow-spec.js +78 -3
- package/lib/node/process-utils.slow-spec.js.map +1 -1
- package/lib/node/process-utils.spec.js +237 -2
- package/lib/node/process-utils.spec.js.map +1 -1
- package/lib/node/shell-environment.d.ts +107 -0
- package/lib/node/shell-environment.d.ts.map +1 -0
- package/lib/node/shell-environment.js +396 -0
- package/lib/node/shell-environment.js.map +1 -0
- package/lib/node/shell-environment.spec.d.ts +2 -0
- package/lib/node/shell-environment.spec.d.ts.map +1 -0
- package/lib/node/shell-environment.spec.js +348 -0
- package/lib/node/shell-environment.spec.js.map +1 -0
- package/lib/node/test/exiting-backend.d.ts +5 -0
- package/lib/node/test/exiting-backend.d.ts.map +1 -1
- package/lib/node/test/exiting-backend.js +16 -3
- package/lib/node/test/exiting-backend.js.map +1 -1
- package/package.json +7 -4
- package/src/browser/encoding-registry.spec.ts +48 -0
- package/src/browser/encoding-registry.ts +1 -1
- package/src/browser/messaging/service-connection-provider.spec.ts +88 -0
- package/src/browser/messaging/service-connection-provider.ts +9 -2
- package/src/browser/shell/application-shell.ts +14 -1
- package/src/browser/shell/tab-bars.spec.ts +452 -1
- package/src/browser/shell/tab-bars.ts +285 -20
- package/src/browser/style/tabs.css +58 -3
- package/src/browser/widgets/widget.ts +36 -1
- package/src/common/core-preferences.ts +23 -1
- package/src/common/messaging/handler.ts +11 -0
- package/src/common/messaging/proxy-factory.spec.ts +17 -1
- package/src/common/messaging/proxy-factory.ts +16 -2
- package/src/common/messaging/socket-write-buffer.spec.ts +90 -0
- package/src/common/messaging/socket-write-buffer.ts +18 -14
- package/src/common/shell-environment.ts +81 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-contribution.spec.ts +95 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-contribution.ts +72 -0
- package/src/electron-browser/shell-environment/electron-shell-environment-module.ts +29 -0
- package/src/electron-main/electron-main-application.ts +15 -4
- package/src/electron-node/keyboard/electron-backend-keyboard-module.ts +2 -1
- package/src/electron-node/request/electron-backend-request-service.ts +59 -11
- package/src/node/backend-application-module.ts +19 -5
- package/src/node/env-variables/env-variables-server.spec.ts +93 -0
- package/src/node/env-variables/env-variables-server.ts +22 -14
- package/src/node/i18n/i18n-backend-module.ts +2 -2
- package/src/node/index.ts +1 -0
- package/src/node/logger-backend-module.ts +1 -1
- package/src/node/messaging/connection-container-module.spec.ts +39 -0
- package/src/node/messaging/connection-container-module.ts +16 -4
- package/src/node/messaging/default-messaging-service.ts +64 -10
- package/src/node/messaging/gated-channel-multiplexer.spec.ts +80 -0
- package/src/node/messaging/gated-channel-multiplexer.ts +52 -0
- package/src/node/messaging/index.ts +1 -0
- package/src/node/messaging/messaging-backend-module.ts +1 -1
- package/src/node/messaging/messaging-service.ts +5 -1
- package/src/node/messaging/test/default-messaging-service.spec.ts +89 -2
- package/src/node/messaging/websocket-frontend-connection-service.spec.ts +158 -0
- package/src/node/messaging/websocket-frontend-connection-service.ts +9 -0
- package/src/node/performance/measurement-backend-bindings.ts +1 -1
- package/src/node/process-utils.slow-spec.ts +90 -3
- package/src/node/process-utils.spec.ts +268 -3
- package/src/node/process-utils.ts +342 -24
- package/src/node/shell-environment.spec.ts +388 -0
- package/src/node/shell-environment.ts +406 -0
- package/src/node/test/exiting-backend.ts +17 -3
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
// *****************************************************************************
|
|
2
|
+
// Copyright (C) 2026 STMicroelectronics and others.
|
|
3
|
+
//
|
|
4
|
+
// This program and the accompanying materials are made available under the
|
|
5
|
+
// terms of the Eclipse Public License v. 2.0 which is available at
|
|
6
|
+
// http://www.eclipse.org/legal/epl-2.0.
|
|
7
|
+
//
|
|
8
|
+
// This Source Code may also be made available under the following Secondary
|
|
9
|
+
// Licenses when the conditions for such availability set forth in the Eclipse
|
|
10
|
+
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
|
|
11
|
+
// with the GNU Classpath Exception which is available at
|
|
12
|
+
// https://www.gnu.org/software/classpath/license.html.
|
|
13
|
+
//
|
|
14
|
+
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
|
|
15
|
+
// *****************************************************************************
|
|
16
|
+
|
|
17
|
+
import { expect } from 'chai';
|
|
18
|
+
import { ChildProcess } from 'child_process';
|
|
19
|
+
import { Container } from 'inversify';
|
|
20
|
+
import { ILogger } from '../common/logger.js';
|
|
21
|
+
import { Stopwatch } from '../common/performance/index.js';
|
|
22
|
+
import { ShellEnvironmentResolutionTimeout } from '../common/shell-environment.js';
|
|
23
|
+
import { MockLogger } from '../common/test/mock-logger.js';
|
|
24
|
+
import { NodeStopwatch } from './performance/node-stopwatch.js';
|
|
25
|
+
import { SettingService } from './setting-service.js';
|
|
26
|
+
import { ShellEnvironmentServerImpl } from './shell-environment.js';
|
|
27
|
+
|
|
28
|
+
/** A setting service that keeps its values in memory and counts the writes. */
|
|
29
|
+
class TestSettingService implements SettingService {
|
|
30
|
+
readonly values = new Map<string, string>();
|
|
31
|
+
writes = 0;
|
|
32
|
+
|
|
33
|
+
async get(key: string): Promise<string | undefined> {
|
|
34
|
+
return this.values.get(key);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async set(key: string, value: string): Promise<void> {
|
|
38
|
+
this.writes++;
|
|
39
|
+
this.values.set(key, value);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The service with the login shell replaced by Node running a script, so that the tests run without a shell,
|
|
45
|
+
* and with the resolution enabled, which it is not where the tests run.
|
|
46
|
+
*/
|
|
47
|
+
class TestShellEnvironment extends ShellEnvironmentServerImpl {
|
|
48
|
+
/** The script to run in place of the login shell's command. Its first argument is the marker. */
|
|
49
|
+
script = '';
|
|
50
|
+
|
|
51
|
+
protected override getSkipReason(): string | undefined {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
protected override getLoginShell(): string {
|
|
56
|
+
return process.execPath;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected override getShellArguments(shell: string, mark: string): string[] {
|
|
60
|
+
return ['-e', this.script, mark];
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
override getResolutionTimeout(): Promise<number> {
|
|
64
|
+
return super.getResolutionTimeout();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The environment that was handed over to be applied. */
|
|
68
|
+
applied: NodeJS.ProcessEnv | undefined;
|
|
69
|
+
|
|
70
|
+
protected override apply(env: NodeJS.ProcessEnv): void {
|
|
71
|
+
this.applied = env;
|
|
72
|
+
super.apply(env);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** How often the login shell was killed. */
|
|
76
|
+
kills = 0;
|
|
77
|
+
|
|
78
|
+
protected override kill(child: ChildProcess): void {
|
|
79
|
+
this.kills++;
|
|
80
|
+
super.kill(child);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Settles once the login shell is running. */
|
|
84
|
+
async whenShellStarted(): Promise<void> {
|
|
85
|
+
while (!this.shell) {
|
|
86
|
+
await new Promise(resolve => setTimeout(resolve, 10));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/** The service with the shell arguments exposed. */
|
|
92
|
+
class ExposedShellEnvironment extends ShellEnvironmentServerImpl {
|
|
93
|
+
override getShellArguments(shell: string, mark: string, executable?: string): string[] {
|
|
94
|
+
return super.getShellArguments(shell, mark, executable);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
describe('ShellEnvironmentServerImpl', () => {
|
|
99
|
+
|
|
100
|
+
const prefix = 'THEIA_SHELL_ENVIRONMENT_SPEC_';
|
|
101
|
+
const restored = ['PATH', 'ELECTRON_RUN_AS_NODE', 'THEIA_RESOLVING_ENVIRONMENT', 'DISABLE_AUTO_UPDATE', 'XDG_RUNTIME_DIR', 'DEBUG'];
|
|
102
|
+
let original: Map<string, string | undefined>;
|
|
103
|
+
|
|
104
|
+
/** The script writes the given JSON source between the markers, with what dotfiles might print around it. */
|
|
105
|
+
const printing = (json: string) => `process.stdout.write('Welcome!\\n' + process.argv[1] + JSON.stringify(${json}) + process.argv[1] + '\\nbye\\n')`;
|
|
106
|
+
|
|
107
|
+
/** The script starts a detached program that inherits the stdout of the "shell" and keeps it open for four seconds. */
|
|
108
|
+
const backgroundJob = "require('child_process').spawn(process.execPath, ['-e', 'setTimeout(() => { }, 4000)'], "
|
|
109
|
+
+ "{ detached: true, stdio: ['ignore', 'inherit', 'ignore'] }).unref();";
|
|
110
|
+
|
|
111
|
+
const setup = (script: string, timeout?: string): { environment: TestShellEnvironment, settings: TestSettingService } => {
|
|
112
|
+
const container = new Container({ defaultScope: 'Singleton' });
|
|
113
|
+
container.bind(ILogger).to(MockLogger);
|
|
114
|
+
container.bind(Stopwatch).to(NodeStopwatch);
|
|
115
|
+
container.bind(TestSettingService).toSelf();
|
|
116
|
+
container.bind(SettingService).toService(TestSettingService);
|
|
117
|
+
container.bind(TestShellEnvironment).toSelf();
|
|
118
|
+
container.bind(ShellEnvironmentServerImpl).toSelf();
|
|
119
|
+
const settings = container.get(TestSettingService);
|
|
120
|
+
if (timeout !== undefined) {
|
|
121
|
+
settings.values.set(ShellEnvironmentResolutionTimeout.PREFERENCE, timeout);
|
|
122
|
+
}
|
|
123
|
+
const environment = container.get(TestShellEnvironment);
|
|
124
|
+
environment.script = script;
|
|
125
|
+
return { environment, settings };
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
beforeEach(() => {
|
|
129
|
+
original = new Map(restored.map(key => [key, process.env[key]]));
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
afterEach(() => {
|
|
133
|
+
for (const key of Object.keys(process.env)) {
|
|
134
|
+
if (key.startsWith(prefix)) {
|
|
135
|
+
delete process.env[key];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
for (const [key, value] of original) {
|
|
139
|
+
if (value === undefined) {
|
|
140
|
+
delete process.env[key];
|
|
141
|
+
} else {
|
|
142
|
+
process.env[key] = value;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('applies the PATH that the login shell prints, ignoring what its configuration prints around it', async () => {
|
|
148
|
+
const { environment } = setup(printing("{ PATH: '/login/bin:/usr/bin' }"));
|
|
149
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
150
|
+
expect(process.env.PATH).to.equal('/login/bin:/usr/bin');
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it('runs the login shell with a variable that tells the shell configuration that the environment is being resolved', async () => {
|
|
154
|
+
const { environment } = setup(printing("{ PATH: '/resolving/' + process.env.THEIA_RESOLVING_ENVIRONMENT }"));
|
|
155
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
156
|
+
expect(process.env.PATH).to.equal('/resolving/1');
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it('applies no variable of the login shell but PATH', async () => {
|
|
160
|
+
const { environment } = setup(printing(`{
|
|
161
|
+
PATH: '/login/bin', ${prefix}VARIABLE: 'from the shell',
|
|
162
|
+
ELECTRON_RUN_AS_NODE: process.env.ELECTRON_RUN_AS_NODE, THEIA_RESOLVING_ENVIRONMENT: '1',
|
|
163
|
+
DISABLE_AUTO_UPDATE: 'true', XDG_RUNTIME_DIR: '/run/user/login', DEBUG: '*'
|
|
164
|
+
}`));
|
|
165
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
166
|
+
expect(process.env.PATH).to.equal('/login/bin');
|
|
167
|
+
expect(process.env[`${prefix}VARIABLE`]).to.be.undefined;
|
|
168
|
+
for (const key of restored.filter(variable => variable !== 'PATH')) {
|
|
169
|
+
expect(process.env[key], key).to.equal(original.get(key));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('hands over the environment of the login shell without the variables that were set for the resolution', async () => {
|
|
174
|
+
process.env.DISABLE_AUTO_UPDATE = 'backend';
|
|
175
|
+
const { environment } = setup(printing(`{ ...process.env, PATH: '/login/bin', ${prefix}VARIABLE: 'from the shell' }`));
|
|
176
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
177
|
+
expect(environment.applied).to.include({ PATH: '/login/bin', [`${prefix}VARIABLE`]: 'from the shell' });
|
|
178
|
+
for (const key of ['ELECTRON_RUN_AS_NODE', 'ELECTRON_NO_ATTACH_CONSOLE', 'THEIA_RESOLVING_ENVIRONMENT',
|
|
179
|
+
'DISABLE_AUTO_UPDATE', 'ZSH_TMUX_AUTOSTART', 'ZSH_TMUX_AUTOSTARTED']) {
|
|
180
|
+
expect(environment.applied![key], key).to.equal(process.env[key]);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('reports a login shell environment that defines no PATH', async () => {
|
|
185
|
+
const { environment } = setup(printing(`{ ${prefix}VARIABLE: 'from the shell' }`));
|
|
186
|
+
const resolution = await environment.whenResolved();
|
|
187
|
+
expect(resolution.status).to.equal('failed');
|
|
188
|
+
expect(resolution.reason).to.contain('does not define PATH');
|
|
189
|
+
expect(process.env.PATH).to.equal(original.get('PATH'));
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('gives up on a login shell that does not answer within the timeout', async function (): Promise<void> {
|
|
193
|
+
this.timeout(10_000);
|
|
194
|
+
const { environment } = setup('setInterval(() => { }, 1000)', '1');
|
|
195
|
+
const start = Date.now();
|
|
196
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'timeout' });
|
|
197
|
+
const elapsed = Date.now() - start;
|
|
198
|
+
expect(elapsed).to.be.at.least(900).and.at.most(5000);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('gives up at the timeout even if a program started by the shell configuration keeps the output open', async function (): Promise<void> {
|
|
202
|
+
this.timeout(10_000);
|
|
203
|
+
// the detached program escapes the killing of the shell's process group and keeps the pipe open
|
|
204
|
+
const { environment } = setup(backgroundJob + 'setInterval(() => { }, 1000)', '1');
|
|
205
|
+
const start = Date.now();
|
|
206
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'timeout' });
|
|
207
|
+
expect(Date.now() - start).to.be.at.most(2500);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('applies the environment once the login shell has exited, even if a program that it started keeps the output open', async function (): Promise<void> {
|
|
211
|
+
this.timeout(10_000);
|
|
212
|
+
const { environment } = setup(backgroundJob + printing("{ PATH: '/background/job' }"), '3');
|
|
213
|
+
const start = Date.now();
|
|
214
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
215
|
+
expect(Date.now() - start).to.be.at.most(2000);
|
|
216
|
+
expect(process.env.PATH).to.equal('/background/job');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('reports a login shell that exits without printing its environment while a program that it started keeps the output open',
|
|
220
|
+
async function (): Promise<void> {
|
|
221
|
+
this.timeout(10_000);
|
|
222
|
+
const { environment } = setup(backgroundJob, '1');
|
|
223
|
+
const resolution = await environment.whenResolved();
|
|
224
|
+
expect(resolution.status).to.equal('failed');
|
|
225
|
+
expect(resolution.reason).to.contain('did not print its environment');
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it('applies the environment that the login shell printed, even if it does not exit within the timeout', async function (): Promise<void> {
|
|
229
|
+
this.timeout(10_000);
|
|
230
|
+
const { environment } = setup(printing("{ PATH: '/hanging/shell' }") + '; setInterval(() => { }, 1000)', '1');
|
|
231
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
232
|
+
expect(process.env.PATH).to.equal('/hanging/shell');
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it('kills a login shell that is still running when the backend stops', async function (): Promise<void> {
|
|
236
|
+
this.timeout(10_000);
|
|
237
|
+
const { environment } = setup('setInterval(() => { }, 1000)', '8');
|
|
238
|
+
const start = Date.now();
|
|
239
|
+
const resolved = environment.whenResolved();
|
|
240
|
+
await environment.whenShellStarted();
|
|
241
|
+
environment.onStop();
|
|
242
|
+
const resolution = await resolved;
|
|
243
|
+
expect(resolution.status).to.equal('failed');
|
|
244
|
+
// SIGKILL for its process group, or SIGTERM on Windows, where there is none and any signal ends the process
|
|
245
|
+
expect(resolution.reason).to.contain('exited with signal');
|
|
246
|
+
expect(Date.now() - start).to.be.at.most(5000);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it('kills nothing when the backend stops after the login shell has exited', async function (): Promise<void> {
|
|
250
|
+
this.timeout(10_000);
|
|
251
|
+
// the program that the shell configuration started is still running
|
|
252
|
+
const { environment } = setup(backgroundJob + printing("{ PATH: '/exited' }"), '3');
|
|
253
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
254
|
+
environment.onStop();
|
|
255
|
+
expect(environment.kills).to.equal(0);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it('settles with the default timeout when the stored timeout cannot be read', async () => {
|
|
259
|
+
const { environment, settings } = setup(printing("{ PATH: '/default/timeout' }"));
|
|
260
|
+
settings.get = async () => { throw new Error('The settings cannot be read'); };
|
|
261
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
262
|
+
expect(process.env.PATH).to.equal('/default/timeout');
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('reports a login shell that fails', async () => {
|
|
266
|
+
const { environment } = setup('process.exit(3)');
|
|
267
|
+
const resolution = await environment.whenResolved();
|
|
268
|
+
expect(resolution.status).to.equal('failed');
|
|
269
|
+
expect(resolution.reason).to.contain('code 3');
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
it('reports a login shell that does not print its environment', async () => {
|
|
273
|
+
const { environment } = setup("process.stdout.write('nothing to see')");
|
|
274
|
+
const resolution = await environment.whenResolved();
|
|
275
|
+
expect(resolution.status).to.equal('failed');
|
|
276
|
+
expect(resolution.reason).to.contain('did not print its environment');
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it('reports an environment that cannot be parsed', async () => {
|
|
280
|
+
const { environment } = setup("process.stdout.write(process.argv[1] + '{' + process.argv[1])");
|
|
281
|
+
const resolution = await environment.whenResolved();
|
|
282
|
+
expect(resolution.status).to.equal('failed');
|
|
283
|
+
expect(resolution.reason).to.contain('could not be parsed');
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('resolves once and shares the outcome', async () => {
|
|
287
|
+
const { environment } = setup(printing("{ PATH: '/once' }"));
|
|
288
|
+
environment.initialize();
|
|
289
|
+
const first = environment.whenResolved();
|
|
290
|
+
expect(environment.whenResolved()).to.equal(first);
|
|
291
|
+
expect(await first).to.deep.equal({ status: 'applied' });
|
|
292
|
+
process.env.PATH = '/changed';
|
|
293
|
+
expect(await environment.whenResolved()).to.deep.equal({ status: 'applied' });
|
|
294
|
+
expect(process.env.PATH).to.equal('/changed');
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it('skips the resolution where it does not apply', async () => {
|
|
298
|
+
const { environment } = setup('');
|
|
299
|
+
const container = new Container();
|
|
300
|
+
container.bind(ILogger).to(MockLogger);
|
|
301
|
+
container.bind(Stopwatch).to(NodeStopwatch);
|
|
302
|
+
container.bind(SettingService).toConstantValue(new TestSettingService());
|
|
303
|
+
container.bind(ShellEnvironmentServerImpl).toSelf();
|
|
304
|
+
const unmodified = container.get(ShellEnvironmentServerImpl);
|
|
305
|
+
const resolution = await unmodified.whenResolved();
|
|
306
|
+
expect(resolution.status).to.equal('skipped');
|
|
307
|
+
expect(resolution.reason).to.match(process.platform === 'win32' ? /Windows/ : /Electron/);
|
|
308
|
+
expect(await environment.getResolutionTimeout()).to.equal(ShellEnvironmentResolutionTimeout.DEFAULT);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('skips the resolution in a backend that the login shell being resolved has started', async function (): Promise<void> {
|
|
312
|
+
if (process.platform === 'win32') {
|
|
313
|
+
this.skip();
|
|
314
|
+
}
|
|
315
|
+
const versions = process.versions as { electron?: string };
|
|
316
|
+
const electron = versions.electron;
|
|
317
|
+
versions.electron = electron ?? '0.0.0-test';
|
|
318
|
+
process.env.THEIA_RESOLVING_ENVIRONMENT = '1';
|
|
319
|
+
try {
|
|
320
|
+
const container = new Container();
|
|
321
|
+
container.bind(ILogger).to(MockLogger);
|
|
322
|
+
container.bind(Stopwatch).to(NodeStopwatch);
|
|
323
|
+
container.bind(SettingService).toConstantValue(new TestSettingService());
|
|
324
|
+
container.bind(ShellEnvironmentServerImpl).toSelf();
|
|
325
|
+
const resolution = await container.get(ShellEnvironmentServerImpl).whenResolved();
|
|
326
|
+
expect(resolution.status).to.equal('skipped');
|
|
327
|
+
expect(resolution.reason).to.contain('login shell');
|
|
328
|
+
} finally {
|
|
329
|
+
if (electron === undefined) {
|
|
330
|
+
delete versions.electron;
|
|
331
|
+
} else {
|
|
332
|
+
versions.electron = electron;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('uses the stored resolution timeout within its bounds', async () => {
|
|
338
|
+
const timeout = (stored?: string) => setup('', stored).environment.getResolutionTimeout();
|
|
339
|
+
expect(await timeout()).to.equal(10);
|
|
340
|
+
expect(await timeout('')).to.equal(10);
|
|
341
|
+
expect(await timeout('soon')).to.equal(10);
|
|
342
|
+
expect(await timeout('30')).to.equal(30);
|
|
343
|
+
expect(await timeout('0')).to.equal(1);
|
|
344
|
+
expect(await timeout('300')).to.equal(120);
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it('stores the resolution timeout for the next start when it changes', async () => {
|
|
348
|
+
const { environment, settings } = setup('');
|
|
349
|
+
await environment.setResolutionTimeout(30);
|
|
350
|
+
expect(settings.values.get(ShellEnvironmentResolutionTimeout.PREFERENCE)).to.equal('30');
|
|
351
|
+
await environment.setResolutionTimeout(30);
|
|
352
|
+
expect(settings.writes).to.equal(1);
|
|
353
|
+
await environment.setResolutionTimeout(undefined);
|
|
354
|
+
expect(settings.values.get(ShellEnvironmentResolutionTimeout.PREFERENCE)).to.equal('');
|
|
355
|
+
await environment.setResolutionTimeout(undefined);
|
|
356
|
+
expect(settings.writes).to.equal(2);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('runs the login shell interactively and as a login shell, printing the environment with this executable', () => {
|
|
360
|
+
const environment = new ExposedShellEnvironment();
|
|
361
|
+
const mark = 'abc123';
|
|
362
|
+
const posix = environment.getShellArguments('/bin/zsh', mark);
|
|
363
|
+
expect(posix.slice(0, 3)).to.deep.equal(['-i', '-l', '-c']);
|
|
364
|
+
expect(posix[3]).to.contain(process.execPath).and.to.contain(`"${mark}" + JSON.stringify(process.env) + "${mark}"`);
|
|
365
|
+
expect(environment.getShellArguments('/bin/tcsh', mark).slice(0, 1)).to.deep.equal(['-ic']);
|
|
366
|
+
for (const pwsh of ['/usr/local/bin/pwsh', '/usr/local/bin/pwsh-preview', '/usr/bin/powershell']) {
|
|
367
|
+
const powershell = environment.getShellArguments(pwsh, mark);
|
|
368
|
+
expect(powershell.slice(0, 2), pwsh).to.deep.equal(['-Login', '-Command']);
|
|
369
|
+
expect(powershell[2], pwsh).to.contain(process.execPath).and.to.contain(`''${mark}''`);
|
|
370
|
+
}
|
|
371
|
+
const nu = environment.getShellArguments('/opt/homebrew/bin/nu', mark);
|
|
372
|
+
expect(nu.slice(0, 3)).to.deep.equal(['-i', '-l', '-c']);
|
|
373
|
+
expect(nu[3]).to.contain(`^'${process.execPath}' -p`).and.to.contain(`"${mark}" + JSON.stringify(process.env) + "${mark}"`);
|
|
374
|
+
const xonsh = environment.getShellArguments('/usr/bin/xonsh', mark);
|
|
375
|
+
expect(xonsh).to.deep.equal(['-i', '-l', '-c', `import os, json; print("${mark}", json.dumps(dict(os.environ)), "${mark}")`]);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('quotes the executable for the shell even if its path contains a single quote', () => {
|
|
379
|
+
const environment = new ExposedShellEnvironment();
|
|
380
|
+
const executable = "/Applications/Theia's IDE.app/Contents/MacOS/Theia";
|
|
381
|
+
const quoted = "'/Applications/Theia'\\''s IDE.app/Contents/MacOS/Theia' -p";
|
|
382
|
+
expect(environment.getShellArguments('/bin/zsh', 'abc123', executable)[3]).to.contain(quoted);
|
|
383
|
+
expect(environment.getShellArguments('/bin/tcsh', 'abc123', executable)[1]).to.contain(quoted);
|
|
384
|
+
expect(environment.getShellArguments('/usr/local/bin/pwsh', 'abc123', executable)[2]).to.contain("& '/Applications/Theia''s IDE.app/Contents/MacOS/Theia' -p");
|
|
385
|
+
expect(environment.getShellArguments('/usr/local/bin/nu', 'abc123', executable)[3]).to.contain('^"/Applications/Theia\'s IDE.app/Contents/MacOS/Theia" -p');
|
|
386
|
+
expect(environment.getShellArguments('/usr/local/bin/nu', 'abc123', '/opt/Theia\'s "IDE"\\theia')[3]).to.contain('^"/opt/Theia\'s \\"IDE\\"\\\\theia" -p');
|
|
387
|
+
});
|
|
388
|
+
});
|