@theia/core 1.72.0-next.5 → 1.72.0-next.52

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.
Files changed (62) hide show
  1. package/README.md +3 -3
  2. package/lib/browser/catalog.json +480 -30
  3. package/lib/browser/frontend-application-module.d.ts +3 -0
  4. package/lib/browser/frontend-application-module.d.ts.map +1 -1
  5. package/lib/browser/frontend-application-module.js +5 -2
  6. package/lib/browser/frontend-application-module.js.map +1 -1
  7. package/lib/browser/hover-service.d.ts +4 -4
  8. package/lib/browser/hover-service.d.ts.map +1 -1
  9. package/lib/browser/hover-service.js +10 -7
  10. package/lib/browser/hover-service.js.map +1 -1
  11. package/lib/browser/index.d.ts +1 -0
  12. package/lib/browser/index.d.ts.map +1 -1
  13. package/lib/browser/index.js +1 -0
  14. package/lib/browser/index.js.map +1 -1
  15. package/lib/browser/markdown-rendering/markdown-link-handler.d.ts +15 -0
  16. package/lib/browser/markdown-rendering/markdown-link-handler.d.ts.map +1 -0
  17. package/lib/browser/markdown-rendering/markdown-link-handler.js +60 -0
  18. package/lib/browser/markdown-rendering/markdown-link-handler.js.map +1 -0
  19. package/lib/browser/markdown-rendering/markdown-renderer.d.ts +5 -0
  20. package/lib/browser/markdown-rendering/markdown-renderer.d.ts.map +1 -1
  21. package/lib/browser/markdown-rendering/markdown-renderer.js +6 -1
  22. package/lib/browser/markdown-rendering/markdown-renderer.js.map +1 -1
  23. package/lib/browser/widgets/select-component.d.ts.map +1 -1
  24. package/lib/browser/widgets/select-component.js.map +1 -1
  25. package/lib/common/markdown-rendering/markdown-string.d.ts +7 -0
  26. package/lib/common/markdown-rendering/markdown-string.d.ts.map +1 -1
  27. package/lib/common/markdown-rendering/markdown-string.js +34 -2
  28. package/lib/common/markdown-rendering/markdown-string.js.map +1 -1
  29. package/lib/common/markdown-rendering/markdown-string.spec.d.ts +2 -0
  30. package/lib/common/markdown-rendering/markdown-string.spec.d.ts.map +1 -0
  31. package/lib/common/markdown-rendering/markdown-string.spec.js +47 -0
  32. package/lib/common/markdown-rendering/markdown-string.spec.js.map +1 -0
  33. package/lib/node/backend-application-module.d.ts.map +1 -1
  34. package/lib/node/backend-application-module.js +7 -0
  35. package/lib/node/backend-application-module.js.map +1 -1
  36. package/lib/node/backend-application.d.ts +43 -3
  37. package/lib/node/backend-application.d.ts.map +1 -1
  38. package/lib/node/backend-application.js +82 -15
  39. package/lib/node/backend-application.js.map +1 -1
  40. package/lib/node/backend-application.spec.d.ts +2 -0
  41. package/lib/node/backend-application.spec.d.ts.map +1 -0
  42. package/lib/node/backend-application.spec.js +252 -0
  43. package/lib/node/backend-application.spec.js.map +1 -0
  44. package/lib/node/logger-cli-contribution.spec.js +9 -9
  45. package/lib/node/logger-cli-contribution.spec.js.map +1 -1
  46. package/package.json +16 -16
  47. package/src/browser/frontend-application-module.ts +6 -3
  48. package/src/browser/hover-service.ts +9 -7
  49. package/src/browser/index.ts +1 -0
  50. package/src/browser/markdown-rendering/markdown-link-handler.ts +61 -0
  51. package/src/browser/markdown-rendering/markdown-renderer.ts +6 -0
  52. package/src/browser/style/hover-service.css +1 -0
  53. package/src/browser/style/index.css +31 -32
  54. package/src/browser/style/scrollbars.css +0 -2
  55. package/src/browser/style/select-component.css +6 -3
  56. package/src/browser/widgets/select-component.tsx +1 -1
  57. package/src/common/markdown-rendering/markdown-string.spec.ts +50 -0
  58. package/src/common/markdown-rendering/markdown-string.ts +34 -2
  59. package/src/node/backend-application-module.ts +11 -1
  60. package/src/node/backend-application.spec.ts +310 -0
  61. package/src/node/backend-application.ts +104 -19
  62. package/src/node/logger-cli-contribution.spec.ts +9 -9
