


























@@ -389,8 +389,17 @@ function getMessageContent(payload: unknown): Array<Record<string, any>> {
389389return Array.isArray(content) ? (content as Array<Record<string, any>>) : [];
390390}
391391392+function mockCallAt(
393+mock: { mock: { calls: ReadonlyArray<ReadonlyArray<unknown>> } },
394+index: number,
395+): ReadonlyArray<unknown> | undefined {
396+const calls = mock.mock.calls;
397+const normalizedIndex = index < 0 ? calls.length + index : index;
398+return calls[normalizedIndex];
399+}
400+392401function lastRespondCall(respond: ReturnType<typeof vi.fn>) {
393-return respond.mock.calls.at(-1) as
402+return mockCallAt(respond, -1) as
394403| [boolean, Record<string, any> | undefined, Record<string, any> | undefined]
395404| undefined;
396405}
@@ -410,13 +419,13 @@ function responseErrorMessage(error: unknown): string {
410419}
411420412421function lastBroadcastPayload(context: ChatContext): Record<string, any> | undefined {
413-const chatCall = (context.broadcast as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1);
422+const chatCall = mockCallAt(context.broadcast as unknown as ReturnType<typeof vi.fn>, -1);
414423expect(chatCall?.[0]).toBe("chat");
415424return chatCall?.[1] as Record<string, any> | undefined;
416425}
417426418427function lastNodeSendCall(context: ChatContext) {
419-return (context.nodeSendToSession as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1) as
428+return mockCallAt(context.nodeSendToSession as unknown as ReturnType<typeof vi.fn>, -1) as
420429| [string, string, Record<string, any>]
421430| undefined;
422431}
@@ -553,7 +562,7 @@ async function runNonStreamingChatSend(params: {
553562waitForCompletion?: boolean;
554563waitForDedupe?: boolean;
555564waitFor?: NonStreamingChatSendWaitFor;
556-}) {
565+}): Promise<Record<string, any> | undefined> {
557566const sendParams: {
558567sessionKey: string;
559568message: string;
@@ -604,11 +613,9 @@ async function runNonStreamingChatSend(params: {
604613).toBe(1);
605614});
606615607-const chatCall = (params.context.broadcast as unknown as ReturnType<typeof vi.fn>).mock.calls.at(
608-0,
609-);
616+const chatCall = mockCallAt(params.context.broadcast as unknown as ReturnType<typeof vi.fn>, 0);
610617expect(chatCall?.[0]).toBe("chat");
611-return chatCall?.[1];
618+return chatCall?.[1] as Record<string, any> | undefined;
612619}
613620614621describe("chat directive tag stripping for non-streaming final payloads", () => {
@@ -1096,7 +1103,7 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
10961103});
1097110410981105expect(respond).toHaveBeenCalled();
1099-const chatCall = (context.broadcast as unknown as ReturnType<typeof vi.fn>).mock.calls.at(-1);
1106+const chatCall = mockCallAt(context.broadcast as unknown as ReturnType<typeof vi.fn>, -1);
11001107expect(chatCall?.[0]).toBe("chat");
11011108expect(extractFirstTextBlock(chatCall?.[1])).toBe("hello");
11021109});
@@ -2978,9 +2985,10 @@ describe("chat directive tag stripping for non-streaming final payloads", () =>
29782985expect(payload).toBeUndefined();
29792986expect(error?.code).toBe(ErrorCodes.UNAVAILABLE);
29802987expect(responseErrorMessage(error)).toMatch(/ENOSPC|non-image attachments/i);
2981-const unavailableLogCall = (
2982-context.logGateway.error as unknown as ReturnType<typeof vi.fn>
2983-).mock.calls.at(0) as [string, Record<string, string>] | undefined;
2988+const unavailableLogCall = mockCallAt(
2989+context.logGateway.error as unknown as ReturnType<typeof vi.fn>,
2990+0,
2991+) as [string, Record<string, string>] | undefined;
29842992expect(unavailableLogCall?.[0]).toBe("chat.send attachment parse/stage failed");
29852993expect(unavailableLogCall?.[1].consoleMessage).toContain(
29862994"chat.send attachment parse/stage failed: MediaOffloadError",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。