fix(windows): resolve cmd handoff path

This commit is contained in:
Vincent Koc
2026-06-21 10:32:35 +02:00
parent 675c56692a
commit 7dd01d15c5
11 changed files with 56 additions and 22 deletions
+11 -6
View File
@@ -4,6 +4,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import { getWindowsCmdExePath } from "../../infra/windows-install-roots.js";
import { prepareRestartScript, runRestartScript } from "./restart-helper.js";
vi.mock("node:child_process", async () => {
@@ -616,7 +617,7 @@ exit 0
await runRestartScript(scriptPath);
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", scriptPath], {
expect(spawn).toHaveBeenCalledWith(getWindowsCmdExePath(), ["/d", "/s", "/c", scriptPath], {
detached: true,
stdio: "ignore",
windowsHide: true,
@@ -633,11 +634,15 @@ exit 0
await runRestartScript(scriptPath);
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", `"${scriptPath}"`], {
detached: true,
stdio: "ignore",
windowsHide: true,
});
expect(spawn).toHaveBeenCalledWith(
getWindowsCmdExePath(),
["/d", "/s", "/c", `"${scriptPath}"`],
{
detached: true,
stdio: "ignore",
windowsHide: true,
},
);
});
it("does not throw when spawn fails synchronously", async () => {
+2 -1
View File
@@ -16,6 +16,7 @@ import {
resolveGatewayRestartLogPath,
shellEscapeRestartLogValue,
} from "../../daemon/restart-logs.js";
import { getWindowsCmdExePath } from "../../infra/windows-install-roots.js";
/**
* Shell-escape a string for embedding in single-quoted shell arguments.
@@ -404,7 +405,7 @@ exit $status
*/
export async function runRestartScript(scriptPath: string): Promise<void> {
const isWindows = process.platform === "win32";
const file = isWindows ? "cmd.exe" : "/bin/sh";
const file = isWindows ? getWindowsCmdExePath() : "/bin/sh";
const args = isWindows ? ["/d", "/s", "/c", quoteCmdScriptArg(scriptPath)] : [scriptPath];
try {