






















@@ -71,6 +71,26 @@ function makeMinimalSlackConfig(
7171return { channels: { slack } } as OpenClawConfig;
7272}
737374+type MockWithCalls = {
75+mock: { calls: unknown[][] };
76+};
77+78+function mockCallAt(mock: MockWithCalls, index: number): unknown[] {
79+const call = mock.mock.calls[index];
80+if (!call) {
81+throw new Error(`expected mock call ${index}`);
82+}
83+return call;
84+}
85+86+function mockRecordArgAt(mock: MockWithCalls, callIndex: number, argIndex: number) {
87+const value = mockCallAt(mock, callIndex)[argIndex];
88+if (!value || typeof value !== "object" || Array.isArray(value)) {
89+throw new Error(`expected mock call ${callIndex} argument ${argIndex} to be an object`);
90+}
91+return value as Record<string, unknown>;
92+}
93+7494// --- Status: buildChannelSummary -------------------------------------------------
75957696describe("slackPlugin.status.buildChannelSummary lazy SDK forwarding", () => {
@@ -100,8 +120,10 @@ describe("slackPlugin.status.buildChannelSummary lazy SDK forwarding", () => {
100120} as never);
101121102122expect(buildPassiveProbedChannelStatusSummaryMock).toHaveBeenCalledTimes(1);
103-const [forwardedSnapshot, forwardedExtras] =
104-buildPassiveProbedChannelStatusSummaryMock.mock.calls[0] ?? [];
123+const [forwardedSnapshot, forwardedExtras] = mockCallAt(
124+buildPassiveProbedChannelStatusSummaryMock,
125+0,
126+);
105127// Snapshot must be forwarded by reference / structurally intact.
106128expect(forwardedSnapshot).toBe(snapshot);
107129// The channel must forward the (possibly fallback'd) token sources.
@@ -125,7 +147,7 @@ describe("slackPlugin.status.buildChannelSummary lazy SDK forwarding", () => {
125147runtime: undefined,
126148} as never);
127149128-const [, forwardedExtras] = buildPassiveProbedChannelStatusSummaryMock.mock.calls[0] ?? [];
150+const [, forwardedExtras] = mockCallAt(buildPassiveProbedChannelStatusSummaryMock, 0);
129151expect(forwardedExtras).toEqual({ botTokenSource: "none", appTokenSource: "none" });
130152});
131153});
@@ -166,8 +188,8 @@ describe("slackPlugin.status.buildCapabilitiesDiagnostics lazy scopes loader", (
166188const result = await buildDiagnostics({ account, timeoutMs: 5000, cfg } as never);
167189168190expect(fetchSlackScopesMock).toHaveBeenCalledTimes(2);
169-expect(fetchSlackScopesMock.mock.calls[0]).toEqual(["xoxb-bot", 5000]);
170-expect(fetchSlackScopesMock.mock.calls[1]).toEqual(["xoxp-user", 5000]);
191+expect(mockCallAt(fetchSlackScopesMock, 0)).toEqual(["xoxb-bot", 5000]);
192+expect(mockCallAt(fetchSlackScopesMock, 1)).toEqual(["xoxp-user", 5000]);
171193expect(result?.details).toEqual({
172194botScopes: { ok: true, scopes: ["chat:write"] },
173195userScopes: { ok: true, scopes: ["users:read"] },
@@ -215,7 +237,7 @@ describe("slackPlugin.security.collectAuditFindings lazy module forwarding", ()
215237const result = await collectAuditFindings({ cfg, accountId: "default", account } as never);
216238217239expect(collectAuditFindingsMock).toHaveBeenCalledTimes(1);
218-expect(collectAuditFindingsMock.mock.calls[0]?.[0]).toEqual({
240+expect(mockCallAt(collectAuditFindingsMock, 0)[0]).toEqual({
219241 cfg,
220242accountId: "default",
221243 account,
@@ -260,18 +282,20 @@ describe("slackPlugin.resolver.resolveTargets lazy SDK forwarding", () => {
260282} as never);
261283262284expect(resolveTargetsWithOptionalTokenMock).toHaveBeenCalledTimes(1);
263-const [params] = resolveTargetsWithOptionalTokenMock.mock.calls[0] ?? [];
285+const params = mockRecordArgAt(resolveTargetsWithOptionalTokenMock, 0, 0);
264286expect(params.token).toBe("xoxb-bot");
265287expect(params.inputs).toEqual(["U123"]);
266288expect(params.missingTokenNote).toBe("missing Slack token");
267-if (typeof params.resolveWithToken !== "function") {
289+const resolveWithToken = params.resolveWithToken;
290+if (typeof resolveWithToken !== "function") {
268291throw new Error("expected Slack target resolver callback");
269292}
270-if (typeof params.mapResolved !== "function") {
293+const mapResolved = params.mapResolved;
294+if (typeof mapResolved !== "function") {
271295throw new Error("expected Slack target mapper callback");
272296}
273297expect(
274-params.mapResolved({
298+mapResolved({
275299input: "U123",
276300resolved: true,
277301id: "U123",
@@ -303,7 +327,7 @@ describe("slackPlugin.resolver.resolveTargets lazy SDK forwarding", () => {
303327kind: "user",
304328} as never);
305329306-const [params] = resolveTargetsWithOptionalTokenMock.mock.calls[0] ?? [];
330+const params = mockRecordArgAt(resolveTargetsWithOptionalTokenMock, 0, 0);
307331expect(params.token).toBe("xoxp-user");
308332});
309333@@ -323,7 +347,7 @@ describe("slackPlugin.resolver.resolveTargets lazy SDK forwarding", () => {
323347} as never);
324348325349expect(resolveTargetsWithOptionalTokenMock).toHaveBeenCalledTimes(1);
326-const [params] = resolveTargetsWithOptionalTokenMock.mock.calls[0] ?? [];
350+const params = mockRecordArgAt(resolveTargetsWithOptionalTokenMock, 0, 0);
327351expect(params.token).toBe("xoxb-bot");
328352expect(params.inputs).toEqual(["C1"]);
329353});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。