mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 18:31:33 +00:00
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.
This commit is contained in:
@@ -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" }),
|
||||
});
|
||||
|
||||
|
||||
@@ -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 } : {}),
|
||||
|
||||
Reference in New Issue
Block a user