Files
openclaw/extensions/discord/src/monitor/native-command.options.test.ts
scoootscooob 5682ec37fa refactor: move Discord channel implementation to extensions/ (#45660)
* refactor: move Discord channel implementation to extensions/discord/src/

Move all Discord source files from src/discord/ to extensions/discord/src/,
following the extension migration pattern. Source files in src/discord/ are
replaced with re-export shims. Channel-plugin files from
src/channels/plugins/*/discord* are similarly moved and shimmed.

- Copy all .ts source files preserving subdirectory structure (monitor/, voice/)
- Move channel-plugin files (actions, normalize, onboarding, outbound, status-issues)
- Fix all relative imports to use correct paths from new location
- Create re-export shims at original locations for backward compatibility
- Delete test files from shim locations (tests live in extension now)
- Update tsconfig.plugin-sdk.dts.json rootDir from "src" to "." to accommodate
  extension files outside src/
- Update write-plugin-sdk-entry-dts.ts to match new declaration output paths

* fix: add importOriginal to thread-bindings session-meta mock for extensions test

* style: fix formatting in thread-bindings lifecycle test
2026-03-14 02:53:57 -07:00

70 lines
2.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { listNativeCommandSpecs } from "../../../../src/auto-reply/commands-registry.js";
import type { OpenClawConfig, loadConfig } from "../../../../src/config/config.js";
import { createDiscordNativeCommand } from "./native-command.js";
import { createNoopThreadBindingManager } from "./thread-bindings.js";
function createNativeCommand(name: string): ReturnType<typeof createDiscordNativeCommand> {
const command = listNativeCommandSpecs({ provider: "discord" }).find(
(entry) => entry.name === name,
);
if (!command) {
throw new Error(`missing native command: ${name}`);
}
const cfg = {} as ReturnType<typeof loadConfig>;
const discordConfig = {} as NonNullable<OpenClawConfig["channels"]>["discord"];
return createDiscordNativeCommand({
command,
cfg,
discordConfig,
accountId: "default",
sessionPrefix: "discord:slash",
ephemeralDefault: true,
threadBindings: createNoopThreadBindingManager("default"),
});
}
type CommandOption = NonNullable<ReturnType<typeof createDiscordNativeCommand>["options"]>[number];
function findOption(
command: ReturnType<typeof createDiscordNativeCommand>,
name: string,
): CommandOption | undefined {
return command.options?.find((entry) => entry.name === name);
}
function readAutocomplete(option: CommandOption | undefined): unknown {
if (!option || typeof option !== "object") {
return undefined;
}
return (option as { autocomplete?: unknown }).autocomplete;
}
function readChoices(option: CommandOption | undefined): unknown[] | undefined {
if (!option || typeof option !== "object") {
return undefined;
}
const value = (option as { choices?: unknown }).choices;
return Array.isArray(value) ? value : undefined;
}
describe("createDiscordNativeCommand option wiring", () => {
it("uses autocomplete for /acp action so inline action values are accepted", () => {
const command = createNativeCommand("acp");
const action = findOption(command, "action");
expect(action).toBeDefined();
expect(typeof readAutocomplete(action)).toBe("function");
expect(readChoices(action)).toBeUndefined();
});
it("keeps static choices for non-acp string action arguments", () => {
const command = createNativeCommand("voice");
const action = findOption(command, "action");
expect(action).toBeDefined();
expect(readAutocomplete(action)).toBeUndefined();
expect(readChoices(action)?.length).toBeGreaterThan(0);
});
});