mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-23 14:45:46 +00:00
[codex] harden clawhub plugin publishing and install (#56870)
* fix: harden clawhub plugin publishing and install * fix(process): preserve windows shim exit success
This commit is contained in:
@@ -227,6 +227,8 @@ export async function runCommandWithTimeout(
|
||||
const finalArgv = process.platform === "win32" ? (resolveNpmArgvForWindows(argv) ?? argv) : argv;
|
||||
const resolvedCommand = finalArgv !== argv ? (finalArgv[0] ?? "") : resolveCommand(argv[0] ?? "");
|
||||
const useCmdWrapper = isWindowsBatchCommand(resolvedCommand);
|
||||
const usesWindowsExitCodeShim =
|
||||
process.platform === "win32" && (useCmdWrapper || finalArgv !== argv);
|
||||
const child = spawn(
|
||||
useCmdWrapper ? (process.env.ComSpec ?? "cmd.exe") : resolvedCommand,
|
||||
useCmdWrapper
|
||||
@@ -341,8 +343,18 @@ export async function runCommandWithTimeout(
|
||||
clearTimeout(timer);
|
||||
clearNoOutputTimer();
|
||||
clearCloseFallbackTimer();
|
||||
const resolvedCode = childExitState?.code ?? code ?? child.exitCode ?? null;
|
||||
const resolvedSignal = childExitState?.signal ?? signal ?? child.signalCode ?? null;
|
||||
const resolvedCode =
|
||||
childExitState?.code ??
|
||||
code ??
|
||||
child.exitCode ??
|
||||
(usesWindowsExitCodeShim &&
|
||||
resolvedSignal == null &&
|
||||
!timedOut &&
|
||||
!noOutputTimedOut &&
|
||||
!child.killed
|
||||
? 0
|
||||
: null);
|
||||
const termination = noOutputTimedOut
|
||||
? "no-output-timeout"
|
||||
: timedOut
|
||||
|
||||
@@ -143,6 +143,25 @@ describe("windows command wrapper behavior", () => {
|
||||
}
|
||||
});
|
||||
|
||||
it("treats shimmed Windows commands without a reported exit code as success when they close cleanly", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
const child = createMockChild({
|
||||
closeCode: null,
|
||||
exitCode: null,
|
||||
});
|
||||
|
||||
spawnMock.mockImplementation(() => child);
|
||||
|
||||
try {
|
||||
const result = await runCommandWithTimeout(["npm", "--version"], { timeoutMs: 1000 });
|
||||
expect(result.code).toBe(0);
|
||||
expect(result.signal).toBeNull();
|
||||
expect(result.termination).toBe("exit");
|
||||
} finally {
|
||||
platformSpy.mockRestore();
|
||||
}
|
||||
});
|
||||
|
||||
it("uses cmd.exe wrapper with windowsVerbatimArguments in runExec for .cmd shims", async () => {
|
||||
const platformSpy = vi.spyOn(process, "platform", "get").mockReturnValue("win32");
|
||||
const expectedComSpec = process.env.ComSpec ?? "cmd.exe";
|
||||
|
||||
Reference in New Issue
Block a user