Skip to content

Commit ab4a761

Browse files
committed
fix(core): resolve Windows shells installed as app-execution aliases
A configured shell silently fell back to Windows PowerShell 5.1 when it came from a Store/MSIX install. Those expose the executable as a Windows app-execution alias, a zero-byte AppExecLink reparse point that stat and which cannot see, even though CreateProcess resolves it by name. So which() returned null for pwsh, resolve() returned undefined, and select() dropped through to win()[0]. where.exe does resolve app-execution aliases, so use it as the tiebreaker when which() finds nothing: trust a known shell family the OS can locate, and keep falling back when the shell genuinely is not installed. Closes anomalyco#41426
1 parent 8e0f1c2 commit ab4a761

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

‎packages/core/src/shell.ts‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export * as Shell from "./shell"
22

33
import path from "path"
4-
import { spawn, type ChildProcess } from "child_process"
4+
import { spawn, spawnSync, type ChildProcess } from "child_process"
55
import { readFile } from "fs/promises"
66
import { statSync } from "fs"
77
import { setTimeout as sleep } from "node:timers/promises"
@@ -92,7 +92,18 @@ function resolve(file: string) {
9292
if (stat(shell)?.isFile()) return shell
9393
return
9494
}
95-
return which(shell) ?? undefined
95+
const found = which(shell)
96+
if (found) return found
97+
// Store/MSIX installs expose their executable as a Windows app-execution alias, an
98+
// AppExecLink reparse point that stat and which cannot see even though CreateProcess
99+
// resolves it by name. where.exe does see it, so it separates "installed as an alias"
100+
// from "not installed" and keeps a configured shell like pwsh from silently falling back.
101+
if (process.platform === "win32" && meta(shell) && aliased(shell)) return shell
102+
return undefined
103+
}
104+
105+
function aliased(file: string) {
106+
return spawnSync("where.exe", [file], { stdio: "ignore", windowsHide: true }).status === 0
96107
}
97108

98109
function win() {

‎packages/core/test/shell.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ describe("shell", () => {
4949
})
5050
})
5151

52+
test("falls back for known shell families that are not installed", async () => {
53+
if (process.platform !== "win32") return
54+
await withShell(undefined, () => {
55+
// ksh is in the shell metadata table but is not present on Windows. Resolution must not
56+
// trust a bare name just because the family is known, only when the OS can actually find it.
57+
expect(Shell.acceptable("ksh")).toBe(Shell.acceptable())
58+
})
59+
})
60+
5261
test("falls back for terminal-only acceptable shells", () => {
5362
expect(Shell.name(Shell.acceptable("fish"))).not.toBe("fish")
5463
expect(Shell.name(Shell.acceptable("nu"))).not.toBe("nu")

0 commit comments

Comments
 (0)