-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathterminalManager.unit.test.ts
More file actions
619 lines (520 loc) · 26.4 KB
/
terminalManager.unit.test.ts
File metadata and controls
619 lines (520 loc) · 26.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as assert from 'assert';
import * as fsapi from 'fs-extra';
import * as os from 'os';
import * as path from 'path';
import * as sinon from 'sinon';
import {
Disposable,
Event,
EventEmitter,
Progress,
Terminal,
TerminalOptions,
Uri,
WorkspaceConfiguration,
} from 'vscode';
import { PythonEnvironment } from '../../../api';
import * as windowApis from '../../../common/window.apis';
import * as workspaceApis from '../../../common/workspace.apis';
import * as activationUtils from '../../../features/common/activation';
import * as shellDetector from '../../../features/common/shellDetector';
import * as shellUtils from '../../../features/terminal/shells/common/shellUtils';
import {
ShellEnvsProvider,
ShellScriptEditState,
ShellSetupState,
ShellStartupScriptProvider,
} from '../../../features/terminal/shells/startupProvider';
import {
DidChangeTerminalActivationStateEvent,
TerminalActivationInternal,
} from '../../../features/terminal/terminalActivationState';
import { TerminalManagerImpl } from '../../../features/terminal/terminalManager';
import * as terminalUtils from '../../../features/terminal/utils';
/**
* Test implementation of TerminalActivationInternal that tracks method calls.
*/
class TestTerminalActivation implements TerminalActivationInternal {
public callOrder: string[] = [];
public activateCalls = 0;
public deactivateCalls = 0;
private onDidChangeEmitter = new EventEmitter<DidChangeTerminalActivationStateEvent>();
public onDidChangeTerminalActivationState: Event<DidChangeTerminalActivationStateEvent> =
this.onDidChangeEmitter.event;
isActivated(_terminal: Terminal, _environment?: PythonEnvironment): boolean {
return false;
}
async activate(_terminal: Terminal, _environment: PythonEnvironment): Promise<void> {
this.activateCalls += 1;
this.callOrder.push('activate');
}
async deactivate(_terminal: Terminal): Promise<void> {
this.deactivateCalls += 1;
}
getEnvironment(_terminal: Terminal): PythonEnvironment | undefined {
return undefined;
}
updateActivationState(_terminal: Terminal, _environment: PythonEnvironment, _activated: boolean): void {
// Not used in these tests
}
dispose(): void {
this.onDidChangeEmitter.dispose();
}
}
suite('TerminalManager - create()', () => {
let terminalActivation: TestTerminalActivation;
let mockGetAutoActivationType: sinon.SinonStub;
let terminalManager: TerminalManagerImpl;
let mockTerminal: Partial<Terminal> & { show: sinon.SinonStub };
const createMockEnvironment = (): PythonEnvironment => ({
envId: { id: 'test-env-id', managerId: 'test-manager' },
name: 'Test Environment',
displayName: 'Test Environment',
shortDisplayName: 'TestEnv',
displayPath: '/path/to/env',
version: '3.9.0',
environmentPath: Uri.file('/path/to/python'),
sysPrefix: '/path/to/env',
execInfo: {
run: { executable: '/path/to/python' },
activation: [{ executable: '/path/to/activate' }],
},
});
setup(() => {
terminalActivation = new TestTerminalActivation();
mockTerminal = {
name: 'Test Terminal',
creationOptions: {} as TerminalOptions,
shellIntegration: undefined,
show: sinon.stub().callsFake(() => {
terminalActivation.callOrder.push('show');
}),
sendText: sinon.stub(),
};
mockGetAutoActivationType = sinon.stub(terminalUtils, 'getAutoActivationType');
sinon.stub(terminalUtils, 'waitForShellIntegration').resolves(false);
sinon.stub(activationUtils, 'isActivatableEnvironment').returns(true);
sinon.stub(shellDetector, 'identifyTerminalShell').returns('bash');
sinon.stub(windowApis, 'createTerminal').returns(mockTerminal as Terminal);
sinon.stub(windowApis, 'onDidOpenTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidCloseTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidChangeWindowState').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'terminals').returns([]);
sinon.stub(windowApis, 'withProgress').callsFake(async (_options, task) => {
const mockProgress: Progress<{ message?: string; increment?: number }> = { report: () => {} };
const mockCancellationToken = {
isCancellationRequested: false,
onCancellationRequested: () => new Disposable(() => {}),
};
return task(mockProgress, mockCancellationToken as never);
});
sinon.stub(workspaceApis, 'onDidChangeConfiguration').returns(new Disposable(() => {}));
});
teardown(() => {
sinon.restore();
terminalActivation.dispose();
});
function createTerminalManager(): TerminalManagerImpl {
const emptyEnvProviders: ShellEnvsProvider[] = [];
const emptyScriptProviders: ShellStartupScriptProvider[] = [];
return new TerminalManagerImpl(terminalActivation, emptyEnvProviders, emptyScriptProviders);
}
// Regression test for https://github.com/microsoft/vscode-python-environments/issues/640
// With ACT_TYPE_COMMAND, create() awaits activation which blocks returning the terminal.
// Without showing the terminal early, users wouldn't see it until activation completes (2-5 seconds).
test('ACT_TYPE_COMMAND: shows terminal before awaiting activation to prevent hidden terminal during activation', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_COMMAND);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
await terminalManager.create(env, { cwd: '/workspace' });
const { callOrder } = terminalActivation;
assert.ok(callOrder.includes('show'), 'Terminal show() should be called');
assert.ok(callOrder.includes('activate'), 'Terminal activate() should be called');
const showIndex = callOrder.indexOf('show');
const activateIndex = callOrder.indexOf('activate');
assert.ok(
showIndex < activateIndex,
`show() at index ${showIndex} must precede activate() at index ${activateIndex}`,
);
});
// With ACT_TYPE_SHELL/OFF, create() returns immediately without blocking.
// The caller (runInTerminal) handles showing the terminal, so create() shouldn't call show().
test('ACT_TYPE_SHELL: does not call show() since create() returns immediately and caller handles visibility', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_SHELL);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
await terminalManager.create(env, { cwd: '/workspace' });
const { callOrder } = terminalActivation;
assert.strictEqual(callOrder.includes('show'), false, 'show() deferred to caller');
assert.strictEqual(callOrder.includes('activate'), false, 'No command activation for shell startup mode');
});
test('ACT_TYPE_OFF: does not call show() since create() returns immediately and caller handles visibility', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
await terminalManager.create(env, { cwd: '/workspace' });
const { callOrder } = terminalActivation;
assert.strictEqual(callOrder.includes('show'), false, 'show() deferred to caller');
assert.strictEqual(callOrder.includes('activate'), false, 'Activation disabled');
});
test('disableActivation option: skips both show() and activation, returns terminal immediately', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_COMMAND);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
const terminal = await terminalManager.create(env, { cwd: '/workspace', disableActivation: true });
const { callOrder } = terminalActivation;
assert.ok(terminal, 'Terminal should be returned');
assert.strictEqual(callOrder.includes('show'), false, 'No show() when activation skipped');
assert.strictEqual(terminalActivation.activateCalls, 0, 'No activate() when disableActivation is true');
});
});
suite('TerminalManager - terminal naming', () => {
let terminalActivation: TestTerminalActivation;
let mockGetAutoActivationType: sinon.SinonStub;
let terminalManager: TerminalManagerImpl;
let mockTerminal: Partial<Terminal> & { show: sinon.SinonStub };
let createTerminalStub: sinon.SinonStub;
const createMockEnvironment = (): PythonEnvironment => ({
envId: { id: 'test-env-id', managerId: 'test-manager' },
name: 'Test Environment',
displayName: 'Test Environment',
shortDisplayName: 'TestEnv',
displayPath: '/path/to/env',
version: '3.9.0',
environmentPath: Uri.file('/path/to/python'),
sysPrefix: '/path/to/env',
execInfo: {
run: { executable: '/path/to/python' },
activation: [{ executable: '/path/to/activate' }],
},
});
setup(() => {
terminalActivation = new TestTerminalActivation();
mockTerminal = {
name: 'Test Terminal',
creationOptions: {} as TerminalOptions,
shellIntegration: undefined,
show: sinon.stub(),
sendText: sinon.stub(),
};
mockGetAutoActivationType = sinon.stub(terminalUtils, 'getAutoActivationType');
sinon.stub(terminalUtils, 'waitForShellIntegration').resolves(false);
sinon.stub(activationUtils, 'isActivatableEnvironment').returns(true);
sinon.stub(shellDetector, 'identifyTerminalShell').returns('bash');
createTerminalStub = sinon.stub(windowApis, 'createTerminal').returns(mockTerminal as Terminal);
sinon.stub(windowApis, 'onDidOpenTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidCloseTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidChangeWindowState').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'terminals').returns([]);
sinon.stub(windowApis, 'withProgress').callsFake(async (_options, task) => {
const mockProgress: Progress<{ message?: string; increment?: number }> = { report: () => {} };
const mockCancellationToken = {
isCancellationRequested: false,
onCancellationRequested: () => new Disposable(() => {}),
};
return task(mockProgress, mockCancellationToken as never);
});
sinon.stub(workspaceApis, 'onDidChangeConfiguration').returns(new Disposable(() => {}));
});
teardown(() => {
sinon.restore();
terminalActivation.dispose();
});
function createTerminalManager(): TerminalManagerImpl {
const emptyEnvProviders: ShellEnvsProvider[] = [];
const emptyScriptProviders: ShellStartupScriptProvider[] = [];
return new TerminalManagerImpl(terminalActivation, emptyEnvProviders, emptyScriptProviders);
}
test('getDedicatedTerminal sets Python file name as terminal name', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
const optionsList: TerminalOptions[] = [];
createTerminalStub.callsFake((options) => {
optionsList.push(options);
return mockTerminal as Terminal;
});
const tempRoot = await fsapi.mkdtemp(path.join(os.tmpdir(), 'py-envs-'));
const projectPath = path.join(tempRoot, 'project');
const filePath = path.join(projectPath, 'main.py');
await fsapi.ensureDir(projectPath);
await fsapi.writeFile(filePath, 'print("hello")');
const projectUri = Uri.file(projectPath);
const fileUri = Uri.file(filePath);
const config = { get: sinon.stub().returns(false) } as unknown as WorkspaceConfiguration;
sinon.stub(workspaceApis, 'getConfiguration').returns(config);
try {
await terminalManager.getDedicatedTerminal(fileUri, projectUri, env);
assert.strictEqual(
optionsList[0]?.name,
'Python: main',
'Dedicated terminal should use the file name in the title',
);
} finally {
await fsapi.remove(tempRoot);
}
});
test('getProjectTerminal sets Python as terminal name', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
const optionsList: TerminalOptions[] = [];
createTerminalStub.callsFake((options) => {
optionsList.push(options);
return mockTerminal as Terminal;
});
const tempRoot = await fsapi.mkdtemp(path.join(os.tmpdir(), 'py-envs-'));
const projectPath = path.join(tempRoot, 'project');
await fsapi.ensureDir(projectPath);
const projectUri = Uri.file(projectPath);
try {
await terminalManager.getProjectTerminal(projectUri, env);
assert.strictEqual(optionsList[0]?.name, 'Python', 'Project terminal should use the Python title');
} finally {
await fsapi.remove(tempRoot);
}
});
// Regression test for https://github.com/microsoft/vscode-python-environments/issues/1230
test('getDedicatedTerminal with string key uses string as terminal name', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
const optionsList: TerminalOptions[] = [];
createTerminalStub.callsFake((options) => {
optionsList.push(options);
return mockTerminal as Terminal;
});
const tempRoot = await fsapi.mkdtemp(path.join(os.tmpdir(), 'py-envs-'));
const projectPath = path.join(tempRoot, 'project');
await fsapi.ensureDir(projectPath);
const projectUri = Uri.file(projectPath);
const config = { get: sinon.stub().returns(false) } as unknown as WorkspaceConfiguration;
sinon.stub(workspaceApis, 'getConfiguration').returns(config);
try {
await terminalManager.getDedicatedTerminal('my-terminal-key', projectUri, env);
assert.strictEqual(
optionsList[0]?.name,
'Python: my-terminal-key',
'Dedicated terminal with string key should use the string in the title',
);
assert.strictEqual(
Uri.file(optionsList[0]?.cwd as string).fsPath,
Uri.file(projectPath).fsPath,
'Dedicated terminal with string key should use project directory as cwd',
);
} finally {
await fsapi.remove(tempRoot);
}
});
// Regression test for https://github.com/microsoft/vscode-python-environments/issues/1230
test('getDedicatedTerminal with string key reuses terminal for same key', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
let createCount = 0;
createTerminalStub.callsFake((options) => {
createCount++;
return { ...mockTerminal, name: options.name } as Terminal;
});
const tempRoot = await fsapi.mkdtemp(path.join(os.tmpdir(), 'py-envs-'));
const projectPath = path.join(tempRoot, 'project');
await fsapi.ensureDir(projectPath);
const projectUri = Uri.file(projectPath);
const config = { get: sinon.stub().returns(false) } as unknown as WorkspaceConfiguration;
sinon.stub(workspaceApis, 'getConfiguration').returns(config);
try {
const terminal1 = await terminalManager.getDedicatedTerminal('my-key', projectUri, env);
const terminal2 = await terminalManager.getDedicatedTerminal('my-key', projectUri, env);
assert.strictEqual(terminal1, terminal2, 'Same string key should return the same terminal');
assert.strictEqual(createCount, 1, 'Terminal should be created only once');
} finally {
await fsapi.remove(tempRoot);
}
});
// Regression test for https://github.com/microsoft/vscode-python-environments/issues/1230
test('getDedicatedTerminal with string key uses different terminals for different keys', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_OFF);
terminalManager = createTerminalManager();
const env = createMockEnvironment();
let createCount = 0;
createTerminalStub.callsFake((options) => {
createCount++;
return { ...mockTerminal, name: options.name, id: createCount } as unknown as Terminal;
});
const tempRoot = await fsapi.mkdtemp(path.join(os.tmpdir(), 'py-envs-'));
const projectPath = path.join(tempRoot, 'project');
await fsapi.ensureDir(projectPath);
const projectUri = Uri.file(projectPath);
const config = { get: sinon.stub().returns(false) } as unknown as WorkspaceConfiguration;
sinon.stub(workspaceApis, 'getConfiguration').returns(config);
try {
const terminal1 = await terminalManager.getDedicatedTerminal('key-1', projectUri, env);
const terminal2 = await terminalManager.getDedicatedTerminal('key-2', projectUri, env);
assert.notStrictEqual(terminal1, terminal2, 'Different string keys should return different terminals');
assert.strictEqual(createCount, 2, 'Two terminals should be created');
} finally {
await fsapi.remove(tempRoot);
}
});
});
suite('TerminalManager - initialize() with activateEnvInCurrentTerminal', () => {
let terminalActivation: TestTerminalActivation;
let terminalManager: TerminalManagerImpl;
let mockGetAutoActivationType: sinon.SinonStub;
let mockShouldActivateInCurrentTerminal: sinon.SinonStub;
let mockTerminals: sinon.SinonStub;
let mockGetEnvironmentForTerminal: sinon.SinonStub;
const createMockTerminal = (name: string): Terminal =>
({
name,
creationOptions: {} as TerminalOptions,
shellIntegration: undefined,
show: sinon.stub(),
sendText: sinon.stub(),
}) as unknown as Terminal;
const createMockEnvironment = (): PythonEnvironment => ({
envId: { id: 'test-env-id', managerId: 'test-manager' },
name: 'Test Environment',
displayName: 'Test Environment',
shortDisplayName: 'TestEnv',
displayPath: '/path/to/env',
version: '3.9.0',
environmentPath: Uri.file('/path/to/python'),
sysPrefix: '/path/to/env',
execInfo: {
run: { executable: '/path/to/python' },
activation: [{ executable: '/path/to/activate' }],
},
});
setup(() => {
terminalActivation = new TestTerminalActivation();
mockGetAutoActivationType = sinon.stub(terminalUtils, 'getAutoActivationType');
mockShouldActivateInCurrentTerminal = sinon.stub(terminalUtils, 'shouldActivateInCurrentTerminal');
mockGetEnvironmentForTerminal = sinon.stub(terminalUtils, 'getEnvironmentForTerminal');
sinon.stub(terminalUtils, 'waitForShellIntegration').resolves(false);
sinon.stub(activationUtils, 'isActivatableEnvironment').returns(true);
sinon.stub(shellDetector, 'identifyTerminalShell').returns('bash');
sinon.stub(windowApis, 'createTerminal').callsFake(() => createMockTerminal('new'));
sinon.stub(windowApis, 'onDidOpenTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidCloseTerminal').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'onDidChangeWindowState').returns(new Disposable(() => {}));
sinon.stub(windowApis, 'activeTerminal').returns(undefined);
mockTerminals = sinon.stub(windowApis, 'terminals');
sinon.stub(windowApis, 'withProgress').callsFake(async (_options, task) => {
const mockProgress = { report: () => {} };
const mockToken = {
isCancellationRequested: false,
onCancellationRequested: () => new Disposable(() => {}),
};
return task(mockProgress as never, mockToken as never);
});
sinon.stub(workspaceApis, 'onDidChangeConfiguration').returns(new Disposable(() => {}));
});
teardown(() => {
sinon.restore();
terminalActivation.dispose();
});
function createTerminalManager(): TerminalManagerImpl {
return new TerminalManagerImpl(terminalActivation, [], []);
}
test('initialize activates all pre-existing terminals when shouldActivateInCurrentTerminal returns true', async () => {
const terminal1 = createMockTerminal('terminal1');
const terminal2 = createMockTerminal('terminal2');
const env = createMockEnvironment();
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_COMMAND);
mockShouldActivateInCurrentTerminal.returns(true);
mockTerminals.returns([terminal1, terminal2]);
mockGetEnvironmentForTerminal.resolves(env);
terminalManager = createTerminalManager();
await terminalManager.initialize({} as never);
assert.strictEqual(
terminalActivation.activateCalls,
2,
'Should activate all pre-existing terminals when activateEnvInCurrentTerminal is true/default',
);
});
test('initialize skips all pre-existing terminals when shouldActivateInCurrentTerminal returns false', async () => {
const terminal1 = createMockTerminal('terminal1');
const terminal2 = createMockTerminal('terminal2');
const env = createMockEnvironment();
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_COMMAND);
mockShouldActivateInCurrentTerminal.returns(false);
mockTerminals.returns([terminal1, terminal2]);
mockGetEnvironmentForTerminal.resolves(env);
terminalManager = createTerminalManager();
await terminalManager.initialize({} as never);
assert.strictEqual(
terminalActivation.activateCalls,
0,
'Should skip all pre-existing terminals when activateEnvInCurrentTerminal is explicitly false',
);
});
test('initialize proceeds normally when shouldActivateInCurrentTerminal returns false but no pre-existing terminals', async () => {
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_COMMAND);
mockShouldActivateInCurrentTerminal.returns(false);
mockTerminals.returns([]);
terminalManager = createTerminalManager();
await terminalManager.initialize({} as never);
assert.strictEqual(
terminalActivation.activateCalls,
0,
'Should have no activations when there are no terminals',
);
});
test('initialize skips shell fallback activation for pre-existing terminals when shouldActivateInCurrentTerminal returns false (ACT_TYPE_SHELL)', async () => {
const terminal1 = createMockTerminal('terminal1');
const env = createMockEnvironment();
// Mock a shell startup provider that reports NotSetup so shellSetup gets set to false,
// which would normally trigger the command fallback activation.
const mockShellProvider: ShellStartupScriptProvider = {
name: 'bash-test',
shellType: 'bash',
isSetup: sinon.stub().resolves(ShellSetupState.NotSetup),
setupScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
teardownScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
clearCache: sinon.stub().resolves(),
};
sinon.stub(shellUtils, 'getShellIntegrationEnabledCache').resolves(false);
sinon.stub(shellUtils, 'shouldUseProfileActivation').returns(false);
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_SHELL);
mockShouldActivateInCurrentTerminal.returns(false);
mockTerminals.returns([terminal1]);
mockGetEnvironmentForTerminal.resolves(env);
terminalManager = new TerminalManagerImpl(terminalActivation, [], [mockShellProvider]);
await terminalManager.initialize({} as never);
assert.strictEqual(
terminalActivation.activateCalls,
0,
'Should skip shell fallback activation for pre-existing terminals when activateEnvInCurrentTerminal is explicitly false',
);
});
test('initialize activates via shell command fallback for pre-existing terminals when shouldActivateInCurrentTerminal returns true (ACT_TYPE_SHELL)', async () => {
const terminal1 = createMockTerminal('terminal1');
const env = createMockEnvironment();
// Mock a shell startup provider that reports NotSetup so shellSetup gets set to false,
// triggering the command fallback activation.
const mockShellProvider: ShellStartupScriptProvider = {
name: 'bash-test',
shellType: 'bash',
isSetup: sinon.stub().resolves(ShellSetupState.NotSetup),
setupScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
teardownScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
clearCache: sinon.stub().resolves(),
};
sinon.stub(shellUtils, 'getShellIntegrationEnabledCache').resolves(false);
sinon.stub(shellUtils, 'shouldUseProfileActivation').returns(false);
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_SHELL);
mockShouldActivateInCurrentTerminal.returns(true);
mockTerminals.returns([terminal1]);
mockGetEnvironmentForTerminal.resolves(env);
terminalManager = new TerminalManagerImpl(terminalActivation, [], [mockShellProvider]);
await terminalManager.initialize({} as never);
assert.strictEqual(
terminalActivation.activateCalls,
1,
'Should activate via command fallback when shell setup reports not setup',
);
});
});