From b4a5b12422c7a90054dbb7473dd6c4b3e9ca8df5 Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Sat, 21 Feb 2026 17:39:58 -0500 Subject: [PATCH] test(telegram): cover debug account log formatting --- src/telegram/accounts.test.ts | 39 +++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/telegram/accounts.test.ts b/src/telegram/accounts.test.ts index e488d27c20b..c254ced27c0 100644 --- a/src/telegram/accounts.test.ts +++ b/src/telegram/accounts.test.ts @@ -1,9 +1,27 @@ -import { describe, expect, it } from "vitest"; +import { afterEach, describe, expect, it, vi } from "vitest"; import type { OpenClawConfig } from "../config/config.js"; import { withEnv } from "../test-utils/env.js"; -import { resolveTelegramAccount } from "./accounts.js"; +import { listTelegramAccountIds, resolveTelegramAccount } from "./accounts.js"; + +const { warnMock } = vi.hoisted(() => ({ + warnMock: vi.fn(), +})); + +vi.mock("../logging/subsystem.js", () => ({ + createSubsystemLogger: () => { + const logger = { + warn: warnMock, + child: () => logger, + }; + return logger; + }, +})); describe("resolveTelegramAccount", () => { + afterEach(() => { + warnMock.mockReset(); + }); + it("falls back to the first configured account when accountId is omitted", () => { withEnv({ TELEGRAM_BOT_TOKEN: "" }, () => { const cfg: OpenClawConfig = { @@ -63,4 +81,21 @@ describe("resolveTelegramAccount", () => { expect(account.token).toBe(""); }); }); + + it("formats debug logs with inspect-style output when debug env is enabled", () => { + withEnv({ TELEGRAM_BOT_TOKEN: "", OPENCLAW_DEBUG_TELEGRAM_ACCOUNTS: "1" }, () => { + const cfg: OpenClawConfig = { + channels: { + telegram: { accounts: { work: { botToken: "tok-work" } } }, + }, + }; + + expect(listTelegramAccountIds(cfg)).toEqual(["work"]); + resolveTelegramAccount({ cfg, accountId: "work" }); + }); + + const lines = warnMock.mock.calls.map(([line]) => String(line)); + expect(lines).toContain("listTelegramAccountIds [ 'work' ]"); + expect(lines).toContain("resolve { accountId: 'work', enabled: true, tokenSource: 'config' }"); + }); });