test: remove remaining account helper boilerplate

This commit is contained in:
Peter Steinberger 2026-03-22 20:32:37 +00:00
parent 8eb881ef18
commit 822c68a2d0
5 changed files with 20 additions and 10 deletions

View File

@ -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<typeof resolveBlueBubblesAccount>[0]["cfg"],

View File

@ -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
? {

View File

@ -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,
},

View File

@ -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: {

View File

@ -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,