[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:
George Zhang
2026-03-29 11:59:19 -07:00
committed by GitHub
parent 58dde4b016
commit e133924047
23 changed files with 638 additions and 148 deletions

View File

@@ -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

View File

@@ -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";