Skip to content

Commit 6963398

Browse files
committed
fix(slack): preserve structured payload dispatch custody
1 parent 621220a commit 6963398

4 files changed

Lines changed: 37 additions & 22 deletions

File tree

‎extensions/slack/src/channel.message-adapter.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,20 +132,23 @@ describe("slack channel message adapter", () => {
132132

133133
const provePayload = async () => {
134134
sendSlack.mockClear();
135+
const onPlatformSendDispatch = vi.fn();
135136
const result = await sendPayload({
136137
cfg,
137138
to: "C123",
138139
text: "payload",
139140
payload: { text: "payload" },
140141
accountId: "default",
141142
deliveryQueueId: "queue-1",
143+
onPlatformSendDispatch,
142144
deps: { sendSlack },
143145
});
144146
const [to, text, options] = expectLastSendSlackCall();
145147
expect(to).toBe("C123");
146148
expect(text).toBe("payload");
147149
expect(options.accountId).toBe("default");
148150
expect(options.deliveryQueueId).toBeUndefined();
151+
expect(options.onPlatformSendDispatch).toBe(onPlatformSendDispatch);
149152
expect(result.receipt.platformMessageIds).toEqual(["msg-1"]);
150153
};
151154

‎extensions/slack/src/channel.ts‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,6 @@ function withSlackSendOverride(params: {
254254
deps?: { [channelId: string]: unknown } | null;
255255
send: SlackSendFn;
256256
tokenOverride?: string;
257-
deliveryQueueId?: string;
258-
onPlatformSendDispatch?: () => Promise<void>;
259257
}) {
260258
return {
261259
...params.deps,
@@ -267,10 +265,6 @@ function withSlackSendOverride(params: {
267265
await params.send(to, text, {
268266
...opts,
269267
...(params.tokenOverride ? { token: params.tokenOverride } : {}),
270-
...(params.deliveryQueueId ? { deliveryQueueId: params.deliveryQueueId } : {}),
271-
...(params.onPlatformSendDispatch
272-
? { onPlatformSendDispatch: params.onPlatformSendDispatch }
273-
: {}),
274268
}),
275269
};
276270
}
@@ -531,7 +525,6 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
531525
replyToId: threadTsValue,
532526
threadId: null,
533527
deliveryQueueId: undefined,
534-
onPlatformSendDispatch: undefined,
535528
deps: withSlackSendOverride({
536529
deps: ctx.deps,
537530
send,
@@ -554,14 +547,10 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
554547
to,
555548
replyToId: threadTsValue,
556549
threadId: null,
557-
deliveryQueueId: undefined,
558-
onPlatformSendDispatch: undefined,
559550
deps: withSlackSendOverride({
560551
deps: ctx.deps,
561552
send,
562553
tokenOverride,
563-
deliveryQueueId: ctx.deliveryQueueId,
564-
onPlatformSendDispatch: ctx.onPlatformSendDispatch,
565554
}),
566555
});
567556
},
@@ -581,12 +570,10 @@ const slackChannelOutbound: ChannelOutboundAdapter = {
581570
replyToId: threadTsValue,
582571
threadId: null,
583572
deliveryQueueId: undefined,
584-
onPlatformSendDispatch: undefined,
585573
deps: withSlackSendOverride({
586574
deps: ctx.deps,
587575
send,
588576
tokenOverride,
589-
onPlatformSendDispatch: ctx.onPlatformSendDispatch,
590577
}),
591578
});
592579
},

‎extensions/slack/src/outbound-adapter.ts‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,6 @@ export const slackOutbound: ChannelOutboundAdapter = {
318318
text,
319319
mediaUrl,
320320
deliveryQueueId: useSingleDeliveryMarker ? ctx.deliveryQueueId : undefined,
321-
onPlatformSendDispatch: useSingleDeliveryMarker
322-
? ctx.onPlatformSendDispatch
323-
: undefined,
324321
}),
325322
finalize: async () => {
326323
let lastResult: Awaited<ReturnType<SlackSendFn>> | undefined;
@@ -337,9 +334,6 @@ export const slackOutbound: ChannelOutboundAdapter = {
337334
: {}),
338335
...(message.textIsSlackPlainText ? { textIsSlackPlainText: true } : {}),
339336
deliveryQueueId: useSingleDeliveryMarker ? ctx.deliveryQueueId : undefined,
340-
onPlatformSendDispatch: useSingleDeliveryMarker
341-
? ctx.onPlatformSendDispatch
342-
: undefined,
343337
});
344338
}
345339
if (!lastResult) {

‎extensions/slack/src/outbound-payload.test.ts‎

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,9 @@ describe("slackOutbound sendPayload", () => {
482482
expect(client.chat.postMessage.mock.calls.length).toBeGreaterThanOrEqual(3);
483483
expect(capturedSendOptions).not.toHaveLength(0);
484484
expect(capturedSendOptions.every((opts) => opts.deliveryQueueId === undefined)).toBe(true);
485-
expect(capturedSendOptions.every((opts) => opts.onPlatformSendDispatch === undefined)).toBe(
486-
true,
487-
);
485+
expect(
486+
capturedSendOptions.every((opts) => opts.onPlatformSendDispatch === onPlatformSendDispatch),
487+
).toBe(true);
488488
expect(postedSlackMessage(client, 0)).toMatchObject({
489489
text: expect.stringContaining("Pipeline <!channel>"),
490490
mrkdwn: false,
@@ -662,6 +662,37 @@ describe("slackOutbound sendPayload", () => {
662662
});
663663
});
664664

665+
it("refreshes dispatch custody before each structured fanout request", async () => {
666+
const payload: ReplyPayload = {
667+
channelData: {
668+
slack: { blocks: Array.from({ length: 49 }, () => ({ type: "divider" })) },
669+
},
670+
presentation: { title: "Deploy status", blocks: [{ type: "divider" }] },
671+
interactive: interactiveButtons("Allow", "pluginbind:approval-123:o"),
672+
};
673+
const onPlatformSendDispatch = vi.fn(async () => undefined);
674+
675+
const { capturedSendOptions, client } = await sendThroughRealSlack({
676+
payload,
677+
deliveryQueueId: "queue-1",
678+
onPlatformSendDispatch,
679+
});
680+
681+
expect(client.chat.postMessage).toHaveBeenCalledTimes(2);
682+
expect(capturedSendOptions).toHaveLength(2);
683+
expect(capturedSendOptions.every((opts) => opts.deliveryQueueId === undefined)).toBe(true);
684+
expect(
685+
capturedSendOptions.every((opts) => opts.onPlatformSendDispatch === onPlatformSendDispatch),
686+
).toBe(true);
687+
expect(onPlatformSendDispatch).toHaveBeenCalledTimes(2);
688+
for (const [
689+
index,
690+
dispatchOrder,
691+
] of onPlatformSendDispatch.mock.invocationCallOrder.entries()) {
692+
expect(dispatchOrder).toBeLessThan(client.chat.postMessage.mock.invocationCallOrder[index]!);
693+
}
694+
});
695+
665696
it("uses the full ordered table fallback when preserved siblings exceed the block limit", async () => {
666697
const payload: ReplyPayload = {
667698
channelData: {

0 commit comments

Comments
 (0)