import { expect, test } from "@playwright/test"; /** * Cluster C Playwright sweep — range-request 206 path. The SW must * intercept a packed URL whose cached body exceeds the configured * `rangeThreshold` and serve a `206 Partial Content` response when the * page issues a fetch carrying a `Range` header. The spec is harness- * agnostic and assumes the page exposes a packed asset at * `/sample-large.packed`. */ test.describe("packed-resource SW range request (cluster C)", () => { test("serves 206 Partial Content for a ranged packed request", async ({ page, }) => { await page.goto("/"); await page.evaluate(async () => { await navigator.serviceWorker.register("/service-worker.js"); await navigator.serviceWorker.ready; }); const response = await page.evaluate(async () => { const r = await fetch("/sample-large.packed", { headers: { Range: "bytes=0-9" }, }); return { status: r.status, contentRange: r.headers.get("Content-Range"), acceptRanges: r.headers.get("Accept-Ranges"), contentLength: r.headers.get("Content-Length"), }; }); expect(response.status).toBe(206); expect(response.contentRange).toMatch(/^bytes 0-9\/\d+$/); expect(response.acceptRanges).toBe("bytes"); expect(response.contentLength).toBe("10"); }); });