From b00a1aaeaef78ae801832d1a0bcaf74348a0c68d Mon Sep 17 00:00:00 2001 From: Ayaan Zaidi Date: Wed, 29 Jul 2026 02:39:00 +0200 Subject: [PATCH] test(telegram): give the media harness a bot identity instead of per-context ids The previous commit patched me.id into 13 contexts in one suite. That treated the symptom: the harness itself never passes botInfo, so resolveBotUserId has no fallback when a test ctx carries only a username. Fix the harness instead. Production always builds the bot from getMe(), so botInfo is present in every real path; supplying telegramBotInfoForTest matches that and drops the per-context ids. Also revives bot.media.stickers-and-fragments.e2e.test.ts, which shares the harness and failed 3/6 for the same reason and was not covered before. The other ~84 bare me literals across 8 Telegram suites are fine: those tests supply botInfo through their own harnesses. Verified, 371 pass, so no sweep. --- ...dia-file-path-no-file-download.e2e.test.ts | 26 +++++++++---------- .../telegram/src/bot.media.test-utils.ts | 4 +++ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/extensions/telegram/src/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts b/extensions/telegram/src/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts index b3a233d6ebca..171d1aff17eb 100644 --- a/extensions/telegram/src/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts +++ b/extensions/telegram/src/bot.media.downloads-media-file-path-no-file-download.e2e.test.ts @@ -202,7 +202,7 @@ describe("telegram inbound media", () => { photo: [{ file_id: "fid" }], date: 1736380800, // 2025-01-09T00:00:00Z }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: scenario.getFile, }); @@ -239,7 +239,7 @@ describe("telegram inbound media", () => { photo: [{ file_id: "fid" }], date: 1736380800, }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/1.jpg" }), }); @@ -281,7 +281,7 @@ describe("telegram inbound media", () => { chat: { id: 1234, type: "private" }, photo: [{ file_id: "fid" }], }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/2.jpg" }), }); @@ -342,7 +342,7 @@ describe("telegram inbound media", () => { replySpy.mockClear(); await handler({ message: testCase.message, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "unused" }), }); @@ -392,7 +392,7 @@ describe("telegram media groups", () => { media_group_id: "album-custom-api-root", photo: [{ file_id: "photo1" }], }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/photo1.jpg" }), }), handler({ @@ -404,7 +404,7 @@ describe("telegram media groups", () => { media_group_id: "album-custom-api-root", photo: [{ file_id: "photo2" }], }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/photo2.jpg" }), }), ]); @@ -514,7 +514,7 @@ describe("telegram media groups", () => { scenario.messages.map((message) => handler({ message, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: message.filePath }), }), ), @@ -605,7 +605,7 @@ describe("telegram media groups", () => { ]) { await handler({ message: message.message, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: message.getFile, }); } @@ -718,7 +718,7 @@ describe("telegram media groups", () => { ]) { await handler({ message: message.message, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: message.getFile, }); } @@ -800,7 +800,7 @@ describe("telegram media groups", () => { media_group_id: "album-shared-by-telegram", photo: [{ file_id: "topic1photo" }], }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/topic1.jpg" }), }), handler({ @@ -815,7 +815,7 @@ describe("telegram media groups", () => { media_group_id: "album-shared-by-telegram", photo: [{ file_id: "topic2photo" }], }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/topic2.jpg" }), }), ]); @@ -885,7 +885,7 @@ describe("telegram forwarded bursts", () => { date: 1736380800, forward_origin: { type: "hidden_user", date: 1736380700, sender_user_name: "A" }, }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({}), }); @@ -898,7 +898,7 @@ describe("telegram forwarded bursts", () => { photo: [{ file_id: "fwd_photo_1" }], forward_origin: { type: "hidden_user", date: 1736380701, sender_user_name: "A" }, }, - me: { id: 999, username: "openclaw_bot" }, + me: { username: "openclaw_bot" }, getFile: async () => ({ file_path: "photos/fwd1.jpg" }), }); diff --git a/extensions/telegram/src/bot.media.test-utils.ts b/extensions/telegram/src/bot.media.test-utils.ts index 7e8e27fd5855..c9de2f6ac852 100644 --- a/extensions/telegram/src/bot.media.test-utils.ts +++ b/extensions/telegram/src/bot.media.test-utils.ts @@ -1,6 +1,7 @@ // Telegram helper module supports bot.media utils behavior. import * as ssrf from "openclaw/plugin-sdk/ssrf-runtime"; import { afterEach, beforeAll, beforeEach, expect, vi, type Mock } from "vitest"; +import { telegramBotInfoForTest } from "./bot.create-telegram-bot.test-support.js"; import * as harness from "./bot.media.e2e-harness.js"; type StickerSpy = Mock<(...args: unknown[]) => unknown>; @@ -62,6 +63,9 @@ export async function createBotHandlerWithOptions(options: { const effectiveProxyFetch = options.proxyFetch ?? (undiciFetchSpyRef as unknown as typeof fetch); createTelegramBotRef({ token: "tok", + // Production always constructs the bot from getMe(), so inbound handlers may + // resolve the bot user id from botInfo when a test ctx carries only a username. + botInfo: telegramBotInfoForTest, config: harness.telegramBotDepsForTest.getRuntimeConfig(), testTimings: TELEGRAM_TEST_TIMINGS, ...(effectiveProxyFetch ? { proxyFetch: effectiveProxyFetch } : {}),