diff --git a/src/main/cli/wsl-cli-installer.test.ts b/src/main/cli/wsl-cli-installer.test.ts index a728e0acafe2..d86d0f4ec07a 100644 --- a/src/main/cli/wsl-cli-installer.test.ts +++ b/src/main/cli/wsl-cli-installer.test.ts @@ -330,6 +330,37 @@ describe('WslCliInstaller', () => { expect(launcher.indexOf('ORCA_WSL_CWD=$(pwd -P')).toBeLessThan( launcher.indexOf('ORCA_BRIDGE_PS1_WIN=$(wslpath') ) + const bridgeUncRewrite = launcher + .split('\n') + .find((line) => line.startsWith('ORCA_BRIDGE_PS1_WIN=${ORCA_BRIDGE_PS1_WIN/')) + expect(bridgeUncRewrite).toBe( + 'ORCA_BRIDGE_PS1_WIN=${ORCA_BRIDGE_PS1_WIN/#\\\\\\\\wsl.localhost\\\\/\\\\\\\\wsl\\$\\\\}' + ) + expect(launcher).not.toMatch(/^ORCA_WSL_CWD_WIN=\$\{/m) + const rewritten = execFileSync( + 'bash', + [ + '-c', + `ORCA_BRIDGE_PS1_WIN='\\\\wsl.localhost\\Ubuntu-24.04\\tmp\\orca-wsl-bridge.ps1'\n${bridgeUncRewrite}\nprintf '%s' "$ORCA_BRIDGE_PS1_WIN"` + ], + { encoding: 'utf8' } + ) + expect(rewritten).toBe('\\\\wsl$\\Ubuntu-24.04\\tmp\\orca-wsl-bridge.ps1') + const rewriteBridgePath = (windowsPath: string): string => + execFileSync( + 'bash', + [ + '-c', + `ORCA_BRIDGE_PS1_WIN='${windowsPath}'\n${bridgeUncRewrite}\nprintf '%s' "$ORCA_BRIDGE_PS1_WIN"` + ], + { encoding: 'utf8' } + ) + expect(rewriteBridgePath('\\\\wsl$\\Ubuntu-24.04\\tmp\\orca-wsl-bridge.ps1')).toBe( + '\\\\wsl$\\Ubuntu-24.04\\tmp\\orca-wsl-bridge.ps1' + ) + expect(rewriteBridgePath('C:\\Users\\alice\\orca-wsl-bridge.ps1')).toBe( + 'C:\\Users\\alice\\orca-wsl-bridge.ps1' + ) expect(launcher).toContain('"$ORCA_WIN_LAUNCHER" -WslCwd "$ORCA_WSL_CWD_WIN" "$@"') expect(launcher).not.toContain('-Command') expect(bridge).not.toContain('[CmdletBinding') diff --git a/src/main/cli/wsl-cli-scripts.ts b/src/main/cli/wsl-cli-scripts.ts index 3f4e4156433d..3220aca253fb 100644 --- a/src/main/cli/wsl-cli-scripts.ts +++ b/src/main/cli/wsl-cli-scripts.ts @@ -55,6 +55,9 @@ ORCA_WSL_CWD=$(pwd -P 2>/dev/null) || { cd / } ORCA_BRIDGE_PS1_WIN=$(wslpath -w "$ORCA_BRIDGE_PS1") +# Why: PowerShell AuthorizationManager rejects noninteractive -File on \\\\wsl.localhost\\ +# script paths. \\\\wsl$\\ is the same share. The cwd UNC is only -WslCwd, so leave it. +ORCA_BRIDGE_PS1_WIN=\${ORCA_BRIDGE_PS1_WIN/#\\\\\\\\wsl.localhost\\\\/\\\\\\\\wsl\\$\\\\} ORCA_WSL_CWD_WIN=$(wslpath -w "$ORCA_WSL_CWD") if [ -n "\${WSL_DISTRO_NAME:-}" ]; then set -- -WslDistro "$WSL_DISTRO_NAME" "$@"