mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
* fix(scripts): bound GHSA patch subprocesses Co-authored-by: 唐梓夷0668001293 <tang.ziyi@xydigit.com> * fix(scripts): satisfy GHSA runner control-flow lint --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { runGhCommand } from "../../scripts/lib/ghsa-patch-subprocess.mjs";
|
|
|
|
describe("GHSA patch subprocess", () => {
|
|
it("bounds each GitHub lookup with a timeout and SIGKILL", () => {
|
|
const spawnSyncImpl = vi.fn(() => ({
|
|
status: 0,
|
|
stdout: "result",
|
|
stderr: "",
|
|
}));
|
|
|
|
expect(runGhCommand(["api", "rate_limit"], { spawnSyncImpl })).toBe("result");
|
|
expect(spawnSyncImpl).toHaveBeenCalledWith("gh", ["api", "rate_limit"], {
|
|
encoding: "utf8",
|
|
killSignal: "SIGKILL",
|
|
timeout: 60_000,
|
|
});
|
|
});
|
|
|
|
it("throws the GitHub CLI error when a lookup exits non-zero", () => {
|
|
const spawnSyncImpl = vi.fn(() => ({
|
|
status: 1,
|
|
stdout: "",
|
|
stderr: "gh api failed",
|
|
}));
|
|
|
|
expect(() => runGhCommand(["api", "rate_limit"], { spawnSyncImpl })).toThrow("gh api failed");
|
|
});
|
|
|
|
it("propagates the timeout error from a stalled GitHub CLI process", () => {
|
|
const timeout = Object.assign(new Error("spawnSync gh ETIMEDOUT"), { code: "ETIMEDOUT" });
|
|
const spawnSyncImpl = vi.fn(() => ({
|
|
error: timeout,
|
|
status: null,
|
|
stdout: "",
|
|
stderr: "",
|
|
}));
|
|
|
|
expect(() => runGhCommand(["api", "rate_limit"], { spawnSyncImpl })).toThrow(timeout);
|
|
});
|
|
});
|