Skip to content

Commit c4e0c00

Browse files
authored
fix(ci): await Slack provider reply delivery (#128234)
* test(slack): await provider reply delivery * fix(ci): exercise real Slack dispatch lifecycle * test(slack): await recovered identity delivery
1 parent e27fb66 commit c4e0c00

2 files changed

Lines changed: 60 additions & 12 deletions

File tree

‎extensions/slack/src/monitor.test-helpers.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export function useSlackStartupAuthClientOnce(factory: SlackStartupAuthClientFac
113113
slackTestState.createSlackStartupAuthClientMock.mockImplementationOnce(factory);
114114
}
115115

116+
export async function runSlackHandlerWithDispatch(
117+
handler: SlackHandler,
118+
args: unknown,
119+
): Promise<void> {
120+
await handler(withSlackDispatchLifecycle(args));
121+
}
122+
116123
type SlackClient = {
117124
auth: { test: Mock<(...args: unknown[]) => Promise<Record<string, unknown>>> };
118125
conversations: {
@@ -271,9 +278,12 @@ async function runSlackEventOnce(
271278
const handler = await getSlackHandlerOrThrow(name);
272279
// Normal Bolt handlers return after queue admission. Terminal-state tests use the
273280
// durable-ingress lifecycle so this helper can await the actual dispatch boundary.
274-
const handlerArgs = opts?.awaitDispatch ? withSlackDispatchLifecycle(args) : args;
275281
try {
276-
await handler(handlerArgs);
282+
if (opts?.awaitDispatch) {
283+
await runSlackHandlerWithDispatch(handler, args);
284+
} else {
285+
await handler(args);
286+
}
277287
} finally {
278288
await stopSlackMonitor({ controller, run });
279289
}

‎extensions/slack/src/monitor/provider.auth-test-token.test.ts‎

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
getSlackHandlers,
1717
getSlackTestState,
1818
resetSlackTestState,
19+
runSlackHandlerWithDispatch,
1920
startSlackMonitor as startSlackMonitorUntracked,
2021
stopSlackMonitor,
2122
useSlackStartupAuthClientOnce,
@@ -375,7 +376,7 @@ describe("auth.test boot call", () => {
375376
expect(getSlackInstallationKind("default")).toBe("enterprise");
376377

377378
const handler = await getSlackHandlerOrThrow("message");
378-
await handler({
379+
await runSlackHandlerWithDispatch(handler, {
379380
event: {
380381
type: "message",
381382
user: "UOTHER123",
@@ -394,7 +395,17 @@ describe("auth.test boot call", () => {
394395
});
395396

396397
expect(replyMock).toHaveBeenCalledTimes(1);
397-
await vi.waitFor(() => expect(sendMock).toHaveBeenCalledTimes(1));
398+
const dispatchedContext = replyMock.mock.calls[0]?.[0];
399+
expect(dispatchedContext).toMatchObject({
400+
Body: expect.stringMatching(/<@UENTERPRISE>.*status/u),
401+
ChatType: "channel",
402+
WasMentioned: true,
403+
});
404+
expect(sendMock).toHaveBeenCalledWith(
405+
"channel:C12345678",
406+
"identity preserved",
407+
expect.any(Object),
408+
);
398409
await expect(stopSlackMonitor(monitor)).resolves.toBeUndefined();
399410
expect(getSlackInstallationKind("default")).toBeUndefined();
400411
});
@@ -477,7 +488,8 @@ describe("presence polling transport", () => {
477488
...options,
478489
env: options.env ?? process.env,
479490
});
480-
getSlackTestState().replyMock.mockResolvedValue({ text: "ok" });
491+
const { replyMock, sendMock } = getSlackTestState();
492+
replyMock.mockResolvedValue({ text: "ok" });
481493

482494
const nativeSetInterval = globalThis.setInterval;
483495
let triggerPresencePoll: (() => void) | undefined;
@@ -496,7 +508,7 @@ describe("presence polling transport", () => {
496508
const monitor = startSlackMonitor(monitorSlackProvider);
497509
try {
498510
const handler = await getSlackHandlerOrThrow("message");
499-
await handler({
511+
await runSlackHandlerWithDispatch(handler, {
500512
event: {
501513
type: "message",
502514
user: "U_STALLED",
@@ -508,6 +520,15 @@ describe("presence polling transport", () => {
508520
context: { botUserId: "bot-user" },
509521
body: {},
510522
});
523+
const dispatchedContext = replyMock.mock.calls[0]?.[0];
524+
expect(dispatchedContext).toMatchObject({
525+
Body: expect.stringMatching(
526+
/Ada: hello\n\[slack message id: 100\.000 channel: D_STALLED\]$/u,
527+
),
528+
ChatType: "direct",
529+
WasMentioned: false,
530+
});
531+
expect(sendMock).toHaveBeenCalledWith("channel:D_STALLED", "ok", expect.any(Object));
511532
expect(triggerPresencePoll).toBeTypeOf("function");
512533
triggerPresencePoll?.();
513534
await vi.waitFor(() => expect(server.requestCount).toBe(1), { timeout: 1_000 });
@@ -621,7 +642,7 @@ describe("user identity provider transport", () => {
621642
const monitor = await startWithoutBotToken(config);
622643
const handler = await getSlackHandlerOrThrow("message");
623644

624-
await handler({
645+
await runSlackHandlerWithDispatch(handler, {
625646
event: {
626647
type: "message",
627648
user: "U_OTHER",
@@ -634,7 +655,13 @@ describe("user identity provider transport", () => {
634655
body: {},
635656
});
636657

637-
await vi.waitFor(() => expect(sendMock).toHaveBeenCalledTimes(1));
658+
const dispatchedContext = replyMock.mock.calls[0]?.[0];
659+
expect(dispatchedContext).toMatchObject({
660+
Body: expect.stringMatching(/<@U_SELF>.*status/u),
661+
ChatType: "channel",
662+
WasMentioned: true,
663+
});
664+
expect(sendMock).toHaveBeenCalledWith("channel:C1", "acknowledged", expect.any(Object));
638665
await stopSlackMonitor(monitor);
639666
});
640667

@@ -658,12 +685,18 @@ describe("user identity provider transport", () => {
658685
text: "hello",
659686
};
660687

661-
await handler({
688+
await runSlackHandlerWithDispatch(handler, {
662689
event: { ...baseEvent, user: "U_OTHER", ts: "100.000" },
663690
context: { botUserId: "U_SELF" },
664691
body: {},
665692
});
666-
await vi.waitFor(() => expect(sendMock).toHaveBeenCalledTimes(1));
693+
const dispatchedContext = replyMock.mock.calls[0]?.[0];
694+
expect(dispatchedContext).toMatchObject({
695+
Body: expect.stringMatching(/Ada: hello\n\[slack message id: 100\.000 channel: D1\]$/u),
696+
ChatType: "direct",
697+
WasMentioned: false,
698+
});
699+
expect(sendMock).toHaveBeenCalledWith("channel:D1", "hello back", expect.any(Object));
667700

668701
await handler({
669702
event: { ...baseEvent, user: "U_SELF", ts: "101.000" },
@@ -948,7 +981,7 @@ describe("connected identity health", () => {
948981
});
949982
expect(getSlackHandlers().has("reaction_added")).toBe(true);
950983

951-
await handler({
984+
await runSlackHandlerWithDispatch(handler, {
952985
event: {
953986
type: "message",
954987
user: "UOTHER123",
@@ -970,7 +1003,12 @@ describe("connected identity health", () => {
9701003
expect.objectContaining({ channel: "C12345678" }),
9711004
);
9721005
expect(replyMock).toHaveBeenCalledTimes(1);
973-
await vi.waitFor(() => expect(sendMock).toHaveBeenCalledTimes(1));
1006+
const dispatchedContext = replyMock.mock.calls[0]?.[0];
1007+
expect(dispatchedContext).toMatchObject({
1008+
Body: expect.stringMatching(/<@UENTERPRISE>.*status/u),
1009+
ChatType: "channel",
1010+
WasMentioned: true,
1011+
});
9741012
expect(sendMock).toHaveBeenCalledWith(
9751013
"channel:C12345678",
9761014
"identity restored",

0 commit comments

Comments
 (0)