mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 16:50:43 +00:00
fix(discord): skip disabled native command cleanup
This commit is contained in:
@@ -24,6 +24,7 @@ const {
|
||||
createThreadBindingManagerMock,
|
||||
getAcpSessionStatusMock,
|
||||
getPluginCommandSpecsMock,
|
||||
isNativeCommandsExplicitlyDisabledMock,
|
||||
isVerboseMock,
|
||||
listNativeCommandSpecsForConfigMock,
|
||||
listSkillCommandsForAgentsMock,
|
||||
@@ -992,6 +993,35 @@ describe("monitorDiscordProvider", () => {
|
||||
expect(getConstructedClientOptions().eventQueue?.listenerTimeout).toBe(120_000);
|
||||
});
|
||||
|
||||
it("skips slash-command lifecycle REST when native commands are disabled", async () => {
|
||||
const runtime = baseRuntime();
|
||||
isNativeCommandsExplicitlyDisabledMock.mockReturnValue(true);
|
||||
resolveNativeCommandsEnabledMock.mockReturnValue(false);
|
||||
resolveDiscordAccountMock.mockReturnValue({
|
||||
accountId: "default",
|
||||
token: "MTIz.abc.def",
|
||||
config: {
|
||||
applicationId: "987654321098765432",
|
||||
commands: { native: false, nativeSkills: false },
|
||||
voice: { enabled: false },
|
||||
agentComponents: { enabled: false },
|
||||
execApprovals: { enabled: false },
|
||||
},
|
||||
});
|
||||
|
||||
await monitorDiscordProvider({
|
||||
config: baseConfig(),
|
||||
runtime,
|
||||
});
|
||||
|
||||
expect(listNativeCommandSpecsForConfigMock).not.toHaveBeenCalled();
|
||||
expect(getPluginCommandSpecsMock).not.toHaveBeenCalled();
|
||||
expect(clientDeployCommandsMock).not.toHaveBeenCalled();
|
||||
expect(runtime.log).not.toHaveBeenCalledWith(
|
||||
expect.stringContaining("cleared native commands"),
|
||||
);
|
||||
});
|
||||
|
||||
it("derives application id from token before probing Discord over REST", async () => {
|
||||
const fetchApplicationId = vi.fn(async () => "network-app");
|
||||
providerTesting.setFetchDiscordApplicationId(fetchApplicationId);
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
import type { OpenClawConfig, ReplyToMode } from "openclaw/plugin-sdk/config-types";
|
||||
import { createConnectedChannelStatusPatch } from "openclaw/plugin-sdk/gateway-runtime";
|
||||
import {
|
||||
isNativeCommandsExplicitlyDisabled,
|
||||
resolveNativeCommandsEnabled,
|
||||
resolveNativeSkillsEnabled,
|
||||
} from "openclaw/plugin-sdk/native-command-config-runtime";
|
||||
@@ -52,10 +51,7 @@ import {
|
||||
formatDiscordDeployErrorDetails,
|
||||
formatDiscordDeployErrorMessage,
|
||||
} from "./provider.deploy-errors.js";
|
||||
import {
|
||||
clearDiscordNativeCommands,
|
||||
runDiscordCommandDeployInBackground,
|
||||
} from "./provider.deploy.js";
|
||||
import { runDiscordCommandDeployInBackground } from "./provider.deploy.js";
|
||||
import { createDiscordProviderInteractionSurface } from "./provider.interactions.js";
|
||||
import { runDiscordGatewayLifecycle } from "./provider.lifecycle.js";
|
||||
import { logDiscordStartupPhase as logDiscordStartupPhaseBase } from "./provider.startup-log.js";
|
||||
@@ -275,10 +271,6 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
providerSetting: discordCfg.commands?.nativeSkills,
|
||||
globalSetting: cfg.commands?.nativeSkills,
|
||||
});
|
||||
const nativeDisabledExplicit = isNativeCommandsExplicitlyDisabled({
|
||||
providerSetting: discordCfg.commands?.native,
|
||||
globalSetting: cfg.commands?.native,
|
||||
});
|
||||
const useAccessGroups = cfg.commands?.useAccessGroups !== false;
|
||||
const slashCommand = resolveDiscordSlashCommandConfig(discordCfg.slashCommand);
|
||||
const sessionPrefix = "discord:slash";
|
||||
@@ -505,28 +497,6 @@ export async function monitorDiscordProvider(opts: MonitorDiscordOpts = {}) {
|
||||
});
|
||||
let voiceManager: DiscordVoiceManager | null = null;
|
||||
|
||||
if (nativeDisabledExplicit) {
|
||||
logDiscordStartupPhase({
|
||||
runtime,
|
||||
accountId: account.accountId,
|
||||
phase: "clear-native-commands:start",
|
||||
startAt: startupStartedAt,
|
||||
gateway: lifecycleGateway,
|
||||
});
|
||||
await clearDiscordNativeCommands({
|
||||
client,
|
||||
applicationId,
|
||||
runtime,
|
||||
});
|
||||
logDiscordStartupPhase({
|
||||
runtime,
|
||||
accountId: account.accountId,
|
||||
phase: "clear-native-commands:done",
|
||||
startAt: startupStartedAt,
|
||||
gateway: lifecycleGateway,
|
||||
});
|
||||
}
|
||||
|
||||
if (voiceEnabled) {
|
||||
const { DiscordVoiceManager, DiscordVoiceReadyListener, DiscordVoiceResumedListener } =
|
||||
await loadDiscordVoiceRuntime();
|
||||
|
||||
@@ -58,6 +58,7 @@ type ProviderMonitorTestMocks = {
|
||||
(params?: { cfg?: unknown; accountId?: string | null; token?: string | null }) => unknown
|
||||
>;
|
||||
resolveDiscordAllowlistConfigMock: Mock<() => Promise<unknown>>;
|
||||
isNativeCommandsExplicitlyDisabledMock: Mock<(params?: unknown) => boolean>;
|
||||
resolveNativeCommandsEnabledMock: Mock<(params?: unknown) => boolean>;
|
||||
resolveNativeSkillsEnabledMock: Mock<(params?: unknown) => boolean>;
|
||||
isVerboseMock: Mock<() => boolean>;
|
||||
@@ -150,6 +151,7 @@ const providerMonitorTestMocks: ProviderMonitorTestMocks = vi.hoisted(() => {
|
||||
guildEntries: undefined,
|
||||
allowFrom: undefined,
|
||||
})),
|
||||
isNativeCommandsExplicitlyDisabledMock: vi.fn((_params) => false),
|
||||
resolveNativeCommandsEnabledMock: vi.fn((_params) => true),
|
||||
resolveNativeSkillsEnabledMock: vi.fn((_params) => false),
|
||||
isVerboseMock,
|
||||
@@ -183,6 +185,7 @@ const {
|
||||
monitorLifecycleMock,
|
||||
resolveDiscordAccountMock,
|
||||
resolveDiscordAllowlistConfigMock,
|
||||
isNativeCommandsExplicitlyDisabledMock,
|
||||
resolveNativeCommandsEnabledMock,
|
||||
resolveNativeSkillsEnabledMock,
|
||||
isVerboseMock,
|
||||
@@ -259,6 +262,7 @@ export function resetDiscordProviderMonitorMocks(params?: {
|
||||
guildEntries: undefined,
|
||||
allowFrom: undefined,
|
||||
});
|
||||
isNativeCommandsExplicitlyDisabledMock.mockClear().mockReturnValue(false);
|
||||
resolveNativeCommandsEnabledMock.mockClear().mockReturnValue(true);
|
||||
resolveNativeSkillsEnabledMock.mockClear().mockReturnValue(false);
|
||||
isVerboseMock.mockClear().mockReturnValue(false);
|
||||
@@ -387,7 +391,7 @@ vi.mock("openclaw/plugin-sdk/native-command-config-runtime", async () => {
|
||||
>("openclaw/plugin-sdk/native-command-config-runtime");
|
||||
return {
|
||||
...actual,
|
||||
isNativeCommandsExplicitlyDisabled: () => false,
|
||||
isNativeCommandsExplicitlyDisabled: isNativeCommandsExplicitlyDisabledMock,
|
||||
resolveNativeCommandsEnabled: resolveNativeCommandsEnabledMock,
|
||||
resolveNativeSkillsEnabled: resolveNativeSkillsEnabledMock,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user