
























@@ -45,9 +45,18 @@ function getChannelPostHandler() {
4545return getOnHandler("channel_post") as (ctx: Record<string, unknown>) => Promise<void>;
4646}
474748+function getChannelPostHandlerWithRuntimeTimings() {
49+createTelegramBot({ token: "tok" });
50+return getOnHandler("channel_post") as (ctx: Record<string, unknown>) => Promise<void>;
51+}
52+4853function resolveFlushTimer(setTimeoutSpy: ReturnType<typeof vi.spyOn>) {
54+return resolveFlushTimerForDelay(setTimeoutSpy, TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs);
55+}
56+57+function resolveFlushTimerForDelay(setTimeoutSpy: ReturnType<typeof vi.spyOn>, delayMs: number) {
4958const flushTimerCallIndex = setTimeoutSpy.mock.calls.findLastIndex(
50-(call: Parameters<typeof setTimeout>) => call[1] === TELEGRAM_TEST_TIMINGS.mediaGroupFlushMs,
59+(call: Parameters<typeof setTimeout>) => call[1] === delayMs,
5160);
5261const flushTimer =
5362flushTimerCallIndex >= 0
@@ -104,6 +113,15 @@ async function flushChannelPostMediaGroup(setTimeoutSpy: ReturnType<typeof vi.sp
104113await flushTimer?.();
105114}
106115116+async function flushChannelPostMediaGroupForDelay(
117+setTimeoutSpy: ReturnType<typeof vi.spyOn>,
118+delayMs: number,
119+) {
120+const flushTimer = resolveFlushTimerForDelay(setTimeoutSpy, delayMs);
121+expect(flushTimer).toBeTypeOf("function");
122+await flushTimer?.();
123+}
124+107125async function queueChannelPostAlbum(
108126handler: ReturnType<typeof getChannelPostHandler>,
109127params: {
@@ -181,6 +199,44 @@ describe("createTelegramBot channel_post media", () => {
181199}
182200});
183201202+it("honors configured mediaGroupFlushMs for channel_post albums", async () => {
203+loadConfig.mockReturnValue({
204+channels: {
205+telegram: {
206+groupPolicy: "open",
207+mediaGroupFlushMs: 75,
208+groups: {
209+"-100777111222": {
210+enabled: true,
211+requireMention: false,
212+},
213+},
214+},
215+},
216+});
217+218+const fetchSpy = createImageFetchSpy();
219+const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
220+try {
221+const handler = getChannelPostHandlerWithRuntimeTimings();
222+await queueChannelPostAlbum(handler, {
223+caption: "configured album",
224+mediaGroupId: "channel-album-configured",
225+firstMessageId: 211,
226+secondMessageId: 212,
227+});
228+expect(replySpy).not.toHaveBeenCalled();
229+await flushChannelPostMediaGroupForDelay(setTimeoutSpy, 75);
230+231+expect(replySpy).toHaveBeenCalledTimes(1);
232+const payload = replySpy.mock.calls[0]?.[0] as { Body?: string };
233+expect(payload.Body).toContain("configured album");
234+} finally {
235+setTimeoutSpy.mockRestore();
236+fetchSpy.mockRestore();
237+}
238+});
239+184240it("coalesces channel_post near-limit text fragments into one message", async () => {
185241setOpenChannelPostConfig();
186242此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。