import { expect, test } from "@playwright/test"; const json = (body, status = 200) => ({ status, contentType: "application/json", headers: { "access-control-allow-origin": "*", "access-control-allow-headers": "Content-Type, Authorization, X-Customer-Number, X-Release-Trace, X-Release-Channel, X-Frontend-Version, *", "access-control-allow-methods": "GET, POST, PUT, PATCH, DELETE, OPTIONS", }, body: JSON.stringify(body), }); test("non-default release frontend loads from api-v2.truckwash.io without redirecting", async ({ page }) => { const releaseApiRequests = []; const releaseEntryRequests = []; const runtimeRequests = []; const runtime = { generated_at: "2026-05-20T10:00:00.000Z", trace_id: "trace-release-bootstrap", channel: { id: 2, slug: "canary", name: "Canary", default_channel: false, }, versions: { frontend: { version_label: "frontend-canary", deployed_url: "https://api-v2.truckwash.io/canary/frontend" }, api: { version_label: "api-canary", deployed_url: "https://api-v2.truckwash.io/canary/api" }, bundle_id: 31, }, urls: { frontend_base_url: "https://api-v2.truckwash.io/canary/frontend", api_base_url: "https://api-v2.truckwash.io/canary/api", }, availability: { configured: true, missing: [], status: "ready", }, capture_policy: { enabled: false, capture_level: "metadata", all_failure_metadata: true, retention_days: 14, }, }; await page.addInitScript(() => { window.localStorage.setItem("release_channel_selected_slug", "canary"); }); await page.route("https://api-v2.truckwash.io/canary/api/release/runtime**", async (route) => { runtimeRequests.push(route.request().url()); await route.fulfill(json({ data: runtime })); }); await page.route("https://api-v2.truckwash.io/canary/frontend/release-entry.json", async (route) => { releaseEntryRequests.push(route.request().url()); await route.fulfill( json({ entry: "assets/release-canary.js", css: ["assets/release-canary.css"], }) ); }); await page.route("https://api-v2.truckwash.io/canary/frontend/assets/release-canary.css", async (route) => { await route.fulfill({ status: 200, contentType: "text/css", headers: { "access-control-allow-origin": "*" }, body: "body::before { content: ''; }", }); }); await page.route("https://api-v2.truckwash.io/canary/frontend/assets/release-canary.js", async (route) => { await route.fulfill({ status: 200, contentType: "application/javascript", headers: { "access-control-allow-origin": "*" }, body: ` document.body.dataset.releaseFrontend = 'canary'; document.body.dataset.releaseOrigin = window.location.origin; fetch('https://api-v2.truckwash.io/canary/api/ping').catch(() => {}); `, }); }); await page.route("https://api-v2.truckwash.io/canary/api/ping", async (route) => { releaseApiRequests.push(route.request().url()); await route.fulfill(json({ data: { ok: true } })); }); await page.goto("/shared/passkey-safe-link", { waitUntil: "domcontentloaded" }); await expect(page.locator("body")).toHaveAttribute("data-release-frontend", "canary"); const currentOrigin = await page.evaluate(() => window.location.origin); expect(page.url()).toContain("/shared/passkey-safe-link"); expect(page.url()).not.toContain("api-v2.truckwash.io"); expect(runtimeRequests).toEqual(["https://api-v2.truckwash.io/canary/api/release/runtime?release_channel=canary"]); expect(releaseEntryRequests).toEqual(["https://api-v2.truckwash.io/canary/frontend/release-entry.json"]); await expect.poll(() => releaseApiRequests.length).toBe(1); expect(releaseApiRequests[0]).toBe("https://api-v2.truckwash.io/canary/api/ping"); await expect(page.locator("body")).toHaveAttribute("data-release-origin", currentOrigin); });