diff --git a/src/auto-reply/command-auth.owner-default.test.ts b/src/auto-reply/command-auth.owner-default.test.ts index 3cb6b48d3..d2f99c1a9 100644 --- a/src/auto-reply/command-auth.owner-default.test.ts +++ b/src/auto-reply/command-auth.owner-default.test.ts @@ -1,26 +1,10 @@ -import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; -import { setActivePluginRegistry } from "../plugins/runtime.js"; -import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js"; import { resolveCommandAuthorization } from "./command-auth.js"; import type { MsgContext } from "./templating.js"; +import { installDiscordRegistryHooks } from "./test-helpers/command-auth-registry-fixture.js"; -const createRegistry = () => - createTestRegistry([ - { - pluginId: "discord", - plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }), - source: "test", - }, - ]); - -beforeEach(() => { - setActivePluginRegistry(createRegistry()); -}); - -afterEach(() => { - setActivePluginRegistry(createRegistry()); -}); +installDiscordRegistryHooks(); describe("senderIsOwner only reflects explicit owner authorization", () => { it("does not treat direct-message senders as owners when no ownerAllowFrom is configured", () => { diff --git a/src/auto-reply/command-control.test.ts b/src/auto-reply/command-control.test.ts index cb829871b..9d5dc1de0 100644 --- a/src/auto-reply/command-control.test.ts +++ b/src/auto-reply/command-control.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, it } from "vitest"; +import { describe, expect, it } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; import { createOutboundTestPlugin, createTestRegistry } from "../test-utils/channel-plugins.js"; @@ -8,23 +8,9 @@ import { listChatCommands } from "./commands-registry.js"; import { parseActivationCommand } from "./group-activation.js"; import { parseSendPolicyCommand } from "./send-policy.js"; import type { MsgContext } from "./templating.js"; +import { installDiscordRegistryHooks } from "./test-helpers/command-auth-registry-fixture.js"; -const createRegistry = () => - createTestRegistry([ - { - pluginId: "discord", - plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }), - source: "test", - }, - ]); - -beforeEach(() => { - setActivePluginRegistry(createRegistry()); -}); - -afterEach(() => { - setActivePluginRegistry(createRegistry()); -}); +installDiscordRegistryHooks(); describe("resolveCommandAuthorization", () => { function resolveWhatsAppAuthorization(params: { diff --git a/src/auto-reply/test-helpers/command-auth-registry-fixture.ts b/src/auto-reply/test-helpers/command-auth-registry-fixture.ts new file mode 100644 index 000000000..31d24d976 --- /dev/null +++ b/src/auto-reply/test-helpers/command-auth-registry-fixture.ts @@ -0,0 +1,22 @@ +import { afterEach, beforeEach } from "vitest"; +import { setActivePluginRegistry } from "../../plugins/runtime.js"; +import { createOutboundTestPlugin, createTestRegistry } from "../../test-utils/channel-plugins.js"; + +export const createDiscordRegistry = () => + createTestRegistry([ + { + pluginId: "discord", + plugin: createOutboundTestPlugin({ id: "discord", outbound: { deliveryMode: "direct" } }), + source: "test", + }, + ]); + +export function installDiscordRegistryHooks() { + beforeEach(() => { + setActivePluginRegistry(createDiscordRegistry()); + }); + + afterEach(() => { + setActivePluginRegistry(createDiscordRegistry()); + }); +}