






















@@ -68,6 +68,18 @@ async function flushPendingDelivery(): Promise<void> {
6868await Promise.resolve();
6969}
707071+type DeliveryArgs = {
72+payloads?: Array<{ text?: string; interactive?: unknown }>;
73+};
74+75+function deliveryArgs(deliver: ReturnType<typeof vi.fn>): DeliveryArgs | undefined {
76+return deliver.mock.calls.at(0)?.at(0) as DeliveryArgs | undefined;
77+}
78+79+function firstDeliveredPayload(deliver: ReturnType<typeof vi.fn>) {
80+return deliveryArgs(deliver)?.payloads?.at(0);
81+}
82+7183function registerSlackAdapterPlugin(plugin: SlackAdapterPlugin): void {
7284const registry = createTestRegistry([{ pluginId: "slack", plugin, source: "test" }]);
7385setActivePluginRegistry(registry);
@@ -119,10 +131,7 @@ describe("plugin approval forwarding", () => {
119131expect(result).toBe(true);
120132await flushPendingDelivery();
121133expect(deliver).toHaveBeenCalled();
122-const deliveryArgs = deliver.mock.calls[0]?.[0] as
123-| { payloads?: Array<{ text?: string; interactive?: unknown }> }
124-| undefined;
125-const payload = deliveryArgs?.payloads?.[0];
134+const payload = firstDeliveredPayload(deliver);
126135const text = payload?.text ?? "";
127136expect(text).toContain("Plugin approval required");
128137expect(text).toContain("Sensitive tool call");
@@ -167,10 +176,7 @@ describe("plugin approval forwarding", () => {
167176);
168177expect(result).toBe(true);
169178await flushPendingDelivery();
170-const deliveryArgs = deliver.mock.calls[0]?.[0] as
171-| { payloads?: Array<{ text?: string; interactive?: unknown }> }
172-| undefined;
173-const payload = deliveryArgs?.payloads?.[0];
179+const payload = firstDeliveredPayload(deliver);
174180expect(payload?.text).toContain("Reply with: /approve <id> allow-once|deny");
175181expect(payload?.text).not.toContain("allow-always");
176182expect(payload?.interactive).toEqual({
@@ -202,9 +208,7 @@ describe("plugin approval forwarding", () => {
202208await forwarder.handlePluginApprovalRequested!(request);
203209await flushPendingDelivery();
204210expect(deliver).toHaveBeenCalled();
205-const text =
206-(deliver.mock.calls[0]?.[0] as { payloads?: Array<{ text?: string }> })?.payloads?.[0]
207-?.text ?? "";
211+const text = firstDeliveredPayload(deliver)?.text ?? "";
208212expect(text).toMatch(/🚨/);
209213});
210214@@ -267,10 +271,7 @@ describe("plugin approval forwarding", () => {
267271await forwarder.handlePluginApprovalRequested!(makePluginRequest());
268272await flushPendingDelivery();
269273expect(deliver).toHaveBeenCalled();
270-const deliveryArgs = deliver.mock.calls[0]?.[0] as
271-| { payloads?: Array<{ text?: string }> }
272-| undefined;
273-expect(deliveryArgs?.payloads?.[0]?.text).toBe("custom adapter payload");
274+expect(firstDeliveredPayload(deliver)?.text).toBe("custom adapter payload");
274275});
275276276277it("calls outbound beforeDeliverPayload before plugin approval delivery", async () => {
@@ -314,10 +315,7 @@ describe("plugin approval forwarding", () => {
314315await forwarder.handlePluginApprovalResolved!(makePluginResolved());
315316await flushPendingDelivery();
316317expect(deliver).toHaveBeenCalled();
317-const deliveryArgs = deliver.mock.calls[0]?.[0] as
318-| { payloads?: Array<{ text?: string }> }
319-| undefined;
320-expect(deliveryArgs?.payloads?.[0]?.text).toBe("custom resolved payload");
318+expect(firstDeliveredPayload(deliver)?.text).toBe("custom resolved payload");
321319});
322320});
323321@@ -330,9 +328,7 @@ describe("plugin approval forwarding", () => {
330328331329await forwarder.handlePluginApprovalResolved!(makePluginResolved());
332330expect(deliver).toHaveBeenCalled();
333-const text =
334-(deliver.mock.calls[0]?.[0] as { payloads?: Array<{ text?: string }> })?.payloads?.[0]
335-?.text ?? "";
331+const text = firstDeliveredPayload(deliver)?.text ?? "";
336332expect(text).toContain("Plugin approval");
337333expect(text).toContain("allowed once");
338334});
@@ -358,9 +354,7 @@ describe("plugin approval forwarding", () => {
358354});
359355360356expect(deliver).toHaveBeenCalled();
361-const text =
362-(deliver.mock.calls[0]?.[0] as { payloads?: Array<{ text?: string }> })?.payloads?.[0]
363-?.text ?? "";
357+const text = firstDeliveredPayload(deliver)?.text ?? "";
364358expect(text).toContain("Plugin approval");
365359expect(text).toContain("denied");
366360});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。