|
1 | | -import { describe, expect, it } from "vitest"; |
| 1 | +import { describe, expect, it, vi } from "vitest"; |
2 | 2 | import { slackApprovalNativeRuntime } from "./approval-handler.runtime.js"; |
3 | 3 |
|
4 | 4 | type SlackPayload = { |
5 | 5 | text: string; |
6 | 6 | blocks?: unknown; |
7 | 7 | }; |
| 8 | +const SLACK_TEXT_LIMIT = 8000; |
8 | 9 |
|
9 | 10 | function findSlackActionsBlock(blocks: Array<{ type?: string; elements?: unknown[] }>) { |
10 | 11 | return blocks.find((block) => block.type === "actions"); |
@@ -114,6 +115,53 @@ describe("slackApprovalNativeRuntime", () => { |
114 | 115 | ).toBe(false); |
115 | 116 | }); |
116 | 117 |
|
| 118 | + it("caps resolved update fallback text while preserving approval blocks", async () => { |
| 119 | + const blocks = [ |
| 120 | + { |
| 121 | + type: "section", |
| 122 | + text: { |
| 123 | + type: "mrkdwn", |
| 124 | + text: "*Command*\n```short preview```", |
| 125 | + }, |
| 126 | + }, |
| 127 | + ]; |
| 128 | + const chatUpdate = vi.fn(async (_payload: { text: string; blocks: typeof blocks }) => ({})); |
| 129 | + |
| 130 | + await slackApprovalNativeRuntime.transport.updateEntry?.({ |
| 131 | + cfg: {} as never, |
| 132 | + accountId: "default", |
| 133 | + context: { |
| 134 | + app: { |
| 135 | + client: { |
| 136 | + chat: { |
| 137 | + update: chatUpdate, |
| 138 | + }, |
| 139 | + }, |
| 140 | + }, |
| 141 | + config: {}, |
| 142 | + } as never, |
| 143 | + entry: { |
| 144 | + channelId: "C123", |
| 145 | + messageTs: "1712345678.999999", |
| 146 | + }, |
| 147 | + payload: { |
| 148 | + text: `*Exec approval: Allowed once*\n\n*Command*\n${"a".repeat(9000)}`, |
| 149 | + blocks, |
| 150 | + }, |
| 151 | + phase: "resolved", |
| 152 | + }); |
| 153 | + |
| 154 | + expect(chatUpdate).toHaveBeenCalledWith( |
| 155 | + expect.objectContaining({ |
| 156 | + channel: "C123", |
| 157 | + ts: "1712345678.999999", |
| 158 | + text: expect.stringMatching(/…$/), |
| 159 | + blocks, |
| 160 | + }), |
| 161 | + ); |
| 162 | + expect(chatUpdate.mock.calls[0]?.[0].text).toHaveLength(SLACK_TEXT_LIMIT); |
| 163 | + }); |
| 164 | + |
117 | 165 | it("keeps pending metadata context within Slack Block Kit limits", async () => { |
118 | 166 | const payload = (await slackApprovalNativeRuntime.presentation.buildPendingPayload({ |
119 | 167 | cfg: {} as never, |
|
0 commit comments