mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 18:30:44 +00:00
fix: cap slack approval update text
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { slackApprovalNativeRuntime } from "./approval-handler.runtime.js";
|
||||
|
||||
type SlackPayload = {
|
||||
text: string;
|
||||
blocks?: unknown;
|
||||
};
|
||||
const SLACK_TEXT_LIMIT = 8000;
|
||||
|
||||
function findSlackActionsBlock(blocks: Array<{ type?: string; elements?: unknown[] }>) {
|
||||
return blocks.find((block) => block.type === "actions");
|
||||
@@ -114,6 +115,53 @@ describe("slackApprovalNativeRuntime", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("caps resolved update fallback text while preserving approval blocks", async () => {
|
||||
const blocks = [
|
||||
{
|
||||
type: "section",
|
||||
text: {
|
||||
type: "mrkdwn",
|
||||
text: "*Command*\n```short preview```",
|
||||
},
|
||||
},
|
||||
];
|
||||
const chatUpdate = vi.fn(async (_payload: { text: string; blocks: typeof blocks }) => ({}));
|
||||
|
||||
await slackApprovalNativeRuntime.transport.updateEntry?.({
|
||||
cfg: {} as never,
|
||||
accountId: "default",
|
||||
context: {
|
||||
app: {
|
||||
client: {
|
||||
chat: {
|
||||
update: chatUpdate,
|
||||
},
|
||||
},
|
||||
},
|
||||
config: {},
|
||||
} as never,
|
||||
entry: {
|
||||
channelId: "C123",
|
||||
messageTs: "1712345678.999999",
|
||||
},
|
||||
payload: {
|
||||
text: `*Exec approval: Allowed once*\n\n*Command*\n${"a".repeat(9000)}`,
|
||||
blocks,
|
||||
},
|
||||
phase: "resolved",
|
||||
});
|
||||
|
||||
expect(chatUpdate).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
channel: "C123",
|
||||
ts: "1712345678.999999",
|
||||
text: expect.stringMatching(/…$/),
|
||||
blocks,
|
||||
}),
|
||||
);
|
||||
expect(chatUpdate.mock.calls[0]?.[0].text).toHaveLength(SLACK_TEXT_LIMIT);
|
||||
});
|
||||
|
||||
it("keeps pending metadata context within Slack Block Kit limits", async () => {
|
||||
const payload = (await slackApprovalNativeRuntime.presentation.buildPendingPayload({
|
||||
cfg: {} as never,
|
||||
|
||||
@@ -17,8 +17,10 @@ import {
|
||||
shouldHandleSlackExecApprovalRequest,
|
||||
normalizeSlackApproverId,
|
||||
} from "./exec-approvals.js";
|
||||
import { SLACK_TEXT_LIMIT } from "./limits.js";
|
||||
import { resolveSlackReplyBlocks } from "./reply-blocks.js";
|
||||
import { sendMessageSlack } from "./send.js";
|
||||
import { truncateSlackText } from "./truncate.js";
|
||||
|
||||
type SlackBlock = Block | KnownBlock;
|
||||
type SlackPendingApproval = {
|
||||
@@ -229,7 +231,7 @@ async function updateMessage(params: {
|
||||
await params.app.client.chat.update({
|
||||
channel: params.channelId,
|
||||
ts: params.messageTs,
|
||||
text: params.text,
|
||||
text: truncateSlackText(params.text, SLACK_TEXT_LIMIT),
|
||||
blocks: params.blocks,
|
||||
});
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user