Skip to content

Commit 3f13dcb

Browse files
committed
address copilot comments
1 parent 822c040 commit 3f13dcb

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/managers/conda/condaUtils.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,11 @@ export function getCondaPathSetting(): string | undefined {
8484
export async function getCondaForWorkspace(fsPath: string): Promise<string | undefined> {
8585
// Check persisted user selection first so explicit choices survive restarts
8686
const state = await getWorkspacePersistentState();
87-
const data: { [key: string]: string } | undefined = await state.get(CONDA_WORKSPACE_KEY);
88-
if (data) {
89-
try {
90-
const saved = data[fsPath];
91-
if (saved) {
92-
return saved;
93-
}
94-
} catch {
95-
// fall through to CONDA_PREFIX fallback
87+
const data = await state.get<unknown>(CONDA_WORKSPACE_KEY);
88+
if (data && typeof data === 'object') {
89+
const workspaceSelections = data as { [key: string]: string };
90+
if (Object.prototype.hasOwnProperty.call(workspaceSelections, fsPath)) {
91+
return workspaceSelections[fsPath];
9692
}
9793
}
9894

src/test/managers/conda/condaUtils.getCondaForWorkspace.unit.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,17 @@ suite('Conda Utils - getCondaForWorkspace prioritization', () => {
9191

9292
assert.strictEqual(result, userSelectedEnv);
9393
});
94+
95+
test('Returns persisted empty string without falling back to CONDA_PREFIX', async () => {
96+
const workspacePath = '/home/user/project';
97+
process.env.CONDA_PREFIX = '/home/user/miniconda3';
98+
99+
mockState.get.withArgs(CONDA_WORKSPACE_KEY).resolves({
100+
[workspacePath]: '',
101+
});
102+
103+
const result = await getCondaForWorkspace(workspacePath);
104+
105+
assert.strictEqual(result, '');
106+
});
94107
});

0 commit comments

Comments
 (0)