fix(regression): handle telegram command error envelopes

This commit is contained in:
Tak Hoffman
2026-03-27 23:36:19 -05:00
parent b5958ce5fd
commit 84af16e9c7
2 changed files with 29 additions and 1 deletions

View File

@@ -279,4 +279,32 @@ describe("bot-native-command-menu", () => {
);
expect(runtimeError).not.toHaveBeenCalled();
});
it.each([
{ label: "description envelope", error: { description: "BOT_COMMANDS_TOO_MUCH" } },
{ label: "message envelope", error: { message: "BOT_COMMANDS_TOO_MUCH" } },
])("retries when Telegram returns a plain-object $label error", async ({ error }) => {
const deleteMyCommands = vi.fn(async () => undefined);
const setMyCommands = vi.fn().mockRejectedValueOnce(error).mockResolvedValue(undefined);
const runtimeLog = vi.fn();
syncMenuCommandsWithMocks({
deleteMyCommands,
setMyCommands,
runtimeLog,
commandsToRegister: Array.from({ length: 10 }, (_, i) => ({
command: `cmd_${i}`,
description: `Command ${i}`,
})),
accountId: `test-envelope-${Date.now()}`,
botIdentity: "bot-a",
});
await vi.waitFor(() => {
expect(setMyCommands).toHaveBeenCalledTimes(2);
});
expect(runtimeLog).toHaveBeenCalledWith(
"Telegram rejected 10 commands (BOT_COMMANDS_TOO_MUCH); retrying with 8.",
);
});
});

View File

@@ -29,7 +29,7 @@ function readErrorTextField(value: unknown, key: "description" | "message"): str
if (!value || typeof value !== "object" || !(key in value)) {
return undefined;
}
const text = value[key];
const text = (value as Record<string, unknown>)[key];
return typeof text === "string" ? text : undefined;
}