mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 04:11:35 +00:00
fix(discord): autoThread ack reactions + exec approval null handling (#1511)
* fix(discord): gate autoThread by thread owner * fix(discord): ack bot-owned autoThreads * fix(discord): ack mentions in open channels - Ack reactions in bot-owned autoThreads - Ack reactions in open channels (no mention required) - DRY: Pass pre-computed isAutoThreadOwnedByBot to avoid redundant checks - Consolidate ack logic with explanatory comment * fix: allow null values in exec.approval.request schema The ExecApprovalRequestParamsSchema was rejecting null values for optional fields like resolvedPath, but the calling code in bash-tools.exec.ts passes null. This caused intermittent 'invalid exec.approval.request params' validation errors. Fix: Accept Type.Union([Type.String(), Type.Null()]) for all optional string fields in the schema. Update test to reflect new behavior. * fix: align discord ack reactions with mention gating (#1511) (thanks @pvoo) --------- Co-authored-by: Wimmie <wimmie@tameson.com> Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
committed by
GitHub
parent
242add587f
commit
7d0a0ae3ba
123
src/discord/monitor/message-handler.process.test.ts
Normal file
123
src/discord/monitor/message-handler.process.test.ts
Normal file
@@ -0,0 +1,123 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const reactMessageDiscord = vi.fn(async () => {});
|
||||
const removeReactionDiscord = vi.fn(async () => {});
|
||||
|
||||
vi.mock("../send.js", () => ({
|
||||
reactMessageDiscord: (...args: unknown[]) => reactMessageDiscord(...args),
|
||||
removeReactionDiscord: (...args: unknown[]) => removeReactionDiscord(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../../auto-reply/reply/dispatch-from-config.js", () => ({
|
||||
dispatchReplyFromConfig: vi.fn(async () => ({
|
||||
queuedFinal: false,
|
||||
counts: { final: 0, tool: 0, block: 0 },
|
||||
})),
|
||||
}));
|
||||
|
||||
vi.mock("../../auto-reply/reply/reply-dispatcher.js", () => ({
|
||||
createReplyDispatcherWithTyping: vi.fn(() => ({
|
||||
dispatcher: {},
|
||||
replyOptions: {},
|
||||
markDispatchIdle: vi.fn(),
|
||||
})),
|
||||
}));
|
||||
|
||||
import { processDiscordMessage } from "./message-handler.process.js";
|
||||
|
||||
async function createBaseContext(overrides: Record<string, unknown> = {}) {
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "clawdbot-discord-"));
|
||||
const storePath = path.join(dir, "sessions.json");
|
||||
return {
|
||||
cfg: { messages: { ackReaction: "👀" }, session: { store: storePath } },
|
||||
discordConfig: {},
|
||||
accountId: "default",
|
||||
token: "token",
|
||||
runtime: { log: () => {}, error: () => {} },
|
||||
guildHistories: new Map(),
|
||||
historyLimit: 0,
|
||||
mediaMaxBytes: 1024,
|
||||
textLimit: 4000,
|
||||
replyToMode: "off",
|
||||
ackReactionScope: "group-mentions",
|
||||
groupPolicy: "open",
|
||||
data: { guild: { id: "g1", name: "Guild" } },
|
||||
client: { rest: {} },
|
||||
message: {
|
||||
id: "m1",
|
||||
channelId: "c1",
|
||||
timestamp: new Date().toISOString(),
|
||||
attachments: [],
|
||||
},
|
||||
author: {
|
||||
id: "U1",
|
||||
username: "alice",
|
||||
discriminator: "0",
|
||||
globalName: "Alice",
|
||||
},
|
||||
channelInfo: { name: "general" },
|
||||
channelName: "general",
|
||||
isGuildMessage: true,
|
||||
isDirectMessage: false,
|
||||
isGroupDm: false,
|
||||
commandAuthorized: true,
|
||||
baseText: "hi",
|
||||
messageText: "hi",
|
||||
wasMentioned: false,
|
||||
shouldRequireMention: true,
|
||||
canDetectMention: true,
|
||||
effectiveWasMentioned: true,
|
||||
shouldBypassMention: false,
|
||||
threadChannel: null,
|
||||
threadParentId: undefined,
|
||||
threadParentName: undefined,
|
||||
threadParentType: undefined,
|
||||
threadName: undefined,
|
||||
displayChannelSlug: "general",
|
||||
guildInfo: null,
|
||||
guildSlug: "guild",
|
||||
channelConfig: null,
|
||||
baseSessionKey: "agent:main:discord:guild:g1",
|
||||
route: {
|
||||
agentId: "main",
|
||||
channel: "discord",
|
||||
accountId: "default",
|
||||
sessionKey: "agent:main:discord:guild:g1",
|
||||
mainSessionKey: "agent:main:main",
|
||||
},
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
reactMessageDiscord.mockClear();
|
||||
removeReactionDiscord.mockClear();
|
||||
});
|
||||
|
||||
describe("processDiscordMessage ack reactions", () => {
|
||||
it("skips ack reactions for group-mentions when mentions are not required", async () => {
|
||||
const ctx = await createBaseContext({
|
||||
shouldRequireMention: false,
|
||||
effectiveWasMentioned: false,
|
||||
});
|
||||
|
||||
await processDiscordMessage(ctx as any);
|
||||
|
||||
expect(reactMessageDiscord).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sends ack reactions for mention-gated guild messages when mentioned", async () => {
|
||||
const ctx = await createBaseContext({
|
||||
shouldRequireMention: true,
|
||||
effectiveWasMentioned: true,
|
||||
});
|
||||
|
||||
await processDiscordMessage(ctx as any);
|
||||
|
||||
expect(reactMessageDiscord).toHaveBeenCalledWith("c1", "m1", "👀", { rest: {} });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user