Skip to content

Commit 2bf29c1

Browse files
committed
address comment about test
1 parent 866b180 commit 2bf29c1

File tree

1 file changed

+71
-1
lines changed

1 file changed

+71
-1
lines changed

src/test/features/terminal/terminalManager.unit.test.ts

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ import * as windowApis from '../../../common/window.apis';
2121
import * as workspaceApis from '../../../common/workspace.apis';
2222
import * as activationUtils from '../../../features/common/activation';
2323
import * as shellDetector from '../../../features/common/shellDetector';
24-
import { ShellEnvsProvider, ShellStartupScriptProvider } from '../../../features/terminal/shells/startupProvider';
24+
import * as shellUtils from '../../../features/terminal/shells/common/shellUtils';
25+
import {
26+
ShellEnvsProvider,
27+
ShellScriptEditState,
28+
ShellSetupState,
29+
ShellStartupScriptProvider,
30+
} from '../../../features/terminal/shells/startupProvider';
2531
import {
2632
DidChangeTerminalActivationStateEvent,
2733
TerminalActivationInternal,
@@ -546,4 +552,68 @@ suite('TerminalManager - initialize() with activateEnvInCurrentTerminal', () =>
546552
'Should have no activations when there are no terminals',
547553
);
548554
});
555+
556+
test('initialize skips shell fallback activation for pre-existing terminals when shouldActivateInCurrentTerminal returns false (ACT_TYPE_SHELL)', async () => {
557+
const terminal1 = createMockTerminal('terminal1');
558+
const env = createMockEnvironment();
559+
560+
// Mock a shell startup provider that reports NotSetup so shellSetup gets set to false,
561+
// which would normally trigger the command fallback activation.
562+
const mockShellProvider: ShellStartupScriptProvider = {
563+
name: 'bash-test',
564+
shellType: 'bash',
565+
isSetup: sinon.stub().resolves(ShellSetupState.NotSetup),
566+
setupScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
567+
teardownScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
568+
clearCache: sinon.stub().resolves(),
569+
};
570+
sinon.stub(shellUtils, 'getShellIntegrationEnabledCache').resolves(false);
571+
sinon.stub(shellUtils, 'shouldUseProfileActivation').returns(false);
572+
573+
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_SHELL);
574+
mockShouldActivateInCurrentTerminal.returns(false);
575+
mockTerminals.returns([terminal1]);
576+
mockGetEnvironmentForTerminal.resolves(env);
577+
578+
terminalManager = new TerminalManagerImpl(terminalActivation, [], [mockShellProvider]);
579+
await terminalManager.initialize({} as never);
580+
581+
assert.strictEqual(
582+
terminalActivation.activateCalls,
583+
0,
584+
'Should skip shell fallback activation for pre-existing terminals when activateEnvInCurrentTerminal is explicitly false',
585+
);
586+
});
587+
588+
test('initialize activates via shell command fallback for pre-existing terminals when shouldActivateInCurrentTerminal returns true (ACT_TYPE_SHELL)', async () => {
589+
const terminal1 = createMockTerminal('terminal1');
590+
const env = createMockEnvironment();
591+
592+
// Mock a shell startup provider that reports NotSetup so shellSetup gets set to false,
593+
// triggering the command fallback activation.
594+
const mockShellProvider: ShellStartupScriptProvider = {
595+
name: 'bash-test',
596+
shellType: 'bash',
597+
isSetup: sinon.stub().resolves(ShellSetupState.NotSetup),
598+
setupScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
599+
teardownScripts: sinon.stub().resolves(ShellScriptEditState.NotEdited),
600+
clearCache: sinon.stub().resolves(),
601+
};
602+
sinon.stub(shellUtils, 'getShellIntegrationEnabledCache').resolves(false);
603+
sinon.stub(shellUtils, 'shouldUseProfileActivation').returns(false);
604+
605+
mockGetAutoActivationType.returns(terminalUtils.ACT_TYPE_SHELL);
606+
mockShouldActivateInCurrentTerminal.returns(true);
607+
mockTerminals.returns([terminal1]);
608+
mockGetEnvironmentForTerminal.resolves(env);
609+
610+
terminalManager = new TerminalManagerImpl(terminalActivation, [], [mockShellProvider]);
611+
await terminalManager.initialize({} as never);
612+
613+
assert.strictEqual(
614+
terminalActivation.activateCalls,
615+
1,
616+
'Should activate via command fallback when shell setup reports not setup',
617+
);
618+
});
549619
});

0 commit comments

Comments
 (0)