@@ -14,8 +14,36 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- @import url("~@lumino/widgets/style/index.css");
18
- @import url("~font-awesome/css/font-awesome.min.css");
17
+ /*-----------------------------------------------------------------------------
18
+ | Import children style files
19
+ |----------------------------------------------------------------------------*/
20
+
21
+ @import "./os.css";
22
+ @import "./dockpanel.css";
23
+ @import "./dialog.css";
24
+ @import "./menus.css";
25
+ @import "./sidepanel.css";
26
+ @import "./tabs.css";
27
+ @import "./scrollbars.css";
28
+ @import "./tree.css";
29
+ @import "./status-bar.css";
30
+ @import "./tree-decorators.css";
31
+ @import "./about.css";
32
+ @import "./search-box.css";
33
+ @import "./ansi.css";
34
+ @import "./view-container.css";
35
+ @import "./notification.css";
36
+ @import "./alert-messages.css";
37
+ @import "./icons.css";
38
+ @import "./widget.css";
39
+ @import "./quick-title-bar.css";
40
+ @import "./progress-bar.css";
41
+ @import "./breadcrumbs.css";
42
+ @import "./tooltip.css";
43
+ @import "./split-widget.css";
44
+ @import "./symbol-icon.css";
45
+ @import "./card.css";
46
+
19
47
 
20
48
  /*-----------------------------------------------------------------------------
21
49
  | General
@@ -160,6 +188,7 @@ blockquote {
160
188
  right: 0;
161
189
  bottom: 0;
162
190
  background: var(--theia-editor-background);
191
+ height: 100%;
163
192
  }
164
193
 
165
194
  .theia-preload {
@@ -324,33 +353,3 @@ button.secondary[disabled],
324
353
  .theia-cursor-no-drop:active {
325
354
  cursor: no-drop;
326
355
  }
327
-
328
- /*-----------------------------------------------------------------------------
329
- | Import children style files
330
- |----------------------------------------------------------------------------*/
331
-
332
- @import "./os.css";
333
- @import "./dockpanel.css";
334
- @import "./dialog.css";
335
- @import "./menus.css";
336
- @import "./sidepanel.css";
337
- @import "./tabs.css";
338
- @import "./scrollbars.css";
339
- @import "./tree.css";
340
- @import "./status-bar.css";
341
- @import "./tree-decorators.css";
342
- @import "./about.css";
343
- @import "./search-box.css";
344
- @import "./ansi.css";
345
- @import "./view-container.css";
346
- @import "./notification.css";
347
- @import "./alert-messages.css";
348
- @import "./icons.css";
349
- @import "./widget.css";
350
- @import "./quick-title-bar.css";
351
- @import "./progress-bar.css";
352
- @import "./breadcrumbs.css";
353
- @import "./tooltip.css";
354
- @import "./split-widget.css";
355
- @import "./symbol-icon.css";
356
- @import "./card.css";
@@ -14,8 +14,6 @@
14
14
  * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
15
  ********************************************************************************/
16
16
 
