fix: harden Pi management readiness

This commit is contained in:
2026-08-05 06:20:25 +02:00
parent 7a8bcacbfe
commit 7df21b5f21
24 changed files with 577 additions and 274 deletions
@@ -56,7 +56,7 @@ test("flushes pending stream text before a structural event", () => {
test("opens an EventSource and feeds NAMED events to the store", () => {
renderHook(() => useSessionStream("s1"));
const es = FakeEventSource.instances[0];
expect(es.url).toBe("http://localhost:8787/sessions/s1/events");
expect(es.url).toBe("/api/sessions/s1/events");
// Backend sends `event: ui_request` (named) — drive the addEventListener path
// that production relies on, not the unnamed onmessage fallback.
act(() =>
@@ -146,7 +146,7 @@ test("a same-session generation reconnect includes the last consumed SSE id", ()
expect(first.closed).toBe(true);
expect(FakeEventSource.instances).toHaveLength(2);
expect(FakeEventSource.instances[1].url).toBe(
"http://localhost:8787/sessions/s1/events?lastEventId=7",
"/api/sessions/s1/events?lastEventId=7",
);
act(() =>
@@ -176,7 +176,7 @@ test("a same-session reset epoch drops a high cursor and accepts fresh low-id ev
expect(first.closed).toBe(true);
expect(FakeEventSource.instances).toHaveLength(2);
expect(FakeEventSource.instances[1].url).toBe(
"http://localhost:8787/sessions/s1/events",
"/api/sessions/s1/events",
);
act(() =>
@@ -199,7 +199,7 @@ test("a reset epoch also accepts an in-process preserved high id and resumes fro
rerender({ generation: 0, resetEpoch: 1 });
const replacement = FakeEventSource.instances[1];
expect(replacement.url).toBe("http://localhost:8787/sessions/s1/events");
expect(replacement.url).toBe("/api/sessions/s1/events");
act(() =>
replacement.emitNamed(
"ui_request",
@@ -211,7 +211,7 @@ test("a reset epoch also accepts an in-process preserved high id and resumes fro
expect(useSessionStore.getState().pendingWidget?.id).toBe("preserved-high-gate");
rerender({ generation: 1, resetEpoch: 1 });
expect(FakeEventSource.instances[2].url).toBe(
"http://localhost:8787/sessions/s1/events?lastEventId=902",
"/api/sessions/s1/events?lastEventId=902",
);
});
@@ -226,7 +226,7 @@ test("changing the session resets the manual reconnect cursor", () => {
rerender({ sessionId: "s2" });
expect(first.closed).toBe(true);
expect(FakeEventSource.instances[1].url).toBe("http://localhost:8787/sessions/s2/events");
expect(FakeEventSource.instances[1].url).toBe("/api/sessions/s2/events");
});
test("a queued event from a replaced source cannot mutate the new session or its cursor", () => {
@@ -239,7 +239,7 @@ test("a queued event from a replaced source cannot mutate the new session or its
rerender({ sessionId: "s2", generation: 0 });
expect(first.closed).toBe(true);
expect(FakeEventSource.instances[1].url).toBe("http://localhost:8787/sessions/s2/events");
expect(FakeEventSource.instances[1].url).toBe("/api/sessions/s2/events");
useSessionStore.getState().resetSession();
act(() =>
@@ -252,7 +252,7 @@ test("a queued event from a replaced source cannot mutate the new session or its
expect(useSessionStore.getState().transcript).toEqual([]);
rerender({ sessionId: "s2", generation: 1 });
expect(FakeEventSource.instances[2].url).toBe("http://localhost:8787/sessions/s2/events");
expect(FakeEventSource.instances[2].url).toBe("/api/sessions/s2/events");
});
test("the old source is invalid before later layout effects can deliver a queued event", () => {