From 178aa343e422482a3dc0d68942f41630c3f81185 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 17 Oct 2024 21:26:21 -0700 Subject: [PATCH 1/2] Fix for duplication of python envs --- src/client/pythonEnvironments/nativeAPI.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/client/pythonEnvironments/nativeAPI.ts b/src/client/pythonEnvironments/nativeAPI.ts index 31ad80608283..7e2f7aa3515b 100644 --- a/src/client/pythonEnvironments/nativeAPI.ts +++ b/src/client/pythonEnvironments/nativeAPI.ts @@ -384,10 +384,12 @@ class NativePythonEnvironments implements IDiscoveryAPI, Disposable { const info = toPythonEnvInfo(native); if (info) { const old = this._envs.find((item) => item.executable.filename === info.executable.filename); - if (old && hasChanged(old, info)) { + if (old) { this._envs = this._envs.filter((item) => item.executable.filename !== info.executable.filename); this._envs.push(info); - this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation }); + if (hasChanged(old, info)) { + this._onChanged.fire({ type: FileChangeType.Changed, old, new: info, searchLocation }); + } } else { this._envs.push(info); this._onChanged.fire({ type: FileChangeType.Created, new: info, searchLocation }); From d021aa9029ee1f871c9651943a5d09c47248fb2a Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 17 Oct 2024 21:31:34 -0700 Subject: [PATCH 2/2] Test for duplication --- .../pythonEnvironments/nativeAPI.unit.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/test/pythonEnvironments/nativeAPI.unit.test.ts b/src/test/pythonEnvironments/nativeAPI.unit.test.ts index f7f956c7a20e..008d19b4738d 100644 --- a/src/test/pythonEnvironments/nativeAPI.unit.test.ts +++ b/src/test/pythonEnvironments/nativeAPI.unit.test.ts @@ -239,6 +239,27 @@ suite('Native Python API', () => { assert.deepEqual(actual, [expectedConda1]); }); + test('Ensure no duplication on resolve', async () => { + mockFinder + .setup((f) => f.refresh()) + .returns(() => { + async function* generator() { + yield* [conda1]; + } + return generator(); + }) + .verifiable(typemoq.Times.once()); + mockFinder + .setup((f) => f.resolve(typemoq.It.isAny())) + .returns(() => Promise.resolve(conda)) + .verifiable(typemoq.Times.once()); + + await api.triggerRefresh(); + await api.resolveEnv('/home/user/.conda/envs/conda_python/python'); + const actual = api.getEnvs(); + assert.deepEqual(actual, [expectedConda1]); + }); + test('Conda environment with no python', async () => { mockFinder .setup((f) => f.refresh())