fix(channels): add optional defaultAccount routing

This commit is contained in:
Peter Steinberger
2026-03-02 04:03:13 +00:00
parent 0437ac1a89
commit 41537e9303
45 changed files with 461 additions and 35 deletions

View File

@@ -1,7 +1,11 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../config/config.js";
import { withEnv } from "../test-utils/env.js";
import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js";
import {
listTelegramAccountIds,
resolveDefaultTelegramAccountId,
resolveTelegramAccount,
} from "./accounts.js";
const { warnMock } = vi.hoisted(() => ({
warnMock: vi.fn(),
@@ -100,6 +104,47 @@ describe("resolveTelegramAccount", () => {
});
});
describe("resolveDefaultTelegramAccountId", () => {
it("prefers channels.telegram.defaultAccount when it matches a configured account", () => {
const cfg: OpenClawConfig = {
channels: {
telegram: {
defaultAccount: "work",
accounts: { default: { botToken: "tok-default" }, work: { botToken: "tok-work" } },
},
},
};
expect(resolveDefaultTelegramAccountId(cfg)).toBe("work");
});
it("normalizes channels.telegram.defaultAccount before lookup", () => {
const cfg: OpenClawConfig = {
channels: {
telegram: {
defaultAccount: "Router D",
accounts: { "router-d": { botToken: "tok-work" } },
},
},
};
expect(resolveDefaultTelegramAccountId(cfg)).toBe("router-d");
});
it("falls back when channels.telegram.defaultAccount is not configured", () => {
const cfg: OpenClawConfig = {
channels: {
telegram: {
defaultAccount: "missing",
accounts: { default: { botToken: "tok-default" }, work: { botToken: "tok-work" } },
},
},
};
expect(resolveDefaultTelegramAccountId(cfg)).toBe("default");
});
});
describe("resolveTelegramAccount allowFrom precedence", () => {
it("prefers accounts.default allowlists over top-level for default account", () => {
const resolved = resolveTelegramAccount({