mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-28 08:52:45 +00:00
Discord: stabilize provider registry coverage
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import {
|
||||
createAccountActionGate,
|
||||
createAccountListHelpers,
|
||||
normalizeAccountId,
|
||||
resolveAccountEntry,
|
||||
} from "openclaw/plugin-sdk/account-helpers";
|
||||
import { normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
import { resolveAccountEntry } from "openclaw/plugin-sdk/routing";
|
||||
import {
|
||||
type OpenClawConfig,
|
||||
type DiscordAccountConfig,
|
||||
type DiscordActionConfig,
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
vi.mock("./send.js", () => ({
|
||||
addRoleDiscord: vi.fn(),
|
||||
fetchChannelPermissionsDiscord: vi.fn(),
|
||||
}));
|
||||
vi.mock("./send.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("./send.js")>();
|
||||
return {
|
||||
...actual,
|
||||
addRoleDiscord: vi.fn(),
|
||||
fetchChannelPermissionsDiscord: vi.fn(),
|
||||
};
|
||||
});
|
||||
|
||||
describe("discord audit", () => {
|
||||
it("collects numeric channel ids and counts unresolved keys", async () => {
|
||||
|
||||
@@ -67,11 +67,15 @@ const configSessionsMocks = vi.hoisted(() => ({
|
||||
const readSessionUpdatedAt = configSessionsMocks.readSessionUpdatedAt;
|
||||
const resolveStorePath = configSessionsMocks.resolveStorePath;
|
||||
|
||||
vi.mock("../send.js", () => ({
|
||||
addRoleDiscord: vi.fn(),
|
||||
reactMessageDiscord: sendMocks.reactMessageDiscord,
|
||||
removeReactionDiscord: sendMocks.removeReactionDiscord,
|
||||
}));
|
||||
vi.mock("../send.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../send.js")>();
|
||||
return {
|
||||
...actual,
|
||||
addRoleDiscord: vi.fn(),
|
||||
reactMessageDiscord: sendMocks.reactMessageDiscord,
|
||||
removeReactionDiscord: sendMocks.removeReactionDiscord,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../send.messages.js", () => ({
|
||||
editMessageDiscord: deliveryMocks.editMessageDiscord,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { clearPluginCommands, registerPluginCommand } from "../../../../src/plugins/commands.js";
|
||||
import {
|
||||
baseConfig,
|
||||
baseRuntime,
|
||||
getProviderMonitorTestMocks,
|
||||
resetDiscordProviderMonitorMocks,
|
||||
} from "../../../../test/helpers/extensions/discord-provider.test-support.js";
|
||||
|
||||
const { createDiscordNativeCommandMock, clientHandleDeployRequestMock, monitorLifecycleMock } =
|
||||
getProviderMonitorTestMocks();
|
||||
|
||||
describe("monitorDiscordProvider real plugin registry", () => {
|
||||
beforeEach(() => {
|
||||
clearPluginCommands();
|
||||
resetDiscordProviderMonitorMocks({
|
||||
nativeCommands: [{ name: "status", description: "Status", acceptsArgs: false }],
|
||||
});
|
||||
});
|
||||
|
||||
it("registers plugin commands from the real registry as native Discord commands", async () => {
|
||||
expect(
|
||||
registerPluginCommand("demo-plugin", {
|
||||
name: "pair",
|
||||
description: "Pair device",
|
||||
acceptsArgs: true,
|
||||
requireAuth: false,
|
||||
handler: async ({ args }) => ({ text: `paired:${args ?? ""}` }),
|
||||
}),
|
||||
).toEqual({ ok: true });
|
||||
|
||||
const { monitorDiscordProvider } = await import("./provider.js");
|
||||
|
||||
await monitorDiscordProvider({
|
||||
config: baseConfig(),
|
||||
runtime: baseRuntime(),
|
||||
});
|
||||
|
||||
const commandNames = (createDiscordNativeCommandMock.mock.calls as Array<unknown[]>)
|
||||
.map((call) => (call[0] as { command?: { name?: string } } | undefined)?.command?.name)
|
||||
.filter((value): value is string => typeof value === "string");
|
||||
|
||||
expect(commandNames).toContain("status");
|
||||
expect(commandNames).toContain("pair");
|
||||
expect(clientHandleDeployRequestMock).toHaveBeenCalledTimes(1);
|
||||
expect(monitorLifecycleMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
@@ -468,6 +468,43 @@ describe("monitorDiscordProvider", () => {
|
||||
expect(commandNames).toContain("cron_jobs");
|
||||
});
|
||||
|
||||
it("registers plugin commands from the real registry as native Discord commands", async () => {
|
||||
const { clearPluginCommands, getPluginCommandSpecs, registerPluginCommand } =
|
||||
await import("../../../../src/plugins/commands.js");
|
||||
clearPluginCommands();
|
||||
const { monitorDiscordProvider } = await import("./provider.js");
|
||||
listNativeCommandSpecsForConfigMock.mockReturnValue([
|
||||
{ name: "status", description: "Status", acceptsArgs: false },
|
||||
]);
|
||||
getPluginCommandSpecsMock.mockImplementation((provider?: string) =>
|
||||
getPluginCommandSpecs(provider),
|
||||
);
|
||||
|
||||
expect(
|
||||
registerPluginCommand("demo-plugin", {
|
||||
name: "pair",
|
||||
description: "Pair device",
|
||||
acceptsArgs: true,
|
||||
requireAuth: false,
|
||||
handler: async ({ args }) => ({ text: `paired:${args ?? ""}` }),
|
||||
}),
|
||||
).toEqual({ ok: true });
|
||||
|
||||
await monitorDiscordProvider({
|
||||
config: baseConfig(),
|
||||
runtime: baseRuntime(),
|
||||
});
|
||||
|
||||
const commandNames = (createDiscordNativeCommandMock.mock.calls as Array<unknown[]>)
|
||||
.map((call) => (call[0] as { command?: { name?: string } } | undefined)?.command?.name)
|
||||
.filter((value): value is string => typeof value === "string");
|
||||
|
||||
expect(commandNames).toContain("status");
|
||||
expect(commandNames).toContain("pair");
|
||||
expect(clientHandleDeployRequestMock).toHaveBeenCalledTimes(1);
|
||||
expect(monitorLifecycleMock).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it("continues startup when Discord daily slash-command create quota is exhausted", async () => {
|
||||
const { RateLimitError } = await import("@buape/carbon");
|
||||
const { monitorDiscordProvider } = await import("./provider.js");
|
||||
|
||||
@@ -24,11 +24,15 @@ vi.mock("../client.js", () => ({
|
||||
createDiscordRestClient: hoisted.createDiscordRestClient,
|
||||
}));
|
||||
|
||||
vi.mock("../send.js", () => ({
|
||||
addRoleDiscord: vi.fn(),
|
||||
sendMessageDiscord: (...args: unknown[]) => hoisted.sendMessageDiscord(...args),
|
||||
sendWebhookMessageDiscord: (...args: unknown[]) => hoisted.sendWebhookMessageDiscord(...args),
|
||||
}));
|
||||
vi.mock("../send.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../send.js")>();
|
||||
return {
|
||||
...actual,
|
||||
addRoleDiscord: vi.fn(),
|
||||
sendMessageDiscord: (...args: unknown[]) => hoisted.sendMessageDiscord(...args),
|
||||
sendWebhookMessageDiscord: (...args: unknown[]) => hoisted.sendWebhookMessageDiscord(...args),
|
||||
};
|
||||
});
|
||||
|
||||
const { maybeSendBindingMessage, resolveChannelIdForBinding } =
|
||||
await import("./thread-bindings.discord-api.js");
|
||||
|
||||
@@ -41,11 +41,15 @@ const hoisted = vi.hoisted(() => {
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../send.js", () => ({
|
||||
addRoleDiscord: vi.fn(),
|
||||
sendMessageDiscord: hoisted.sendMessageDiscord,
|
||||
sendWebhookMessageDiscord: hoisted.sendWebhookMessageDiscord,
|
||||
}));
|
||||
vi.mock("../send.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../send.js")>();
|
||||
return {
|
||||
...actual,
|
||||
addRoleDiscord: vi.fn(),
|
||||
sendMessageDiscord: hoisted.sendMessageDiscord,
|
||||
sendWebhookMessageDiscord: hoisted.sendWebhookMessageDiscord,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("../send.messages.js", () => ({
|
||||
createThreadDiscord: hoisted.createThreadDiscord,
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
export {
|
||||
buildComputedAccountStatusSnapshot,
|
||||
buildTokenChannelStatusSummary,
|
||||
listDiscordDirectoryGroupsFromConfig,
|
||||
listDiscordDirectoryPeersFromConfig,
|
||||
PAIRING_APPROVED_MESSAGE,
|
||||
projectCredentialSnapshotFields,
|
||||
resolveConfiguredFromCredentialStatuses,
|
||||
} from "openclaw/plugin-sdk/discord";
|
||||
} from "openclaw/plugin-sdk/channel-runtime";
|
||||
export {
|
||||
buildChannelConfigSchema,
|
||||
getChatChannelMeta,
|
||||
@@ -37,10 +35,9 @@ export {
|
||||
export {
|
||||
createAccountActionGate,
|
||||
createAccountListHelpers,
|
||||
DEFAULT_ACCOUNT_ID,
|
||||
normalizeAccountId,
|
||||
resolveAccountEntry,
|
||||
} from "openclaw/plugin-sdk/account-resolution";
|
||||
} from "openclaw/plugin-sdk/account-helpers";
|
||||
export { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "openclaw/plugin-sdk/account-id";
|
||||
export { resolveAccountEntry } from "openclaw/plugin-sdk/routing";
|
||||
export type {
|
||||
ChannelMessageActionAdapter,
|
||||
ChannelMessageActionName,
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { RateLimitError } from "@buape/carbon";
|
||||
import { ChannelType, Routes } from "discord-api-types/v10";
|
||||
import { loadWebMediaRaw } from "openclaw/plugin-sdk/web-media";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
addRoleDiscord,
|
||||
@@ -18,7 +19,7 @@ import {
|
||||
} from "./send.js";
|
||||
import { makeDiscordRest } from "./send.test-harness.js";
|
||||
|
||||
vi.mock("../../whatsapp/src/media.js", async () => {
|
||||
vi.mock("openclaw/plugin-sdk/web-media", async () => {
|
||||
const { discordWebMediaMockFactory } = await import("./send.test-harness.js");
|
||||
return discordWebMediaMockFactory();
|
||||
});
|
||||
@@ -288,6 +289,7 @@ describe("uploadEmojiDiscord", () => {
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(loadWebMediaRaw).toHaveBeenCalledWith("file:///tmp/party.png", 256 * 1024);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -325,6 +327,7 @@ describe("uploadStickerDiscord", () => {
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(loadWebMediaRaw).toHaveBeenCalledWith("file:///tmp/wave.png", 512 * 1024);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { ChannelType, PermissionFlagsBits, Routes } from "discord-api-types/v10";
|
||||
import { loadWebMedia } from "openclaw/plugin-sdk/web-media";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { loadWebMedia } from "../../whatsapp/src/media.js";
|
||||
import {
|
||||
__resetDiscordDirectoryCacheForTest,
|
||||
rememberDiscordDirectoryUser,
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
} from "./send.js";
|
||||
import { makeDiscordRest } from "./send.test-harness.js";
|
||||
|
||||
vi.mock("../../whatsapp/src/media.js", async () => {
|
||||
vi.mock("openclaw/plugin-sdk/web-media", async () => {
|
||||
const { discordWebMediaMockFactory } = await import("./send.test-harness.js");
|
||||
return discordWebMediaMockFactory();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user