import { expect, test, type Page } from "@playwright/test"; // Clicks every open link on the user homepage and asserts the destination is // the real app, reached through the guard chain without an authentik prompt. // The link set is read live from the rendered homepage (it mirrors // shared/homepage/services.json open entries) so a registry edit cannot leave // this test asserting a stale world. const CHALLENGE = "Making sure you're not a bot"; async function settleThroughGuard(page: Page, targetHost: string): Promise { // Each guarded vhost runs its own Anubis proof-of-work on first visit; // wait for the challenge to clear before judging the destination. await expect .poll(async () => !(await page.locator("body").innerText()).includes(CHALLENGE), { timeout: 90_000 }) .toBe(true); await expect .poll(() => new URL(page.url()).hostname, { timeout: 60_000 }) .toBe(targetHost); expect(await page.locator('input[name="uidField"]').count()).toBe(0); } test("every user open link reaches its app", async ({ page }) => { test.setTimeout(420_000); await page.goto("/"); await expect(page.locator("#grid a.open")).toHaveCount(9); const hrefs = await page .locator("#grid a.open") .evaluateAll((els) => els.map((el) => ({ href: (el as HTMLAnchorElement).href, label: el.textContent ?? "" }))); const failures: string[] = []; for (const link of hrefs) { const target = new URL(link.href); try { await page.goto(link.href); await settleThroughGuard(page, target.hostname); const resp = await page.request.get(page.url()); if (resp.status() >= 500) { failures.push(`${link.label}: ${page.url()} answered ${resp.status()}`); } } catch (err) { failures.push(`${link.label}: ${err instanceof Error ? err.message : String(err)}`); } await page.goto("/"); await expect(page.locator("#grid a.open")).toHaveCount(9); } expect(failures, failures.join("\n")).toEqual([]); });