* 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
127 lines
3.4 KiB
TypeScript
127 lines
3.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import type { OpenClawConfig } from "../../../src/config/config.js";
|
|
import { inspectDiscordAccount } from "./account-inspect.js";
|
|
|
|
function asConfig(value: unknown): OpenClawConfig {
|
|
return value as OpenClawConfig;
|
|
}
|
|
|
|
describe("inspectDiscordAccount", () => {
|
|
it("prefers account token over channel token and strips Bot prefix", () => {
|
|
const inspected = inspectDiscordAccount({
|
|
cfg: asConfig({
|
|
channels: {
|
|
discord: {
|
|
token: "Bot channel-token",
|
|
accounts: {
|
|
work: {
|
|
token: "Bot account-token",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
accountId: "work",
|
|
});
|
|
|
|
expect(inspected.token).toBe("account-token");
|
|
expect(inspected.tokenSource).toBe("config");
|
|
expect(inspected.tokenStatus).toBe("available");
|
|
expect(inspected.configured).toBe(true);
|
|
});
|
|
|
|
it("reports configured_unavailable for unresolved configured secret input", () => {
|
|
const inspected = inspectDiscordAccount({
|
|
cfg: asConfig({
|
|
channels: {
|
|
discord: {
|
|
accounts: {
|
|
work: {
|
|
token: { source: "env", id: "DISCORD_TOKEN" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
accountId: "work",
|
|
});
|
|
|
|
expect(inspected.token).toBe("");
|
|
expect(inspected.tokenSource).toBe("config");
|
|
expect(inspected.tokenStatus).toBe("configured_unavailable");
|
|
expect(inspected.configured).toBe(true);
|
|
});
|
|
|
|
it("does not fall back when account token key exists but is missing", () => {
|
|
const inspected = inspectDiscordAccount({
|
|
cfg: asConfig({
|
|
channels: {
|
|
discord: {
|
|
token: "Bot channel-token",
|
|
accounts: {
|
|
work: {
|
|
token: "",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
accountId: "work",
|
|
});
|
|
|
|
expect(inspected.token).toBe("");
|
|
expect(inspected.tokenSource).toBe("none");
|
|
expect(inspected.tokenStatus).toBe("missing");
|
|
expect(inspected.configured).toBe(false);
|
|
});
|
|
|
|
it("falls back to channel token when account token is absent", () => {
|
|
const inspected = inspectDiscordAccount({
|
|
cfg: asConfig({
|
|
channels: {
|
|
discord: {
|
|
token: "Bot channel-token",
|
|
accounts: {
|
|
work: {},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
accountId: "work",
|
|
});
|
|
|
|
expect(inspected.token).toBe("channel-token");
|
|
expect(inspected.tokenSource).toBe("config");
|
|
expect(inspected.tokenStatus).toBe("available");
|
|
expect(inspected.configured).toBe(true);
|
|
});
|
|
|
|
it("allows env token only for default account", () => {
|
|
const defaultInspected = inspectDiscordAccount({
|
|
cfg: asConfig({}),
|
|
accountId: "default",
|
|
envToken: "Bot env-default",
|
|
});
|
|
const namedInspected = inspectDiscordAccount({
|
|
cfg: asConfig({
|
|
channels: {
|
|
discord: {
|
|
accounts: {
|
|
work: {},
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
accountId: "work",
|
|
envToken: "Bot env-work",
|
|
});
|
|
|
|
expect(defaultInspected.token).toBe("env-default");
|
|
expect(defaultInspected.tokenSource).toBe("env");
|
|
expect(defaultInspected.configured).toBe(true);
|
|
expect(namedInspected.token).toBe("");
|
|
expect(namedInspected.tokenSource).toBe("none");
|
|
expect(namedInspected.configured).toBe(false);
|
|
});
|
|
});
|