forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.unit.test.ts
More file actions
702 lines (584 loc) · 27.1 KB
/
utils.unit.test.ts
File metadata and controls
702 lines (584 loc) · 27.1 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
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
import * as assert from 'assert';
import * as sinon from 'sinon';
import { Terminal } from 'vscode';
import * as windowApis from '../../../common/window.apis';
import * as workspaceApis from '../../../common/workspace.apis';
import * as shellDetector from '../../../features/common/shellDetector';
import {
ACT_TYPE_COMMAND,
ACT_TYPE_OFF,
ACT_TYPE_SHELL,
AutoActivationType,
getAutoActivationType,
shouldActivateInCurrentTerminal,
waitForShellIntegration,
} from '../../../features/terminal/utils';
interface MockWorkspaceConfig {
get: sinon.SinonStub;
inspect: sinon.SinonStub;
update: sinon.SinonStub;
}
suite('Terminal Utils - getAutoActivationType', () => {
let mockGetConfiguration: sinon.SinonStub;
let pyEnvsConfig: MockWorkspaceConfig;
let pythonConfig: MockWorkspaceConfig;
setup(() => {
// Initialize mocks
mockGetConfiguration = sinon.stub(workspaceApis, 'getConfiguration');
// Create mock configuration objects
pyEnvsConfig = {
get: sinon.stub(),
inspect: sinon.stub(),
update: sinon.stub(),
};
pythonConfig = {
get: sinon.stub(),
inspect: sinon.stub(),
update: sinon.stub(),
};
// Set up default configuration returns
mockGetConfiguration.withArgs('python-envs').returns(pyEnvsConfig);
mockGetConfiguration.withArgs('python').returns(pythonConfig);
});
teardown(() => {
sinon.restore();
});
suite('Priority Order Tests', () => {
test('should return globalRemoteValue when set (highest priority)', () => {
// Mock - globalRemoteValue is set
const mockInspectResult = {
globalRemoteValue: ACT_TYPE_SHELL,
globalLocalValue: ACT_TYPE_COMMAND,
globalValue: ACT_TYPE_OFF,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_SHELL, 'Should return globalRemoteValue when set');
});
test('should return globalLocalValue when globalRemoteValue is undefined', () => {
// Mock - globalRemoteValue is undefined, globalLocalValue is set
const mockInspectResult = {
globalRemoteValue: undefined,
globalLocalValue: ACT_TYPE_SHELL,
globalValue: ACT_TYPE_OFF,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_SHELL,
'Should return globalLocalValue when globalRemoteValue is undefined',
);
});
test('should return globalValue when both globalRemoteValue and globalLocalValue are undefined', () => {
// Mock - only globalValue is set
const mockInspectResult = {
globalRemoteValue: undefined,
globalLocalValue: undefined,
globalValue: ACT_TYPE_OFF,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_OFF,
'Should return globalValue when higher priority values are undefined',
);
});
test('should ignore globalLocalValue and globalValue when globalRemoteValue exists', () => {
// Mock - all values set, should prioritize globalRemoteValue
const mockInspectResult = {
globalRemoteValue: ACT_TYPE_OFF,
globalLocalValue: ACT_TYPE_SHELL,
globalValue: ACT_TYPE_COMMAND,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_OFF, 'Should prioritize globalRemoteValue over other values');
});
test('should ignore globalValue when globalLocalValue exists', () => {
// Mock - globalLocalValue and globalValue set, should prioritize globalLocalValue
const mockInspectResult = {
globalLocalValue: ACT_TYPE_SHELL,
globalValue: ACT_TYPE_COMMAND,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_SHELL, 'Should prioritize globalLocalValue over globalValue');
});
});
suite('Custom Properties Handling', () => {
test('should handle case when globalRemoteValue property does not exist', () => {
// Mock - standard VS Code inspection result without custom properties
const mockInspectResult = {
key: 'terminal.autoActivationType',
globalValue: ACT_TYPE_SHELL,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_SHELL, 'Should return globalValue when custom properties do not exist');
});
test('should handle case when globalLocalValue property does not exist', () => {
// Mock - inspection result without globalLocalValue property
const mockInspectResult = {
key: 'terminal.autoActivationType',
globalValue: ACT_TYPE_COMMAND,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_COMMAND,
'Should return globalValue when globalLocalValue property does not exist',
);
});
test('should handle case when custom properties exist but are undefined', () => {
// Mock - custom properties exist but have undefined values
const mockInspectResult = {
globalRemoteValue: undefined,
globalLocalValue: undefined,
globalValue: ACT_TYPE_OFF,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_OFF,
'Should fall back to globalValue when custom properties are undefined',
);
});
});
suite('Legacy Python Setting Fallback', () => {
test('should return ACT_TYPE_OFF and update config when python.terminal.activateEnvironment is false', () => {
// Mock - no python-envs settings, python.terminal.activateEnvironment is false
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_OFF, 'Should return ACT_TYPE_OFF when legacy setting is false');
assert.ok(
pyEnvsConfig.update.calledWithExactly('terminal.autoActivationType', ACT_TYPE_OFF),
'Should update python-envs config to ACT_TYPE_OFF',
);
});
test('should return ACT_TYPE_COMMAND when python.terminal.activateEnvironment is true', () => {
// Mock - no python-envs settings, python.terminal.activateEnvironment is true
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(true);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_COMMAND, 'Should return ACT_TYPE_COMMAND when legacy setting is true');
assert.ok(
pyEnvsConfig.update.notCalled,
'Should not update python-envs config when legacy setting is true',
);
});
test('should return ACT_TYPE_COMMAND when python.terminal.activateEnvironment is undefined', () => {
// Mock - no python-envs settings, python.terminal.activateEnvironment is undefined
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(undefined);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_COMMAND, 'Should return ACT_TYPE_COMMAND when no settings are found');
assert.ok(
pyEnvsConfig.update.notCalled,
'Should not update python-envs config when no legacy setting exists',
);
});
});
suite('Fallback Scenarios', () => {
test('should return ACT_TYPE_COMMAND when no configuration exists', () => {
// Mock - no configurations exist
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(undefined);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(undefined);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_COMMAND,
'Should return default ACT_TYPE_COMMAND when no configurations exist',
);
});
test('should return ACT_TYPE_COMMAND when python-envs config exists but all values are undefined', () => {
// Mock - python-envs config exists but all relevant values are undefined
const mockInspectResult = {
key: 'terminal.autoActivationType',
globalValue: undefined,
workspaceValue: undefined,
workspaceFolderValue: undefined,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(undefined);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_COMMAND,
'Should return default when python-envs config exists but values are undefined',
);
});
test('should prioritize python-envs settings over legacy python settings', () => {
// Mock - python-envs has globalValue, python has conflicting setting
const mockInspectResult = {
globalValue: ACT_TYPE_SHELL,
};
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(false);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(
result,
ACT_TYPE_SHELL,
'Should prioritize python-envs globalValue over legacy python setting',
);
assert.ok(
pyEnvsConfig.update.notCalled,
'Should not update python-envs config when it already has a value',
);
});
});
suite('Edge Cases', () => {
test('should handle null inspect result', () => {
// Mock - inspect returns null
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(null);
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(undefined);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_COMMAND, 'Should handle null inspect result gracefully');
});
test('should handle empty object inspect result', () => {
// Mock - inspect returns empty object
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns({});
pythonConfig.get.withArgs('terminal.activateEnvironment', undefined).returns(undefined);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, ACT_TYPE_COMMAND, 'Should handle empty inspect result gracefully');
});
test('should handle all AutoActivationType values correctly', () => {
const testCases: { input: AutoActivationType; expected: AutoActivationType }[] = [
{ input: ACT_TYPE_COMMAND, expected: ACT_TYPE_COMMAND },
{ input: ACT_TYPE_SHELL, expected: ACT_TYPE_SHELL },
{ input: ACT_TYPE_OFF, expected: ACT_TYPE_OFF },
];
testCases.forEach(({ input, expected }) => {
// Reset stubs for each test case
pyEnvsConfig.inspect.resetHistory();
pythonConfig.get.resetHistory();
// Mock - set globalValue to test input
const mockInspectResult = { globalValue: input };
pyEnvsConfig.inspect.withArgs('terminal.autoActivationType').returns(mockInspectResult);
// Run
const result = getAutoActivationType();
// Assert
assert.strictEqual(result, expected, `Should handle ${input} value correctly`);
});
});
});
});
suite('Terminal Utils - shouldActivateInCurrentTerminal', () => {
let mockGetConfiguration: sinon.SinonStub;
let pythonConfig: MockWorkspaceConfig;
setup(() => {
mockGetConfiguration = sinon.stub(workspaceApis, 'getConfiguration');
pythonConfig = {
get: sinon.stub(),
inspect: sinon.stub(),
update: sinon.stub(),
};
mockGetConfiguration.withArgs('python').returns(pythonConfig);
});
teardown(() => {
sinon.restore();
});
test('should return true when inspect returns undefined (no config)', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns(undefined);
assert.strictEqual(shouldActivateInCurrentTerminal(), true, 'Should default to true when no config exists');
});
test('should return true when no explicit values are set (all undefined)', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: undefined,
workspaceValue: undefined,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
true,
'Should return true when only defaultValue is set (not user-explicit)',
);
});
test('should return false when globalValue is explicitly false', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: false,
workspaceValue: undefined,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Should return false when user explicitly set globalValue to false',
);
});
test('should return false when workspaceValue is explicitly false', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: undefined,
workspaceValue: false,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Should return false when user explicitly set workspaceValue to false',
);
});
test('should return false when workspaceFolderValue is explicitly false', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: undefined,
workspaceValue: undefined,
workspaceFolderValue: false,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Should return false when user explicitly set workspaceFolderValue to false',
);
});
test('should return true when globalValue is explicitly true', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: true,
workspaceValue: undefined,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
true,
'Should return true when user explicitly set globalValue to true',
);
});
test('workspaceFolderValue false takes precedence over globalValue true', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: true,
workspaceValue: undefined,
workspaceFolderValue: false,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'workspaceFolderValue false should take precedence',
);
});
test('should return false when globalRemoteValue is explicitly false', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalRemoteValue: false,
globalValue: undefined,
workspaceValue: undefined,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Should return false when user explicitly set globalRemoteValue to false',
);
});
test('should return false when globalLocalValue is explicitly false', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalLocalValue: false,
globalValue: undefined,
workspaceValue: undefined,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Should return false when user explicitly set globalLocalValue to false',
);
});
test('workspaceValue false takes precedence over globalRemoteValue true', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalRemoteValue: true,
globalValue: undefined,
workspaceValue: false,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'workspaceValue false should take precedence over globalRemoteValue true',
);
});
test('should return false when globalValue is false even if workspaceValue is true (any explicit false wins)', () => {
pythonConfig.inspect.withArgs('terminal.activateEnvInCurrentTerminal').returns({
key: 'terminal.activateEnvInCurrentTerminal',
defaultValue: false,
globalValue: false,
workspaceValue: true,
workspaceFolderValue: undefined,
});
assert.strictEqual(
shouldActivateInCurrentTerminal(),
false,
'Any explicit false at any scope should return false, regardless of higher-precedence true values',
);
});
});
suite('Terminal Utils - waitForShellIntegration', () => {
let mockGetConfiguration: sinon.SinonStub;
let identifyTerminalShellStub: sinon.SinonStub;
let onDidChangeTerminalShellIntegrationStub: sinon.SinonStub;
let onDidWriteTerminalDataStub: sinon.SinonStub;
function setupLongTimeoutConfig() {
// Make the timeout effectively infinite so tests resolve via the listener,
// not the timer. Avoids flakiness while keeping the race code paths exercised.
const config = {
get: sinon.stub(),
inspect: sinon.stub(),
update: sinon.stub(),
};
config.get.withArgs('shellIntegration.timeout').returns(60_000);
config.get.withArgs('shellIntegration.enabled', true).returns(true);
mockGetConfiguration.withArgs('terminal.integrated').returns(config);
}
setup(() => {
mockGetConfiguration = sinon.stub(workspaceApis, 'getConfiguration');
identifyTerminalShellStub = sinon.stub(shellDetector, 'identifyTerminalShell');
onDidChangeTerminalShellIntegrationStub = sinon.stub(windowApis, 'onDidChangeTerminalShellIntegration');
onDidWriteTerminalDataStub = sinon.stub(windowApis, 'onDidWriteTerminalData');
// Default: dispose-only fake event registrations. Tests that need to fire
// events override these via .callsFake.
const fakeDisposable = { dispose: () => undefined };
onDidChangeTerminalShellIntegrationStub.returns(fakeDisposable);
onDidWriteTerminalDataStub.returns(fakeDisposable);
});
teardown(() => {
sinon.restore();
});
test('returns false immediately when terminal is undefined', async () => {
const result = await waitForShellIntegration(undefined);
assert.strictEqual(result, false);
sinon.assert.notCalled(identifyTerminalShellStub);
sinon.assert.notCalled(onDidChangeTerminalShellIntegrationStub);
});
test('returns true immediately when terminal.shellIntegration is already set', async () => {
const terminal = { shellIntegration: {} } as unknown as Terminal;
const result = await waitForShellIntegration(terminal);
assert.strictEqual(result, true);
sinon.assert.notCalled(identifyTerminalShellStub);
sinon.assert.notCalled(onDidChangeTerminalShellIntegrationStub);
});
test('returns false immediately for nu without registering event listeners', async () => {
const terminal = {} as Terminal;
identifyTerminalShellStub.returns('nu');
const result = await waitForShellIntegration(terminal);
assert.strictEqual(result, false);
sinon.assert.calledOnce(identifyTerminalShellStub);
sinon.assert.notCalled(onDidChangeTerminalShellIntegrationStub);
sinon.assert.notCalled(onDidWriteTerminalDataStub);
});
test('returns false immediately for cmd', async () => {
const terminal = {} as Terminal;
identifyTerminalShellStub.returns('cmd');
const result = await waitForShellIntegration(terminal);
assert.strictEqual(result, false);
sinon.assert.notCalled(onDidChangeTerminalShellIntegrationStub);
});
test('returns false immediately for csh / tcsh / ksh / xonsh', async () => {
const unsupported = ['csh', 'tcsh', 'ksh', 'xonsh'];
for (const shell of unsupported) {
identifyTerminalShellStub.resetHistory();
identifyTerminalShellStub.returns(shell);
onDidChangeTerminalShellIntegrationStub.resetHistory();
const result = await waitForShellIntegration({} as Terminal);
assert.strictEqual(result, false, `expected false for shell '${shell}'`);
sinon.assert.notCalled(onDidChangeTerminalShellIntegrationStub);
}
});
test('falls through to event race for bash (supported shell)', async () => {
setupLongTimeoutConfig();
const terminal = {} as Terminal;
identifyTerminalShellStub.returns('bash');
let listenerRef: ((e: { terminal: Terminal }) => void) | undefined;
onDidChangeTerminalShellIntegrationStub.callsFake((listener: (e: { terminal: Terminal }) => void) => {
listenerRef = listener;
return { dispose: () => undefined };
});
const racePromise = waitForShellIntegration(terminal);
// Yield once so the Promise.race body has a chance to register listeners.
await new Promise<void>((r) => setImmediate(r));
assert.ok(listenerRef, 'shell integration listener should be registered');
listenerRef!({ terminal });
const result = await racePromise;
assert.strictEqual(result, true);
sinon.assert.calledOnce(onDidChangeTerminalShellIntegrationStub);
});
test('falls through to event race when shell type is unknown', async () => {
setupLongTimeoutConfig();
const terminal = {} as Terminal;
identifyTerminalShellStub.returns('unknown');
let listenerRef: ((e: { terminal: Terminal }) => void) | undefined;
onDidChangeTerminalShellIntegrationStub.callsFake((listener: (e: { terminal: Terminal }) => void) => {
listenerRef = listener;
return { dispose: () => undefined };
});
const racePromise = waitForShellIntegration(terminal);
await new Promise<void>((r) => setImmediate(r));
listenerRef!({ terminal });
const result = await racePromise;
assert.strictEqual(result, true);
});
test('falls through to event race when identifyTerminalShell throws', async () => {
setupLongTimeoutConfig();
const terminal = {} as Terminal;
identifyTerminalShellStub.throws(new Error('detection failed'));
let listenerRef: ((e: { terminal: Terminal }) => void) | undefined;
onDidChangeTerminalShellIntegrationStub.callsFake((listener: (e: { terminal: Terminal }) => void) => {
listenerRef = listener;
return { dispose: () => undefined };
});
const racePromise = waitForShellIntegration(terminal);
await new Promise<void>((r) => setImmediate(r));
listenerRef!({ terminal });
const result = await racePromise;
assert.strictEqual(result, true, 'should not regress when detection throws');
});
});