fix: restart Windows gateway via Scheduled Task (#38825) (#38825)

This commit is contained in:
Ayaan Zaidi
2026-03-07 18:00:38 +05:30
committed by GitHub
parent 26c9796736
commit 05c240fad6
12 changed files with 371 additions and 54 deletions

View File

@@ -298,11 +298,25 @@ describe("restart-helper", () => {
await runRestartScript(scriptPath);
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/c", scriptPath], {
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", scriptPath], {
detached: true,
stdio: "ignore",
});
expect(mockChild.unref).toHaveBeenCalled();
});
it("quotes cmd.exe /c paths with metacharacters on Windows", async () => {
Object.defineProperty(process, "platform", { value: "win32" });
const scriptPath = "C:\\Temp\\me&(ow)\\fake-script.bat";
const mockChild = { unref: vi.fn() };
vi.mocked(spawn).mockReturnValue(mockChild as unknown as ChildProcess);
await runRestartScript(scriptPath);
expect(spawn).toHaveBeenCalledWith("cmd.exe", ["/d", "/s", "/c", `"${scriptPath}"`], {
detached: true,
stdio: "ignore",
});
});
});
});

View File

@@ -3,6 +3,7 @@ import fs from "node:fs/promises";
import os from "node:os";
import path from "node:path";
import { DEFAULT_GATEWAY_PORT } from "../../config/paths.js";
import { quoteCmdScriptArg } from "../../daemon/cmd-argv.js";
import {
resolveGatewayLaunchAgentLabel,
resolveGatewaySystemdServiceName,
@@ -161,7 +162,7 @@ del "%~f0"
export async function runRestartScript(scriptPath: string): Promise<void> {
const isWindows = process.platform === "win32";
const file = isWindows ? "cmd.exe" : "/bin/sh";
const args = isWindows ? ["/c", scriptPath] : [scriptPath];
const args = isWindows ? ["/d", "/s", "/c", quoteCmdScriptArg(scriptPath)] : [scriptPath];
const child = spawn(file, args, {
detached: true,