From 7bc216db036cb0707b4032df9b92e86d568ed5fa Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 12 Mar 2026 04:00:12 -0400 Subject: [PATCH] Tests: cover Slack streaming fallback helpers --- .../dispatch.streaming.test.ts | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/slack/monitor/message-handler/dispatch.streaming.test.ts b/src/slack/monitor/message-handler/dispatch.streaming.test.ts index dc6eae7a44d..77566447b9f 100644 --- a/src/slack/monitor/message-handler/dispatch.streaming.test.ts +++ b/src/slack/monitor/message-handler/dispatch.streaming.test.ts @@ -1,5 +1,11 @@ import { describe, expect, it } from "vitest"; -import { isSlackStreamingEnabled, resolveSlackStreamingThreadHint } from "./dispatch.js"; +import type { ReplyPayload } from "../../../auto-reply/types.js"; +import { + buildSlackStreamFallbackText, + isSlackStreamingEnabled, + resolveSlackStreamingThreadHint, + shouldFinalizeSlackStreamBeforePlainPayload, +} from "./dispatch.js"; describe("slack native streaming defaults", () => { it("is enabled for partial mode when native streaming is on", () => { @@ -45,3 +51,46 @@ describe("slack native streaming thread hint", () => { ).toBe("2000.1"); }); }); + +describe("slack native streaming fallback helpers", () => { + it("replays accumulated streamed text before the failing chunk", () => { + expect(buildSlackStreamFallbackText("First chunk", "Second chunk")).toBe( + "First chunk\nSecond chunk", + ); + expect(buildSlackStreamFallbackText("", "Only chunk")).toBe("Only chunk"); + }); + + it("finalizes an active stream before sending plain payloads", () => { + const mediaPayload: ReplyPayload = { + text: "Image caption", + mediaUrl: "file:///tmp/example.png", + }; + const emptyTextPayload: ReplyPayload = { text: " " }; + const normalTextPayload: ReplyPayload = { text: "Continue streaming" }; + + expect( + shouldFinalizeSlackStreamBeforePlainPayload({ + hasActiveStream: true, + payload: mediaPayload, + }), + ).toBe(true); + expect( + shouldFinalizeSlackStreamBeforePlainPayload({ + hasActiveStream: true, + payload: emptyTextPayload, + }), + ).toBe(true); + expect( + shouldFinalizeSlackStreamBeforePlainPayload({ + hasActiveStream: true, + payload: normalTextPayload, + }), + ).toBe(false); + expect( + shouldFinalizeSlackStreamBeforePlainPayload({ + hasActiveStream: false, + payload: mediaPayload, + }), + ).toBe(false); + }); +});