mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: guard extension messaging mock calls
This commit is contained in:
@@ -95,7 +95,7 @@ function registerProviderWithPluginConfig(pluginConfig: Record<string, unknown>)
|
||||
);
|
||||
|
||||
expect(registerProviderMock).toHaveBeenCalledTimes(1);
|
||||
return registerProviderMock.mock.calls[0]?.[0];
|
||||
return registerProviderMock.mock.calls.at(0)?.[0];
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
@@ -106,7 +106,7 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
}
|
||||
|
||||
function requireConfiguredStreamParams(): Record<string, unknown> {
|
||||
return requireRecord(createConfiguredOllamaStreamFnMock.mock.calls[0]?.[0], "stream params");
|
||||
return requireRecord(createConfiguredOllamaStreamFnMock.mock.calls.at(0)?.[0], "stream params");
|
||||
}
|
||||
|
||||
function captureWrappedOllamaPayload(
|
||||
|
||||
@@ -1163,7 +1163,7 @@ describe("openai image generation provider", () => {
|
||||
],
|
||||
});
|
||||
|
||||
const body = postJsonRequestMock.mock.calls[0]?.[0].body as {
|
||||
const body = postJsonRequestMock.mock.calls.at(0)?.[0].body as {
|
||||
input: Array<{ content: Array<Record<string, string>> }>;
|
||||
};
|
||||
expect(body.input[0]?.content).toEqual([
|
||||
@@ -1192,7 +1192,7 @@ describe("openai image generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledTimes(2);
|
||||
const firstBody = postJsonRequestMock.mock.calls[0]?.[0].body as {
|
||||
const firstBody = postJsonRequestMock.mock.calls.at(0)?.[0].body as {
|
||||
tools: Array<Record<string, unknown>>;
|
||||
};
|
||||
expect(firstBody.tools[0]).toEqual({
|
||||
|
||||
@@ -90,7 +90,7 @@ describe("runQaManualLane", () => {
|
||||
});
|
||||
|
||||
expect(startQaProviderServer).toHaveBeenCalledWith("mock-openai");
|
||||
const [gatewayOptions] = startQaGatewayChild.mock.calls[0] ?? [];
|
||||
const [gatewayOptions] = startQaGatewayChild.mock.calls.at(0) ?? [];
|
||||
expect(gatewayOptions?.repoRoot).toBe("/tmp/openclaw-repo");
|
||||
expect(gatewayOptions?.providerMode).toBe("mock-openai");
|
||||
expect(gatewayOptions?.providerBaseUrl).toBe("http://127.0.0.1:44080/v1");
|
||||
@@ -120,7 +120,7 @@ describe("runQaManualLane", () => {
|
||||
repoRoot: "/tmp/openclaw-repo",
|
||||
embeddedGateway: "disabled",
|
||||
});
|
||||
const [gatewayOptions] = startQaGatewayChild.mock.calls[0] ?? [];
|
||||
const [gatewayOptions] = startQaGatewayChild.mock.calls.at(0) ?? [];
|
||||
expect(gatewayOptions?.providerMode).toBe("live-frontier");
|
||||
expect(gatewayOptions?.providerBaseUrl).toBeUndefined();
|
||||
expect(result.reply).toBe("Protocol note: mock reply.");
|
||||
|
||||
@@ -51,7 +51,7 @@ describe("bridge/tools/remind", () => {
|
||||
time: "5m",
|
||||
});
|
||||
|
||||
const addCall = callGatewayToolMock.mock.calls[0];
|
||||
const addCall = callGatewayToolMock.mock.calls.at(0);
|
||||
const addPayload = addCall?.[2] as CronAddToolPayload | undefined;
|
||||
expect(addCall?.[0]).toBe("cron.add");
|
||||
expect(addCall?.[1]).toEqual({ timeoutMs: 60_000 });
|
||||
@@ -103,7 +103,7 @@ describe("bridge/tools/remind", () => {
|
||||
time: "5m",
|
||||
});
|
||||
|
||||
const cronParams = callCron.mock.calls[0]?.[0] as RemindCronAction | undefined;
|
||||
const cronParams = callCron.mock.calls.at(0)?.[0] as RemindCronAction | undefined;
|
||||
expect(cronParams?.action).toBe("add");
|
||||
if (cronParams?.action !== "add") {
|
||||
throw new Error("Expected add reminder cron params");
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("getImageSizeFromUrl", () => {
|
||||
await getImageSizeFromUrl("https://cdn.example.com/photo.png");
|
||||
|
||||
expect(adapterMocks.fetchMedia).toHaveBeenCalledOnce();
|
||||
const opts = adapterMocks.fetchMedia.mock.calls[0][0];
|
||||
const opts = adapterMocks.fetchMedia.mock.calls.at(0)?.[0];
|
||||
|
||||
expect(opts.url).toBe("https://cdn.example.com/photo.png");
|
||||
expect(opts.maxBytes).toBe(65_536);
|
||||
@@ -70,7 +70,7 @@ describe("getImageSizeFromUrl", () => {
|
||||
|
||||
await getImageSizeFromUrl("https://cdn.example.com/img.png", 3000);
|
||||
|
||||
const opts = adapterMocks.fetchMedia.mock.calls[0][0];
|
||||
const opts = adapterMocks.fetchMedia.mock.calls.at(0)?.[0];
|
||||
expect(opts.requestInit.signal).toBeInstanceOf(AbortSignal);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ describe("qwen video generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledTimes(1);
|
||||
expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], {
|
||||
expectPostJsonRequest(postJsonRequestMock.mock.calls.at(0)?.[0], {
|
||||
url: "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis",
|
||||
body: {
|
||||
model: "wan2.6-r2v-flash",
|
||||
@@ -135,7 +135,7 @@ describe("qwen video generation provider", () => {
|
||||
});
|
||||
|
||||
expect(postJsonRequestMock).toHaveBeenCalledTimes(1);
|
||||
expectPostJsonRequest(postJsonRequestMock.mock.calls[0]?.[0], {
|
||||
expectPostJsonRequest(postJsonRequestMock.mock.calls.at(0)?.[0], {
|
||||
url: "https://coding-intl.dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis",
|
||||
body: {
|
||||
model: "wan2.6-t2v",
|
||||
|
||||
@@ -140,7 +140,7 @@ describe("monitorSignalProvider tool results", () => {
|
||||
await vi.waitFor(() => {
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
expect(sendMock.mock.calls[0][1]).toBe("PFX final reply");
|
||||
expect(sendMock.mock.calls.at(0)?.[1]).toBe("PFX final reply");
|
||||
});
|
||||
|
||||
it("replies with pairing code when dmPolicy is pairing and no allowFrom is set", async () => {
|
||||
@@ -165,7 +165,7 @@ describe("monitorSignalProvider tool results", () => {
|
||||
expect(replyMock).not.toHaveBeenCalled();
|
||||
expect(upsertPairingRequestMock).toHaveBeenCalled();
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
expectPairingReplyText(String(sendMock.mock.calls[0]?.[1] ?? ""), {
|
||||
expectPairingReplyText(String(sendMock.mock.calls.at(0)?.[1] ?? ""), {
|
||||
channel: "signal",
|
||||
idLine: "Your Signal number: +15550001111",
|
||||
code: "PAIRCODE",
|
||||
|
||||
@@ -221,7 +221,7 @@ describe("registerSlackMessageEvents", () => {
|
||||
});
|
||||
|
||||
expect(handleSlackMessage).toHaveBeenCalledTimes(1);
|
||||
const call = handleSlackMessage.mock.calls[0] as unknown as
|
||||
const call = handleSlackMessage.mock.calls.at(0) as unknown as
|
||||
| [{ subtype?: string; channel?: string; user?: string }, { source?: string }]
|
||||
| undefined;
|
||||
expect(call?.[0]?.subtype).toBe("thread_broadcast");
|
||||
@@ -239,7 +239,7 @@ describe("registerSlackMessageEvents", () => {
|
||||
});
|
||||
|
||||
expect(handleSlackMessage).toHaveBeenCalledTimes(1);
|
||||
const call = handleSlackMessage.mock.calls[0] as unknown as
|
||||
const call = handleSlackMessage.mock.calls.at(0) as unknown as
|
||||
| [
|
||||
{
|
||||
channel?: string;
|
||||
|
||||
@@ -45,7 +45,7 @@ describe("tavily client X-Client-Source header", () => {
|
||||
await runTavilySearch({ query: "test query" });
|
||||
|
||||
expect(postTrustedWebToolsJson).toHaveBeenCalledOnce();
|
||||
const params = postTrustedWebToolsJson.mock.calls[0][0];
|
||||
const params = postTrustedWebToolsJson.mock.calls.at(0)?.[0];
|
||||
expect(params.extraHeaders).toEqual({ "X-Client-Source": "openclaw" });
|
||||
});
|
||||
|
||||
@@ -53,7 +53,7 @@ describe("tavily client X-Client-Source header", () => {
|
||||
await runTavilyExtract({ urls: ["https://example.com"] });
|
||||
|
||||
expect(postTrustedWebToolsJson).toHaveBeenCalledOnce();
|
||||
const params = postTrustedWebToolsJson.mock.calls[0][0];
|
||||
const params = postTrustedWebToolsJson.mock.calls.at(0)?.[0];
|
||||
expect(params.extraHeaders).toEqual({ "X-Client-Source": "openclaw" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -124,7 +124,7 @@ describe("telegram stickers", () => {
|
||||
expect(cachedSticker?.setName).toBe("NewSet");
|
||||
expect(media?.stickerMetadata?.fileId).toBe("new_file_id");
|
||||
expect(media?.stickerMetadata?.cachedDescription).toBe("Cached description");
|
||||
const [fetchUrl, fetchOptions] = proxyFetch.mock.calls[0] ?? [];
|
||||
const [fetchUrl, fetchOptions] = proxyFetch.mock.calls.at(0) ?? [];
|
||||
expect(fetchUrl).toBe("https://api.telegram.org/file/bottok/stickers/sticker.webp");
|
||||
expect(fetchOptions?.redirect).toBe("manual");
|
||||
},
|
||||
@@ -240,7 +240,7 @@ describe("telegram text fragments", () => {
|
||||
await flushScheduledTimerForDelay(setTimeoutSpy, TELEGRAM_TEST_TIMINGS.textFragmentGapMs);
|
||||
|
||||
expect(replySpy).toHaveBeenCalledTimes(1);
|
||||
const payload = replySpy.mock.calls[0][0] as { RawBody?: string };
|
||||
const payload = replySpy.mock.calls.at(0)?.[0] as { RawBody?: string };
|
||||
expect(payload.RawBody).toContain(part1.slice(0, 32));
|
||||
expect(payload.RawBody).toContain(part2.slice(0, 32));
|
||||
} finally {
|
||||
|
||||
@@ -323,7 +323,7 @@ describe("createTelegramDraftStream", () => {
|
||||
await stream.flush();
|
||||
|
||||
expect(onSupersededPreview).toHaveBeenCalledTimes(1);
|
||||
const [supersededPreview] = onSupersededPreview.mock.calls[0] ?? [];
|
||||
const [supersededPreview] = onSupersededPreview.mock.calls.at(0) ?? [];
|
||||
expect(supersededPreview).toEqual({
|
||||
messageId: 17,
|
||||
textSnapshot: "Message A partial",
|
||||
@@ -443,7 +443,7 @@ describe("createTelegramDraftStream", () => {
|
||||
await stream.flush();
|
||||
|
||||
expect(onSupersededPreview).toHaveBeenCalledTimes(1);
|
||||
const [supersededPreview] = onSupersededPreview.mock.calls[0] ?? [];
|
||||
const [supersededPreview] = onSupersededPreview.mock.calls.at(0) ?? [];
|
||||
expect(supersededPreview).toEqual({
|
||||
messageId: 17,
|
||||
textSnapshot: "Hello world",
|
||||
|
||||
@@ -141,8 +141,8 @@ function installPollingStallWatchdogHarness(
|
||||
|
||||
function expectTelegramBotTransportSequence(firstTransport: unknown, secondTransport: unknown) {
|
||||
expect(createTelegramBotMock).toHaveBeenCalledTimes(2);
|
||||
expect(createTelegramBotMock.mock.calls[0]?.[0]?.telegramTransport).toBe(firstTransport);
|
||||
expect(createTelegramBotMock.mock.calls[1]?.[0]?.telegramTransport).toBe(secondTransport);
|
||||
expect(createTelegramBotMock.mock.calls.at(0)?.[0]?.telegramTransport).toBe(firstTransport);
|
||||
expect(createTelegramBotMock.mock.calls.at(1)?.[0]?.telegramTransport).toBe(secondTransport);
|
||||
}
|
||||
|
||||
function makeTelegramTransport() {
|
||||
|
||||
@@ -904,8 +904,8 @@ describe("web auto-reply connection", () => {
|
||||
});
|
||||
|
||||
expect(resolver).toHaveBeenCalledTimes(2);
|
||||
const firstArgs = resolver.mock.calls[0][0];
|
||||
const secondArgs = resolver.mock.calls[1][0];
|
||||
const firstArgs = resolver.mock.calls.at(0)?.[0];
|
||||
const secondArgs = resolver.mock.calls.at(1)?.[0];
|
||||
const firstTimestamp = formatEnvelopeTimestamp(new Date("2025-01-01T00:00:00Z"));
|
||||
const secondTimestamp = formatEnvelopeTimestamp(new Date("2025-01-01T01:00:00Z"));
|
||||
const firstPattern = escapeRegExp(firstTimestamp);
|
||||
|
||||
@@ -136,7 +136,7 @@ describe("web auto-reply last-route", () => {
|
||||
await awaitBackgroundTasks(backgroundTasks);
|
||||
|
||||
expect(updateLastRouteInBackgroundMock).toHaveBeenCalledTimes(1);
|
||||
const updateParams = updateLastRouteInBackgroundMock.mock.calls[0]?.[0] as
|
||||
const updateParams = updateLastRouteInBackgroundMock.mock.calls.at(0)?.[0] as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
expect(updateParams?.cfg).toBe(cfg);
|
||||
@@ -239,7 +239,7 @@ describe("web auto-reply last-route", () => {
|
||||
await awaitBackgroundTasks(backgroundTasks);
|
||||
|
||||
expect(updateLastRouteInBackgroundMock).toHaveBeenCalledTimes(1);
|
||||
const updateParams = updateLastRouteInBackgroundMock.mock.calls[0]?.[0] as
|
||||
const updateParams = updateLastRouteInBackgroundMock.mock.calls.at(0)?.[0] as
|
||||
| Record<string, unknown>
|
||||
| undefined;
|
||||
expect(updateParams?.cfg).toBe(cfg);
|
||||
|
||||
@@ -103,7 +103,7 @@ describe("zalouser monitor pairing account scoping", () => {
|
||||
|
||||
expect(readAllowFromStore).toHaveBeenCalledOnce();
|
||||
const allowStoreParams = requireRecord(
|
||||
readAllowFromStore.mock.calls[0]?.[0],
|
||||
readAllowFromStore.mock.calls.at(0)?.[0],
|
||||
"allow store params",
|
||||
);
|
||||
expect(allowStoreParams.channel).toBe("zalouser");
|
||||
@@ -111,7 +111,7 @@ describe("zalouser monitor pairing account scoping", () => {
|
||||
|
||||
expect(upsertPairingRequest).toHaveBeenCalledOnce();
|
||||
const pairingRequest = requireRecord(
|
||||
upsertPairingRequest.mock.calls[0]?.[0],
|
||||
upsertPairingRequest.mock.calls.at(0)?.[0],
|
||||
"pairing request params",
|
||||
);
|
||||
expect(pairingRequest.channel).toBe("zalouser");
|
||||
|
||||
Reference in New Issue
Block a user