





















@@ -68,8 +68,32 @@ describe("monitorSlackProvider tool results", () => {
6868};
6969}
707071+function firstMockCall(mock: ReturnType<typeof vi.fn>, label: string): unknown[] {
72+const [call] = mock.mock.calls;
73+if (!call) {
74+throw new Error(`expected ${label} call`);
75+}
76+return call;
77+}
78+79+function firstMockArg(mock: ReturnType<typeof vi.fn>, label: string, argIndex: number): unknown {
80+return firstMockCall(mock, label)[argIndex];
81+}
82+83+function firstMockRecordArg(
84+mock: ReturnType<typeof vi.fn>,
85+label: string,
86+argIndex: number,
87+): Record<string, unknown> {
88+const value = firstMockArg(mock, label, argIndex);
89+if (!value || typeof value !== "object" || Array.isArray(value)) {
90+throw new Error(`expected ${label} argument ${argIndex + 1} to be an object`);
91+}
92+return value as Record<string, unknown>;
93+}
94+7195function firstReplyCtx(): { WasMentioned?: boolean } {
72-return (replyMock.mock.calls[0]?.[0] ?? {}) as { WasMentioned?: boolean };
96+return firstMockRecordArg(replyMock, "reply", 0) as { WasMentioned?: boolean };
7397}
74987599function setRequireMentionChannelConfig(mentionPatterns?: string[]) {
@@ -210,7 +234,7 @@ describe("monitorSlackProvider tool results", () => {
210234ThreadStarterBody?: string;
211235ThreadLabel?: string;
212236} {
213-return (replyMock.mock.calls[0]?.[0] ?? {}) as {
237+return firstMockRecordArg(replyMock, "reply", 0) as {
214238SessionKey?: string;
215239ParentSessionKey?: string;
216240ThreadStarterBody?: string;
@@ -220,9 +244,7 @@ describe("monitorSlackProvider tool results", () => {
220244221245function expectSingleSendWithThread(threadTs: string | undefined) {
222246expect(sendMock).toHaveBeenCalledTimes(1);
223-expect((sendMock.mock.calls[0]?.[2] as { threadTs?: string } | undefined)?.threadTs).toBe(
224-threadTs,
225-);
247+expect(firstMockRecordArg(sendMock, "send", 2).threadTs).toBe(threadTs);
226248}
227249228250function setMentionGatedAckConfig(statusReactionsEnabled: boolean) {
@@ -287,7 +309,7 @@ describe("monitorSlackProvider tool results", () => {
287309event: makeSlackMessageEvent(),
288310});
289311expect(sendMock).toHaveBeenCalledTimes(1);
290-expect(sendMock.mock.calls[0][1]).toBe(expectedText);
312+expect(firstMockArg(sendMock, "send", 1)).toBe(expectedText);
291313}
292314293315it("skips socket startup when Slack channel is disabled", async () => {
@@ -751,7 +773,7 @@ describe("monitorSlackProvider tool results", () => {
751773expect(replyMock).not.toHaveBeenCalled();
752774expect(upsertPairingRequestMock).toHaveBeenCalled();
753775expect(sendMock).toHaveBeenCalledTimes(1);
754-const sentText = sendMock.mock.calls[0]?.[1];
776+const sentText = firstMockArg(sendMock, "send", 1);
755777expectPairingReplyText(typeof sentText === "string" ? sentText : "", {
756778channel: "slack",
757779idLine: "Your Slack user id: U1",
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。