diff --git a/src/managers/conda/condaStepBasedFlow.ts b/src/managers/conda/condaStepBasedFlow.ts index 0a3e50343..8b5b2ced7 100644 --- a/src/managers/conda/condaStepBasedFlow.ts +++ b/src/managers/conda/condaStepBasedFlow.ts @@ -14,6 +14,11 @@ import { // Recommended Python version for Conda environments const RECOMMENDED_CONDA_PYTHON = '3.11.11'; +const DEFAULT_CONDA_NAMED_LABEL = 'Named'; + +function getCondaNamedLabel(): string { + return CondaStrings.condaNamed || DEFAULT_CONDA_NAMED_LABEL; +} /** * State interface for the Conda environment creation flow. @@ -60,13 +65,13 @@ async function selectEnvironmentType(state: CondaCreationState): Promise 1) { - state.envType = 'Named'; + state.envType = getCondaNamedLabel(); return selectPythonVersion; } const selection = (await showQuickPickWithButtons( [ - { label: CondaStrings.condaNamed, description: CondaStrings.condaNamedDescription }, + { label: getCondaNamedLabel(), description: CondaStrings.condaNamedDescription }, { label: CondaStrings.condaPrefix, description: CondaStrings.condaPrefixDescription }, ], { @@ -129,7 +134,7 @@ async function selectPythonVersion(state: CondaCreationState): Promise): CondaEnvMa return manager; } +suite('CondaEnvManager.create - step-based flow', () => { + let originalCondaNamed: string; + + setup(() => { + originalCondaNamed = CondaStrings.condaNamed; + Object.defineProperty(CondaStrings, 'condaNamed', { value: '명명됨', configurable: true }); + }); + + teardown(() => { + sinon.restore(); + Object.defineProperty(CondaStrings, 'condaNamed', { value: originalCondaNamed, configurable: true }); + }); + + test('routes a localized Named selection to named environment creation', async () => { + const createdEnvironment = {} as PythonEnvironment; + const showQuickPickStub = sinon.stub(windowApis, 'showQuickPickWithButtons'); + showQuickPickStub.onFirstCall().callsFake(async (items: readonly QuickPickItem[]) => items[0]); + showQuickPickStub.onSecondCall().resolves({ label: 'Python', description: '3.12' } as QuickPickItem); + const showInputBoxStub = sinon.stub(windowApis, 'showInputBoxWithButtons').resolves('localized-env'); + const createNamedStub = sinon.stub(condaUtils, 'createNamedCondaEnvironment').resolves(createdEnvironment); + const createPrefixStub = sinon.stub(condaUtils, 'createPrefixCondaEnvironment'); + const api = { + getEnvironments: sinon.stub().resolves([]), + getPythonProject: sinon.stub().returns(undefined), + } as unknown as PythonEnvironmentApi; + + const result = await createStepBasedCondaFlow( + api, + createMockLogOutputChannel(), + {} as EnvironmentManager, + Uri.file('workspace'), + ); + + assert.strictEqual(result, createdEnvironment); + assert.strictEqual((showQuickPickStub.firstCall.args[0] as QuickPickItem[])[0].label, '명명됨'); + assert.ok(showInputBoxStub.calledOnce); + assert.ok(createNamedStub.calledOnceWithExactly(api, sinon.match.any, sinon.match.any, 'localized-env', '3.12')); + assert.ok(createPrefixStub.notCalled); + }); + + test('falls back to English Named when the localized label is unavailable', async () => { + Object.defineProperty(CondaStrings, 'condaNamed', { value: undefined, configurable: true }); + const createdEnvironment = {} as PythonEnvironment; + const showQuickPickStub = sinon.stub(windowApis, 'showQuickPickWithButtons'); + showQuickPickStub.resolves({ label: 'Python', description: '3.12' } as QuickPickItem); + const showInputBoxStub = sinon.stub(windowApis, 'showInputBoxWithButtons').resolves('fallback-env'); + const createNamedStub = sinon.stub(condaUtils, 'createNamedCondaEnvironment').resolves(createdEnvironment); + const createPrefixStub = sinon.stub(condaUtils, 'createPrefixCondaEnvironment'); + const api = { + getEnvironments: sinon.stub().resolves([]), + getPythonProject: sinon.stub().returns(undefined), + } as unknown as PythonEnvironmentApi; + + const result = await createStepBasedCondaFlow( + api, + createMockLogOutputChannel(), + {} as EnvironmentManager, + [Uri.file(testPath('workspace', 'one')), Uri.file(testPath('workspace', 'two'))], + ); + + assert.strictEqual(result, createdEnvironment); + assert.ok(showQuickPickStub.calledOnce); + assert.ok(showInputBoxStub.calledOnce); + assert.ok(createNamedStub.calledOnceWithExactly(api, sinon.match.any, sinon.match.any, 'fallback-env', '3.12')); + assert.ok(createPrefixStub.notCalled); + }); +}); + suite('CondaEnvManager.create - orchestration', () => { let createCondaStub: sinon.SinonStub; let generateNameStub: sinon.SinonStub;