Fix terminal log follow and wrapping

This commit is contained in:
npc0-hue
2026-08-11 00:16:27 +08:00
parent 75a2c5aac5
commit 82ee28522c
5 changed files with 88 additions and 29 deletions
+22
View File
@@ -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",