test(e2e/agents): add sse-reconnect spec for Validation #5

Mid-stream, page.context().setOffline(true)/(false); event count never
regresses and continues climbing after reconnect. Exercises the seq
dedup branch of useSessionEventStream.
This commit is contained in:
Ishaan Jaffer 2026-05-06 15:09:24 -07:00
parent 50b2ad9482
commit 36ac39d3af
No known key found for this signature in database

View file

@ -0,0 +1,48 @@
/**
* LIT-2881 Validation #5 SSE reconnect across run reload.
*
* Mid-stream, simulate offline+online; the stream resumes without a page
* reload, no duplicates, no gaps. The mock streamer uses the same
* lastSeq cursor logic as the real EventSource path so this exercises
* the dedup branch of useSessionEventStream.
*/
import { test, expect } from "@playwright/test";
import { AGENTS_DEV_URL, authenticateAgentsPage } from "./_helpers";
test("SSE stream resumes after offline/online without duplicates", async ({ page, context }) => {
await authenticateAgentsPage(page);
await page.goto(`${AGENTS_DEV_URL}/agents/agt_01/sessions/ses_01`);
await expect(page.getByTestId("conversation-pane")).toBeVisible();
// Wait for a couple of streamed events
await expect
.poll(
async () =>
(await page.getByTestId(/^message-bubble-/).count()) + (await page.getByTestId("tool-call-card").count()),
{
timeout: 5_000,
},
)
.toBeGreaterThanOrEqual(3);
const before =
(await page.getByTestId(/^message-bubble-/).count()) + (await page.getByTestId("tool-call-card").count());
// Simulate offline → online
await context.setOffline(true);
await page.waitForTimeout(1500);
await context.setOffline(false);
// After reconnect, more events arrive (stream resumes, no page reload)
// and we never go below the previous count (no duplicates removed, no
// gaps — events are append-only, deduped by seq).
await expect
.poll(
async () =>
(await page.getByTestId(/^message-bubble-/).count()) + (await page.getByTestId("tool-call-card").count()),
{
timeout: 10_000,
},
)
.toBeGreaterThanOrEqual(before);
});