fix(FN-3760): add SSE first-event watchdog for legacy chat streams

- Add a first-event watchdog in legacy chat SSE handling to prevent hangs before initial stream data
- Cover watchdog behavior with legacy chat stream API tests
- Add hook-level regression tests for useChat and useQuickChat first-send stream scenarios
- Include a changeset for @runfusion/fusion patch release

Fusion-Task-Id: FN-3760
This commit is contained in:
Fusion
2026-05-08 20:45:45 -07:00
committed by gsxdsm
parent df9f5a95c6
commit b080ea0bc5
5 changed files with 133 additions and 5 deletions

View File

@@ -120,4 +120,23 @@ describe("streamChatResponse SSE parser", () => {
expect(donePayloads).toEqual([{ messageId: "" }]);
});
});
it("fires onError when no stream events arrive before timeout", async () => {
vi.useFakeTimers();
vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(new ReadableStream<Uint8Array>({
start(controller) {
controller.enqueue(new TextEncoder().encode(": connected\n\n"));
},
}), { status: 200 }));
const onError = vi.fn();
streamChatResponse("s-1", "hi", { onError }, undefined, undefined, { firstEventTimeoutMs: 1_000 });
await Promise.resolve();
await Promise.resolve();
await vi.advanceTimersByTimeAsync(1_100);
expect(onError).toHaveBeenCalledWith("Timed out waiting for first response event");
vi.useRealTimers();
});
});