From bc26023b7ec2fb1edcf4eb8b1de31d35db43f673 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Tue, 12 May 2026 20:53:44 +0100 Subject: [PATCH] test: dedupe feishu comment mock reads --- extensions/feishu/src/monitor.comment.test.ts | 37 ++++++++++++++----- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/extensions/feishu/src/monitor.comment.test.ts b/extensions/feishu/src/monitor.comment.test.ts index 910aad17932..03e8ddd0d51 100644 --- a/extensions/feishu/src/monitor.comment.test.ts +++ b/extensions/feishu/src/monitor.comment.test.ts @@ -212,6 +212,18 @@ async function setupCommentMonitorHandler(): Promise<(data: unknown) => Promise< }); } +function mockCallAt( + mock: { mock: { calls: Array } }, + index: number, + label: string, +): readonly unknown[] { + const call = mock.mock.calls[index]; + if (!call) { + throw new Error(`expected ${label} call`); + } + return call; +} + describe("resolveDriveCommentEventTurn", () => { it("builds a real comment-turn prompt for add_comment notices", async () => { const client = makeOpenApiClient({ includeTargetReplyInBatch: true }); @@ -828,7 +840,7 @@ describe("drive.notice.comment_add_v1 monitor handler", () => { await onComment(makeDriveCommentEvent()); expect(handleFeishuCommentEventMock).toHaveBeenCalledTimes(1); - const handleArgs = handleFeishuCommentEventMock.mock.calls.at(0)?.[0] as + const handleArgs = mockCallAt(handleFeishuCommentEventMock, 0, "Feishu comment handler")[0] as | { accountId?: string; botOpenId?: string; @@ -880,12 +892,16 @@ describe("drive.notice.comment_add_v1 monitor handler", () => { await vi.waitFor(() => { expect(handleFeishuCommentEventMock).toHaveBeenCalledTimes(2); }); - const firstCallArgs = handleFeishuCommentEventMock.mock.calls.at(0) as - | [{ event?: { event_id?: string } }] - | undefined; - const secondCallArgs = handleFeishuCommentEventMock.mock.calls.at(1) as - | [{ event?: { event_id?: string } }] - | undefined; + const firstCallArgs = mockCallAt( + handleFeishuCommentEventMock, + 0, + "first Feishu comment handler", + ) as [{ event?: { event_id?: string } }] | undefined; + const secondCallArgs = mockCallAt( + handleFeishuCommentEventMock, + 1, + "second Feishu comment handler", + ) as [{ event?: { event_id?: string } }] | undefined; const firstCall = firstCallArgs?.[0]; const secondCall = secondCallArgs?.[0]; expect(firstCall?.event?.event_id).toBe("evt_1"); @@ -917,8 +933,11 @@ describe("drive.notice.comment_add_v1 monitor handler", () => { "feishu[default]: error handling drive comment notice: Error: post-send failure", ); }); - const [recordedMessageId, recordedNamespace, recordedLogger] = - (dedup.recordProcessedFeishuMessage as ReturnType).mock.calls.at(0) ?? []; + const [recordedMessageId, recordedNamespace, recordedLogger] = mockCallAt( + dedup.recordProcessedFeishuMessage as ReturnType, + 0, + "Feishu processed-message record", + ); expect(recordedMessageId).toBe("drive-comment:10d9d60b990db39f96a4c2fd357fb877"); expect(recordedNamespace).toBe("default"); expect(typeof recordedLogger).toBe("function");