17
- @import url("~perfect-scrollbar/css/perfect-scrollbar.css");
18
-
19
17
  ::-webkit-scrollbar {
20
18
  height: var(--theia-scrollbar-width);
21
19
  width: var(--theia-scrollbar-width);
@@ -15,9 +15,12 @@
15
15
  ********************************************************************************/
16
16
 
17
17
  .theia-select-component-container {
18
- /* required to set z-index */
19
- position: fixed;
20
- /* dialog overlay has a z-index of 5000 */
18
+ /* position is required for z-index to take effect; top/left at 0 anchors
19
+ the container so the absolutely-positioned dropdown resolves its
20
+ viewport-relative coordinates correctly. */
21
+ position: absolute;
22
+ top: 0;
23
+ left: 0;
21
24
  z-index: 6000;
22
25
  }
23
26
 
@@ -149,7 +149,7 @@ export class SelectComponent extends React.Component<SelectComponentProps, Selec
149
149
  return optimal + 20; // Just to be safe, add another 20 pixels here
150
150
  }
151
151
 
152
- protected attachListeners(): void {
152
+ protected attachListeners(): void {
153
153
  const hide = (event: Event) => {
154
154
  if (!this.dropdownRef.current?.contains(event.target as Node)) {
155
155
  this.hide();
@@ -0,0 +1,50 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 EclipseSource 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 { MarkdownStringImpl } from './markdown-string';
19
+
20
+ describe('MarkdownStringImpl#appendCodeblock', () => {
21
+
22
+ it('uses a triple-backtick fence for code without backticks', () => {
23
+ const md = new MarkdownStringImpl();
24
+ md.appendCodeblock('json', '{ "type": "adaptive" }');
25
+ expect(md.value).to.equal('\n```json\n{ "type": "adaptive" }\n```\n');
26
+ });
27
+
28
+ it('uses a longer fence when the code contains a triple-backtick run', () => {
29
+ const md = new MarkdownStringImpl();
30
+ const code = 'before\n```json\n{ "x": 1 }\n```\nafter';
31
+ md.appendCodeblock('', code);
32
+ // The fence must be at least 4 backticks so the inner ``` cannot close it.
33
+ expect(md.value).to.equal('\n````\n' + code + '\n````\n');
34
+ });
35
+
36
+ it('grows the fence to be longer than the longest backtick run inside the code', () => {
37
+ const md = new MarkdownStringImpl();
38
+ const code = 'a ```` b ``` c';
39
+ md.appendCodeblock('', code);
40
+ // Longest run is 4, so fence must be 5.
41
+ expect(md.value).to.equal('\n`````\n' + code + '\n`````\n');
42
+ });
43
+
44
+ it('still uses a triple-backtick fence when only single/double backticks appear', () => {
45
+ const md = new MarkdownStringImpl();
46
+ const code = 'inline `code` and ``double`` only';
47
+ md.appendCodeblock('', code);
48
+ expect(md.value).to.equal('\n```\n' + code + '\n```\n');
49
+ });
50
+ });
@@ -44,6 +44,16 @@ export namespace MarkdownString {
44
44
  export function is(candidate: unknown): candidate is MarkdownString {
45
45
  return isObject<MarkdownString>(candidate) && isString(candidate.value);
46
46
  }
47
+
48
+ /**
49
+ * @returns whether `commandId` is allowed to execute given the markdown string's
50
+ * {@link MarkdownString.isTrusted} setting. Fully trusted strings allow any command;
51
+ * partially trusted strings restrict execution to their `enabledCommands` list.
52
+ */
53
+ export function isCommandAllowed(isTrusted: MarkdownString['isTrusted'], commandId: string): boolean {
54
+ return isTrusted === true
55
+ || (typeof isTrusted === 'object' && isTrusted.enabledCommands.includes(commandId));
56
+ }
47
57
  }
48
58
 
49
59
  // Copied from https://github.com/microsoft/vscode/blob/7d9b1c37f8e5ae3772782ba3b09d827eb3fdd833/src/vs/base/common/htmlContent.ts
@@ -90,14 +100,36 @@ export class MarkdownStringImpl implements MarkdownString {
90
100
  }
91
101
 
92
102
  appendCodeblock(langId: string, code: string): MarkdownStringImpl {
93
- this.value += '\n```';
103
+ // Use a fence longer than any run of backticks in the code so that triple-backtick
104
+ // sequences inside `code` cannot prematurely close the surrounding fenced block.
105
+ const fence = '`'.repeat(Math.max(3, MarkdownStringImpl.longestBacktickRun(code) + 1));
106
+ this.value += '\n';
107
+ this.value += fence;
94
108
  this.value += langId;
95
109
  this.value += '\n';
96
110
  this.value += code;
97
- this.value += '\n```\n';
111
+ this.value += '\n';
112
+ this.value += fence;
113
+ this.value += '\n';
98
114
  return this;
99
115
  }
100
116
 
117
+ private static longestBacktickRun(value: string): number {
118
+ let longest = 0;
119
+ let current = 0;
120
+ for (let i = 0; i < value.length; i++) {
121
+ if (value.charCodeAt(i) === 96 /* ` */) {
122
+ current++;
123
+ if (current > longest) {
124
+ longest = current;
125
+ }
126
+ } else {
127
+ current = 0;
128
+ }
129
+ }
130
+ return longest;
131
+ }
132
+
101
133
  appendLink(target: UriComponents | string, label: string, title?: string): MarkdownStringImpl {
102
134
  this.value += '[';
103
135
  this.value += this._escape(label, ']');
@@ -34,7 +34,10 @@ import {
34
34
  PreferenceProviderProvider,
35
35
  PreferenceProvider
36
36
  } from '../common';
37
- import { BackendApplication, BackendApplicationContribution, BackendApplicationCliContribution, BackendApplicationServer, BackendApplicationPath } from './backend-application';
37
+ import {
38
+ BackendApplication, BackendApplicationContribution, BackendApplicationCliContribution,
39
+ BackendApplicationServer, BackendApplicationPath, RootContainer
40
+ } from './backend-application';
38
41
  import { CliManager, CliContribution } from './cli';
39
42
  import { IPCConnectionProvider } from './messaging';
40
43
  import { ApplicationServerImpl } from './application-server';
@@ -87,6 +90,13 @@ export const backendApplicationModule = new ContainerModule(bind => {
87
90
  bind(CliContribution).toService(BackendApplicationCliContribution);
88
91
 
89
92
  bind(BackendApplication).toSelf().inSingletonScope();
93
+ bind(RootContainer).toDynamicValue(({ container }) => {
94
+ let root = container;
95
+ while (root.parent) {
96
+ root = root.parent;
97
+ }
98
+ return root;
99
+ }).inSingletonScope();
90
100
  bindRootContributionProvider(bind, BackendApplicationContribution);
91
101
  // Bind the BackendApplicationServer as a BackendApplicationContribution
92
102
  // and fallback to an empty contribution if never bound.
@@ -0,0 +1,310 @@
1
+ // *****************************************************************************
2
+ // Copyright (C) 2026 EclipseSource 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 * as sinon from 'sinon';
19
+ import { Container, ContainerModule, injectable, preDestroy } from 'inversify';
20
+ import { bindContributionProvider, ILogger, Stopwatch } from '../common';
21
+ import { Deferred } from '../common/promise-util';
22
+ import { MockLogger } from '../common/test/mock-logger';
23
+ import { NodeStopwatch } from './performance/node-stopwatch';
24
+ import { ProcessUtils } from './process-utils';
25
+ import {
26
+ BackendApplication,
27
+ BackendApplicationCliContribution,
28
+ BackendApplicationContribution,
29
+ RootContainer
30
+ } from './backend-application';
31
+ import { CliContribution } from './cli';
32
+
33
+ /**
34
+ * Test subclass that exposes the protected `gracefulShutdown` for direct testing.
35
+ */
36
+ @injectable()
37
+ class TestBackendApplication extends BackendApplication {
38
+ public invokeGracefulShutdown(): Promise<void> {
39
+ return this.gracefulShutdown();
40
+ }
41
+ }
42
+
43
+ // All process events on which `BackendApplication` installs listeners in its
44
+ // constructor. We snapshot and restore them around each test to avoid leaking
45
+ // listeners across tests (and triggering `MaxListenersExceededWarning`).
46
+ const PROCESS_EVENTS = ['SIGINT', 'SIGTERM', 'SIGPIPE', 'exit', 'uncaughtException'] as const;
47
+ type ProcessEventName = typeof PROCESS_EVENTS[number];
48
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
49
+ type AnyListener = (...args: any[]) => void;
50
+
51
+ describe('BackendApplication', () => {
52
+ let sandbox: sinon.SinonSandbox;
53
+ let exitStub: sinon.SinonStub;
54
+ let savedListeners: Partial<Record<ProcessEventName, AnyListener[]>>;
55
+
56
+ beforeEach(() => {
57
+ sandbox = sinon.createSandbox();
58
+
59
+ // Snapshot any existing listeners so we can restore after each test
60
+ // (BackendApplication installs its own as part of construction).
61
+ savedListeners = {};
62
+ for (const evt of PROCESS_EVENTS) {
63
+ savedListeners[evt] = [...process.listeners(evt as NodeJS.Signals)] as AnyListener[];
64
+ process.removeAllListeners(evt);
65
+ }
66
+
67
+ exitStub = sandbox.stub(process, 'exit');
68
+ });
69
+
70
+ afterEach(() => {
71
+ for (const evt of PROCESS_EVENTS) {
72
+ process.removeAllListeners(evt);
73
+ for (const listener of savedListeners[evt] ?? []) {
74
+ process.on(evt, listener);
75
+ }
76
+ }
77
+
78
+ sandbox.restore();
79
+ });
80
+
81
+ function createTestContainer(): Container {
82
+ const container = new Container();
83
+
84
+ container.bind(RootContainer).toConstantValue(container);
85
+
86
+ container.bind(ILogger).to(MockLogger).inSingletonScope();
87
+ container.bind(Stopwatch).to(NodeStopwatch).inSingletonScope();
88
+ container.bind(ProcessUtils).toSelf().inSingletonScope();
89
+ container.bind(BackendApplicationCliContribution).toSelf().inSingletonScope();
90
+ container.bind(CliContribution).toService(BackendApplicationCliContribution);
91
+ bindContributionProvider(container, BackendApplicationContribution);
92
+
93
+ container.bind(TestBackendApplication).toSelf().inSingletonScope();
94
+ container.bind(BackendApplication).toService(TestBackendApplication);
95
+
96
+ return container;
97
+ }
98
+
99
+ describe('graceful shutdown', () => {
100
+
101
+ it('runs @preDestroy on root-scoped singletons before exiting with code 1', async () => {
102
+ let canaryDisposed = false;
103
+
104
+ @injectable()
105
+ class Canary {
106
+ @preDestroy()
107
+ protected onPreDestroy(): void {
108
+ canaryDisposed = true;
109
+ }
110
+ }
111
+
112
+ const container = createTestContainer();
113
+ const canaryModule = new ContainerModule(bind => {
114
+ bind(Canary).toSelf().inSingletonScope();
115
+ });
116
+ container.load(canaryModule);
117
+ container.get(Canary);
118
+
119
+ const app = container.get(TestBackendApplication);
120
+
121
+ await app.invokeGracefulShutdown();
122
+
123
+ expect(canaryDisposed, '@preDestroy was not invoked on root-scoped singleton').to.be.true;
124
+ expect(exitStub.calledOnceWith(1), 'process.exit(1) was not called exactly once').to.be.true;
125
+ });
126
+
127
+ it('is idempotent: a second invocation does not unbind the container twice', async () => {
128
+ const container = createTestContainer();
129
+ const unbindSpy = sandbox.spy(container, 'unbindAllAsync');
130
+
131
+ const app = container.get(TestBackendApplication);
132
+
133
+ await app.invokeGracefulShutdown();
134
+ await app.invokeGracefulShutdown();
135
+
136
+ expect(unbindSpy.callCount, 'unbindAllAsync should be called only once').to.equal(1);
137
+ expect(exitStub.callCount, 'process.exit should be called only once').to.equal(1);
138
+ });
139
+
140
+ it('still exits if container cleanup rejects', async () => {
141
+ const container = createTestContainer();
142
+ const cleanupError = new Error('cleanup boom');
143
+ sandbox.stub(container, 'unbindAllAsync').rejects(cleanupError);
144
+ const warnStub = sandbox.stub(console, 'warn');
145
+
146
+ const app = container.get(TestBackendApplication);
147
+
148
+ await app.invokeGracefulShutdown();
149
+
150
+ expect(exitStub.calledOnceWith(1), 'process.exit(1) was not called').to.be.true;
151
+ expect(warnStub.calledOnce, 'a warning should be logged when cleanup rejects').to.be.true;
152
+ expect(warnStub.firstCall.args[0]).to.match(/cleanup boom/);
153
+ });
154
+
155
+ it('exits even when container cleanup hangs past the timeout', async () => {
156
+ const clock = sandbox.useFakeTimers();
157
+ const container = createTestContainer();
158
+ sandbox.stub(container, 'unbindAllAsync').returns(new Promise<void>(() => { /* never */ }));
159
+ const warnStub = sandbox.stub(console, 'warn');
160
+
161
+ const app = container.get(TestBackendApplication);
162
+
163
+ const shutdownPromise = app.invokeGracefulShutdown();
164
+
165
+ await clock.tickAsync(5001);
166
+ await shutdownPromise;
167
+
168
+ expect(exitStub.calledOnceWith(1), 'process.exit(1) was not called after timeout').to.be.true;
169
+ expect(warnStub.calledOnce, 'a warning should be logged on timeout').to.be.true;
170
+ expect(warnStub.firstCall.args[0]).to.match(/timed out/);
171
+ });
172
+
173
+ it('awaits async onStop contributions before unbinding the container', async () => {
174
+ const container = createTestContainer();
175
+ const onStopDeferred = new Deferred<void>();
176
+ container.bind(BackendApplicationContribution).toConstantValue({
177
+ onStop: () => onStopDeferred.promise
178
+ });
179
+ const unbindSpy = sandbox.spy(container, 'unbindAllAsync');
180
+
181
+ const app = container.get(TestBackendApplication);
182
+ const shutdownPromise = app.invokeGracefulShutdown();
183
+
184
+ expect(unbindSpy.called, 'unbindAllAsync should not run before onStop resolves').to.be.false;
185
+
186
+ onStopDeferred.resolve();
187
+ await shutdownPromise;
188
+
189
+ expect(unbindSpy.calledOnce, 'unbindAllAsync should run once onStop completes').to.be.true;
190
+ expect(exitStub.calledOnceWith(1)).to.be.true;
191
+ });
192
+
193
+ it('invokes onStop hooks while injected services are still resolvable', async () => {
194
+ @injectable()
195
+ class Helper {
196
+ readonly value = 'still-bound';
197
+ }
198
+
199
+ const container = createTestContainer();
200
+ container.bind(Helper).toSelf().inSingletonScope();
201
+
202
+ let observed: string | undefined;
203
+ container.bind(BackendApplicationContribution).toConstantValue({
204
+ onStop: () => {
205
+ observed = container.get(Helper).value;
206
+ }
207
+ });
208
+
209
+ const app = container.get(TestBackendApplication);
210
+ await app.invokeGracefulShutdown();
211
+
212
+ expect(observed, 'onStop should observe injected services that are still bound').to.equal('still-bound');
213
+ });
214
+
215
+ it('proceeds with shutdown when onStop hooks exceed the timeout', async () => {
216
+ const clock = sandbox.useFakeTimers();
217
+ const container = createTestContainer();
218
+ container.bind(BackendApplicationContribution).toConstantValue({
219
+ onStop: () => new Promise<void>(() => { /* never */ })
220
+ });
221
+ const unbindSpy = sandbox.spy(container, 'unbindAllAsync');
222
+ const warnStub = sandbox.stub(console, 'warn');
223
+
224
+ const app = container.get(TestBackendApplication);
225
+ const shutdownPromise = app.invokeGracefulShutdown();
226
+
227
+ await clock.tickAsync(5001);
228
+ await shutdownPromise;
229
+
230
+ expect(warnStub.calledOnce, 'a warning should be logged on onStop timeout').to.be.true;
231
+ expect(warnStub.firstCall.args[0]).to.match(/Stopping backend contributions/);
232
+ expect(unbindSpy.calledOnce, 'unbind should still run after onStop times out').to.be.true;
233
+ expect(exitStub.calledOnceWith(1)).to.be.true;
234
+ });
235
+
236
+ it('runs all contributions even when one onStop rejects', async () => {
237
+ const container = createTestContainer();
238
+ let secondRan = false;
239
+ container.bind(BackendApplicationContribution).toConstantValue({
240
+ onStop: async () => { throw new Error('boom'); }
241
+ });
242
+ container.bind(BackendApplicationContribution).toConstantValue({
243
+ onStop: () => { secondRan = true; }
244
+ });
245
+ const errorStub = sandbox.stub(console, 'error');
246
+
247
+ const app = container.get(TestBackendApplication);
248
+ await app.invokeGracefulShutdown();
249
+
250
+ expect(secondRan, 'second contribution should still be stopped after first rejects').to.be.true;
251
+ expect(errorStub.calledWithMatch('Could not stop contribution')).to.be.true;
252
+ });
253
+
254
+ it('is idempotent when a contribution re-enters graceful shutdown', async () => {
255
+ const container = createTestContainer();
256
+ // Indirected through a holder so the contribution closure can refer to the
257
+ // application instance that is constructed after the binding is recorded.
258
+ const appHolder: { current?: TestBackendApplication } = {};
259
+ container.bind(BackendApplicationContribution).toConstantValue({
260
+ onStop: () => appHolder.current!.invokeGracefulShutdown()
261
+ });
262
+ const unbindSpy = sandbox.spy(container, 'unbindAllAsync');
263
+
264
+ appHolder.current = container.get(TestBackendApplication);
265
+ await appHolder.current.invokeGracefulShutdown();
266
+
267
+ expect(unbindSpy.callCount, 'unbindAllAsync should be called only once').to.equal(1);
268
+ expect(exitStub.callCount, 'process.exit should be called only once').to.equal(1);
269
+ });
270
+
271
+ });
272
+
273
+ describe('process exit handler', () => {
274
+
275
+ it('does not re-invoke contributions after graceful shutdown ran them', async () => {
276
+ const container = createTestContainer();
277
+ const onStopSpy = sandbox.spy();
278
+ container.bind(BackendApplicationContribution).toConstantValue({ onStop: onStopSpy });
279
+ const terminateStub = sandbox.stub(ProcessUtils.prototype, 'terminateProcessTree');
280
+
281
+ const app = container.get(TestBackendApplication);
282
+ const exitListener = process.listeners('exit')[0] as () => void;
283
+
284
+ await app.invokeGracefulShutdown();
285
+ expect(onStopSpy.callCount, 'contribution onStop should fire from gracefulShutdown').to.equal(1);
286
+
287
+ exitListener();
288
+
289
+ expect(onStopSpy.callCount, 'contribution onStop should not be invoked a second time').to.equal(1);
290
+ expect(terminateStub.called, 'terminateProcessTree should be invoked by the exit handler').to.be.true;
291
+ });
292
+
293
+ it('invokes contributions synchronously when graceful shutdown was bypassed', () => {
294
+ const container = createTestContainer();
295
+ const onStopSpy = sandbox.spy();
296
+ container.bind(BackendApplicationContribution).toConstantValue({ onStop: onStopSpy });
297
+ const terminateStub = sandbox.stub(ProcessUtils.prototype, 'terminateProcessTree');
298
+
299
+ container.get(TestBackendApplication);
300
+ const exitListener = process.listeners('exit')[0] as () => void;
301
+
302
+ exitListener();
303
+
304
+ expect(onStopSpy.calledOnce, 'sync exit path should still invoke contributions').to.be.true;
305
+ expect(terminateStub.called, 'terminateProcessTree should be invoked').to.be.true;
306
+ });
307
+
308
+ });
309
+
310
+ });