test: guard extension one-hit mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 10:00:29 +01:00
parent 7965342425
commit a765668e63
10 changed files with 10 additions and 10 deletions

View File

@@ -87,7 +87,7 @@ describe("canvas CLI", () => {
expect(writtenFile.filePath).toMatch(/openclaw-canvas-snapshot-.*\.png$/);
expect(writtenFile.base64).toBe("aGk=");
expect(runtime.log).toHaveBeenCalledTimes(1);
const mediaMessage = runtime.log.mock.calls[0]?.[0];
const mediaMessage = runtime.log.mock.calls.at(0)?.[0];
expect(mediaMessage?.startsWith("MEDIA:")).toBe(true);
expect(mediaMessage?.endsWith(".png")).toBe(true);
});

View File

@@ -83,7 +83,7 @@ describe("Canvas tool", () => {
await tool.execute("tool-call-1", { action: "snapshot" });
expect(mocks.imageResultFromFile).toHaveBeenCalledTimes(1);
const imageResultParams = mocks.imageResultFromFile.mock.calls[0]?.[0] as
const imageResultParams = mocks.imageResultFromFile.mock.calls.at(0)?.[0] as
| {
label?: string;
path?: string;

View File

@@ -120,7 +120,7 @@ describe("Codex app-server dynamic tool schema boundary contract", () => {
});
expect(request).toHaveBeenCalledTimes(1);
const [method, payload] = request.mock.calls[0] ?? [];
const [method, payload] = request.mock.calls.at(0) ?? [];
if (method !== "thread/start") {
throw new Error(`expected thread/start request, got ${method}`);
}

View File

@@ -15,7 +15,7 @@ function expectFirstBlockReplyText(params: EmbeddedRunAttemptParams): string {
if (onBlockReply === undefined) {
throw new Error("Expected onBlockReply callback");
}
const payload = vi.mocked(onBlockReply).mock.calls[0]?.[0];
const payload = vi.mocked(onBlockReply).mock.calls.at(0)?.[0];
if (typeof payload?.text !== "string") {
throw new Error("Expected first block reply text");
}

View File

@@ -484,7 +484,7 @@ describe("device-pair /pair qr", () => {
const text = requireText(result);
expect(sendMessage).toHaveBeenCalledTimes(1);
const [target, caption, opts] = sendMessage.mock.calls[0] as [
const [target, caption, opts] = sendMessage.mock.calls.at(0) as [
string,
string,
{

View File

@@ -301,7 +301,7 @@ describe("broadcast dispatch", () => {
},
]);
expect(mockCreateFeishuReplyDispatcher).toHaveBeenCalledTimes(1);
const dispatcherParams = mockCreateFeishuReplyDispatcher.mock.calls[0]?.[0] as
const dispatcherParams = mockCreateFeishuReplyDispatcher.mock.calls.at(0)?.[0] as
| { agentId?: string }
| undefined;
expect(dispatcherParams?.agentId).toBe("main");

View File

@@ -973,7 +973,7 @@ describe("handleFeishuMessage command authorization", () => {
await dispatchMessage({ cfg, event });
const after = Date.now();
const call = mockFinalizeInboundContext.mock.calls[0]?.[0] as { Timestamp: number };
const call = mockFinalizeInboundContext.mock.calls.at(0)?.[0] as { Timestamp: number };
expect(call.Timestamp).toBeGreaterThanOrEqual(before);
expect(call.Timestamp).toBeLessThanOrEqual(after);
});

View File

@@ -77,7 +77,7 @@ describe("feishu quick-action launcher", () => {
expect(handled).toBe(true);
expect(sendCardFeishuMock).toHaveBeenCalledTimes(1);
const sendArgs = sendCardFeishuMock.mock.calls[0]?.[0] as
const sendArgs = sendCardFeishuMock.mock.calls.at(0)?.[0] as
| { accountId?: string; card?: unknown; cfg?: ClawdbotConfig; to?: string }
| undefined;
expect(Object.keys(sendArgs ?? {}).toSorted()).toEqual(["accountId", "card", "cfg", "to"]);

View File

@@ -161,7 +161,7 @@ describe("feishu setup wizard", () => {
expect(initAppRegistrationMock).toHaveBeenCalledWith("lark");
expect(beginAppRegistrationMock).toHaveBeenCalledWith("lark");
const [pollOptions] = pollAppRegistrationMock.mock.calls[0] ?? [];
const [pollOptions] = pollAppRegistrationMock.mock.calls.at(0) ?? [];
expect(pollOptions?.deviceCode).toBe("device-code");
expect(pollOptions?.initialDomain).toBe("lark");
expect(pollOptions?.tp).toBe("ob_cli_app");

View File

@@ -442,7 +442,7 @@ export async function setupFeishuLifecycleHandler(params: {
});
const handlers: Record<string, (data: unknown) => Promise<void>> = {};
for (const [key, value] of Object.entries(register.mock.calls[0]?.[0] ?? {})) {
for (const [key, value] of Object.entries(register.mock.calls.at(0)?.[0] ?? {})) {
handlers[key] = value as (data: unknown) => Promise<void>;
}
const handler = handlers[params.handlerKey];