Archived
fix: run doctor version checks under fish
The doctor "can find npm/pi" checks wrap the version command in a POSIX subshell, `(cmd --version 2>&1 || true)`. Fish treats `( ... )` as command substitution syntax and forbids it in command position, so every fish user saw false-negative failures: fish: command substitutions not allowed in command position command -v npm && (npm --version 2>&1 || true) Branch on the detected service shell and emit fish's `begin; ...; end` grouping for fish, mirroring the existing fish-aware quoting in serviceShellQuote. Bash and zsh keep the POSIX subshell. Also guard the `main()` invocation with an ESM main-module check so the CLI helpers can be imported by tests without side effects, and add a regression test covering the bash, zsh, and fish command shapes.
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { commandWithVersionCheck } from "./cli.js";
|
||||
|
||||
const originalShell = process.env["SHELL"];
|
||||
|
||||
afterEach(() => {
|
||||
if (originalShell === undefined) {
|
||||
delete process.env["SHELL"];
|
||||
} else {
|
||||
process.env["SHELL"] = originalShell;
|
||||
}
|
||||
});
|
||||
|
||||
describe("commandWithVersionCheck", () => {
|
||||
it("emits a POSIX subshell group for bash", () => {
|
||||
process.env["SHELL"] = "/bin/bash";
|
||||
expect(commandWithVersionCheck("npm")).toBe("command -v npm && (npm --version 2>&1 || true)");
|
||||
});
|
||||
|
||||
it("emits a POSIX subshell group for zsh", () => {
|
||||
process.env["SHELL"] = "/bin/zsh";
|
||||
expect(commandWithVersionCheck("pi")).toBe("command -v pi && (pi --version 2>&1 || true)");
|
||||
});
|
||||
|
||||
it("uses fish begin/end grouping instead of a POSIX subshell", () => {
|
||||
process.env["SHELL"] = "/usr/local/bin/fish";
|
||||
const command = commandWithVersionCheck("npm");
|
||||
expect(command).toBe("command -v npm && begin; npm --version 2>&1 || true; end");
|
||||
expect(command).not.toContain("(");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user