






















@@ -186,7 +186,10 @@ function expectRecordFields(
186186}
187187188188function getBotCtorOptions(callIndex = 0): Record<string, unknown> {
189-const call = requireValue(botCtorSpy.mock.calls[callIndex], `bot constructor call ${callIndex}`);
189+const call = requireValue(
190+botCtorSpy.mock.calls.at(callIndex),
191+`bot constructor call ${callIndex}`,
192+);
190193expect(call[0]).toBe("tok");
191194return requireRecord(call[1], `bot constructor options ${callIndex}`);
192195}
@@ -246,7 +249,7 @@ describe("createTelegramBot", () => {
246249const catchMock = bot.catch as unknown as {
247250mock: { calls: Array<[(err: unknown) => void]> };
248251};
249-const errorHandler = catchMock.mock.calls[0]?.[0];
252+const errorHandler = catchMock.mock.calls.at(0)?.[0];
250253251254expect(errorHandler).toBeTypeOf("function");
252255errorHandler?.(new Error("handler boom"));
@@ -265,7 +268,7 @@ describe("createTelegramBot", () => {
265268const fetchImpl = resolveTelegramFetch();
266269expect(fetchImpl).toBeTypeOf("function");
267270expect(fetchImpl).not.toBe(fetchSpy);
268-const clientFetch = (botCtorSpy.mock.calls[0]?.[1] as { client?: { fetch?: unknown } })
271+const clientFetch = (botCtorSpy.mock.calls.at(0)?.[1] as { client?: { fetch?: unknown } })
269272?.client?.fetch;
270273expect(clientFetch).toBeTypeOf("function");
271274expect(clientFetch).not.toBe(fetchSpy);
@@ -753,7 +756,7 @@ describe("createTelegramBot", () => {
753756});
754757755758expect(replySpy).toHaveBeenCalledTimes(1);
756-const payload = replySpy.mock.calls[0][0];
759+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
757760expect(payload.Body).toContain("cmd:option_a");
758761expect(answerCallbackQuerySpy).toHaveBeenCalledWith("cbq-1");
759762});
@@ -825,7 +828,9 @@ describe("createTelegramBot", () => {
825828});
826829827830expect(replySpy).toHaveBeenCalledTimes(1);
828-expect(replySpy.mock.calls[0][0].Body).toContain("Multi-select submitted: env|prod");
831+expect(requireValue(replySpy.mock.calls.at(0), "replySpy call")[0].Body).toContain(
832+"Multi-select submitted: env|prod",
833+);
829834});
830835831836it("submits OC_SELECT values as a synthetic inbound message and clears buttons", async () => {
@@ -859,7 +864,9 @@ describe("createTelegramBot", () => {
859864reply_markup: { inline_keyboard: [] },
860865});
861866expect(replySpy).toHaveBeenCalledTimes(1);
862-expect(replySpy.mock.calls[0][0].Body).toContain("Single-select submitted: env|canary");
867+expect(requireValue(replySpy.mock.calls.at(0), "replySpy call")[0].Body).toContain(
868+"Single-select submitted: env|canary",
869+);
863870});
864871865872it("preserves native command source for prefixed callback_query payloads", async () => {
@@ -894,7 +901,7 @@ describe("createTelegramBot", () => {
894901});
895902896903expect(replySpy).toHaveBeenCalledTimes(1);
897-const payload = replySpy.mock.calls[0][0];
904+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
898905expect(payload.CommandBody).toBe("/fast status");
899906expect(payload.CommandSource).toBe("native");
900907expect(answerCallbackQuerySpy).toHaveBeenCalledWith("cbq-native-1");
@@ -976,7 +983,7 @@ describe("createTelegramBot", () => {
976983});
977984978985expect(replySpy).toHaveBeenCalledTimes(1);
979-const payload = replySpy.mock.calls[0][0];
986+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
980987const expectedTimestamp = formatEnvelopeTimestamp(new Date("2025-01-09T00:00:00Z"));
981988const timestampPattern = escapeRegExp(expectedTimestamp);
982989expect(payload.Body).toMatch(
@@ -1043,12 +1050,16 @@ describe("createTelegramBot", () => {
1043105010441051expect(replySpy, testCase.name).not.toHaveBeenCalled();
10451052expect(sendMessageSpy, testCase.name).toHaveBeenCalledTimes(testCase.expectedSendCount);
1046-expect(sendMessageSpy.mock.calls[0]?.[0], testCase.name).toBe(1234);
1047-const pairingText = String(sendMessageSpy.mock.calls[0]?.[1]);
1053+expect(sendMessageSpy.mock.calls.at(0)?.[0], testCase.name).toBe(1234);
1054+const pairingText = String(sendMessageSpy.mock.calls.at(0)?.[1]);
10481055expect(pairingText, testCase.name).toContain(`Your Telegram user id: ${senderId}`);
10491056expect(pairingText, testCase.name).toContain("Pairing code:");
10501057expect(pairingText, testCase.name).toContain("openclaw pairing approve telegram");
1051-expectRecordFields(sendMessageSpy.mock.calls[0]?.[2], { parse_mode: "HTML" }, testCase.name);
1058+expectRecordFields(
1059+sendMessageSpy.mock.calls.at(0)?.[2],
1060+{ parse_mode: "HTML" },
1061+testCase.name,
1062+);
10521063}
10531064});
10541065@@ -1125,11 +1136,11 @@ describe("createTelegramBot", () => {
11251136expect(getFileSpy).not.toHaveBeenCalled();
11261137expect(fetchSpy).not.toHaveBeenCalled();
11271138expect(sendMessageSpy).toHaveBeenCalledTimes(1);
1128-const pairingText = String(sendMessageSpy.mock.calls[0]?.[1]);
1139+const pairingText = String(sendMessageSpy.mock.calls.at(0)?.[1]);
11291140expect(pairingText).toContain("Pairing code:");
11301141expect(pairingText).toContain("<pre><code>");
11311142expectRecordFields(
1132-sendMessageSpy.mock.calls[0]?.[2],
1143+sendMessageSpy.mock.calls.at(0)?.[2],
11331144{ parse_mode: "HTML" },
11341145"pairing reply options",
11351146);
@@ -1247,11 +1258,11 @@ describe("createTelegramBot", () => {
12471258expect(getFileSpy).not.toHaveBeenCalled();
12481259expect(fetchSpy).not.toHaveBeenCalled();
12491260expect(sendMessageSpy).toHaveBeenCalledTimes(1);
1250-const pairingText = String(sendMessageSpy.mock.calls[0]?.[1]);
1261+const pairingText = String(sendMessageSpy.mock.calls.at(0)?.[1]);
12511262expect(pairingText).toContain("Pairing code:");
12521263expect(pairingText).toContain("<pre><code>");
12531264expectRecordFields(
1254-sendMessageSpy.mock.calls[0]?.[2],
1265+sendMessageSpy.mock.calls.at(0)?.[2],
12551266{ parse_mode: "HTML" },
12561267"album pairing reply options",
12571268);
@@ -2004,7 +2015,7 @@ describe("createTelegramBot", () => {
20042015});
2005201620062017expect(replySpy).toHaveBeenCalledTimes(1);
2007-const payload = replySpy.mock.calls[0][0];
2018+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
20082019expect(payload.AccountId).toBe("opie");
20092020expect(payload.SessionKey).toBe("agent:opie:main");
20102021});
@@ -2060,14 +2071,14 @@ describe("createTelegramBot", () => {
2060207120612072await sendDm(42, "hello one");
20622073expect(replySpy).toHaveBeenCalledTimes(1);
2063-expect(replySpy.mock.calls[0]?.[0].AccountId).toBe("opie");
2064-expect(replySpy.mock.calls[0]?.[0].SessionKey).toContain("agent:agent-a:");
2074+expect(replySpy.mock.calls.at(0)?.[0].AccountId).toBe("opie");
2075+expect(replySpy.mock.calls.at(0)?.[0].SessionKey).toContain("agent:agent-a:");
2065207620662077boundAgentId = "agent-b";
20672078await sendDm(43, "hello two");
20682079expect(replySpy).toHaveBeenCalledTimes(2);
2069-expect(replySpy.mock.calls[1]?.[0].AccountId).toBe("opie");
2070-expect(replySpy.mock.calls[1]?.[0].SessionKey).toContain("agent:agent-b:");
2080+expect(replySpy.mock.calls.at(1)?.[0].AccountId).toBe("opie");
2081+expect(replySpy.mock.calls.at(1)?.[0].SessionKey).toContain("agent:agent-b:");
20712082});
2072208320732084it("reloads topic agent overrides between messages without recreating the bot", async () => {
@@ -2113,12 +2124,12 @@ describe("createTelegramBot", () => {
2113212421142125await sendTopicMessage(301);
21152126expect(replySpy).toHaveBeenCalledTimes(1);
2116-expect(replySpy.mock.calls[0]?.[0].SessionKey).toContain("agent:topic-a:");
2127+expect(replySpy.mock.calls.at(0)?.[0].SessionKey).toContain("agent:topic-a:");
2117212821182129topicAgentId = "topic-b";
21192130await sendTopicMessage(302);
21202131expect(replySpy).toHaveBeenCalledTimes(2);
2121-expect(replySpy.mock.calls[1]?.[0].SessionKey).toContain("agent:topic-b:");
2132+expect(replySpy.mock.calls.at(1)?.[0].SessionKey).toContain("agent:topic-b:");
21222133});
2123213421242135it("routes non-default account DMs to the per-account fallback session without explicit bindings", async () => {
@@ -2158,7 +2169,7 @@ describe("createTelegramBot", () => {
21582169});
2159217021602171expect(replySpy).toHaveBeenCalledTimes(1);
2161-const payload = replySpy.mock.calls[0]?.[0];
2172+const payload = requireValue(replySpy.mock.calls.at(0), "reply call")[0];
21622173expect(payload.AccountId).toBe("opie");
21632174expect(payload.SessionKey).toContain("agent:main:telegram:opie:");
21642175});
@@ -2342,7 +2353,7 @@ describe("createTelegramBot", () => {
23422353},
23432354});
23442355expect(replySpy).toHaveBeenCalledTimes(1);
2345-const payload = replySpy.mock.calls[0][0];
2356+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
23462357expect(payload.SessionKey).toContain(testCase.expectedSessionKeyFragment);
23472358expect(payload.BodyForAgent).toBe(testCase.text);
23482359expect(payload.BodyForAgent).not.toContain("t.me/c/");
@@ -2375,7 +2386,7 @@ describe("createTelegramBot", () => {
23752386});
2376238723772388expect(sendAnimationSpy).toHaveBeenCalledTimes(1);
2378-const animationCall = requireValue(sendAnimationSpy.mock.calls[0], "animation send call");
2389+const animationCall = requireValue(sendAnimationSpy.mock.calls.at(0), "animation send call");
23792390expect(animationCall[0]).toBe("1234");
23802391requireValue(animationCall[1], "animation payload");
23812392expect(animationCall[2]).toEqual({
@@ -2385,7 +2396,7 @@ describe("createTelegramBot", () => {
23852396});
23862397expect(sendPhotoSpy).not.toHaveBeenCalled();
23872398expect(loadWebMedia).toHaveBeenCalledTimes(1);
2388-expect(loadWebMedia.mock.calls[0]?.[0]).toBe("https://example.com/fun");
2399+expect(loadWebMedia.mock.calls.at(0)?.[0]).toBe("https://example.com/fun");
23892400});
2390240123912402function resetHarnessSpies() {
@@ -2461,7 +2472,7 @@ describe("createTelegramBot", () => {
24612472});
2462247324632474expect(replySpy.mock.calls.length, testCase.name).toBe(1);
2464-const payload = replySpy.mock.calls[0][0];
2475+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
24652476expect(payload.WasMentioned, testCase.name).toBe(true);
24662477if (testCase.assertEnvelope) {
24672478expect(payload.SenderName).toBe("Ada");
@@ -2507,7 +2518,7 @@ describe("createTelegramBot", () => {
25072518});
2508251925092520expect(replySpy).toHaveBeenCalledTimes(1);
2510-const payload = replySpy.mock.calls[0][0];
2521+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
25112522expect(payload.SenderName).toBe("Ada Lovelace");
25122523expect(payload.SenderId).toBe("99");
25132524expect(payload.SenderUsername).toBe("ada");
@@ -2604,7 +2615,7 @@ describe("createTelegramBot", () => {
2604261526052616expect(replySpy.mock.calls.length, testCase.name).toBe(testCase.expectedReplyCount);
26062617if (testCase.expectedWasMentioned != null) {
2607-const payload = replySpy.mock.calls[0][0];
2618+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
26082619expect(payload.WasMentioned, testCase.name).toBe(testCase.expectedWasMentioned);
26092620}
26102621}
@@ -2626,7 +2637,7 @@ describe("createTelegramBot", () => {
26262637});
2627263826282639expect(replySpy).toHaveBeenCalledTimes(1);
2629-const payload = replySpy.mock.calls[0][0];
2640+const payload = requireValue(replySpy.mock.calls.at(0), "replySpy call")[0];
26302641expect(payload.Body).toContain("[Reply chain - nearest first]");
26312642expect(payload.Body).toContain("[1. Ada id:9001]");
26322643expect(payload.Body).toContain("Can you summarize this?");
@@ -2874,7 +2885,7 @@ describe("createTelegramBot", () => {
28742885await handler(makeForumGroupMessageCtx({ threadId: testCase.threadId }));
2875288628762887expect(sendMessageSpy.mock.calls.length, testCase.name).toBe(1);
2877-const sendParams = sendMessageSpy.mock.calls[0]?.[2] as { message_thread_id?: number };
2888+const sendParams = sendMessageSpy.mock.calls.at(0)?.[2] as { message_thread_id?: number };
28782889if (testCase.expectedMessageThreadId == null) {
28792890expect(sendParams?.message_thread_id, testCase.name).toBeUndefined();
28802891} else {
@@ -3078,7 +3089,9 @@ describe("createTelegramBot", () => {
30783089});
3079309030803091expect(sendMessageSpy).toHaveBeenCalledTimes(1);
3081-expect(sendMessageSpy.mock.calls[0][1]).toBe("PFX final reply");
3092+expect(requireValue(sendMessageSpy.mock.calls.at(0), "sendMessageSpy call")[1]).toBe(
3093+"PFX final reply",
3094+);
30823095});
3083309630843097it("sends Codex usage-limit reset details as the Telegram reply body", async () => {
@@ -3104,11 +3117,15 @@ describe("createTelegramBot", () => {
31043117});
3105311831063119expect(sendMessageSpy).toHaveBeenCalledTimes(1);
3107-expect(String(sendMessageSpy.mock.calls[0][0])).toBe("5");
3108-expect(sendMessageSpy.mock.calls[0][1]).toBe(codexRateLimitText);
3109-expect(String(sendMessageSpy.mock.calls[0][1])).not.toContain(
3110-"All models are temporarily rate-limited",
3120+expect(String(requireValue(sendMessageSpy.mock.calls.at(0), "sendMessageSpy call")[0])).toBe(
3121+"5",
3122+);
3123+expect(requireValue(sendMessageSpy.mock.calls.at(0), "sendMessageSpy call")[1]).toBe(
3124+codexRateLimitText,
31113125);
3126+expect(
3127+String(requireValue(sendMessageSpy.mock.calls.at(0), "sendMessageSpy call")[1]),
3128+).not.toContain("All models are temporarily rate-limited");
31123129});
3113313031143131it("honors threaded replies for replyToMode=first/all", async () => {
@@ -3271,14 +3288,16 @@ describe("createTelegramBot", () => {
3271328832723289createTelegramBot({ token: "tok" });
32733290expect(commandSpy).toHaveBeenCalled();
3274-const handler = commandSpy.mock.calls[0][1] as (ctx: Record<string, unknown>) => Promise<void>;
3291+const handler = requireValue(commandSpy.mock.calls.at(0), "commandSpy call")[1] as (
3292+ctx: Record<string, unknown>,
3293+) => Promise<void>;
3275329432763295await handler({
32773296 ...makeForumGroupMessageCtx({ threadId: 99, text: "/status" }),
32783297match: "",
32793298});
328032993281-const statusCall = requireValue(sendMessageSpy.mock.calls[0], "status reply call");
3300+const statusCall = requireValue(sendMessageSpy.mock.calls.at(0), "status reply call");
32823301expect(statusCall[0]).toBe("-1001234567890");
32833302expect(statusCall[1]).toBeTypeOf("string");
32843303expectRecordFields(
@@ -3334,12 +3353,12 @@ describe("createTelegramBot", () => {
3334335333353354await invokeStatus(401);
33363355expect(replySpy).toHaveBeenCalledTimes(1);
3337-expect(replySpy.mock.calls[0]?.[0].SessionKey).toContain("agent:agent-a:");
3356+expect(replySpy.mock.calls.at(0)?.[0].SessionKey).toContain("agent:agent-a:");
3338335733393358boundAgentId = "agent-b";
33403359await invokeStatus(402);
33413360expect(replySpy).toHaveBeenCalledTimes(2);
3342-expect(replySpy.mock.calls[1]?.[0].SessionKey).toContain("agent:agent-b:");
3361+expect(replySpy.mock.calls.at(1)?.[0].SessionKey).toContain("agent:agent-b:");
33433362});
33443363it("skips tool summaries for native slash commands", async () => {
33453364commandSpy.mockClear();
@@ -3378,7 +3397,7 @@ describe("createTelegramBot", () => {
33783397});
3379339833803399expect(sendMessageSpy).toHaveBeenCalledTimes(1);
3381-expect(sendMessageSpy.mock.calls[0]?.[1]).toContain("final reply");
3400+expect(sendMessageSpy.mock.calls.at(0)?.[1]).toContain("final reply");
33823401});
33833402it("dedupes duplicate message updates by update_id", async () => {
33843403onSpy.mockReset();
@@ -3665,10 +3684,10 @@ describe("createTelegramBot", () => {
3665368436663685expect(buildModelsProviderDataMock).toHaveBeenCalledTimes(2);
36673686expect(editMessageTextSpy).toHaveBeenCalledTimes(1);
3668-expect(editMessageTextSpy.mock.calls[0]?.[2]).toContain("Select a provider:");
3687+expect(editMessageTextSpy.mock.calls.at(0)?.[2]).toContain("Select a provider:");
36693688expect(
36703689(
3671-editMessageTextSpy.mock.calls[0]?.[3] as {
3690+editMessageTextSpy.mock.calls.at(0)?.[3] as {
36723691reply_markup?: { inline_keyboard?: unknown[][] };
36733692}
36743693)?.reply_markup?.inline_keyboard?.[0]?.[0],
@@ -3936,7 +3955,7 @@ describe("createTelegramBot", () => {
3936395539373956expect(editMessageReplyMarkupSpy).toHaveBeenCalledTimes(1);
39383957expect(sendMessageSpy).toHaveBeenCalledTimes(1);
3939-expect(sendMessageSpy.mock.calls[0]?.[1]).toContain("plugin bind approval");
3958+expect(sendMessageSpy.mock.calls.at(0)?.[1]).toContain("plugin bind approval");
39403959});
3941396039423961it("retries exec approval callbacks after a bubbled resolution failure", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。