diff --git a/src/auto-reply/reply.block-streaming.test.ts b/src/auto-reply/reply.block-streaming.test.ts index 18c037789c1..a525071399f 100644 --- a/src/auto-reply/reply.block-streaming.test.ts +++ b/src/auto-reply/reply.block-streaming.test.ts @@ -98,7 +98,7 @@ describe("block streaming", () => { ]); }); - it("waits for block replies and preserves ordering when typing start is slow", async () => { + it("handles ordering, timeout fallback, and telegram streamMode block", async () => { await withTempHome(async (home) => { let releaseTyping: (() => void) | undefined; const typingGate = new Promise((resolve) => { @@ -161,13 +161,9 @@ describe("block streaming", () => { const res = await replyPromise; expect(res).toBeUndefined(); expect(seen).toEqual(["first\n\nsecond"]); - }); - }); - it("falls back to final payloads and respects telegram streamMode block", async () => { - await withTempHome(async (home) => { let sawAbort = false; - const onBlockReply = vi.fn((_, context) => { + const onBlockReplyTimeout = vi.fn((_, context) => { return new Promise((resolve) => { context?.abortSignal?.addEventListener( "abort", @@ -180,7 +176,7 @@ describe("block streaming", () => { }); }); - const impl = async (params: RunEmbeddedPiAgentParams) => { + const timeoutImpl = async (params: RunEmbeddedPiAgentParams) => { void params.onBlockReply?.({ text: "streamed" }); return { payloads: [{ text: "final" }], @@ -190,9 +186,9 @@ describe("block streaming", () => { }, }; }; - piEmbeddedMock.runEmbeddedPiAgent.mockImplementation(impl); + piEmbeddedMock.runEmbeddedPiAgent.mockImplementation(timeoutImpl); - const replyPromise = getReplyFromConfig( + const timeoutReplyPromise = getReplyFromConfig( { Body: "ping", From: "+1004", @@ -201,7 +197,7 @@ describe("block streaming", () => { Provider: "telegram", }, { - onBlockReply, + onBlockReply: onBlockReplyTimeout, blockReplyTimeoutMs: 1, disableBlockStreaming: false, }, @@ -217,8 +213,8 @@ describe("block streaming", () => { }, ); - const res = await replyPromise; - expect(res).toMatchObject({ text: "final" }); + const timeoutRes = await timeoutReplyPromise; + expect(timeoutRes).toMatchObject({ text: "final" }); expect(sawAbort).toBe(true); const onBlockReplyStreamMode = vi.fn().mockResolvedValue(undefined);