fix(cli): disable tmux auto-install in spawn preflight

This commit is contained in:
suraj-markup 2026-03-26 13:59:29 +05:30
parent 32591c2adc
commit c5cc0620e2
2 changed files with 6 additions and 51 deletions

View File

@ -97,24 +97,14 @@ describe("preflight.checkTmux", () => {
expect(mockExec).toHaveBeenCalledWith("tmux", ["-V"]);
});
it("attempts auto-install when tmux is missing", async () => {
// First call: tmux -V fails (not installed)
// Second call: auto-install attempt (brew/apt/dnf)
// Third call: tmux -V succeeds (installed now)
mockExec
.mockRejectedValueOnce(new Error("ENOENT")) // tmux -V
.mockResolvedValueOnce({ stdout: "", stderr: "" }) // install command
.mockResolvedValueOnce({ stdout: "tmux 3.3a", stderr: "" }); // verify
await expect(preflight.checkTmux()).resolves.toBeUndefined();
});
it("throws with install instructions when auto-install fails", async () => {
// All attempts fail
it("throws with install instructions when tmux is missing", async () => {
mockExec.mockRejectedValue(new Error("ENOENT"));
const err = await preflight.checkTmux().catch((e: Error) => e);
expect(err).toBeInstanceOf(Error);
expect(err.message).toContain("tmux is not installed");
expect(err.message).toContain("Install it:");
expect(mockExec).toHaveBeenCalledTimes(1);
expect(mockExec).toHaveBeenCalledWith("tmux", ["-V"]);
});
});

View File

@ -66,22 +66,17 @@ function findPackageUp(startDir: string, ...segments: string[]): string | null {
}
/**
* Check that tmux is installed. If missing, attempt auto-install.
* Falls back to a clear error with platform-appropriate instructions
* if auto-install is not possible.
* Check that tmux is installed.
* Throws with platform-appropriate manual install instructions when missing.
*/
async function checkTmux(): Promise<void> {
try {
await exec("tmux", ["-V"]);
return;
} catch {
// tmux not found — try to install it
// tmux not found
}
// Attempt auto-install based on platform
const installed = await autoInstallTmux();
if (installed) return;
const hint =
process.platform === "darwin"
? "brew install tmux"
@ -91,36 +86,6 @@ async function checkTmux(): Promise<void> {
throw new Error(`tmux is not installed. Install it: ${hint}`);
}
/**
* Try to auto-install tmux. Returns true if successful.
* Tries brew (macOS), apt-get, then dnf (Linux). Silent on failure.
*/
async function autoInstallTmux(): Promise<boolean> {
const attempts: Array<{ cmd: string; args: string[] }> =
process.platform === "darwin"
? [{ cmd: "brew", args: ["install", "tmux"] }]
: process.platform === "linux"
? [
{ cmd: "sudo", args: ["apt-get", "install", "-y", "tmux"] },
{ cmd: "sudo", args: ["dnf", "install", "-y", "tmux"] },
]
: [];
for (const { cmd, args } of attempts) {
try {
const label = [cmd, ...args].join(" ");
console.log(` Attempting: ${label}`);
await exec(cmd, args);
// Verify it actually worked
await exec("tmux", ["-V"]);
return true;
} catch {
// Try next method
}
}
return false;
}
/**
* Check that the GitHub CLI is installed and authenticated.
* Distinguishes between "not installed" and "not authenticated"