From acd65037f71fcf30f1c5d4a4070d207b3115b4d2 Mon Sep 17 00:00:00 2001 From: TEJA P C <39472754+PCTEJA@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:09:04 -0500 Subject: [PATCH] Prepend noConfigScripts directory to PATH so bundled debugpy wrapper wins Since debugpy 1.8.5, the debugpy Python package installs its own debugpy command. The extension appended the noConfigScripts directory to the end of the integrated terminal PATH, so a user-installed debugpy package shadowed the bundled wrapper and 'debugpy script.py' ran the wrong command. Prepend the directory (with its trailing separator) instead, and update the unit tests that asserted the append behaviour. Fixes #931 --- src/extension/noConfigDebugInit.ts | 8 +++++--- .../unittest/noConfigDebugInit.unit.test.ts | 18 +++++++++--------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/extension/noConfigDebugInit.ts b/src/extension/noConfigDebugInit.ts index 955040f9..1a9b31a9 100644 --- a/src/extension/noConfigDebugInit.ts +++ b/src/extension/noConfigDebugInit.ts @@ -30,7 +30,7 @@ import { TriggerType } from './types'; * Environment Variables: * - `DEBUGPY_ADAPTER_ENDPOINTS`: Path to the file containing the debugger adapter endpoint. * - `BUNDLED_DEBUGPY_PATH`: Path to the bundled debugpy library. - * - `PATH`: Appends the path to the noConfigScripts directory. + * - `PATH`: Prepends the path to the noConfigScripts directory. */ export async function registerNoConfigDebug( envVarCollection: GlobalEnvironmentVariableCollection, @@ -68,8 +68,10 @@ export async function registerNoConfigDebug( const noConfigScriptsDir = path.join(extPath, 'bundled', 'scripts', 'noConfigScripts'); const pathSeparator = process.platform === 'win32' ? ';' : ':'; - // Always prepend separator when appending to PATH since append() concatenates to existing value - collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`); + // Prepend so the bundled `debugpy` wrapper wins over any user-installed debugpy + // package that also provides a `debugpy` command on PATH. Always append the + // separator since prepend() concatenates to the existing value. + collection.prepend('PATH', `${noConfigScriptsDir}${pathSeparator}`); const bundledDebugPath = path.join(extPath, 'bundled', 'libs', 'debugpy'); collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath); diff --git a/src/test/unittest/noConfigDebugInit.unit.test.ts b/src/test/unittest/noConfigDebugInit.unit.test.ts index 2e9a7ca9..84023d4e 100644 --- a/src/test/unittest/noConfigDebugInit.unit.test.ts +++ b/src/test/unittest/noConfigDebugInit.unit.test.ts @@ -69,11 +69,11 @@ suite('setup for no-config debug scenario', function () { }) .returns(envVarCollectionReplaceStub); environmentVariableCollectionMock - .setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .setup((x) => x.prepend(TypeMoq.It.isAny(), TypeMoq.It.isAny())) .callback((key, value) => { if (key === 'PATH') { const pathSeparator = process.platform === 'win32' ? ';' : ':'; - assert(value === `${pathSeparator}${noConfigScriptsDir}`); + assert(value === `${noConfigScriptsDir}${pathSeparator}`); } }) .returns(envVarCollectionAppendStub); @@ -90,12 +90,12 @@ suite('setup for no-config debug scenario', function () { sinon.assert.calledOnce(envVarCollectionAppendStub); }); - test('should always add separator when appending to PATH', async () => { + test('should always add separator when prepending to PATH', async () => { const environmentVariableCollectionMock = TypeMoq.Mock.ofType(); envVarCollectionReplaceStub = sinon.stub(); envVarCollectionAppendStub = sinon.stub(); - // The separator should always be prepended regardless of process.env.PATH + // The separator should always be appended regardless of process.env.PATH const pathSeparator = process.platform === 'win32' ? ';' : ':'; environmentVariableCollectionMock @@ -103,12 +103,12 @@ suite('setup for no-config debug scenario', function () { .returns(envVarCollectionReplaceStub); environmentVariableCollectionMock - .setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .setup((x) => x.prepend(TypeMoq.It.isAny(), TypeMoq.It.isAny())) .callback((key, value) => { if (key === 'PATH') { - // Should always add separator when appending - assert(value === `${pathSeparator}${noConfigScriptsDir}`); - assert(value.startsWith(pathSeparator)); + // Should always add separator when prepending + assert(value === `${noConfigScriptsDir}${pathSeparator}`); + assert(value.endsWith(pathSeparator)); } }) .returns(envVarCollectionAppendStub); @@ -120,7 +120,7 @@ suite('setup for no-config debug scenario', function () { // run init for no config debug await registerNoConfigDebug(context.object.environmentVariableCollection, context.object.extensionPath); - // assert that append was called for PATH + // assert that prepend was called for PATH sinon.assert.calledOnce(envVarCollectionAppendStub); });