fix(cron): ignore blank Windows shell override (#111260)

This commit is contained in:
LZY3538
2026-07-20 11:18:36 +08:00
committed by GitHub
parent 6d39d3cf0b
commit e1a82f4991
2 changed files with 11 additions and 2 deletions
+1 -1
View File
@@ -5,7 +5,7 @@ export function resolveExitWatchShell(platform: NodeJS.Platform = process.platfo
} {
if (platform === "win32") {
return {
command: process.env.ComSpec ?? "cmd.exe",
command: process.env.ComSpec?.trim() || "cmd.exe",
// /d skip AutoRun, /s strip outer quotes, /c run then exit.
argsFor: (command: string) => ["/d", "/s", "/c", command],
};
+10 -1
View File
@@ -1,5 +1,5 @@
import { expectDefined } from "@openclaw/normalization-core";
import { describe, expect, it, vi } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { CronJob } from "../cron/types.js";
import { resolveExitWatchShell } from "./cron-exit-watch-shell.js";
import { createCronExitWatchers, type CronExitResult } from "./cron-exit-watchers.js";
@@ -437,12 +437,21 @@ describe("createCronExitWatchers", () => {
});
describe("resolveExitWatchShell", () => {
afterEach(() => {
vi.unstubAllEnvs();
});
it("uses cmd.exe on Windows so native gateways without bash can run on-exit", () => {
const shell = resolveExitWatchShell("win32");
expect(shell.command).toMatch(/cmd\.exe$/i);
expect(shell.argsFor("echo hi")).toEqual(["/d", "/s", "/c", "echo hi"]);
});
it("uses cmd.exe when ComSpec is blank", () => {
vi.stubEnv("ComSpec", " ");
expect(resolveExitWatchShell("win32").command).toBe("cmd.exe");
});
it("uses bash -lc on POSIX", () => {
expect(resolveExitWatchShell("linux").command).toBe("bash");
expect(resolveExitWatchShell("linux").argsFor("echo hi")).toEqual(["-lc", "echo hi"]);