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/git/"); await expect( page.getByRole("banner").getByRole("heading", { name: "Git Tools" }), ).toBeVisible(); expect(external).toEqual([]); expect(errors).toEqual([]); }); test("authors and re-inspects a patch without flashing state", async ({ page, }) => { const external = await localOnly(page); await page.goto("/deep/nested/git/"); await page.getByRole("button", { name: "Author" }).click(); await page.getByLabel("After text").fill("alpha\nbeta\n"); await page.getByRole("button", { name: "Generate patch" }).click(); await expect(page.getByLabel("Generated patch")).toContainText("+alpha"); await page.getByRole("button", { name: "Inspect generated patch" }).click(); await expect(page.getByText("src/example.ts", { exact: true })).toBeVisible(); expect(external).toEqual([]); }); test("serves release identity and hardened headers", async ({ request }) => { const index = await request.get("/deep/nested/git/"); 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/git/toolbox-app.json"); await expect(manifest.json()).resolves.toMatchObject({ id: "de.add-ideas.git-tools", version: "0.2.0", entry: "./", privacy: { processing: "local", telemetry: false }, }); });