import { expect, test, type Page, type Response } 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/file/"); await expect(page.getByRole("heading", { name: "File Tools" })).toBeVisible(); expect(external).toEqual([]); expect(errors).toEqual([]); }); test("inspects and hashes a local file in an immutable module worker", async ({ page, }) => { const external = await localOnly(page); const responses: Response[] = []; page.on("response", (response) => responses.push(response)); await page.goto("/deep/nested/file/"); await page .locator('input[type="file"]') .first() .setInputFiles("tests/fixtures/hello.txt"); await expect(page.getByRole("heading", { name: "hello.txt" })).toBeVisible(); await expect( page.getByText("text/plain (.txt)", { exact: true }), ).toBeVisible(); await page.getByRole("button", { name: "Hash", exact: true }).click(); await expect(page.getByText(/^[0-9a-f]{64}$/u)).toBeVisible(); const worker = responses.find((response) => /\/deep\/nested\/file\/assets\/inspect\.worker-[\w-]+\.js$/u.test( new URL(response.url()).pathname, ), ); expect(worker, "inspection worker request").toBeTruthy(); expect(worker!.headers()["content-type"]).toContain("text/javascript"); expect(worker!.headers()["cache-control"]).toBe( "public, max-age=31536000, immutable", ); expect(new URL(worker!.url()).origin).toBe(ORIGIN); expect(external).toEqual([]); }); test("automatically inspects every file in a bounded batch", async ({ page, }) => { await page.goto("/deep/nested/file/"); await page .locator('input[type="file"]') .first() .setInputFiles([ "tests/fixtures/hello.txt", "tests/fixtures/second.txt", "tests/fixtures/third.csv", ]); await expect( page.locator(".file-row small", { hasText: "inspected" }), ).toHaveCount(3, { timeout: 30_000, }); await expect(page.getByText("Inspecting 3 of 3 files")).toBeHidden(); await page.getByRole("button", { name: "third.csv" }).click(); await expect( page.getByText("text/plain (.txt)", { exact: true }), ).toBeVisible(); }); test("previews collision-safe batch renames and exposes split/hash workflows", async ({ page, }) => { await page.goto("/deep/nested/file/"); await page .locator('input[type="file"]') .first() .setInputFiles(["tests/fixtures/hello.txt", "tests/fixtures/second.txt"]); await page.getByLabel("Template").fill("same.{ext}"); await page.getByRole("button", { name: "Plan rename" }).click(); await expect(page.getByRole("list", { name: "Rename plan" })).toContainText( "same (2).txt", ); await expect( page.getByRole("button", { name: "Download parts + manifest" }), ).toBeEnabled(); await expect( page.getByRole("button", { name: "Download SHA256SUMS" }), ).toBeVisible(); }); test("serves the release identity and hardened headers", async ({ request, }) => { const index = await request.get("/deep/nested/file/"); expect(index.ok()).toBe(true); expect(index.headers()["content-security-policy"]).toContain( "default-src 'self'", ); expect(await index.text()).not.toMatch(/\b(?:src|href)=["']\//u); const manifest = await request.get("/deep/nested/file/toolbox-app.json"); await expect(manifest.json()).resolves.toMatchObject({ id: "de.add-ideas.file-tools", version: "0.2.0", entry: "./", }); });