Files
openclaw/src/commands/doctor-config-flow.missing-default-account-bindings.integration.test.ts
Sid 4ffe15c6b2 fix(telegram): warn when accounts.default is missing in multi-account setup (#32544)
Merged via squash.

Prepared head SHA: 7ebc3f65b2
Co-authored-by: Sid-Qin <201593046+Sid-Qin@users.noreply.github.com>
Co-authored-by: gumadeiras <5599352+gumadeiras@users.noreply.github.com>
Reviewed-by: @gumadeiras
2026-03-03 03:27:19 -05:00

123 lines
3.2 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { note } from "../terminal/note.js";
import { withEnvAsync } from "../test-utils/env.js";
import { runDoctorConfigWithInput } from "./doctor-config-flow.test-utils.js";
vi.mock("../terminal/note.js", () => ({
note: vi.fn(),
}));
vi.mock("./doctor-legacy-config.js", async (importOriginal) => {
const actual = await importOriginal<typeof import("./doctor-legacy-config.js")>();
return {
...actual,
normalizeCompatibilityConfigValues: (cfg: unknown) => ({
config: cfg,
changes: [],
}),
};
});
import { loadAndMaybeMigrateDoctorConfig } from "./doctor-config-flow.js";
const noteSpy = vi.mocked(note);
describe("doctor missing default account binding warning", () => {
beforeEach(() => {
noteSpy.mockClear();
});
it("emits a doctor warning when named accounts have no valid account-scoped bindings", async () => {
await withEnvAsync(
{
TELEGRAM_BOT_TOKEN: undefined,
TELEGRAM_BOT_TOKEN_FILE: undefined,
},
async () => {
await runDoctorConfigWithInput({
config: {
channels: {
telegram: {
accounts: {
alerts: {},
work: {},
},
},
},
bindings: [{ agentId: "ops", match: { channel: "telegram" } }],
},
run: loadAndMaybeMigrateDoctorConfig,
});
},
);
expect(noteSpy).toHaveBeenCalledWith(
expect.stringContaining("channels.telegram: accounts.default is missing"),
"Doctor warnings",
);
});
it("emits a warning when multiple accounts have no explicit default", async () => {
await withEnvAsync(
{
TELEGRAM_BOT_TOKEN: undefined,
TELEGRAM_BOT_TOKEN_FILE: undefined,
},
async () => {
await runDoctorConfigWithInput({
config: {
channels: {
telegram: {
accounts: {
alerts: {},
work: {},
},
},
},
},
run: loadAndMaybeMigrateDoctorConfig,
});
},
);
expect(noteSpy).toHaveBeenCalledWith(
expect.stringContaining(
"channels.telegram: multiple accounts are configured but no explicit default is set",
),
"Doctor warnings",
);
});
it("emits a warning when defaultAccount does not match configured accounts", async () => {
await withEnvAsync(
{
TELEGRAM_BOT_TOKEN: undefined,
TELEGRAM_BOT_TOKEN_FILE: undefined,
},
async () => {
await runDoctorConfigWithInput({
config: {
channels: {
telegram: {
defaultAccount: "missing",
accounts: {
alerts: {},
work: {},
},
},
},
},
run: loadAndMaybeMigrateDoctorConfig,
});
},
);
expect(noteSpy).toHaveBeenCalledWith(
expect.stringContaining(
'channels.telegram: defaultAccount is set to "missing" but does not match configured accounts',
),
"Doctor warnings",
);
});
});