

























@@ -1,3 +1,8 @@
1+import type { OpenClawConfig } from "openclaw/plugin-sdk/config-types";
2+import {
3+clearRuntimeConfigSnapshot,
4+setRuntimeConfigSnapshot,
5+} from "openclaw/plugin-sdk/runtime-config-snapshot";
16import { afterEach, describe, expect, it, vi } from "vitest";
27import {
38createDiscordActionGate,
@@ -9,6 +14,7 @@ import {
914} from "./accounts.js";
10151116afterEach(() => {
17+clearRuntimeConfigSnapshot();
1218vi.unstubAllEnvs();
1319});
1420@@ -245,3 +251,60 @@ describe("Discord duplicate-token account filtering", () => {
245251expect(listEnabledDiscordAccounts(cfg).map((account) => account.accountId)).toEqual(["active"]);
246252});
247253});
254+255+describe("resolveDiscordAccount runtime config selection", () => {
256+it("resolves named account SecretRefs from the active runtime snapshot", () => {
257+const sourceCfg = {
258+channels: {
259+discord: {
260+defaultAccount: "work",
261+accounts: {
262+work: {
263+name: "Work",
264+token: { source: "env", provider: "default", id: "DISCORD_WORK_TOKEN" },
265+},
266+},
267+},
268+},
269+} as unknown as OpenClawConfig;
270+const runtimeCfg = {
271+channels: {
272+discord: {
273+defaultAccount: "work",
274+accounts: {
275+work: {
276+name: "Work",
277+token: "Bot runtime-work-token",
278+},
279+},
280+},
281+},
282+} as OpenClawConfig;
283+setRuntimeConfigSnapshot(runtimeCfg, sourceCfg);
284+285+const resolved = resolveDiscordAccount({ cfg: sourceCfg });
286+287+expect(resolved.accountId).toBe("work");
288+expect(resolved.token).toBe("runtime-work-token");
289+expect(resolved.tokenSource).toBe("config");
290+expect(resolved.tokenStatus).toBe("available");
291+});
292+293+it("preserves configured unavailable tokens without falling through to env", () => {
294+vi.stubEnv("DISCORD_BOT_TOKEN", "env-token");
295+const resolved = resolveDiscordAccount({
296+cfg: {
297+channels: {
298+discord: {
299+token: { source: "env", provider: "default", id: "DISCORD_BOT_TOKEN" },
300+},
301+},
302+} as unknown as OpenClawConfig,
303+accountId: "default",
304+});
305+306+expect(resolved.token).toBe("");
307+expect(resolved.tokenSource).toBe("config");
308+expect(resolved.tokenStatus).toBe("configured_unavailable");
309+});
310+});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。