import { expect, test, type Page } from "@playwright/test"; const ORIGIN = "http://127.0.0.1:4173"; async function localOnly(page: Page) { const external: string[] = []; await page.route("**/*", async (route) => { const url = new URL(route.request().url()); if (url.origin !== ORIGIN) { external.push(url.href); await route.abort(); } else await route.continue(); }); return external; } test("runs from a nested path without external requests", async ({ page }) => { const errors: string[] = []; page.on("pageerror", (error) => errors.push(error.message)); page.on("console", (message) => { if (message.type() === "error") errors.push(message.text()); }); const external = await localOnly(page); await page.goto("/deep/nested/calendar/"); await expect( page.getByRole("banner").getByRole("heading", { name: "Calendar Tools" }), ).toBeVisible(); expect(external).toEqual([]); expect(errors).toEqual([]); }); test("keeps prior inspection on failure and diagnoses a DST overlap", async ({ page, }) => { const external = await localOnly(page); await page.goto("/deep/nested/calendar/"); await expect(page.getByText("Weekly review", { exact: true })).toBeVisible(); await page.getByLabel("iCalendar source").fill("broken"); await page.getByRole("button", { name: "Inspect calendar" }).click(); await expect(page.getByRole("alert")).toBeVisible(); await page.getByRole("tab", { name: "Timezone" }).click(); await page.getByRole("button", { name: "Diagnose" }).click(); await expect( page.getByText(/Overlap: this local time occurs 2 times/u), ).toBeVisible(); expect(external).toEqual([]); }); test("serves release identity and hardened headers", async ({ request }) => { const index = await request.get("/deep/nested/calendar/"); expect(index.ok()).toBe(true); expect(index.headers()["content-security-policy"]).toContain( "connect-src 'self'", ); expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u); const manifest = await request.get("/deep/nested/calendar/toolbox-app.json"); await expect(manifest.json()).resolves.toMatchObject({ id: "de.add-ideas.calendar-tools", version: "0.1.0", entry: "./", privacy: { processing: "local", telemetry: false }, }); });