Vendor OpenClaw source as Adolf fork baseline
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Some checks failed
ClawSweeper Dispatch / dispatch (push) Has been cancelled
CodeQL / Security High (actions) (push) Has been cancelled
CodeQL / Security High (channel-runtime-boundary) (push) Has been cancelled
CodeQL / Security High (core-auth-secrets) (push) Has been cancelled
CodeQL / Security High (mcp-process-tool-boundary) (push) Has been cancelled
CodeQL / Security High (network-ssrf-boundary) (push) Has been cancelled
CodeQL / Security High (plugin-trust-boundary) (push) Has been cancelled
CodeQL / Security High (process-exec-boundary) (push) Has been cancelled
Docs Sync Publish Repo / sync-publish-repo (push) Has been cancelled
Docs / docs (push) Has been cancelled
OpenClaw Stable Main Closeout / Resolve stable release closeout inputs (push) Has been cancelled
OpenClaw Stable Main Closeout / Verify stable main closeout (push) Has been cancelled
Workflow Sanity / no-tabs (push) Has been cancelled
Workflow Sanity / actionlint (push) Has been cancelled
Workflow Sanity / generated-doc-baselines (push) Has been cancelled
CI / runner-admission (push) Has been cancelled
CI / preflight (push) Has been cancelled
CI / security-fast (push) Has been cancelled
CI / pnpm-store-warmup (push) Has been cancelled
CI / build-artifacts (push) Has been cancelled
CI / native-i18n (push) Has been cancelled
CI / ${{ matrix.check_name }} (push) Has been cancelled
CI / ${{ matrix.checkName }} (push) Has been cancelled
CI / checks-node-compat-node22 (push) Has been cancelled
CI / check-bundled-channel-config-metadata (push) Has been cancelled
CI / check-dependencies (push) Has been cancelled
CI / check-guards (push) Has been cancelled
CI / check-lint (push) Has been cancelled
CI / check-prod-types (push) Has been cancelled
CI / check-shrinkwrap (push) Has been cancelled
CI / check-test-types (push) Has been cancelled
CI / check-additional-boundaries-a (push) Has been cancelled
CI / check-additional-boundaries-bcd (push) Has been cancelled
CI / check-additional-extension-bundled (push) Has been cancelled
CI / check-additional-extension-channels (push) Has been cancelled
CI / check-additional-extension-package-boundary (push) Has been cancelled
CI / check-additional-runtime-topology-architecture (push) Has been cancelled
CI / check-session-accessor-boundary (push) Has been cancelled
CI / check-session-transcript-reader-boundary (push) Has been cancelled
CI / check-docs (push) Has been cancelled
CI / skills-python (push) Has been cancelled
CI / macos-swift (push) Has been cancelled
CI / ios-build (push) Has been cancelled
CI / ci-timings-summary (push) Has been cancelled
Native App Locale Refresh / Refresh native fa (push) Has been cancelled
Native App Locale Refresh / Refresh native fr (push) Has been cancelled
Native App Locale Refresh / Refresh native hi (push) Has been cancelled
Native App Locale Refresh / Refresh native id (push) Has been cancelled
Native App Locale Refresh / Refresh native it (push) Has been cancelled
Native App Locale Refresh / Refresh native ja-JP (push) Has been cancelled
Control UI Locale Refresh / plan (push) Has been cancelled
Control UI Locale Refresh / Refresh ${{ matrix.locale }} (push) Has been cancelled
Control UI Locale Refresh / Commit control UI locale refresh (push) Has been cancelled
Live Media Runner Image / Build live media runner image (push) Has been cancelled
Native App Locale Refresh / Refresh native ar (push) Has been cancelled
Native App Locale Refresh / Refresh native de (push) Has been cancelled
Native App Locale Refresh / Refresh native es (push) Has been cancelled
Native App Locale Refresh / Refresh native ko (push) Has been cancelled
Native App Locale Refresh / Refresh native nl (push) Has been cancelled
Native App Locale Refresh / Refresh native pl (push) Has been cancelled
Native App Locale Refresh / Refresh native pt-BR (push) Has been cancelled
Native App Locale Refresh / Refresh native ru (push) Has been cancelled
Native App Locale Refresh / Refresh native sv (push) Has been cancelled
Native App Locale Refresh / Refresh native th (push) Has been cancelled
Native App Locale Refresh / Refresh native tr (push) Has been cancelled
Native App Locale Refresh / Refresh native uk (push) Has been cancelled
Native App Locale Refresh / Refresh native vi (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-CN (push) Has been cancelled
Native App Locale Refresh / Refresh native zh-TW (push) Has been cancelled
Native App Locale Refresh / Commit native locale refresh (push) Has been cancelled
Plugin Init Scaffold Validation / Validate provider scaffold (push) Has been cancelled
Plugin NPM Release / preview_plugins_npm (push) Has been cancelled
Plugin NPM Release / Validate release publish approval (push) Has been cancelled
Plugin NPM Release / preview_plugin_pack (push) Has been cancelled
Plugin NPM Release / publish_plugins_npm (push) Has been cancelled
Sandbox Common Smoke / sandbox-common-smoke (push) Has been cancelled
Website Installer Sync / static (push) Has been cancelled
Website Installer Sync / linux-docker (push) Has been cancelled
Website Installer Sync / macos-installer (push) Has been cancelled
Website Installer Sync / windows-installer (push) Has been cancelled
Website Installer Sync / sync-website (push) Has been cancelled
Adolf is a fork/vendored clone of github.com/openclaw/openclaw (v2026.6.11), free to diverge. Tree copied sans upstream .git; upstream remote added for future syncs. Node pinned to 24 (.nvmrc); engines already require >=22.19. Preserves docs/ARCHITECTURE.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LeqyaxJF2nbRXJtae2kNB2
This commit is contained in:
888
extensions/slack/src/monitor.tool-result.test.ts
Normal file
888
extensions/slack/src/monitor.tool-result.test.ts
Normal file
@@ -0,0 +1,888 @@
|
||||
// Slack tests cover monitor.tool result plugin behavior.
|
||||
import { CURRENT_MESSAGE_MARKER } from "openclaw/plugin-sdk/channel-mention-gating";
|
||||
import { expectPairingReplyText } from "openclaw/plugin-sdk/channel-test-helpers";
|
||||
import { HISTORY_CONTEXT_MARKER } from "openclaw/plugin-sdk/reply-history";
|
||||
import { resetInboundDedupe } from "openclaw/plugin-sdk/reply-runtime";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
defaultSlackTestConfig,
|
||||
getSlackTestState,
|
||||
getSlackHandlerOrThrow,
|
||||
getSlackClient,
|
||||
getSlackHandlers,
|
||||
flush,
|
||||
resetSlackTestState,
|
||||
runSlackMessageOnce,
|
||||
startSlackMonitor,
|
||||
stopSlackMonitor,
|
||||
} from "./monitor.test-helpers.js";
|
||||
|
||||
const { monitorSlackProvider } = await import("./monitor/provider.js");
|
||||
|
||||
const slackTestState = getSlackTestState();
|
||||
const { sendMock, replyMock, reactMock, reactionAddMock, upsertPairingRequestMock } =
|
||||
slackTestState;
|
||||
|
||||
beforeEach(() => {
|
||||
resetInboundDedupe();
|
||||
resetSlackTestState(defaultSlackTestConfig());
|
||||
});
|
||||
|
||||
describe("monitorSlackProvider tool results", () => {
|
||||
type SlackMessageEvent = {
|
||||
type: "message";
|
||||
user: string;
|
||||
text: string;
|
||||
ts: string;
|
||||
channel: string;
|
||||
channel_type: "im" | "channel";
|
||||
thread_ts?: string;
|
||||
parent_user_id?: string;
|
||||
};
|
||||
|
||||
const baseSlackMessageEvent = Object.freeze({
|
||||
type: "message",
|
||||
user: "U1",
|
||||
text: "hello",
|
||||
ts: "123",
|
||||
channel: "C1",
|
||||
channel_type: "im",
|
||||
}) as SlackMessageEvent;
|
||||
|
||||
function makeSlackMessageEvent(overrides: Partial<SlackMessageEvent> = {}): SlackMessageEvent {
|
||||
return { ...baseSlackMessageEvent, ...overrides };
|
||||
}
|
||||
|
||||
function setDirectMessageReplyMode(replyToMode: "off" | "all" | "first") {
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
replyToMode,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function firstMockCall(mock: ReturnType<typeof vi.fn>, label: string): unknown[] {
|
||||
const [call] = mock.mock.calls;
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
function firstMockArg(mock: ReturnType<typeof vi.fn>, label: string, argIndex: number): unknown {
|
||||
return firstMockCall(mock, label)[argIndex];
|
||||
}
|
||||
|
||||
function firstMockRecordArg(
|
||||
mock: ReturnType<typeof vi.fn>,
|
||||
label: string,
|
||||
argIndex: number,
|
||||
): Record<string, unknown> {
|
||||
const value = firstMockArg(mock, label, argIndex);
|
||||
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
||||
throw new Error(`expected ${label} argument ${argIndex + 1} to be an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function firstReplyCtx(): { WasMentioned?: boolean } {
|
||||
return firstMockRecordArg(replyMock, "reply", 0) as { WasMentioned?: boolean };
|
||||
}
|
||||
|
||||
function setRequireMentionChannelConfig(mentionPatterns?: string[]) {
|
||||
slackTestState.config = {
|
||||
...(mentionPatterns
|
||||
? {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
groupChat: { mentionPatterns },
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
channels: { C1: { allow: true, requireMention: true } },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function runDirectMessageEvent(ts: string, extraEvent: Record<string, unknown> = {}) {
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({ ts, ...extraEvent }),
|
||||
});
|
||||
}
|
||||
|
||||
async function runChannelThreadReplyEvent() {
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text: "thread reply",
|
||||
ts: "123.456",
|
||||
thread_ts: "111.222",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
async function runChannelMessageEvent(
|
||||
text: string,
|
||||
overrides: Partial<SlackMessageEvent> = {},
|
||||
): Promise<void> {
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text,
|
||||
channel_type: "channel",
|
||||
...overrides,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
function setHistoryCaptureConfig(channels: Record<string, unknown>) {
|
||||
slackTestState.config = {
|
||||
messages: { ackReactionScope: "group-mentions" },
|
||||
channels: {
|
||||
slack: {
|
||||
historyLimit: 5,
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
channels,
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function captureReplyContexts<T extends Record<string, unknown>>() {
|
||||
const contexts: T[] = [];
|
||||
replyMock.mockImplementation(async (ctx: unknown) => {
|
||||
contexts.push((ctx ?? {}) as T);
|
||||
return undefined;
|
||||
});
|
||||
return contexts;
|
||||
}
|
||||
|
||||
async function runMonitoredSlackMessages(events: SlackMessageEvent[]) {
|
||||
const { controller, run } = startSlackMonitor(monitorSlackProvider);
|
||||
const handler = await getSlackHandlerOrThrow("message");
|
||||
for (const event of events) {
|
||||
await handler({ event });
|
||||
}
|
||||
await stopSlackMonitor({ controller, run });
|
||||
}
|
||||
|
||||
function setPairingOnlyDirectMessages() {
|
||||
const currentConfig = slackTestState.config as {
|
||||
channels?: { slack?: Record<string, unknown> };
|
||||
};
|
||||
slackTestState.config = {
|
||||
...currentConfig,
|
||||
channels: {
|
||||
...currentConfig.channels,
|
||||
slack: {
|
||||
...currentConfig.channels?.slack,
|
||||
dm: { enabled: true, policy: "pairing", allowFrom: [] },
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function setOpenChannelDirectMessages(params?: {
|
||||
bindings?: Array<Record<string, unknown>>;
|
||||
groupPolicy?: "open";
|
||||
includeAckReactionConfig?: boolean;
|
||||
replyToMode?: "off" | "all" | "first";
|
||||
threadInheritParent?: boolean;
|
||||
visibleReplies?: "automatic" | "message_tool";
|
||||
}) {
|
||||
const slackChannelConfig: Record<string, unknown> = {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
channels: { C1: { allow: true, requireMention: false } },
|
||||
...(params?.groupPolicy ? { groupPolicy: params.groupPolicy } : {}),
|
||||
...(params?.replyToMode ? { replyToMode: params.replyToMode } : {}),
|
||||
...(params?.threadInheritParent ? { thread: { inheritParent: true } } : {}),
|
||||
};
|
||||
slackTestState.config = {
|
||||
messages: params?.includeAckReactionConfig
|
||||
? {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
...(params.visibleReplies
|
||||
? { groupChat: { visibleReplies: params.visibleReplies } }
|
||||
: {}),
|
||||
}
|
||||
: {
|
||||
responsePrefix: "PFX",
|
||||
...(params?.visibleReplies
|
||||
? { groupChat: { visibleReplies: params.visibleReplies } }
|
||||
: {}),
|
||||
},
|
||||
channels: { slack: slackChannelConfig },
|
||||
...(params?.bindings ? { bindings: params.bindings } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
function getFirstReplySessionCtx(): {
|
||||
SessionKey?: string;
|
||||
ParentSessionKey?: string;
|
||||
ThreadStarterBody?: string;
|
||||
ThreadLabel?: string;
|
||||
} {
|
||||
return firstMockRecordArg(replyMock, "reply", 0) as {
|
||||
SessionKey?: string;
|
||||
ParentSessionKey?: string;
|
||||
ThreadStarterBody?: string;
|
||||
ThreadLabel?: string;
|
||||
};
|
||||
}
|
||||
|
||||
function expectSingleSendWithThread(threadTs: string | undefined) {
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstMockRecordArg(sendMock, "send", 2).threadTs).toBe(threadTs);
|
||||
}
|
||||
|
||||
function setMentionGatedAckConfig(statusReactionsEnabled: boolean) {
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
groupChat: { visibleReplies: "automatic" },
|
||||
removeAckAfterReply: true,
|
||||
statusReactions: statusReactionsEnabled
|
||||
? { enabled: true, timing: { debounceMs: 0, doneHoldMs: 0, errorHoldMs: 0 } }
|
||||
: { enabled: false },
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
groupPolicy: "open",
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function mockGeneralChannelInfo() {
|
||||
const client = getSlackClient();
|
||||
if (!client) {
|
||||
throw new Error("Slack client not registered");
|
||||
}
|
||||
const conversations = client.conversations as {
|
||||
info: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
conversations.info.mockResolvedValueOnce({
|
||||
channel: { name: "general", is_channel: true },
|
||||
});
|
||||
}
|
||||
|
||||
async function runMentionGatedChannelMessageAndFlush() {
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text: "<@bot-user> hello",
|
||||
ts: "456",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
await flush();
|
||||
}
|
||||
|
||||
function expectReactionFlow(expected: {
|
||||
startsWith: string[];
|
||||
endsWith: string;
|
||||
includes: string;
|
||||
}) {
|
||||
const names = reactionAddMock.mock.calls.map(([args]) => (args as { name: string }).name);
|
||||
expect(names.slice(0, expected.startsWith.length)).toEqual(expected.startsWith);
|
||||
expect(names).toContain(expected.includes);
|
||||
expect(names.at(-1)).toBe(expected.endsWith);
|
||||
}
|
||||
|
||||
async function runDefaultMessageAndExpectSentText(expectedText: string) {
|
||||
replyMock.mockResolvedValue({ text: expectedText.replace(/^PFX /, "") });
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent(),
|
||||
});
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstMockArg(sendMock, "send", 1)).toBe(expectedText);
|
||||
}
|
||||
|
||||
it("skips socket startup when Slack channel is disabled", async () => {
|
||||
slackTestState.config = {
|
||||
channels: {
|
||||
slack: {
|
||||
enabled: false,
|
||||
mode: "socket",
|
||||
botToken: "xoxb-config",
|
||||
appToken: "xapp-config",
|
||||
},
|
||||
},
|
||||
};
|
||||
const client = getSlackClient();
|
||||
if (!client) {
|
||||
throw new Error("Slack client not registered");
|
||||
}
|
||||
client.auth.test.mockClear();
|
||||
|
||||
const { controller, run } = startSlackMonitor(monitorSlackProvider);
|
||||
await flush();
|
||||
controller.abort();
|
||||
await run;
|
||||
|
||||
expect(client.auth.test).not.toHaveBeenCalled();
|
||||
expect(getSlackHandlers()?.size ?? 0).toBe(0);
|
||||
});
|
||||
|
||||
it("skips tool summaries with responsePrefix", async () => {
|
||||
await runDefaultMessageAndExpectSentText("PFX final reply");
|
||||
});
|
||||
|
||||
it("drops events with mismatched api_app_id", async () => {
|
||||
const client = getSlackClient();
|
||||
if (!client) {
|
||||
throw new Error("Slack client not registered");
|
||||
}
|
||||
(client.auth as { test: ReturnType<typeof vi.fn> }).test.mockResolvedValue({
|
||||
user_id: "bot-user",
|
||||
team_id: "T1",
|
||||
api_app_id: "A1",
|
||||
});
|
||||
|
||||
await runSlackMessageOnce(
|
||||
monitorSlackProvider,
|
||||
{
|
||||
body: { api_app_id: "A2", team_id: "T1" },
|
||||
event: makeSlackMessageEvent(),
|
||||
},
|
||||
{ appToken: "xapp-1-A1-abc" },
|
||||
);
|
||||
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expect(replyMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("includes recent channel history in Body when requireMention is false", async () => {
|
||||
setHistoryCaptureConfig({ "*": { requireMention: false } });
|
||||
const capturedCtx = captureReplyContexts<{
|
||||
Body?: string;
|
||||
RawBody?: string;
|
||||
CommandBody?: string;
|
||||
}>();
|
||||
await runMonitoredSlackMessages([
|
||||
makeSlackMessageEvent({ user: "U1", text: "first", ts: "123", channel_type: "channel" }),
|
||||
makeSlackMessageEvent({ user: "U2", text: "second", ts: "124", channel_type: "channel" }),
|
||||
]);
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(2);
|
||||
const latestCtx = capturedCtx.at(-1) ?? {};
|
||||
expect(latestCtx.Body).toContain(HISTORY_CONTEXT_MARKER);
|
||||
expect(latestCtx.Body).toContain("first");
|
||||
expect(latestCtx.Body).toContain(CURRENT_MESSAGE_MARKER);
|
||||
expect(latestCtx.RawBody).toBe("second");
|
||||
expect(latestCtx.CommandBody).toBe("second");
|
||||
});
|
||||
|
||||
it("scopes thread history to the thread by default", async () => {
|
||||
setHistoryCaptureConfig({ C1: { allow: true, requireMention: true } });
|
||||
const capturedCtx = captureReplyContexts<{ Body?: string }>();
|
||||
await runMonitoredSlackMessages([
|
||||
makeSlackMessageEvent({
|
||||
user: "U1",
|
||||
text: "thread-a-one",
|
||||
ts: "200",
|
||||
thread_ts: "100",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
makeSlackMessageEvent({
|
||||
user: "U1",
|
||||
text: "<@bot-user> thread-a-two",
|
||||
ts: "201",
|
||||
thread_ts: "100",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
makeSlackMessageEvent({
|
||||
user: "U2",
|
||||
text: "<@bot-user> thread-b-one",
|
||||
ts: "301",
|
||||
thread_ts: "300",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
]);
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(2);
|
||||
expect(capturedCtx[0]?.Body).toContain("thread-a-one");
|
||||
expect(capturedCtx[1]?.Body).not.toContain("thread-a-one");
|
||||
expect(capturedCtx[1]?.Body).not.toContain("thread-a-two");
|
||||
});
|
||||
|
||||
it("updates assistant thread status when replies start", async () => {
|
||||
replyMock.mockImplementation(async (...args: unknown[]) => {
|
||||
const opts = (args[1] ?? {}) as { onReplyStart?: () => Promise<void> | void };
|
||||
await opts?.onReplyStart?.();
|
||||
return { text: "final reply" };
|
||||
});
|
||||
|
||||
setDirectMessageReplyMode("all");
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent(),
|
||||
});
|
||||
|
||||
const client = getSlackClient() as {
|
||||
assistant?: { threads?: { setStatus?: ReturnType<typeof vi.fn> } };
|
||||
};
|
||||
const setStatus = client.assistant?.threads?.setStatus;
|
||||
expect(setStatus).toHaveBeenCalledTimes(2);
|
||||
expect(setStatus).toHaveBeenNthCalledWith(1, {
|
||||
token: "bot-token",
|
||||
channel_id: "C1",
|
||||
thread_ts: "123",
|
||||
status: "is typing...",
|
||||
loading_messages: [
|
||||
"Reading the thread...",
|
||||
"Checking context...",
|
||||
"Working through the request...",
|
||||
"Putting it all together...",
|
||||
],
|
||||
});
|
||||
expect(setStatus).toHaveBeenNthCalledWith(2, {
|
||||
token: "bot-token",
|
||||
channel_id: "C1",
|
||||
thread_ts: "123",
|
||||
status: "",
|
||||
});
|
||||
});
|
||||
|
||||
async function expectMentionPatternMessageAccepted(text: string): Promise<void> {
|
||||
setRequireMentionChannelConfig(["\\bopenclaw\\b"]);
|
||||
replyMock.mockResolvedValue({ text: "hi" });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text,
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstReplyCtx().WasMentioned).toBe(true);
|
||||
}
|
||||
|
||||
it("accepts channel messages when mentionPatterns match", async () => {
|
||||
await expectMentionPatternMessageAccepted("openclaw: hello");
|
||||
});
|
||||
|
||||
it("accepts channel messages when mentionPatterns match even if another user is mentioned", async () => {
|
||||
await expectMentionPatternMessageAccepted("openclaw: hello <@U2>");
|
||||
});
|
||||
|
||||
it("treats replies to bot threads as implicit mentions", async () => {
|
||||
setRequireMentionChannelConfig();
|
||||
replyMock.mockResolvedValue({ text: "hi" });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text: "following up",
|
||||
ts: "124",
|
||||
thread_ts: "123",
|
||||
parent_user_id: "bot-user",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstReplyCtx().WasMentioned).toBe(true);
|
||||
});
|
||||
|
||||
it("accepts channel messages without mention when channels.slack.requireMention is false", async () => {
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
groupChat: { visibleReplies: "automatic" },
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
groupPolicy: "open",
|
||||
requireMention: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
replyMock.mockResolvedValue({ text: "hi" });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstReplyCtx().WasMentioned).toBe(false);
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("keeps always-on channel messages private when group visible replies use message_tool", async () => {
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "all",
|
||||
groupChat: { visibleReplies: "message_tool" },
|
||||
statusReactions: {
|
||||
enabled: true,
|
||||
timing: { debounceMs: 0, doneHoldMs: 0, errorHoldMs: 0 },
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
groupPolicy: "open",
|
||||
requireMention: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
replyMock.mockResolvedValue({ text: "quiet" });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
await flush();
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expect(reactMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("treats control commands as mentions for group bypass", async () => {
|
||||
replyMock.mockResolvedValue({ text: "ok" });
|
||||
await runChannelMessageEvent("/elevated off");
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(firstReplyCtx().WasMentioned).toBe(true);
|
||||
});
|
||||
|
||||
it("threads replies when incoming message is in a thread", async () => {
|
||||
replyMock.mockResolvedValue({ text: "thread reply" });
|
||||
setOpenChannelDirectMessages({
|
||||
includeAckReactionConfig: true,
|
||||
groupPolicy: "open",
|
||||
replyToMode: "off",
|
||||
visibleReplies: "automatic",
|
||||
});
|
||||
await runChannelThreadReplyEvent();
|
||||
|
||||
expectSingleSendWithThread("111.222");
|
||||
});
|
||||
|
||||
it("ignores replyToId directive when replyToMode is off", async () => {
|
||||
replyMock.mockResolvedValue({ text: "forced reply", replyToId: "555" });
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dmPolicy: "open",
|
||||
allowFrom: ["*"],
|
||||
dm: { enabled: true },
|
||||
replyToMode: "off",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
ts: "789",
|
||||
}),
|
||||
});
|
||||
|
||||
expectSingleSendWithThread(undefined);
|
||||
});
|
||||
|
||||
it("keeps replyToId directive threading when replyToMode is all", async () => {
|
||||
replyMock.mockResolvedValue({ text: "forced reply", replyToId: "555" });
|
||||
setDirectMessageReplyMode("all");
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
ts: "789",
|
||||
}),
|
||||
});
|
||||
|
||||
expectSingleSendWithThread("555");
|
||||
});
|
||||
|
||||
it("reacts to mention-gated room messages when ackReaction is enabled", async () => {
|
||||
replyMock.mockResolvedValue(undefined);
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
groupChat: { visibleReplies: "automatic" },
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
groupPolicy: "open",
|
||||
},
|
||||
},
|
||||
};
|
||||
const client = getSlackClient();
|
||||
if (!client) {
|
||||
throw new Error("Slack client not registered");
|
||||
}
|
||||
const conversations = client.conversations as {
|
||||
info: ReturnType<typeof vi.fn>;
|
||||
};
|
||||
conversations.info.mockResolvedValueOnce({
|
||||
channel: { name: "general", is_channel: true },
|
||||
});
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
text: "<@bot-user> hello",
|
||||
ts: "456",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(reactMock).toHaveBeenCalledWith({
|
||||
channel: "C1",
|
||||
timestamp: "456",
|
||||
name: "eyes",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps ack reaction when no reply is delivered and status reactions are disabled", async () => {
|
||||
replyMock.mockResolvedValue(undefined);
|
||||
setMentionGatedAckConfig(false);
|
||||
mockGeneralChannelInfo();
|
||||
await runMentionGatedChannelMessageAndFlush();
|
||||
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expect(reactMock).toHaveBeenCalledTimes(1);
|
||||
expect(reactMock).toHaveBeenCalledWith({
|
||||
channel: "C1",
|
||||
timestamp: "456",
|
||||
name: "👀",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps ack reaction when no reply is delivered and status reactions are enabled", async () => {
|
||||
replyMock.mockResolvedValue(undefined);
|
||||
setMentionGatedAckConfig(true);
|
||||
mockGeneralChannelInfo();
|
||||
await runMentionGatedChannelMessageAndFlush();
|
||||
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expect(reactMock).toHaveBeenCalledTimes(1);
|
||||
expect(reactMock).toHaveBeenCalledWith({
|
||||
channel: "C1",
|
||||
timestamp: "456",
|
||||
name: "eyes",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps status reactions for mentioned message-tool-only channel turns", async () => {
|
||||
replyMock.mockResolvedValue({ text: "quiet default reply" });
|
||||
slackTestState.config = {
|
||||
messages: {
|
||||
responsePrefix: "PFX",
|
||||
ackReaction: "👀",
|
||||
ackReactionScope: "group-mentions",
|
||||
groupChat: { visibleReplies: "message_tool" },
|
||||
statusReactions: {
|
||||
enabled: true,
|
||||
timing: { debounceMs: 0, doneHoldMs: 0, errorHoldMs: 0 },
|
||||
},
|
||||
},
|
||||
channels: {
|
||||
slack: {
|
||||
dm: { enabled: true, policy: "open", allowFrom: ["*"] },
|
||||
groupPolicy: "open",
|
||||
},
|
||||
},
|
||||
};
|
||||
mockGeneralChannelInfo();
|
||||
|
||||
await runMentionGatedChannelMessageAndFlush();
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expect(reactMock).toHaveBeenCalledWith({
|
||||
channel: "C1",
|
||||
timestamp: "456",
|
||||
name: "eyes",
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps the error reaction when dispatch fails before any reply is delivered", async () => {
|
||||
replyMock.mockRejectedValue(new Error("boom"));
|
||||
setMentionGatedAckConfig(true);
|
||||
mockGeneralChannelInfo();
|
||||
await runMentionGatedChannelMessageAndFlush();
|
||||
|
||||
expect(sendMock).not.toHaveBeenCalled();
|
||||
expectReactionFlow({
|
||||
startsWith: ["eyes", "x"],
|
||||
includes: "x",
|
||||
endsWith: "x",
|
||||
});
|
||||
});
|
||||
|
||||
it("replies with pairing code when dmPolicy is pairing and no allowFrom is set", async () => {
|
||||
setPairingOnlyDirectMessages();
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent(),
|
||||
});
|
||||
|
||||
expect(replyMock).not.toHaveBeenCalled();
|
||||
expect(upsertPairingRequestMock).toHaveBeenCalled();
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
const sentText = firstMockArg(sendMock, "send", 1);
|
||||
expectPairingReplyText(typeof sentText === "string" ? sentText : "", {
|
||||
channel: "slack",
|
||||
idLine: "Your Slack user id: U1",
|
||||
code: "PAIRCODE",
|
||||
});
|
||||
});
|
||||
|
||||
it("does not resend pairing code when a request is already pending", async () => {
|
||||
setPairingOnlyDirectMessages();
|
||||
upsertPairingRequestMock
|
||||
.mockResolvedValueOnce({ code: "PAIRCODE", created: true })
|
||||
.mockResolvedValueOnce({ code: "PAIRCODE", created: false });
|
||||
|
||||
const { controller, run } = startSlackMonitor(monitorSlackProvider);
|
||||
const handler = await getSlackHandlerOrThrow("message");
|
||||
|
||||
const baseEvent = makeSlackMessageEvent();
|
||||
|
||||
await handler({ event: baseEvent });
|
||||
await handler({ event: { ...baseEvent, ts: "124", text: "hello again" } });
|
||||
|
||||
await stopSlackMonitor({ controller, run });
|
||||
|
||||
expect(sendMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("threads top-level replies when replyToMode is all", async () => {
|
||||
replyMock.mockResolvedValue({ text: "thread reply" });
|
||||
setDirectMessageReplyMode("all");
|
||||
await runDirectMessageEvent("123");
|
||||
|
||||
expectSingleSendWithThread("123");
|
||||
});
|
||||
|
||||
it("treats parent_user_id as a thread reply even when thread_ts matches ts", async () => {
|
||||
replyMock.mockResolvedValue({ text: "thread reply" });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
thread_ts: "123",
|
||||
parent_user_id: "U2",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
const ctx = getFirstReplySessionCtx();
|
||||
expect(ctx.SessionKey).toBe("agent:main:main");
|
||||
expect(ctx.ParentSessionKey).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps thread parent inheritance opt-in", async () => {
|
||||
replyMock.mockResolvedValue({ text: "thread reply" });
|
||||
setOpenChannelDirectMessages({ threadInheritParent: true });
|
||||
|
||||
await runSlackMessageOnce(monitorSlackProvider, {
|
||||
event: makeSlackMessageEvent({
|
||||
thread_ts: "111.222",
|
||||
channel_type: "channel",
|
||||
}),
|
||||
});
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
const ctx = getFirstReplySessionCtx();
|
||||
expect(ctx.SessionKey).toBe("agent:main:slack:channel:c1:thread:111.222");
|
||||
expect(ctx.ParentSessionKey).toBe("agent:main:slack:channel:c1");
|
||||
});
|
||||
|
||||
it("injects starter context for thread replies", async () => {
|
||||
replyMock.mockResolvedValue({ text: "ok" });
|
||||
|
||||
const client = getSlackClient();
|
||||
if (client?.conversations?.info) {
|
||||
client.conversations.info.mockResolvedValue({
|
||||
channel: { name: "general", is_channel: true },
|
||||
});
|
||||
}
|
||||
if (client?.conversations?.replies) {
|
||||
client.conversations.replies.mockResolvedValue({
|
||||
messages: [{ text: "starter message", user: "U2", ts: "111.222" }],
|
||||
});
|
||||
}
|
||||
|
||||
setOpenChannelDirectMessages();
|
||||
|
||||
await runChannelThreadReplyEvent();
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
const ctx = getFirstReplySessionCtx();
|
||||
expect(ctx.SessionKey).toBe("agent:main:slack:channel:c1:thread:111.222");
|
||||
expect(ctx.ParentSessionKey).toBeUndefined();
|
||||
expect(ctx.ThreadStarterBody).toContain("starter message");
|
||||
expect(ctx.ThreadLabel).toContain("Slack thread #general");
|
||||
});
|
||||
|
||||
it("scopes thread session keys to the routed agent", async () => {
|
||||
replyMock.mockResolvedValue({ text: "ok" });
|
||||
setOpenChannelDirectMessages({
|
||||
bindings: [{ agentId: "support", match: { channel: "slack", teamId: "T1" } }],
|
||||
});
|
||||
|
||||
const client = getSlackClient();
|
||||
if (client?.auth?.test) {
|
||||
client.auth.test.mockResolvedValue({
|
||||
user_id: "bot-user",
|
||||
team_id: "T1",
|
||||
});
|
||||
}
|
||||
if (client?.conversations?.info) {
|
||||
client.conversations.info.mockResolvedValue({
|
||||
channel: { name: "general", is_channel: true },
|
||||
});
|
||||
}
|
||||
|
||||
await runChannelThreadReplyEvent();
|
||||
|
||||
expect(replyMock).toHaveBeenCalledTimes(1);
|
||||
const ctx = getFirstReplySessionCtx();
|
||||
expect(ctx.SessionKey).toBe("agent:support:slack:channel:c1:thread:111.222");
|
||||
expect(ctx.ParentSessionKey).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps replies in channel root when message is not threaded (replyToMode off)", async () => {
|
||||
replyMock.mockResolvedValue({ text: "root reply" });
|
||||
setDirectMessageReplyMode("off");
|
||||
await runDirectMessageEvent("789");
|
||||
|
||||
expectSingleSendWithThread(undefined);
|
||||
});
|
||||
|
||||
it("threads first reply when replyToMode is first and message is not threaded", async () => {
|
||||
replyMock.mockResolvedValue({ text: "first reply" });
|
||||
setDirectMessageReplyMode("first");
|
||||
await runDirectMessageEvent("789");
|
||||
|
||||
expectSingleSendWithThread("789");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user