Fix set() for global scope not updating globalEnv in memory#1457
Open
StellaHuang95 wants to merge 2 commits intomicrosoft:mainfrom
Open
Fix set() for global scope not updating globalEnv in memory#1457StellaHuang95 wants to merge 2 commits intomicrosoft:mainfrom
set() for global scope not updating globalEnv in memory#1457StellaHuang95 wants to merge 2 commits intomicrosoft:mainfrom
Conversation
cfcd2b9 to
9b1071f
Compare
| import * as condaUtils from '../../../managers/conda/condaUtils'; | ||
| import { NativePythonFinder } from '../../../managers/common/nativePythonFinder'; | ||
|
|
||
| function makeEnv(name: string, envPath: string, version: string = '3.12.0'): PythonEnvironment { |
Member
There was a problem hiding this comment.
can you see if we have a helper function like this elsewhere and if not move this to a common place which many testing files could use
Contributor
Author
There was a problem hiding this comment.
Yes the exact makeEnv(name, envPath, version?) body was duplicated across three conda unit test files, so I refactored the three conda test files to import makeMockPythonEnvironment as makeEnv from the shared location instead of defining it locally:
src/test/managers/conda/condaEnvManager.findEnvironmentByPath.unit.test.tssrc/test/managers/conda/condaEnvManager.setEvents.unit.test.tssrc/test/managers/conda/condaEnvManager.setGlobal.unit.test.ts
9b1071f to
0d3e576
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #1454
Bug
When a user selects a conda environment as the global Python interpreter,
CondaEnvManager.set(undefined, environment)persists the selection to disk viasetCondaForGlobal(), but never updatesthis.globalEnvin memory. Subsequent calls toget(undefined)return the stale old environment becauseget()returnsthis.globalEnvdirectly (line 305).Why it's a bug
The orchestrator's
getEnvironment()method callsmanager.get(scope), which returns the in-memorythis.globalEnv. Since the field is never updated afterset(), the persisted selection is effectively invisible until VS Code is restarted (whenloadEnvMapre-reads from persistent state). This causes the selection to appear to "revert" or "flicker" back to the previous environment.Repro steps
Fix
Update
this.globalEnvin memory before persisting to disk, matching the pattern already used byvenvManager.ts(lines 407–414):Before:

After:

Why this fix is correct
checkedEnvvariable already accounts for no-python environments (it'sundefinedif the user declines Python installation), so settingthis.globalEnv = checkedEnvcorrectly handles both the set and unset cases.globalEnvis only updated during initialization.Tests added
condaEnvManager.setGlobal.unit.test.ts: 4 test cases covering set, persist, clear, and no-python decline scenarios.