test: share telegram inbound body fixture

This commit is contained in:
Peter Steinberger
2026-04-20 17:50:36 +01:00
parent e7befec3ff
commit 873ef6cf45

View File

@@ -9,15 +9,45 @@ vi.mock("./media-understanding.runtime.js", () => ({
const { resolveTelegramInboundBody } = await import("./bot-message-context.body.js");
type TelegramInboundBodyParams = Parameters<typeof resolveTelegramInboundBody>[0];
function resolveTelegramBody(overrides: Partial<TelegramInboundBodyParams>) {
const chatId = overrides.chatId ?? 42;
return resolveTelegramInboundBody({
cfg: {
channels: { telegram: {} },
} as never,
primaryCtx: {
me: { id: 7, username: "bot" },
} as never,
msg: {
message_id: 0,
date: 1_700_000_000,
chat: { id: chatId, type: "private", first_name: "Pat" },
from: { id: chatId, first_name: "Pat" },
} as never,
allMedia: [],
isGroup: false,
chatId,
senderId: String(chatId),
senderUsername: "",
routeAgentId: undefined,
effectiveGroupAllow: normalizeAllowFrom([]),
effectiveDmAllow: normalizeAllowFrom([]),
groupConfig: undefined,
topicConfig: undefined,
requireMention: false,
options: undefined,
groupHistories: new Map(),
historyLimit: 0,
logger: { info: vi.fn() },
...overrides,
} as TelegramInboundBodyParams);
}
describe("resolveTelegramInboundBody", () => {
it("keeps the media marker when a captioned video has no downloaded media", async () => {
const result = await resolveTelegramInboundBody({
cfg: {
channels: { telegram: {} },
} as never,
primaryCtx: {
me: { id: 7, username: "bot" },
} as never,
const result = await resolveTelegramBody({
msg: {
message_id: 0,
date: 1_700_000_000,
@@ -32,21 +62,6 @@ describe("resolveTelegramInboundBody", () => {
height: 240,
},
} as never,
allMedia: [],
isGroup: false,
chatId: 42,
senderId: "42",
senderUsername: "",
routeAgentId: undefined,
effectiveGroupAllow: normalizeAllowFrom([]),
effectiveDmAllow: normalizeAllowFrom([]),
groupConfig: undefined,
topicConfig: undefined,
requireMention: false,
options: undefined,
groupHistories: new Map(),
historyLimit: 0,
logger: { info: vi.fn() },
});
expect(result).toMatchObject({
@@ -59,14 +74,11 @@ describe("resolveTelegramInboundBody", () => {
transcribeFirstAudioMock.mockReset();
const logger = { info: vi.fn() };
const result = await resolveTelegramInboundBody({
const result = await resolveTelegramBody({
cfg: {
channels: { telegram: {} },
messages: { groupChat: { mentionPatterns: ["\\bbot\\b"] } },
} as never,
primaryCtx: {
me: { id: 7, username: "bot" },
} as never,
msg: {
message_id: 1,
date: 1_700_000_000,
@@ -84,11 +96,7 @@ describe("resolveTelegramInboundBody", () => {
effectiveGroupAllow: normalizeAllowFrom(["999"]),
effectiveDmAllow: normalizeAllowFrom([]),
groupConfig: { requireMention: true } as never,
topicConfig: undefined,
requireMention: true,
options: undefined,
groupHistories: new Map(),
historyLimit: 0,
logger,
});
@@ -104,16 +112,13 @@ describe("resolveTelegramInboundBody", () => {
transcribeFirstAudioMock.mockReset();
transcribeFirstAudioMock.mockResolvedValueOnce("hey bot please help");
const result = await resolveTelegramInboundBody({
const result = await resolveTelegramBody({
cfg: {
channels: { telegram: {} },
commands: { useAccessGroups: false },
messages: { groupChat: { mentionPatterns: ["\\bbot\\b"] } },
tools: { media: { audio: { enabled: true } } },
} as never,
primaryCtx: {
me: { id: 7, username: "bot" },
} as never,
msg: {
message_id: 2,
date: 1_700_000_001,
@@ -131,12 +136,7 @@ describe("resolveTelegramInboundBody", () => {
effectiveGroupAllow: normalizeAllowFrom(["999"]),
effectiveDmAllow: normalizeAllowFrom([]),
groupConfig: { requireMention: true } as never,
topicConfig: undefined,
requireMention: true,
options: undefined,
groupHistories: new Map(),
historyLimit: 0,
logger: { info: vi.fn() },
});
expect(transcribeFirstAudioMock).toHaveBeenCalledTimes(1);
@@ -150,14 +150,11 @@ describe("resolveTelegramInboundBody", () => {
transcribeFirstAudioMock.mockReset();
transcribeFirstAudioMock.mockResolvedValueOnce("hello from a voice note");
const result = await resolveTelegramInboundBody({
const result = await resolveTelegramBody({
cfg: {
channels: { telegram: {} },
tools: { media: { audio: { enabled: true } } },
} as never,
primaryCtx: {
me: { id: 7, username: "bot" },
} as never,
msg: {
message_id: 10,
date: 1_700_000_010,
@@ -167,20 +164,6 @@ describe("resolveTelegramInboundBody", () => {
entities: [],
} as never,
allMedia: [{ path: "/tmp/voice-dm.ogg", contentType: "audio/ogg" }],
isGroup: false,
chatId: 42,
senderId: "42",
senderUsername: "",
routeAgentId: undefined,
effectiveGroupAllow: normalizeAllowFrom([]),
effectiveDmAllow: normalizeAllowFrom([]),
groupConfig: undefined,
topicConfig: undefined,
requireMention: false,
options: undefined,
groupHistories: new Map(),
historyLimit: 0,
logger: { info: vi.fn() },
});
expect(transcribeFirstAudioMock).toHaveBeenCalledTimes(1);