Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/extension/noConfigDebugInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions src/test/unittest/noConfigDebugInit.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -90,25 +90,25 @@ 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<any>();
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
.setup((x) => x.replace(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.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);
Expand All @@ -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);
});

Expand Down