From c11fcbcb6acc3eb4add263204ccfe562691fdc71 Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 14 Jun 2026 06:18:47 +0800 Subject: [PATCH] fix(release): repair beta validation fixtures --- .../bot.create-telegram-bot.test-harness.ts | 45 +++++++++++++++++++ .../src/bot.create-telegram-bot.test.ts | 5 ++- extensions/telegram/src/send.proxy.test.ts | 34 +++++++++++--- .../gateway-trajectory-export.live.test.ts | 3 +- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts b/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts index db079ccf45ad..2cda13c8e03c 100644 --- a/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts +++ b/extensions/telegram/src/bot.create-telegram-bot.test-harness.ts @@ -340,6 +340,36 @@ export const sendAnimationSpy: AnyAsyncMock = grammySpies.sendAnimationSpy; export const sendPhotoSpy: AnyAsyncMock = grammySpies.sendPhotoSpy; export const getFileSpy: AnyAsyncMock = grammySpies.getFileSpy; +type RichMessageParams = { + chat_id?: string | number; + message_id?: number; + rich_message?: { + markdown?: string; + html?: string; + }; + [key: string]: unknown; +}; + +function getRichMessageText(params: RichMessageParams): string { + return params.rich_message?.markdown ?? params.rich_message?.html ?? ""; +} + +function toLegacyMessageParams(params: RichMessageParams): Record { + const { chat_id: _chatId, message_id: _messageId, rich_message: _richMessage, ...rest } = params; + const replyParameters = rest.reply_parameters; + if ( + replyParameters && + typeof replyParameters === "object" && + !("quote" in replyParameters) && + typeof (replyParameters as { message_id?: unknown }).message_id === "number" + ) { + rest.reply_to_message_id = (replyParameters as { message_id: number }).message_id; + rest.allow_sending_without_reply = true; + delete rest.reply_parameters; + } + return rest; +} + const runnerHoisted = vi.hoisted(() => ({ sequentializeMiddleware: vi.fn(async (_ctx: unknown, next?: () => Promise) => { if (typeof next === "function") { @@ -369,6 +399,21 @@ export const telegramBotRuntimeForTest: TelegramBotRuntimeForTest = { sendAnimation: grammySpies.sendAnimationSpy, sendPhoto: grammySpies.sendPhotoSpy, getFile: grammySpies.getFileSpy, + raw: { + sendRichMessage: async (params: RichMessageParams) => + grammySpies.sendMessageSpy( + params.chat_id, + getRichMessageText(params), + toLegacyMessageParams(params), + ), + editMessageText: async (params: RichMessageParams) => + grammySpies.editMessageTextSpy( + params.chat_id, + params.message_id, + getRichMessageText(params), + toLegacyMessageParams(params), + ), + }, }; use = grammySpies.middlewareUseSpy; on = grammySpies.onSpy; diff --git a/extensions/telegram/src/bot.create-telegram-bot.test.ts b/extensions/telegram/src/bot.create-telegram-bot.test.ts index 10df1f16587b..7e67a91c62bd 100644 --- a/extensions/telegram/src/bot.create-telegram-bot.test.ts +++ b/extensions/telegram/src/bot.create-telegram-bot.test.ts @@ -70,6 +70,7 @@ const { TelegramSpooledReplayProcessingError, withTelegramSpooledReplayUpdate, } = await import("./bot-processing-outcome.js"); +const { TELEGRAM_RICH_TEXT_LIMIT } = await import("./rich-message.js"); const { resolveTelegramConversationRoute } = await import("./conversation-route.js"); const { clearAccountThrottlersForTest } = await import("./account-throttler.js"); const { @@ -4192,7 +4193,7 @@ describe("createTelegramBot", () => { } }); it("sends replies without native reply threading", async () => { - replySpy.mockResolvedValue({ text: "a".repeat(4500) }); + replySpy.mockResolvedValue({ text: "a".repeat(TELEGRAM_RICH_TEXT_LIMIT + 1024) }); createTelegramBot({ token: "tok" }); const handler = getOnHandler("message") as (ctx: Record) => Promise; @@ -4284,7 +4285,7 @@ describe("createTelegramBot", () => { sendMessageSpy.mockClear(); replySpy.mockClear(); replySpy.mockResolvedValue({ - text: "a".repeat(4500), + text: "a".repeat(TELEGRAM_RICH_TEXT_LIMIT + 1024), replyToId: String(messageId), }); loadConfig.mockReturnValue({ diff --git a/extensions/telegram/src/send.proxy.test.ts b/extensions/telegram/src/send.proxy.test.ts index a02d47ef8dc3..0999a2a23d76 100644 --- a/extensions/telegram/src/send.proxy.test.ts +++ b/extensions/telegram/src/send.proxy.test.ts @@ -2,12 +2,34 @@ import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest"; const { botApi, botCtorSpy } = vi.hoisted(() => ({ - botApi: { - config: { use: vi.fn() }, - sendMessage: vi.fn(), - setMessageReaction: vi.fn(), - deleteMessage: vi.fn(), - }, + botApi: (() => { + const sendMessage = vi.fn(); + type RichMessageParams = { + chat_id?: string | number; + rich_message?: { + markdown?: string; + html?: string; + }; + [key: string]: unknown; + }; + return { + config: { use: vi.fn() }, + sendMessage, + setMessageReaction: vi.fn(), + deleteMessage: vi.fn(), + raw: { + sendRichMessage: vi.fn(async (params: RichMessageParams) => + sendMessage( + params.chat_id, + params.rich_message?.markdown ?? params.rich_message?.html ?? "", + Object.fromEntries( + Object.entries(params).filter(([key]) => key !== "chat_id" && key !== "rich_message"), + ), + ), + ), + }, + }; + })(), botCtorSpy: vi.fn(), })); diff --git a/src/gateway/gateway-trajectory-export.live.test.ts b/src/gateway/gateway-trajectory-export.live.test.ts index 45ad99737021..547140cd6e93 100644 --- a/src/gateway/gateway-trajectory-export.live.test.ts +++ b/src/gateway/gateway-trajectory-export.live.test.ts @@ -59,10 +59,9 @@ async function writeLiveGatewayConfig(params: { list: [{ id: "dev", default: true }], defaults: { workspace: params.workspace, - agentRuntime: { id: "codex" }, skipBootstrap: true, model: { primary: params.modelKey }, - models: { [params.modelKey]: {} }, + models: { [params.modelKey]: { agentRuntime: { id: "codex" } } }, sandbox: { mode: "off" }, }, },