@theia/core 1.77.0 → 1.78.0-next.19
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 +208 -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/tab-bars.d.ts +7 -0
- package/lib/browser/shell/tab-bars.d.ts.map +1 -1
- package/lib/browser/shell/tab-bars.js +25 -11
- package/lib/browser/shell/tab-bars.js.map +1 -1
- package/lib/browser/shell/tab-bars.spec.js +20 -0
- package/lib/browser/shell/tab-bars.spec.js.map +1 -1
- package/lib/common/core-preferences.d.ts +1 -0
- package/lib/common/core-preferences.d.ts.map +1 -1
- package/lib/common/core-preferences.js +11 -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/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/tab-bars.spec.ts +22 -0
- package/src/browser/shell/tab-bars.ts +25 -12
- package/src/common/core-preferences.ts +12 -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/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
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
import { expect } from 'chai';
|
|
18
18
|
import * as sinon from 'sinon';
|
|
19
19
|
import { Container } from 'inversify';
|
|
20
|
-
import { ProcessUtils } from './process-utils.js';
|
|
20
|
+
import { ProcessUtils, UnixProcessInfo } from './process-utils.js';
|
|
21
21
|
import { ILogger } from '../common/index.js';
|
|
22
22
|
import { MockLogger } from '../common/test/mock-logger.js';
|
|
23
23
|
|
|
@@ -32,6 +32,11 @@ const mockPsOutput = `\
|
|
|
32
32
|
0 1
|
|
33
33
|
`;
|
|
34
34
|
|
|
35
|
+
/** PID, PPID, PGID, start time */
|
|
36
|
+
function processTable(rows: [number, number, number, string][]): Map<number, UnixProcessInfo> {
|
|
37
|
+
return new Map(rows.map(([pid, ppid, pgid, startTime]) => [pid, { pid, ppid, pgid, startTime }]));
|
|
38
|
+
}
|
|
39
|
+
|
|
35
40
|
describe('ProcessUtils', () => {
|
|
36
41
|
|
|
37
42
|
let coreProcessManager: ProcessUtils;
|
|
@@ -52,24 +57,119 @@ describe('ProcessUtils', () => {
|
|
|
52
57
|
});
|
|
53
58
|
|
|
54
59
|
describe('#unixTerminateChildProcessTrees', () => {
|
|
60
|
+
const delay = 2000;
|
|
61
|
+
let clock: sinon.SinonFakeTimers;
|
|
55
62
|
let killStub: sinon.SinonStub;
|
|
63
|
+
let alivePids: Set<number>;
|
|
64
|
+
let processes: Map<number, UnixProcessInfo>;
|
|
65
|
+
|
|
66
|
+
function sigtermedPids(): number[] {
|
|
67
|
+
return killStub.args.filter(([, signal]) => signal === undefined).map(([pid]) => pid);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function sigkilledPids(): number[] {
|
|
71
|
+
return killStub.args.filter(([, signal]) => signal === 'SIGKILL').map(([pid]) => pid);
|
|
72
|
+
}
|
|
56
73
|
|
|
57
74
|
beforeEach(() => {
|
|
58
|
-
|
|
75
|
+
clock = sinon.useFakeTimers();
|
|
59
76
|
killStub = sinon.stub();
|
|
60
77
|
coreProcessManager['unixKill'] = killStub;
|
|
78
|
+
// The tree of mockPsOutput under PID 2: 40, 5 and their children 7, 6.
|
|
79
|
+
processes = processTable([
|
|
80
|
+
[2, 1, 2, 'Thu Oct 29 10:00:00 2026'],
|
|
81
|
+
[40, 2, 2, 'Thu Oct 29 10:00:01 2026'],
|
|
82
|
+
[5, 2, 2, 'Thu Oct 29 10:00:01 2026'],
|
|
83
|
+
[7, 40, 2, 'Thu Oct 29 10:00:02 2026'],
|
|
84
|
+
[6, 5, 2, 'Thu Oct 29 10:00:02 2026'],
|
|
85
|
+
[3, 1, 3, 'Thu Oct 29 10:00:00 2026']
|
|
86
|
+
]);
|
|
87
|
+
coreProcessManager['unixListProcesses'] = () => processes;
|
|
88
|
+
coreProcessManager['unixListProcessesAsync'] = async () => processes;
|
|
89
|
+
alivePids = new Set([40, 5, 6, 7]);
|
|
90
|
+
coreProcessManager['unixIsAlive'] = (pid: number) => alivePids.has(pid);
|
|
61
91
|
});
|
|
62
92
|
|
|
63
93
|
afterEach(() => {
|
|
94
|
+
clock.restore();
|
|
64
95
|
sinon.restore();
|
|
65
96
|
});
|
|
66
97
|
|
|
67
98
|
it('kills all descendants but not the process itself', async () => {
|
|
99
|
+
alivePids.clear();
|
|
100
|
+
await coreProcessManager['unixTerminateChildProcessTrees'](2);
|
|
101
|
+
expect(sigtermedPids()).members([40, 5, 6, 7]);
|
|
102
|
+
expect(sigkilledPids()).to.be.empty;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('kills the descendants that are still running with SIGKILL after the delay', async () => {
|
|
106
|
+
let resolved = false;
|
|
107
|
+
const terminated = coreProcessManager['unixTerminateChildProcessTrees'](2).then(() => resolved = true);
|
|
108
|
+
await clock.tickAsync(0);
|
|
109
|
+
expect(sigtermedPids()).members([40, 5, 6, 7]);
|
|
110
|
+
alivePids.delete(40);
|
|
111
|
+
alivePids.delete(5);
|
|
112
|
+
|
|
113
|
+
await clock.tickAsync(delay - 1);
|
|
114
|
+
expect(sigkilledPids()).to.be.empty;
|
|
115
|
+
expect(resolved).to.be.false;
|
|
116
|
+
await clock.tickAsync(1);
|
|
117
|
+
await terminated;
|
|
118
|
+
expect(sigkilledPids()).members([6, 7]);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('kills the processes of an earlier tree that are still running, even if they are no longer descendants', async () => {
|
|
122
|
+
// 424244 was a child of 424243, which has exited since: it was reparented and is no longer in the tree of 2.
|
|
123
|
+
processes.set(424243, { pid: 424243, ppid: 2, pgid: 424243, startTime: 'Thu Oct 29 10:00:03 2026' });
|
|
124
|
+
processes.set(424244, { pid: 424244, ppid: 424243, pgid: 424243, startTime: 'Thu Oct 29 10:00:04 2026' });
|
|
125
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
126
|
+
processes.delete(424243);
|
|
127
|
+
processes.set(424244, { pid: 424244, ppid: 1, pgid: 424243, startTime: 'Thu Oct 29 10:00:04 2026' });
|
|
128
|
+
alivePids = new Set([424244]);
|
|
129
|
+
|
|
130
|
+
const terminated = coreProcessManager['unixTerminateChildProcessTrees'](2);
|
|
131
|
+
await clock.tickAsync(delay);
|
|
132
|
+
await terminated;
|
|
133
|
+
expect(sigkilledPids()).members([424244]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it('also kills the reparented members of the process group that the process leads', async () => {
|
|
137
|
+
// 9 was a child of a process of the group that exited: it is no longer a descendant of 2.
|
|
138
|
+
processes.set(9, { pid: 9, ppid: 1, pgid: 2, startTime: 'Thu Oct 29 10:00:05 2026' });
|
|
139
|
+
alivePids = new Set([9]);
|
|
140
|
+
|
|
141
|
+
const terminated = coreProcessManager['unixTerminateChildProcessTrees'](2);
|
|
142
|
+
await clock.tickAsync(delay);
|
|
143
|
+
await terminated;
|
|
144
|
+
expect(sigtermedPids()).members([40, 5, 6, 7, 9]);
|
|
145
|
+
expect(sigkilledPids()).members([9]);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('measures the delay from the start of the call, including the time it takes to list the processes', async () => {
|
|
149
|
+
coreProcessManager['unixListProcessesAsync'] = () => new Promise(resolve => setTimeout(() => resolve(processes), 1500));
|
|
150
|
+
|
|
151
|
+
const terminated = coreProcessManager['unixTerminateChildProcessTrees'](2);
|
|
152
|
+
await clock.tickAsync(1500);
|
|
153
|
+
expect(sigtermedPids()).members([40, 5, 6, 7]);
|
|
154
|
+
await clock.tickAsync(delay - 1500 - 1);
|
|
155
|
+
expect(sigkilledPids()).to.be.empty;
|
|
156
|
+
// The listing before SIGKILL takes another 1500 ms.
|
|
157
|
+
await clock.tickAsync(1 + 1500);
|
|
158
|
+
await terminated;
|
|
159
|
+
expect(sigkilledPids()).members([40, 5, 6, 7]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it('only sends SIGTERM when the start times cannot be listed', async () => {
|
|
163
|
+
coreProcessManager['unixListProcessesAsync'] = async () => { throw new Error('ps: bad -o argument'); };
|
|
164
|
+
coreProcessManager['execFile'] = async () => ({ stdout: mockPsOutput, stderr: '' });
|
|
68
165
|
await coreProcessManager['unixTerminateChildProcessTrees'](2);
|
|
69
|
-
expect(
|
|
166
|
+
expect(sigtermedPids()).members([40, 5, 6, 7]);
|
|
167
|
+
await clock.tickAsync(delay);
|
|
168
|
+
expect(sigkilledPids()).to.be.empty;
|
|
70
169
|
});
|
|
71
170
|
|
|
72
171
|
it('rejects when the processes cannot be listed', async () => {
|
|
172
|
+
coreProcessManager['unixListProcessesAsync'] = async () => { throw new Error('ps not found'); };
|
|
73
173
|
coreProcessManager['execFile'] = async () => { throw new Error('ps not found'); };
|
|
74
174
|
let error: unknown;
|
|
75
175
|
await coreProcessManager['unixTerminateChildProcessTrees'](2).catch(e => error = e);
|
|
@@ -97,6 +197,8 @@ describe('ProcessUtils', () => {
|
|
|
97
197
|
// One child plus the parent; report the parent as its own group leader so the `kill(-ppid)` branch runs too.
|
|
98
198
|
coreProcessManager['unixGetChildrenRecursive'] = () => new Set([424242]);
|
|
99
199
|
coreProcessManager['unixGetPGID'] = (pid: number) => pid;
|
|
200
|
+
// Without a listing of the processes, they are not killed with SIGKILL later.
|
|
201
|
+
coreProcessManager['unixTryListProcesses'] = () => undefined;
|
|
100
202
|
});
|
|
101
203
|
|
|
102
204
|
afterEach(() => {
|
|
@@ -124,6 +226,169 @@ describe('ProcessUtils', () => {
|
|
|
124
226
|
});
|
|
125
227
|
});
|
|
126
228
|
|
|
229
|
+
describe('#unixTerminateProcessTree with processes that survive SIGTERM', () => {
|
|
230
|
+
const delay = 5000;
|
|
231
|
+
let clock: sinon.SinonFakeTimers;
|
|
232
|
+
let killStub: sinon.SinonStub;
|
|
233
|
+
let alivePids: Set<number>;
|
|
234
|
+
let processes: Map<number, UnixProcessInfo>;
|
|
235
|
+
let listStub: sinon.SinonStub;
|
|
236
|
+
let listAsyncStub: sinon.SinonStub;
|
|
237
|
+
|
|
238
|
+
function sigkilledPids(): number[] {
|
|
239
|
+
return killStub.args.filter(([, signal]) => signal === 'SIGKILL').map(([pid]) => pid);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
beforeEach(() => {
|
|
243
|
+
clock = sinon.useFakeTimers();
|
|
244
|
+
killStub = sinon.stub();
|
|
245
|
+
coreProcessManager['unixKill'] = killStub;
|
|
246
|
+
coreProcessManager['unixGetChildrenRecursive'] = () => expect.fail('the tree should come from the listing');
|
|
247
|
+
coreProcessManager['unixGetPGID'] = () => expect.fail('the group should come from the listing');
|
|
248
|
+
// 424243 leads a group; 424246 is a member of that group that was reparented to init.
|
|
249
|
+
processes = processTable([
|
|
250
|
+
[424243, 1000, 424243, 'Thu Oct 29 10:00:00 2026'],
|
|
251
|
+
[424244, 424243, 424243, 'Thu Oct 29 10:00:01 2026'],
|
|
252
|
+
[424245, 424244, 424243, 'Thu Oct 29 10:00:01 2026'],
|
|
253
|
+
[424246, 1, 424243, 'Thu Oct 29 10:00:02 2026'],
|
|
254
|
+
[424247, 1, 424247, 'Thu Oct 29 10:00:02 2026']
|
|
255
|
+
]);
|
|
256
|
+
listStub = sinon.stub().callsFake(() => processes);
|
|
257
|
+
listAsyncStub = sinon.stub().callsFake(async () => processes);
|
|
258
|
+
coreProcessManager['unixListProcesses'] = listStub;
|
|
259
|
+
coreProcessManager['unixListProcessesAsync'] = listAsyncStub;
|
|
260
|
+
alivePids = new Set([424243, 424244, 424245, 424246, 424247]);
|
|
261
|
+
coreProcessManager['unixIsAlive'] = (pid: number) => alivePids.has(pid);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
afterEach(() => {
|
|
265
|
+
clock.restore();
|
|
266
|
+
sinon.restore();
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('kills the processes of the tree and of its group that are still running with SIGKILL after the delay', async () => {
|
|
270
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
271
|
+
expect(listStub.calledOnce).to.be.true;
|
|
272
|
+
expect(killStub.args.map(([pid]) => pid)).members([424244, 424245, -424243, 424243]);
|
|
273
|
+
expect(sigkilledPids()).to.be.empty;
|
|
274
|
+
|
|
275
|
+
alivePids.delete(424243);
|
|
276
|
+
await clock.tickAsync(delay - 1);
|
|
277
|
+
expect(sigkilledPids()).to.be.empty;
|
|
278
|
+
await clock.tickAsync(1);
|
|
279
|
+
expect(sigkilledPids()).members([424244, 424245, 424246]);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it('spares a PID that a new process has taken since the tree was terminated', async () => {
|
|
283
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
284
|
+
processes = new Map(processes);
|
|
285
|
+
processes.set(424245, { pid: 424245, ppid: 1, pgid: 424245, startTime: 'Thu Oct 29 10:00:04 2026' });
|
|
286
|
+
await clock.tickAsync(delay);
|
|
287
|
+
expect(sigkilledPids()).members([424243, 424244, 424246]);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it('does not list the processes again when all of them have exited', async () => {
|
|
291
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
292
|
+
alivePids.clear();
|
|
293
|
+
await clock.tickAsync(delay);
|
|
294
|
+
expect(listAsyncStub.called).to.be.false;
|
|
295
|
+
expect(sigkilledPids()).to.be.empty;
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it('only sends SIGTERM when the processes cannot be listed', async () => {
|
|
299
|
+
const mockLogger = (coreProcessManager as unknown as { logger: ILogger }).logger;
|
|
300
|
+
const warnStub = sinon.stub(mockLogger, 'warn');
|
|
301
|
+
listStub.throws(new Error('ps: bad -o argument'));
|
|
302
|
+
coreProcessManager['unixGetChildrenRecursive'] = () => new Set([424244, 424245]);
|
|
303
|
+
coreProcessManager['unixGetPGID'] = () => 1;
|
|
304
|
+
expect(() => coreProcessManager['unixTerminateProcessTree'](424243)).to.not.throw();
|
|
305
|
+
expect(killStub.args.map(([pid]) => pid)).members([424243, 424244, 424245]);
|
|
306
|
+
expect(warnStub.called).to.be.true;
|
|
307
|
+
await clock.tickAsync(delay);
|
|
308
|
+
expect(sigkilledPids()).to.be.empty;
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it('checks again for the targets that are not due yet when the timer fires early', async () => {
|
|
312
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
313
|
+
// As if the timer's clock were ahead of the clock of the deadlines.
|
|
314
|
+
for (const target of coreProcessManager['unixForceKillTargets'].values()) {
|
|
315
|
+
target.deadline += 1;
|
|
316
|
+
}
|
|
317
|
+
await clock.tickAsync(delay);
|
|
318
|
+
expect(sigkilledPids()).to.be.empty;
|
|
319
|
+
await clock.tickAsync(1);
|
|
320
|
+
expect(sigkilledPids()).members([424243, 424244, 424245, 424246]);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('kills the processes of a later tree at their own deadline', async () => {
|
|
324
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
325
|
+
await clock.tickAsync(1000);
|
|
326
|
+
processes.set(424248, { pid: 424248, ppid: 1000, pgid: 424247, startTime: 'Thu Oct 29 10:00:03 2026' });
|
|
327
|
+
alivePids.add(424248);
|
|
328
|
+
coreProcessManager['unixTerminateProcessTree'](424248);
|
|
329
|
+
|
|
330
|
+
await clock.tickAsync(delay - 1000);
|
|
331
|
+
expect(sigkilledPids()).members([424243, 424244, 424245, 424246]);
|
|
332
|
+
await clock.tickAsync(1000);
|
|
333
|
+
expect(sigkilledPids()).members([424243, 424244, 424245, 424246, 424248]);
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
it('kills the processes of earlier trees right away, once their start time is checked, when the current process exits', () => {
|
|
337
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
338
|
+
processes = new Map(processes);
|
|
339
|
+
processes.set(424245, { pid: 424245, ppid: 1, pgid: 424245, startTime: 'Thu Oct 29 10:00:04 2026' });
|
|
340
|
+
coreProcessManager['unixGetChildrenRecursive'] = () => new Set();
|
|
341
|
+
coreProcessManager['unixGetPGID'] = () => 1;
|
|
342
|
+
|
|
343
|
+
coreProcessManager['unixTerminateProcessTree'](process.pid);
|
|
344
|
+
expect(sigkilledPids()).members([424243, 424244, 424246]);
|
|
345
|
+
expect(coreProcessManager['unixForceKillTargets'].size).to.equal(0);
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it('keeps the targets that are due until the processes have been listed', async () => {
|
|
349
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
350
|
+
listAsyncStub.callsFake(() => new Promise(resolve => setTimeout(() => resolve(processes), 500)));
|
|
351
|
+
await clock.tickAsync(delay);
|
|
352
|
+
expect(Array.from(coreProcessManager['unixForceKillTargets'].keys())).members([424243, 424244, 424245, 424246]);
|
|
353
|
+
expect(sigkilledPids()).to.be.empty;
|
|
354
|
+
await clock.tickAsync(500);
|
|
355
|
+
expect(sigkilledPids()).members([424243, 424244, 424245, 424246]);
|
|
356
|
+
expect(coreProcessManager['unixForceKillTargets'].size).to.equal(0);
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('does not kill the targets again that the exit handler killed while the processes were being listed', async () => {
|
|
360
|
+
coreProcessManager['unixTerminateProcessTree'](424243);
|
|
361
|
+
listAsyncStub.callsFake(() => new Promise(resolve => setTimeout(() => resolve(processes), 500)));
|
|
362
|
+
await clock.tickAsync(delay);
|
|
363
|
+
coreProcessManager['unixGetChildrenRecursive'] = () => new Set();
|
|
364
|
+
coreProcessManager['unixGetPGID'] = () => 1;
|
|
365
|
+
coreProcessManager['unixTerminateProcessTree'](process.pid);
|
|
366
|
+
expect(sigkilledPids()).members([424243, 424244, 424245, 424246]);
|
|
367
|
+
await clock.tickAsync(500);
|
|
368
|
+
expect(sigkilledPids()).to.have.lengthOf(4);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('does not kill the tree of the current process with SIGKILL', async () => {
|
|
372
|
+
coreProcessManager['unixGetChildrenRecursive'] = () => new Set();
|
|
373
|
+
coreProcessManager['unixGetPGID'] = () => 1;
|
|
374
|
+
coreProcessManager['unixTerminateProcessTree'](process.pid);
|
|
375
|
+
await clock.tickAsync(delay);
|
|
376
|
+
expect(listStub.called).to.be.false;
|
|
377
|
+
expect(sigkilledPids()).to.be.empty;
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it('ProcessUtils#unixParseProcesses', () => {
|
|
382
|
+
const processes = coreProcessManager['unixParseProcesses'](`\
|
|
383
|
+
1 0 1 Thu Oct 29 09:58:12 2026
|
|
384
|
+
42424 1 42424 Thu Oct 29 10:00:01 2026
|
|
385
|
+
`);
|
|
386
|
+
expect(Array.from(processes.values())).to.deep.equal([
|
|
387
|
+
{ pid: 1, ppid: 0, pgid: 1, startTime: 'Thu Oct 29 09:58:12 2026' },
|
|
388
|
+
{ pid: 42424, ppid: 1, pgid: 42424, startTime: 'Thu Oct 29 10:00:01 2026' }
|
|
389
|
+
]);
|
|
390
|
+
});
|
|
391
|
+
|
|
127
392
|
describe('#winTerminateProcessTree', () => {
|
|
128
393
|
let taskkillStub: sinon.SinonStub;
|
|
129
394
|
let warnStub: sinon.SinonStub;
|