test: guard respawn and image mock calls

This commit is contained in:
Peter Steinberger
2026-05-11 23:39:51 +01:00
parent 376f93b62b
commit b0946c1a4e
2 changed files with 19 additions and 4 deletions

View File

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

View File

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