refactor(auto-reply): share discord auth registry test fixture

This commit is contained in:
Peter Steinberger
2026-03-07 17:44:05 +00:00
parent ce9719c654
commit 7eb48d3cf8
3 changed files with 28 additions and 36 deletions

View File

@@ -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", () => {

View File

@@ -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: {

View File

@@ -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());
});
}