

























@@ -63,6 +63,17 @@ function buildResolvedRoute(matchedBy: "binding.channel" | "default" = "binding.
6363};
6464}
656566+function mockCallArg(mockFn: ReturnType<typeof vi.fn>, label: string, callIndex = 0, argIndex = 0) {
67+const call = mockFn.mock.calls.at(callIndex);
68+if (!call) {
69+throw new Error(`expected ${label} call ${callIndex}`);
70+}
71+if (!(argIndex in call)) {
72+throw new Error(`expected ${label} call ${callIndex} argument ${argIndex}`);
73+}
74+return call[argIndex];
75+}
76+6677function createTestRuntime(overrides?: {
6778readAllowFromStore?: () => Promise<unknown[]>;
6879upsertPairingRequest?: () => Promise<{ code: string; created: boolean }>;
@@ -257,7 +268,7 @@ describe("handleFeishuCommentEvent", () => {
257268>;
258269259270expect(finalizeInboundContext).toHaveBeenCalledTimes(1);
260-const finalizedContext = finalizeInboundContext.mock.calls[0]?.[0] as
271+const finalizedContext = mockCallArg(finalizeInboundContext, "finalizeInboundContext") as
261272| Record<string, unknown>
262273| undefined;
263274expect({
@@ -278,7 +289,7 @@ describe("handleFeishuCommentEvent", () => {
278289messageThreadId: "reply_1",
279290});
280291expect(recordInboundSession).toHaveBeenCalledTimes(1);
281-const recordArgs = recordInboundSession.mock.calls[0]?.[0] as
292+const recordArgs = mockCallArg(recordInboundSession, "recordInboundSession") as
282293| { sessionKey?: string }
283294| undefined;
284295expect(recordArgs?.sessionKey).toBe("agent:main:feishu:direct:comment-doc:docx:doc_token_1");
@@ -345,7 +356,7 @@ describe("handleFeishuCommentEvent", () => {
345356});
346357347358expect(maybeCreateDynamicAgentMock).toHaveBeenCalledTimes(1);
348-const dynamicAgentArgs = maybeCreateDynamicAgentMock.mock.calls[0]?.[0] as
359+const dynamicAgentArgs = mockCallArg(maybeCreateDynamicAgentMock, "maybeCreateDynamicAgent") as
349360| { configWritesAllowed?: boolean; senderOpenId?: string }
350361| undefined;
351362expect(dynamicAgentArgs?.senderOpenId).toBe("ou_sender");
@@ -380,7 +391,13 @@ describe("handleFeishuCommentEvent", () => {
380391});
381392382393expect(deliverCommentThreadTextMock).toHaveBeenCalledTimes(1);
383-const [pairingClient, pairingReply] = deliverCommentThreadTextMock.mock.calls[0] ?? [];
394+const pairingClient = mockCallArg(deliverCommentThreadTextMock, "deliverCommentThreadText");
395+const pairingReply = mockCallArg(
396+deliverCommentThreadTextMock,
397+"deliverCommentThreadText",
398+0,
399+1,
400+);
384401expect(pairingClient).toBe(createFeishuClientMock.mock.results[0]?.value);
385402expect(pairingReply).toEqual({
386403file_token: "doc_token_1",
@@ -442,7 +459,10 @@ describe("handleFeishuCommentEvent", () => {
442459});
443460444461expect(createFeishuCommentReplyDispatcherMock).toHaveBeenCalledTimes(1);
445-const dispatcherArgs = createFeishuCommentReplyDispatcherMock.mock.calls[0]?.[0] as
462+const dispatcherArgs = mockCallArg(
463+createFeishuCommentReplyDispatcherMock,
464+"createFeishuCommentReplyDispatcher",
465+) as
446466| {
447467commentId?: string;
448468fileToken?: string;
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。