Skip to content

Commit 2e48c82

Browse files
authored
Prepend noConfigScripts directory to PATH so bundled debugpy wrapper wins (#1148)
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
1 parent 71d4b16 commit 2e48c82

2 files changed

Lines changed: 14 additions & 12 deletions

File tree

‎src/extension/noConfigDebugInit.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import { TriggerType } from './types';
3030
* Environment Variables:
3131
* - `DEBUGPY_ADAPTER_ENDPOINTS`: Path to the file containing the debugger adapter endpoint.
3232
* - `BUNDLED_DEBUGPY_PATH`: Path to the bundled debugpy library.
33-
* - `PATH`: Appends the path to the noConfigScripts directory.
33+
* - `PATH`: Prepends the path to the noConfigScripts directory.
3434
*/
3535
export async function registerNoConfigDebug(
3636
envVarCollection: GlobalEnvironmentVariableCollection,
@@ -68,8 +68,10 @@ export async function registerNoConfigDebug(
6868
const noConfigScriptsDir = path.join(extPath, 'bundled', 'scripts', 'noConfigScripts');
6969
const pathSeparator = process.platform === 'win32' ? ';' : ':';
7070

71-
// Always prepend separator when appending to PATH since append() concatenates to existing value
72-
collection.append('PATH', `${pathSeparator}${noConfigScriptsDir}`);
71+
// Prepend so the bundled `debugpy` wrapper wins over any user-installed debugpy
72+
// package that also provides a `debugpy` command on PATH. Always append the
73+
// separator since prepend() concatenates to the existing value.
74+
collection.prepend('PATH', `${noConfigScriptsDir}${pathSeparator}`);
7375

7476
const bundledDebugPath = path.join(extPath, 'bundled', 'libs', 'debugpy');
7577
collection.replace('BUNDLED_DEBUGPY_PATH', bundledDebugPath);

‎src/test/unittest/noConfigDebugInit.unit.test.ts‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ suite('setup for no-config debug scenario', function () {
7676
})
7777
.returns(envVarCollectionReplaceStub);
7878
environmentVariableCollectionMock
79-
.setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
79+
.setup((x) => x.prepend(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
8080
.callback((key, value) => {
8181
if (key === 'PATH') {
8282
const pathSeparator = process.platform === 'win32' ? ';' : ':';
83-
assert(value === `${pathSeparator}${noConfigScriptsDir}`);
83+
assert(value === `${noConfigScriptsDir}${pathSeparator}`);
8484
}
8585
})
8686
.returns(envVarCollectionAppendStub);
@@ -97,25 +97,25 @@ suite('setup for no-config debug scenario', function () {
9797
sinon.assert.calledOnce(envVarCollectionAppendStub);
9898
});
9999

100-
test('should always add separator when appending to PATH', async () => {
100+
test('should always add separator when prepending to PATH', async () => {
101101
const environmentVariableCollectionMock = TypeMoq.Mock.ofType<any>();
102102
envVarCollectionReplaceStub = sinon.stub();
103103
envVarCollectionAppendStub = sinon.stub();
104104

105-
// The separator should always be prepended regardless of process.env.PATH
105+
// The separator should always be appended regardless of process.env.PATH
106106
const pathSeparator = process.platform === 'win32' ? ';' : ':';
107107

108108
environmentVariableCollectionMock
109109
.setup((x) => x.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
110110
.returns(envVarCollectionReplaceStub);
111111

112112
environmentVariableCollectionMock
113-
.setup((x) => x.append(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
113+
.setup((x) => x.prepend(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
114114
.callback((key, value) => {
115115
if (key === 'PATH') {
116-
// Should always add separator when appending
117-
assert(value === `${pathSeparator}${noConfigScriptsDir}`);
118-
assert(value.startsWith(pathSeparator));
116+
// Should always add separator when prepending
117+
assert(value === `${noConfigScriptsDir}${pathSeparator}`);
118+
assert(value.endsWith(pathSeparator));
119119
}
120120
})
121121
.returns(envVarCollectionAppendStub);
@@ -127,7 +127,7 @@ suite('setup for no-config debug scenario', function () {
127127
// run init for no config debug
128128
await registerNoConfigDebug(context.object.environmentVariableCollection, context.object.extensionPath);
129129

130-
// assert that append was called for PATH
130+
// assert that prepend was called for PATH
131131
sinon.assert.calledOnce(envVarCollectionAppendStub);
132132
});
133133

0 commit comments

Comments
 (0)