

























@@ -12,12 +12,24 @@ function slackConfig() {
1212return { channels: { slack: { botToken: "tok" } } };
1313}
141415+function firstInvokeCall(invoke: ReturnType<typeof createInvokeSpy>) {
16+const [call] = invoke.mock.calls;
17+if (!call) {
18+throw new Error("expected first Slack action invoke");
19+}
20+return call;
21+}
22+1523function expectForwardedCfg(invoke: ReturnType<typeof createInvokeSpy>, cfg: unknown) {
16-expect(invoke.mock.calls[0]?.[1]).toBe(cfg);
24+expect(firstInvokeCall(invoke)[1]).toBe(cfg);
25+}
26+27+function expectNoForwardedToolContext(invoke: ReturnType<typeof createInvokeSpy>) {
28+expect(firstInvokeCall(invoke)[2]).toBeUndefined();
1729}
18301931function firstAction(invoke: ReturnType<typeof createInvokeSpy>) {
20-const action = invoke.mock.calls[0]?.[0];
32+const action = firstInvokeCall(invoke)[0];
2133if (!action || typeof action !== "object") {
2234throw new Error("expected first invoke action");
2335}
@@ -154,7 +166,7 @@ describe("handleSlackMessageAction", () => {
154166expect(actionsBlock.type).toBe("actions");
155167expect(elementAt(actionsBlock, 0).value).toBe("approve");
156168expectForwardedCfg(invoke, cfg);
157-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
169+expectNoForwardedToolContext(invoke);
158170});
159171160172it("passes replyBroadcast through for Slack thread sends", async () => {
@@ -183,7 +195,7 @@ describe("handleSlackMessageAction", () => {
183195expect(action.threadTs).toBe("111.222");
184196expect(action.replyBroadcast).toBe(true);
185197expectForwardedCfg(invoke, cfg);
186-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
198+expectNoForwardedToolContext(invoke);
187199});
188200189201it("passes topLevel through so same-channel Slack sends can suppress thread inheritance", async () => {
@@ -211,7 +223,7 @@ describe("handleSlackMessageAction", () => {
211223expect(action.threadTs).toBeUndefined();
212224expect(action.topLevel).toBe(true);
213225expectForwardedCfg(invoke, cfg);
214-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
226+expectNoForwardedToolContext(invoke);
215227});
216228217229it("treats threadId null as a Slack top-level send request", async () => {
@@ -237,7 +249,7 @@ describe("handleSlackMessageAction", () => {
237249expect(action.threadTs).toBeUndefined();
238250expect(action.topLevel).toBe(true);
239251expectForwardedCfg(invoke, cfg);
240-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
252+expectNoForwardedToolContext(invoke);
241253});
242254243255it("maps upload-file to the internal uploadFile action", async () => {
@@ -270,7 +282,7 @@ describe("handleSlackMessageAction", () => {
270282expect(action.title).toBe("Build Screenshot");
271283expect(action.threadTs).toBe("111.222");
272284expectForwardedCfg(invoke, cfg);
273-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
285+expectNoForwardedToolContext(invoke);
274286});
275287276288it("rejects replyBroadcast for upload-file", async () => {
@@ -318,7 +330,7 @@ describe("handleSlackMessageAction", () => {
318330expect(action.initialComment).toBe("chart attached");
319331expect(action.threadTs).toBe("333.444");
320332expectForwardedCfg(invoke, cfg);
321-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
333+expectNoForwardedToolContext(invoke);
322334});
323335324336it("maps upload-file path alias to filePath", async () => {
@@ -345,7 +357,7 @@ describe("handleSlackMessageAction", () => {
345357expect(action.filePath).toBe("/tmp/report.txt");
346358expect(action.initialComment).toBe("path alias");
347359expectForwardedCfg(invoke, cfg);
348-expect(invoke.mock.calls[0]?.[2]).toBeUndefined();
360+expectNoForwardedToolContext(invoke);
349361});
350362351363it("forwards messageId for read actions", async () => {
@@ -368,7 +380,7 @@ describe("handleSlackMessageAction", () => {
368380expect(action.action).toBe("readMessages");
369381expect(action.channelId).toBe("C1");
370382expect(action.messageId).toBe("1712345678.654321");
371-expect(invoke.mock.calls[0]?.[1]).toEqual({});
383+expect(firstInvokeCall(invoke)[1]).toEqual({});
372384});
373385374386it("requires filePath, path, or media for upload-file", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。