From a3d8a1f4ffbf059371a58db4d18eadf4ea06a25b Mon Sep 17 00:00:00 2001 From: TEJA P C <39472754+PCTEJA@users.noreply.github.com> Date: Fri, 13 Nov 2026 23:00:08 -0500 Subject: [PATCH 1/3] Fix debugpy.ps1 argument forwarding with splatting The PowerShell no-config wrapper forwarded $args without splatting, so an array of arguments passed by a caller reached the Python process concatenated as a single string (e.g. 'arg1 arg2' instead of two separate argv entries). Use @args in both the Windows (python) and non-Windows (python3) invocations so array arguments expand into separate arguments, matching how the caller could pass them to python directly. Fixes #1024 --- bundled/scripts/noConfigScripts/debugpy.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) mode change 100755 => 100644 bundled/scripts/noConfigScripts/debugpy.ps1 diff --git a/bundled/scripts/noConfigScripts/debugpy.ps1 b/bundled/scripts/noConfigScripts/debugpy.ps1 old mode 100755 new mode 100644 index 4b2ff85a..032024a1 --- a/bundled/scripts/noConfigScripts/debugpy.ps1 +++ b/bundled/scripts/noConfigScripts/debugpy.ps1 @@ -2,7 +2,7 @@ $env:DEBUGPY_ADAPTER_ENDPOINTS = $env:VSCODE_DEBUGPY_ADAPTER_ENDPOINTS $os = [System.Environment]::OSVersion.Platform if ($os -eq [System.PlatformID]::Win32NT) { - python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args + python $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args } else { - python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client $args + python3 $env:BUNDLED_DEBUGPY_PATH --listen 0 --wait-for-client @args } \ No newline at end of file From ff04d417a7b4a26816fa34c809becdc4028ce6e6 Mon Sep 17 00:00:00 2001 From: PCTEJA Date: Mon, 16 Nov 2026 09:32:47 +0000 Subject: [PATCH 2/3] Restore executable bit on PowerShell no-config wrapper --- bundled/scripts/noConfigScripts/debugpy.ps1 | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bundled/scripts/noConfigScripts/debugpy.ps1 diff --git a/bundled/scripts/noConfigScripts/debugpy.ps1 b/bundled/scripts/noConfigScripts/debugpy.ps1 old mode 100644 new mode 100755 From 902f3e3ef61f92abb028a5b34b45e355685d4b1a Mon Sep 17 00:00:00 2001 From: TEJA P C Date: Tue, 17 Nov 2026 16:02:03 -0600 Subject: [PATCH 3/3] Add regression test for debugpy.ps1 argument forwarding Run the real wrapper under PowerShell with the bundled debugpy path pointed at a stub that prints sys.argv, called with an array argument. The array must reach the Python process as separate arguments, not one space-joined string. --- .../unittest/noConfigDebugInit.unit.test.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/test/unittest/noConfigDebugInit.unit.test.ts b/src/test/unittest/noConfigDebugInit.unit.test.ts index 2e9a7ca9..b39c7a92 100644 --- a/src/test/unittest/noConfigDebugInit.unit.test.ts +++ b/src/test/unittest/noConfigDebugInit.unit.test.ts @@ -2,7 +2,12 @@ // Licensed under the MIT License. import * as path from 'path'; +import { execFile } from 'child_process'; +import { promisify } from 'util'; +import { expect } from 'chai'; import { IExtensionContext } from '../../extension/common/types'; +import { EXTENSION_ROOT_DIR } from '../../extension/common/constants'; +import { TEST_TIMEOUT } from '../constants'; import { registerNoConfigDebug as registerNoConfigDebug } from '../../extension/noConfigDebugInit'; import * as TypeMoq from 'typemoq'; import * as sinon from 'sinon'; @@ -13,6 +18,8 @@ import * as fs from 'fs'; import * as os from 'os'; import * as crypto from 'crypto'; +const execFileAsync = promisify(execFile); + suite('setup for no-config debug scenario', function () { let envVarCollectionReplaceStub: sinon.SinonStub; let envVarCollectionAppendStub: sinon.SinonStub; @@ -225,8 +232,54 @@ suite('setup for no-config debug scenario', function () { fsExistsSyncStub.restore(); fsUnlinkSyncStub.restore(); }); + + test('debugpy.ps1 forwards array arguments as separate arguments', async function () { + this.timeout(TEST_TIMEOUT); + const shell = await findPowerShell(); + if (!shell) { + return this.skip(); + } + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'debugpy-ps1-test-')); + try { + const adapterStub = path.join(tmpDir, 'print_argv.py'); + fs.writeFileSync(adapterStub, 'import json, sys\nprint(json.dumps(sys.argv[1:]))\n'); + const wrapper = path.join(EXTENSION_ROOT_DIR, 'bundled', 'scripts', 'noConfigScripts', 'debugpy.ps1'); + const caller = path.join(tmpDir, 'caller.ps1'); + fs.writeFileSync( + caller, + `$argList = @('arg1', 'arg2')\n& '${wrapper.replace(/'/g, "''")}' 'test.py' $argList\n`, + ); + const env = { ...process.env }; + env.BUNDLED_DEBUGPY_PATH = adapterStub; + env.VSCODE_DEBUGPY_ADAPTER_ENDPOINTS = ''; + const { stdout } = await execFileAsync( + shell, + ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', caller], + { + env, + }, + ); + const argv = JSON.parse(stdout.trim().split('\n').pop()!); + expect(argv).to.deep.equal(['--listen', '0', '--wait-for-client', 'test.py', 'arg1', 'arg2']); + } finally { + fs.rmSync(tmpDir, { recursive: true, force: true }); + } + }); }); +async function findPowerShell(): Promise { + const shells = process.platform === 'win32' ? ['powershell', 'pwsh'] : ['pwsh', 'powershell']; + for (const shell of shells) { + try { + await execFileAsync(shell, ['-NoProfile', '-Command', '$PSVersionTable.PSVersion']); + return shell; + } catch { + continue; + } + } + return undefined; +} + function setupFileSystemWatchers(): sinon.SinonStub { // create stub of createFileSystemWatcher function that will return a fake watcher with a callback let createFileSystemWatcherFunct: sinon.SinonStub;