mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-16 18:34:18 +00:00
test: guard respawn and image mock calls
This commit is contained in:
@@ -19,6 +19,14 @@ function expectCliRespawnPlan(plan: ReturnType<typeof buildCliRespawnPlan>): Cli
|
||||
return plan;
|
||||
}
|
||||
|
||||
function requireFirstMockCall(mock: { mock: { calls: unknown[][] } }, label: string): unknown[] {
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("buildCliRespawnPlan", () => {
|
||||
it("returns null when respawn policy skips the argv", () => {
|
||||
expect(
|
||||
@@ -185,9 +193,12 @@ describe("runCliRespawnPlan", () => {
|
||||
env: { OPENCLAW_NODE_OPTIONS_READY: "1" },
|
||||
},
|
||||
);
|
||||
expect(attachChildProcessBridge.mock.calls[0]?.[0]).toBe(child);
|
||||
const bridgeOptions = attachChildProcessBridge.mock.calls[0]?.[1];
|
||||
expect(typeof bridgeOptions?.onSignal).toBe("function");
|
||||
const [bridgeChild, bridgeOptions] = requireFirstMockCall(
|
||||
attachChildProcessBridge,
|
||||
"child process bridge attach",
|
||||
);
|
||||
expect(bridgeChild).toBe(child);
|
||||
expect(bridgeOptions).toEqual(expect.objectContaining({ onSignal: expect.any(Function) }));
|
||||
|
||||
child.emit("exit", 0, null);
|
||||
|
||||
|
||||
@@ -61,7 +61,11 @@ vi.mock("openclaw/plugin-sdk/provider-http", () => ({
|
||||
}));
|
||||
|
||||
function requireFirstRequestHeaders(mock: ReturnType<typeof vi.fn>): Headers {
|
||||
const [request] = (mock.mock.calls[0] ?? []) as [{ headers?: Headers }?];
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error("expected request call");
|
||||
}
|
||||
const [request] = call as [{ headers?: Headers }];
|
||||
if (!request) {
|
||||
throw new Error("expected request call");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user