mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-20 14:30:57 +00:00
Move all Slack channel implementation files from src/slack/ to extensions/slack/src/ and replace originals with shim re-exports. This follows the extension migration pattern for channel plugins. - Copy all .ts files to extensions/slack/src/ (preserving directory structure: monitor/, http/, monitor/events/, monitor/message-handler/) - Transform import paths: external src/ imports use relative paths back to src/, internal slack imports stay relative within extension - Replace all src/slack/ files with shim re-exports pointing to the extension copies - Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." so the DTS build can follow shim chains into extensions/ - Update write-plugin-sdk-entry-dts.ts re-export path accordingly - Preserve extensions/slack/index.ts, package.json, openclaw.plugin.json, src/channel.ts, src/runtime.ts, src/channel.test.ts (untouched)
176 lines
5.5 KiB
TypeScript
176 lines
5.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createSlackSendTestClient, installSlackBlockTestMocks } from "./blocks.test-helpers.js";
|
|
|
|
installSlackBlockTestMocks();
|
|
const { sendMessageSlack } = await import("./send.js");
|
|
|
|
describe("sendMessageSlack NO_REPLY guard", () => {
|
|
it("suppresses NO_REPLY text before any Slack API call", async () => {
|
|
const client = createSlackSendTestClient();
|
|
const result = await sendMessageSlack("channel:C123", "NO_REPLY", {
|
|
token: "xoxb-test",
|
|
client,
|
|
});
|
|
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
expect(result.messageId).toBe("suppressed");
|
|
});
|
|
|
|
it("suppresses NO_REPLY with surrounding whitespace", async () => {
|
|
const client = createSlackSendTestClient();
|
|
const result = await sendMessageSlack("channel:C123", " NO_REPLY ", {
|
|
token: "xoxb-test",
|
|
client,
|
|
});
|
|
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
expect(result.messageId).toBe("suppressed");
|
|
});
|
|
|
|
it("does not suppress substantive text containing NO_REPLY", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await sendMessageSlack("channel:C123", "This is not a NO_REPLY situation", {
|
|
token: "xoxb-test",
|
|
client,
|
|
});
|
|
|
|
expect(client.chat.postMessage).toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not suppress NO_REPLY when blocks are attached", async () => {
|
|
const client = createSlackSendTestClient();
|
|
const result = await sendMessageSlack("channel:C123", "NO_REPLY", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [{ type: "section", text: { type: "mrkdwn", text: "content" } }],
|
|
});
|
|
|
|
expect(client.chat.postMessage).toHaveBeenCalled();
|
|
expect(result.messageId).toBe("171234.567");
|
|
});
|
|
});
|
|
|
|
describe("sendMessageSlack blocks", () => {
|
|
it("posts blocks with fallback text when message is empty", async () => {
|
|
const client = createSlackSendTestClient();
|
|
const result = await sendMessageSlack("channel:C123", "", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [{ type: "divider" }],
|
|
});
|
|
|
|
expect(client.conversations.open).not.toHaveBeenCalled();
|
|
expect(client.chat.postMessage).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
channel: "C123",
|
|
text: "Shared a Block Kit message",
|
|
blocks: [{ type: "divider" }],
|
|
}),
|
|
);
|
|
expect(result).toEqual({ messageId: "171234.567", channelId: "C123" });
|
|
});
|
|
|
|
it("derives fallback text from image blocks", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await sendMessageSlack("channel:C123", "", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [{ type: "image", image_url: "https://example.com/a.png", alt_text: "Build chart" }],
|
|
});
|
|
|
|
expect(client.chat.postMessage).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
text: "Build chart",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("derives fallback text from video blocks", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await sendMessageSlack("channel:C123", "", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [
|
|
{
|
|
type: "video",
|
|
title: { type: "plain_text", text: "Release demo" },
|
|
video_url: "https://example.com/demo.mp4",
|
|
thumbnail_url: "https://example.com/thumb.jpg",
|
|
alt_text: "demo",
|
|
},
|
|
],
|
|
});
|
|
|
|
expect(client.chat.postMessage).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
text: "Release demo",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("derives fallback text from file blocks", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await sendMessageSlack("channel:C123", "", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [{ type: "file", source: "remote", external_id: "F123" }],
|
|
});
|
|
|
|
expect(client.chat.postMessage).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
text: "Shared a file",
|
|
}),
|
|
);
|
|
});
|
|
|
|
it("rejects blocks combined with mediaUrl", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await expect(
|
|
sendMessageSlack("channel:C123", "hi", {
|
|
token: "xoxb-test",
|
|
client,
|
|
mediaUrl: "https://example.com/image.png",
|
|
blocks: [{ type: "divider" }],
|
|
}),
|
|
).rejects.toThrow(/does not support blocks with mediaUrl/i);
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects empty blocks arrays from runtime callers", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await expect(
|
|
sendMessageSlack("channel:C123", "hi", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [],
|
|
}),
|
|
).rejects.toThrow(/must contain at least one block/i);
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects blocks arrays above Slack max count", async () => {
|
|
const client = createSlackSendTestClient();
|
|
const blocks = Array.from({ length: 51 }, () => ({ type: "divider" }));
|
|
await expect(
|
|
sendMessageSlack("channel:C123", "hi", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks,
|
|
}),
|
|
).rejects.toThrow(/cannot exceed 50 items/i);
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("rejects blocks missing type from runtime callers", async () => {
|
|
const client = createSlackSendTestClient();
|
|
await expect(
|
|
sendMessageSlack("channel:C123", "hi", {
|
|
token: "xoxb-test",
|
|
client,
|
|
blocks: [{} as { type: string }],
|
|
}),
|
|
).rejects.toThrow(/non-empty string type/i);
|
|
expect(client.chat.postMessage).not.toHaveBeenCalled();
|
|
});
|
|
});
|