diff --git a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts index 863eaa8ff15..972f601bd11 100644 --- a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts +++ b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.test.ts @@ -45,8 +45,13 @@ vi.mock('../../../wsl/execution/wsl-runner', () => ({ if (guest.failure) { return { ...guest.failure, stderr: '', timedOut: false } } + // Real wsl.exe --exec refuses an empty argument before the guest runs. + if (spec.args?.some((arg) => arg === '')) { + return { code: 1, stdout: '', stderr: 'Wsl/Service/E_INVALIDARG', timedOut: false } + } const result = spawnSync('/bin/sh', ['-c', spec.script ?? '', 'sh', ...(spec.args ?? [])], { - encoding: 'utf8' + encoding: 'utf8', + input: spec.input }) return { code: result.status, stdout: result.stdout, stderr: result.stderr, timedOut: false } } @@ -141,6 +146,17 @@ describe.skipIf(!posixHost)('ClaudeWslProfileRouter', () => { expect(readFileSync(f.pointer, 'utf8')).toBe(homeB) }) + it('launches on System default while a managed WSL account still exists', async () => { + const f = fixture() + mkdirSync(join(f.pointer, '..'), { recursive: true }) + writeFileSync(f.pointer, f.profileHome) + f.wsl.Ubuntu = null + await expect(f.router.prepareLaunch('Ubuntu')).resolves.toMatchObject({ + provenance: 'wsl:Ubuntu:system' + }) + expect(readFileSync(f.pointer, 'utf8')).toBe('') + }) + it("runs an account with no login of its own on the guest's ~/.claude while that is signed in to it", async () => { const f = fixture() mkdirSync(f.profileHome, { recursive: true }) diff --git a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts index 4964813369c..42fb95f7571 100644 --- a/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts +++ b/src/main/claude-accounts/profiles/wsl/claude-profile-wsl-router.ts @@ -262,10 +262,11 @@ async function writePointer(distro: string, pointer: string, home: string): Prom if (current === home) { return } + // wsl.exe --exec rejects an empty argument (E_INVALIDARG), and System default writes ''; pass content on stdin. await runGuest(distro, { - script: - 'umask 077; mkdir -p -- "${1%/*}" && printf %s "$2" > "$1.tmp" && mv -f -- "$1.tmp" "$1"', - args: [pointer, home], + script: 'umask 077; mkdir -p -- "${1%/*}" && cat > "$1.tmp" && mv -f -- "$1.tmp" "$1"', + args: [pointer], + input: home, loginPath: 'none' }) }