mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-21 15:01:03 +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)
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
import type { App } from "@slack/bolt";
|
|
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../../../../src/config/config.js";
|
|
import type { RuntimeEnv } from "../../../../src/runtime.js";
|
|
import { createSlackMonitorContext } from "./context.js";
|
|
|
|
function createTestContext() {
|
|
return createSlackMonitorContext({
|
|
cfg: {
|
|
channels: { slack: { enabled: true } },
|
|
session: { dmScope: "main" },
|
|
} as OpenClawConfig,
|
|
accountId: "default",
|
|
botToken: "xoxb-test",
|
|
app: { client: {} } as App,
|
|
runtime: {} as RuntimeEnv,
|
|
botUserId: "U_BOT",
|
|
teamId: "T_EXPECTED",
|
|
apiAppId: "A_EXPECTED",
|
|
historyLimit: 0,
|
|
sessionScope: "per-sender",
|
|
mainKey: "main",
|
|
dmEnabled: true,
|
|
dmPolicy: "open",
|
|
allowFrom: [],
|
|
allowNameMatching: false,
|
|
groupDmEnabled: false,
|
|
groupDmChannels: [],
|
|
defaultRequireMention: true,
|
|
groupPolicy: "allowlist",
|
|
useAccessGroups: true,
|
|
reactionMode: "off",
|
|
reactionAllowlist: [],
|
|
replyToMode: "off",
|
|
threadHistoryScope: "thread",
|
|
threadInheritParent: false,
|
|
slashCommand: {
|
|
enabled: true,
|
|
name: "openclaw",
|
|
ephemeral: true,
|
|
sessionPrefix: "slack:slash",
|
|
},
|
|
textLimit: 4000,
|
|
typingReaction: "",
|
|
ackReactionScope: "group-mentions",
|
|
mediaMaxBytes: 20 * 1024 * 1024,
|
|
removeAckAfterReply: false,
|
|
});
|
|
}
|
|
|
|
describe("createSlackMonitorContext shouldDropMismatchedSlackEvent", () => {
|
|
it("drops mismatched top-level app/team identifiers", () => {
|
|
const ctx = createTestContext();
|
|
expect(
|
|
ctx.shouldDropMismatchedSlackEvent({
|
|
api_app_id: "A_WRONG",
|
|
team_id: "T_EXPECTED",
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
ctx.shouldDropMismatchedSlackEvent({
|
|
api_app_id: "A_EXPECTED",
|
|
team_id: "T_WRONG",
|
|
}),
|
|
).toBe(true);
|
|
});
|
|
|
|
it("drops mismatched nested team.id payloads used by interaction bodies", () => {
|
|
const ctx = createTestContext();
|
|
expect(
|
|
ctx.shouldDropMismatchedSlackEvent({
|
|
api_app_id: "A_EXPECTED",
|
|
team: { id: "T_WRONG" },
|
|
}),
|
|
).toBe(true);
|
|
expect(
|
|
ctx.shouldDropMismatchedSlackEvent({
|
|
api_app_id: "A_EXPECTED",
|
|
team: { id: "T_EXPECTED" },
|
|
}),
|
|
).toBe(false);
|
|
});
|
|
});
|