diff --git a/extensions/bluebubbles/src/setup-surface.test.ts b/extensions/bluebubbles/src/setup-surface.test.ts index 3e39e7dfb79..e2d78cb0a1f 100644 --- a/extensions/bluebubbles/src/setup-surface.test.ts +++ b/extensions/bluebubbles/src/setup-surface.test.ts @@ -1,3 +1,4 @@ +import { adaptScopedAccountAccessor } from "openclaw/plugin-sdk/channel-config-helpers"; import { describe, expect, it, vi } from "vitest"; import { DEFAULT_ACCOUNT_ID } from "../../../src/routing/session-key.js"; import { @@ -23,7 +24,7 @@ async function createBlueBubblesConfigureAdapter() { config: { listAccountIds: () => [DEFAULT_ACCOUNT_ID], defaultAccountId: () => DEFAULT_ACCOUNT_ID, - resolveAccount: (cfg, accountId) => resolveBlueBubblesAccount({ cfg, accountId }), + resolveAccount: adaptScopedAccountAccessor(resolveBlueBubblesAccount), resolveAllowFrom: ({ cfg, accountId }: { cfg: unknown; accountId: string }) => resolveBlueBubblesAccount({ cfg: cfg as Parameters[0]["cfg"], diff --git a/src/commands/channels.status.command-flow.test.ts b/src/commands/channels.status.command-flow.test.ts index 85347c56bf9..29363b2f2a9 100644 --- a/src/commands/channels.status.command-flow.test.ts +++ b/src/commands/channels.status.command-flow.test.ts @@ -1,4 +1,7 @@ import { beforeEach, describe, expect, it, vi } from "vitest"; +import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js"; + +const resolveDefaultAccountId = () => DEFAULT_ACCOUNT_ID; const callGateway = vi.fn(); const resolveCommandSecretRefsViaGateway = vi.fn(); @@ -51,7 +54,7 @@ function createTokenOnlyPlugin() { capabilities: { chatTypes: ["direct"] }, config: { listAccountIds: () => ["default"], - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, inspectAccount: (cfg: { secretResolved?: boolean }) => cfg.secretResolved ? { diff --git a/src/commands/channels/capabilities.test.ts b/src/commands/channels/capabilities.test.ts index 6752924b9a5..01d8eea6a22 100644 --- a/src/commands/channels/capabilities.test.ts +++ b/src/commands/channels/capabilities.test.ts @@ -3,10 +3,12 @@ process.env.NO_COLOR = "1"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { getChannelPlugin, listChannelPlugins } from "../../channels/plugins/index.js"; import type { ChannelPlugin } from "../../channels/plugins/types.js"; +import { DEFAULT_ACCOUNT_ID } from "../../routing/session-key.js"; import { channelsCapabilitiesCommand } from "./capabilities.js"; const logs: string[] = []; const errors: string[] = []; +const resolveDefaultAccountId = () => DEFAULT_ACCOUNT_ID; const mocks = vi.hoisted(() => ({ writeConfigFile: vi.fn(), resolveInstallableChannelPlugin: vi.fn(), @@ -74,7 +76,7 @@ function buildPlugin(params: { config: { listAccountIds: () => ["default"], resolveAccount: () => params.account ?? { accountId: "default" }, - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, isConfigured: () => true, isEnabled: () => true, }, diff --git a/src/commands/health.snapshot.test.ts b/src/commands/health.snapshot.test.ts index 24653eb187c..610dd1388c7 100644 --- a/src/commands/health.snapshot.test.ts +++ b/src/commands/health.snapshot.test.ts @@ -11,6 +11,7 @@ import { listTelegramAccountIds, resolveTelegramAccount, } from "../../extensions/telegram/src/accounts.js"; +import { adaptScopedAccountAccessor } from "../plugin-sdk/channel-config-helpers.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; import { createChannelTestPluginBase, createTestRegistry } from "../test-utils/channel-plugins.js"; import type { HealthSummary } from "./health.js"; @@ -124,7 +125,7 @@ const telegramHealthPlugin: Pick< ...createChannelTestPluginBase({ id: "telegram", label: "Telegram" }), config: { listAccountIds: (cfg) => listTelegramAccountIds(cfg), - resolveAccount: (cfg, accountId) => resolveTelegramAccount({ cfg, accountId }), + resolveAccount: adaptScopedAccountAccessor(resolveTelegramAccount), isConfigured: (account) => Boolean(account.token?.trim()), }, status: { diff --git a/src/plugin-sdk/channel-config-helpers.test.ts b/src/plugin-sdk/channel-config-helpers.test.ts index 0a63f2ad105..1fba887407d 100644 --- a/src/plugin-sdk/channel-config-helpers.test.ts +++ b/src/plugin-sdk/channel-config-helpers.test.ts @@ -1,4 +1,5 @@ import { describe, expect, it } from "vitest"; +import { DEFAULT_ACCOUNT_ID } from "../routing/session-key.js"; import { adaptScopedAccountAccessor, createScopedAccountConfigAccessors, @@ -13,6 +14,8 @@ import { resolveOptionalConfigString, } from "./channel-config-helpers.js"; +const resolveDefaultAccountId = () => DEFAULT_ACCOUNT_ID; + describe("mapAllowFromEntries", () => { it("coerces allowFrom entries to strings", () => { expect(mapAllowFromEntries(["user", 42])).toEqual(["user", "42"]); @@ -114,7 +117,7 @@ describe("createScopedChannelConfigBase", () => { sectionKey: "demo", listAccountIds: () => ["default", "alt"], resolveAccount: (_cfg, accountId) => ({ accountId: accountId ?? "default" }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: ["token"], }); @@ -147,7 +150,7 @@ describe("createScopedChannelConfigBase", () => { sectionKey: "demo", listAccountIds: () => ["default", "alt"], resolveAccount: (_cfg, accountId) => ({ accountId: accountId ?? "default" }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: [], allowTopLevel: false, }); @@ -201,7 +204,7 @@ describe("createScopedChannelConfigAdapter", () => { allowFrom: accountId ? [accountId] : ["fallback"], defaultTo: " room:123 ", }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: ["token"], resolveAllowFrom: (account) => account.allowFrom, formatAllowFrom: (allowFrom) => allowFrom.map((entry) => String(entry).toUpperCase()), @@ -369,7 +372,7 @@ describe("createHybridChannelConfigBase", () => { sectionKey: "demo", listAccountIds: () => ["default", "alt"], resolveAccount: (_cfg, accountId) => ({ accountId: accountId ?? "default" }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: ["token"], }); @@ -411,7 +414,7 @@ describe("createHybridChannelConfigBase", () => { sectionKey: "demo", listAccountIds: () => ["default", "alt"], resolveAccount: (_cfg, accountId) => ({ accountId: accountId ?? "default" }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: ["token", "name"], preserveSectionOnDefaultDelete: true, }); @@ -455,7 +458,7 @@ describe("createHybridChannelConfigAdapter", () => { allowFrom: [accountId ?? "default"], defaultTo: " room:123 ", }), - defaultAccountId: () => "default", + defaultAccountId: resolveDefaultAccountId, clearBaseFields: ["token"], preserveSectionOnDefaultDelete: true, resolveAllowFrom: (account) => account.allowFrom,