Fix terminal log follow and wrapping
This commit is contained in:
@@ -802,6 +802,28 @@ describe("PlatformApiClient AI providers", () => {
|
||||
stream.close();
|
||||
});
|
||||
|
||||
it("reconnects terminal log SSE after the fetch stream ends", async () => {
|
||||
const payloads = [
|
||||
"id: log-1:3\nevent: log\ndata: {\"streamId\":\"log-1\",\"entry\":{\"seq\":3,\"line\":\"first live line\"}}\n\n",
|
||||
"id: log-1:4\nevent: log\ndata: {\"streamId\":\"log-1\",\"entry\":{\"seq\":4,\"line\":\"second live line\"}}\n\n"
|
||||
];
|
||||
const fetchMock = vi.fn(async (_input: RequestInfo | URL, _init?: RequestInit) => new Response(new ReadableStream<Uint8Array>({ start(controller) { controller.enqueue(new TextEncoder().encode(payloads[Math.min(fetchMock.mock.calls.length - 1, payloads.length - 1)])); controller.close(); } }), { status: 200, headers: { "Content-Type": "text/event-stream" } }));
|
||||
vi.stubGlobal("fetch", fetchMock);
|
||||
const client = new PlatformApiClient("/api/v1", () => "terminal-session");
|
||||
const events: string[] = [];
|
||||
const stream = client.openServerLogEvents("server-1");
|
||||
stream.addEventListener("log", (event) => events.push(event.data));
|
||||
|
||||
await vi.waitFor(() => expect(events).toContain('{"streamId":"log-1","entry":{"seq":3,"line":"first live line"}}'));
|
||||
await vi.waitFor(() => expect(fetchMock).toHaveBeenCalledTimes(2), { timeout: 1500 });
|
||||
expect(new Headers(fetchMock.mock.calls[1]?.[1]?.headers).get("Last-Event-ID")).toBe("log-1:3");
|
||||
await vi.waitFor(() => expect(events).toEqual([
|
||||
'{"streamId":"log-1","entry":{"seq":3,"line":"first live line"}}',
|
||||
'{"streamId":"log-1","entry":{"seq":4,"line":"second live line"}}'
|
||||
]), { timeout: 1500 });
|
||||
stream.close();
|
||||
});
|
||||
|
||||
it("surfaces password confirmation denials without exposing generic forbidden text", async () => {
|
||||
vi.stubGlobal("fetch", vi.fn(async () => new Response(JSON.stringify({
|
||||
code: "forbidden",
|
||||
|
||||
Reference in New Issue
Block a user