test(telegram): prove empty account capability fallback

This commit is contained in:
Vincent Koc
2026-06-24 23:22:58 +08:00
parent 273bd54cdb
commit 5e55b5dd30
3 changed files with 43 additions and 1 deletions
+5 -1
View File
@@ -90,6 +90,10 @@ export function mergeTelegramAccountConfig(
baseAllowFrom: base.allowFrom,
accountAllowFrom: account.allowFrom,
});
const capabilities =
Array.isArray(account.capabilities) && account.capabilities.length === 0
? base.capabilities
: (account.capabilities ?? base.capabilities);
return { ...base, ...account, allowFrom, groups };
return { ...base, ...account, allowFrom, capabilities, groups };
}
@@ -1703,6 +1703,25 @@ describe("handleTelegramAction", () => {
expect(sendMessageTelegram).toHaveBeenCalled();
});
it("allows inline buttons when legacy capabilities are empty", async () => {
await handleTelegramAction(
{
action: "sendMessage",
to: "@testchannel",
content: "Choose",
presentation: {
blocks: [{ type: "buttons", buttons: [{ label: "Ok", value: "cmd:ok" }] }],
},
},
telegramConfig({ capabilities: [] }),
);
const call = mockCall(sendMessageTelegram, 0, "empty legacy capabilities");
expect(call[0]).toBe("@testchannel");
expect(requireRecord(call[2], "empty legacy capabilities options").buttons).toEqual([
[{ text: "Ok", callback_data: "cmd:ok" }],
]);
});
it("uses interactive button labels as fallback text when message text is omitted", async () => {
await handleTelegramAction(
{
@@ -123,6 +123,25 @@ describe("resolveTelegramInlineButtonsScope (#75433 SecretRef tolerance)", () =>
expect(isTelegramInlineButtonsEnabled({ cfg })).toBe(true);
});
it("inherits the channel scope when an account legacy capabilities array is empty", () => {
const cfg = {
channels: {
telegram: {
capabilities: { inlineButtons: "off" },
accounts: {
ops: {
botToken: "123:telegram-ops-token",
capabilities: [],
},
},
},
},
} as unknown as OpenClawConfig;
expect(resolveTelegramInlineButtonsScope({ cfg, accountId: "ops" })).toBe("off");
expect(isTelegramInlineButtonsEnabled({ cfg, accountId: "ops" })).toBe(false);
});
it('preserves configured "off" when botToken is an unresolved SecretRef', () => {
const cfg = {
channels: {