Files
fusion/packages/dashboard/app/hooks/__tests__/createChatStreamHandlers.test.ts
Fusion ef3281bc9d feat(FN-3817): fix chat delta spacing in legacy streaming API
Fixes chat streaming delta spacing to preserve proper whitespace, adding regression tests for legacy chat stream handlers and the createChatStreamHandlers factory. A changeset was created for the `@runfusion/fusion` package.

Fusion-Task-Id: FN-3817
2026-05-11 06:47:42 -07:00

50 lines
1.3 KiB
TypeScript

import { describe, expect, it, vi } from "vitest";
import { createChatStreamHandlers } from "../createChatStreamHandlers";
describe("createChatStreamHandlers", () => {
it("preserves whitespace across streamed text deltas", () => {
vi.useFakeTimers();
let text = "";
const onDone = vi.fn();
const onError = vi.fn();
const cancelStreamingFlushesRef = { current: null } as { current: (() => void) | null };
const { handlers } = createChatStreamHandlers({
sessionId: "s-1",
tempUserMessageId: "temp-1",
setStreamingText: (value) => {
text = typeof value === "function" ? value(text) : value;
},
setStreamingThinking: vi.fn(),
setStreamingToolCalls: vi.fn(),
cancelStreamingFlushesRef,
onDone,
onError,
});
handlers.onText("Hello.");
handlers.onText("");
handlers.onText(" World.");
vi.advanceTimersToNextTimer();
expect(text).toBe("Hello. World.");
handlers.onDone({ messageId: "m-1" });
expect(onDone).toHaveBeenCalledWith({
messageId: "m-1",
message: undefined,
accumulated: {
text: "Hello. World.",
thinking: "",
toolCalls: [],
fallbackInfo: undefined,
},
});
expect(onError).not.toHaveBeenCalled();
vi.useRealTimers();
});
});