From 05bfb7f9f9f88f8fbc22f45f326cc41e475dc568 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Feb 2026 22:33:27 +0000 Subject: [PATCH] refactor(test): reuse discord message handler base context harness --- .../monitor/message-handler.process.test.ts | 70 +------------------ 1 file changed, 2 insertions(+), 68 deletions(-) diff --git a/src/discord/monitor/message-handler.process.test.ts b/src/discord/monitor/message-handler.process.test.ts index a58618920..58dda5c73 100644 --- a/src/discord/monitor/message-handler.process.test.ts +++ b/src/discord/monitor/message-handler.process.test.ts @@ -1,7 +1,5 @@ -import fs from "node:fs/promises"; -import os from "node:os"; -import path from "node:path"; import { beforeEach, describe, expect, it, vi } from "vitest"; +import { createBaseDiscordMessageContext } from "./message-handler.test-harness.js"; const reactMessageDiscord = vi.fn(async () => {}); const removeReactionDiscord = vi.fn(async () => {}); @@ -36,71 +34,7 @@ vi.mock("../../auto-reply/reply/reply-dispatcher.js", () => ({ const { processDiscordMessage } = await import("./message-handler.process.js"); -async function createBaseContext(overrides: Record = {}) { - const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-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: [], - }, - messageChannelId: "c1", - 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", - }, - sender: { label: "user" }, - ...overrides, - }; -} +const createBaseContext = createBaseDiscordMessageContext; beforeEach(() => { vi.useRealTimers();