Slack: fail oversized merged block payloads

This commit is contained in:
Vincent Koc
2026-03-15 20:39:43 -07:00
parent 47e0bf522f
commit 3bfd093cdb
2 changed files with 26 additions and 1 deletions

View File

@@ -144,4 +144,27 @@ describe("slackOutbound sendPayload", () => {
);
expect(result).toMatchObject({ channel: "slack", messageId: "sl-controls" });
});
it("fails when merged Slack blocks exceed the platform limit", async () => {
const { run, sendMock } = createHarness({
payload: {
channelData: {
slack: {
blocks: Array.from({ length: 50 }, () => ({ type: "divider" })),
},
},
interactive: {
blocks: [
{
type: "buttons",
buttons: [{ label: "Allow", value: "pluginbind:approval-123:o" }],
},
],
},
},
});
await expect(run()).rejects.toThrow(/Slack blocks cannot exceed 50 items/i);
expect(sendMock).not.toHaveBeenCalled();
});
});

View File

@@ -139,7 +139,9 @@ function resolveSlackBlocks(payload: {
return undefined;
}
if (mergedBlocks.length > SLACK_MAX_BLOCKS) {
return existingBlocks?.length ? existingBlocks : undefined;
throw new Error(
`Slack blocks cannot exceed ${SLACK_MAX_BLOCKS} items after interactive render`,
);
}
return mergedBlocks;
}