import { expect, test } from "@playwright/test"; import AxeBuilder from "@axe-core/playwright"; const path = "/work/constellation-proof"; const headings = [ "Can someone check a coloring without seeing it?", "A certificate you can check", "Inside the verifier", "Can one bit invalidate a proof?", ]; const layers = ["Surface", "Evidence", "Mechanism", "Experiment"]; test("one shared object anchor survives depth navigation, Back, Forward and returning to Surface", async ({ page, }) => { await page.goto("/"); await page .getByRole("link", { name: /The Constellation Proof.*Open evidence/ }) .click(); await expect(page.getByRole("heading", { name: headings[1] })).toBeVisible(); await page.locator(".depth-step").first().click(); await expect(page.getByRole("heading", { name: headings[0] })).toBeVisible(); const title = await page.locator("#constellation").elementHandle(); const originalY = (await page.locator("#constellation").boundingBox())!.y; await page.getByRole("link", { name: "Open evidence", exact: true }).click(); for (const d of [1, 2, 3]) { const link = page.locator(".depth-step").nth(d); if (d > 1) await link.click(); await expect(page).toHaveURL(new RegExp("\\?d=" + d + "$")); await expect( page.getByRole("heading", { name: headings[d], exact: true }), ).toBeVisible(); await expect(link).toHaveAttribute("aria-current", "step"); await expect(link).toBeFocused(); expect( await title!.evaluate( (node) => node === document.getElementById("constellation"), ), ).toBe(true); expect( Math.abs( (await page.locator("#constellation").boundingBox())!.y - originalY, ), ).toBeLessThan(2); } await page.goBack(); await expect(page.getByRole("heading", { name: headings[2] })).toBeVisible(); await page.goForward(); await expect(page.getByRole("heading", { name: headings[3] })).toBeVisible(); await page.locator(".depth-step").first().click(); await expect(page.getByRole("heading", { name: headings[0] })).toBeVisible(); expect(new URL(page.url()).search).toBe(""); }); test("fresh direct links and their HTML work with JavaScript off", async ({ browser, baseURL, }) => { const context = await browser.newContext({ baseURL, javaScriptEnabled: false, }); try { const page = await context.newPage(); for (let d = 0; d < 4; d++) { const res = await page.goto(path + (d ? "?d=" + d : "")); expect(res?.status()).toBe(200); await expect( page.getByRole("heading", { name: headings[d], exact: true }), ).toBeVisible(); await expect(page.locator(".depth-step[aria-current]")).toContainText( layers[d], ); } await expect( page.getByRole("button", { name: "Run verifier" }), ).toHaveCount(0); await page.locator(".depth-step").nth(2).click(); await page.getByRole("link", { name: "Constrain", exact: true }).click(); await expect(page.locator("#constraints")).toBeVisible(); await expect(page.locator("#commitments")).toBeHidden(); await page.locator("#constraints .source-ref").click(); await expect(page.locator("#predicates:target")).toContainText( "function predicates", ); } finally { await context.close(); } }); test("mechanism selections restore on reload and browser history", async ({ page, }) => { await page.goto(path + "?d=2#constraints"); await expect(page.locator("#constraints")).toBeVisible(); await page.getByRole("link", { name: "Bind", exact: true }).click(); await expect(page.locator("#transcript")).toBeVisible(); await page.reload(); await expect(page.locator("#transcript")).toBeVisible(); await page.goBack(); await expect(page.locator("#constraints")).toBeVisible(); await page.goForward(); await expect( page.getByRole("link", { name: "Bind", exact: true }), ).toHaveAttribute("aria-current", "step"); }); test("only declared depths and valid public inputs survive direct navigation", async ({ page, }) => { for (const query of [ "?d=-1", "?d=01", "?d=1&d=2", "?d=0", "?sample=edited", ]) { await page.goto(path + query); expect(new URL(page.url()).search).toBe(""); await expect( page.getByRole("heading", { name: headings[0] }), ).toBeVisible(); } await page.goto(path + "?d=3&sample=missing"); expect(new URL(page.url()).search).toBe("?d=3"); await page.getByRole("link", { name: "Work index", exact: true }).click(); await page .getByRole("link", { name: /Education Math Mastery Platform/ }) .click(); expect(new URL(page.url()).search).toBe(""); await page.goto("/work/ddmaths?d=3"); expect(new URL(page.url()).search).toBe(""); await expect( page.getByRole("navigation", { name: "Project depth" }), ).toHaveCount(0); }); test("the verifier loads on demand, checks both inputs and clears stale results", async ({ page, }) => { const workers: string[] = []; page.on("worker", (worker) => workers.push(worker.url())); await page.goto(path + "?d=3", { waitUntil: "networkidle" }); expect(workers.length).toBe(0); await page.getByRole("button", { name: "Run verifier" }).click(); await expect(page.locator(".verdict strong")).toHaveText("Accepted"); expect(workers.length).toBe(1); await page.getByRole("link", { name: "Flip one bit" }).click(); await expect(page.locator(".verdict")).toHaveText("Ready to verify"); await page.getByRole("button", { name: "Run verifier" }).click(); await expect(page.locator(".verdict strong")).toHaveText("Rejected"); await page.reload(); await expect( page.getByRole("link", { name: "Flip one bit" }), ).toHaveAttribute("aria-current", "true"); await expect(page.locator(".verdict")).toHaveText("Ready to verify"); await page.getByRole("link", { name: "Reset", exact: true }).click(); await expect( page.getByRole("link", { name: "Original vector" }), ).toHaveAttribute("aria-current", "true"); await page.goBack(); await expect( page.getByRole("link", { name: "Flip one bit" }), ).toHaveAttribute("aria-current", "true"); }); test("worker cancellation and failed artifact loads stay distinct from a rejected proof", async ({ page, context, }) => { let release!: () => void, started!: () => void; let responseMode: "wait" | "unavailable" | "live" = "wait"; const pending = new Promise((resolve) => { release = resolve; }); const requested = new Promise((resolve) => { started = resolve; }); await context.route("**/proof-vector.json", async (route) => { if (responseMode === "unavailable") { await route.fulfill({ status: 503, body: "unavailable" }); return; } if (responseMode === "live") { await route.continue(); return; } started(); await pending; await route.abort().catch(() => {}); }); await page.goto(path + "?d=3"); await page.getByRole("button", { name: "Run verifier" }).click(); await requested; await page.getByRole("button", { name: "Cancel" }).click(); await expect(page.locator(".verdict")).toHaveText("Verification cancelled"); responseMode = "unavailable"; release(); await page.getByRole("button", { name: "Run verifier" }).click(); await expect(page.locator(".verdict")).toContainText("could not be loaded"); responseMode = "live"; await page.getByRole("button", { name: "Run verifier" }).click(); await expect(page.locator(".verdict strong")).toHaveText("Accepted"); }); test("mobile, reduced motion, keyboard and automated accessibility across depth", async ({ page, }, testInfo) => { test.setTimeout(90000); await page.setViewportSize({ width: 320, height: 740 }); await page.emulateMedia({ reducedMotion: "reduce" }); await page.goto(path); for (let d = 0; d < 4; d++) { if (d) { const next = page .getByRole("navigation", { name: "Project depth" }) .getByRole("link", { name: "Next", exact: true }); await next.focus(); await page.keyboard.press("Enter"); } await expect( page.getByRole("heading", { name: headings[d], exact: true }), ).toBeVisible(); expect( await page.evaluate( () => document.documentElement.scrollWidth <= innerWidth, ), ).toBe(true); expect( await page .locator(".cut-section") .evaluate((el) => getComputedStyle(el, "::before").animationName), ).toBe("none"); const axe = await new AxeBuilder({ page }) .withTags(["wcag2a", "wcag2aa", "wcag21a", "wcag21aa", "wcag22aa"]) .analyze(); expect( axe.violations.map((v) => [v.id, v.nodes.map((n) => n.target)]), ).toEqual([]); if (d === 2) await page.screenshot({ path: testInfo.outputPath("mechanism-mobile.png"), fullPage: true, }); } await page.setViewportSize({ width: 1440, height: 900 }); await page.goto(path + "?d=1"); await page.screenshot({ path: testInfo.outputPath("evidence-desktop.png"), fullPage: true, }); });