fix: align channel config schemas and env precedence

This commit is contained in:
Peter Steinberger
2026-01-17 00:12:41 +00:00
parent 3ec221c70e
commit 7ecf733342
16 changed files with 249 additions and 38 deletions

View File

@@ -27,7 +27,7 @@ describe("resolveTelegramAccount", () => {
}
});
it("prefers TELEGRAM_BOT_TOKEN when accountId is omitted", () => {
it("uses TELEGRAM_BOT_TOKEN when default account config is missing", () => {
const prevTelegramToken = process.env.TELEGRAM_BOT_TOKEN;
process.env.TELEGRAM_BOT_TOKEN = "tok-env";
try {
@@ -50,6 +50,29 @@ describe("resolveTelegramAccount", () => {
}
});
it("prefers default config token over TELEGRAM_BOT_TOKEN", () => {
const prevTelegramToken = process.env.TELEGRAM_BOT_TOKEN;
process.env.TELEGRAM_BOT_TOKEN = "tok-env";
try {
const cfg: ClawdbotConfig = {
channels: {
telegram: { botToken: "tok-config" },
},
};
const account = resolveTelegramAccount({ cfg });
expect(account.accountId).toBe("default");
expect(account.token).toBe("tok-config");
expect(account.tokenSource).toBe("config");
} finally {
if (prevTelegramToken === undefined) {
delete process.env.TELEGRAM_BOT_TOKEN;
} else {
process.env.TELEGRAM_BOT_TOKEN = prevTelegramToken;
}
}
});
it("does not fall back when accountId is explicitly provided", () => {
const prevTelegramToken = process.env.TELEGRAM_BOT_TOKEN;
process.env.TELEGRAM_BOT_TOKEN = "";