import { test, expect } from "@playwright/test"; import * as urls from "./urls"; import { REDIRECTS } from "./urls"; // --------------------------------------------------------------------------- // Every old page address (umtool/redirects.mjs, the table next.config.ts // answers): requested with redirects OFF, each must be a 308 (permanent since // P6b; a browser caches it forever, so a row is never repointed) to the row's // destination, with the query passed through. Then the destination itself must // answer. // // The rows are read from the table, not copied here, so a new row is covered // the day it is added. Parameters get a sample value; `:path*` gets two // segments, the shape every project URL has. // --------------------------------------------------------------------------- const SAMPLE: Record = { set: "mk-hooks", path: "reports/report-fixture", mode: "sort", }; /** A row's source and destination with each `:param` given its sample. */ function fill(pattern: string): string { return pattern.replace(/:(\w+)(\([^)]*\))?\*?/g, (_m, name: string) => SAMPLE[name] ?? name); } /** Next puts the request's query first, then the destination's own. */ function expected(destination: string, query: string): string { const dest = fill(destination); if (!query) return dest; const [path, own] = dest.split("?"); return own ? `${path}?${query}&${own}` : `${path}?${query}`; } /** An address as path + its parameters in order, so `+` and `%20` read alike. */ function parts(href: string): [string, [string, string][]] { const u = new URL(href, "http://x"); return [u.pathname, [...u.searchParams.entries()]]; } test("the table has the P3, P5 and P6 rows, reserved /browse tools before the catch-all", () => { const sources = REDIRECTS.map((r) => r.source); const catchAll = sources.indexOf("/browse/:path*"); expect(catchAll).toBeGreaterThan(0); for (const s of ["/browse", "/browse/decisions", "/browse/find", "/browse/faces", "/browse/sources", "/browse/trim/:set", "/browse/at"]) { expect(sources.indexOf(s), s).toBeGreaterThanOrEqual(0); expect(sources.indexOf(s), `${s} must come before the catch-all`).toBeLessThan(catchAll); } for (const r of REDIRECTS) expect(r.permanent, r.source).toBe(true); // P5: the editor's hand-off, only when the query has `from`; the new-article form. expect(REDIRECTS.find((r) => r.source === "/")).toMatchObject({ destination: "/create", has: [{ type: "query", key: "from" }] }); expect(REDIRECTS.find((r) => r.source === "/articles/new")?.destination).toBe("/create?make=article"); // P6: the deleted /drafts page lands where it did. expect(REDIRECTS.find((r) => r.source === "/drafts")?.destination).toBe("/create?make=article"); }); for (const row of REDIRECTS) { const from = fill(row.source); // A row that matches only when the query HAS a key is asked with it. const needs = (row.has ?? []).filter((h) => h.type === "query").map((h) => `${h.key}=testchan%2Fvid1`); test(`${row.source}${needs.length ? `?${needs.join("&")}` : ""} → ${row.destination} (308, query kept)`, async ({ request }) => { for (const query of (["", "q=x+y¬e=n1"] as string[]).map((q) => [...needs, ...(q ? [q] : [])].join("&"))) { const url = query ? `${from}?${query}` : from; const res = await request.get(url, { maxRedirects: 0 }); expect(res.status(), url).toBe(308); expect(parts(res.headers()["location"]), url).toEqual(parts(expected(row.destination, query))); } // And where it lands answers (the escape hatch needs a project to open). const landed = await request.get(row.source === "/browse/at" ? `${from}?path=find` : needs.length ? `${from}?${needs.join("&")}` : from); expect(landed.status(), `${from} → ${landed.url()}`).toBe(200); }); } // Release 28's pages link the old addresses by hand (`/browse/${id}/review`, // `…/narration`, `…/takes`, a clip bench); they ride the catch-all row. for (const [old, now] of [ ["/browse/reports/report-fixture/takes", "/projects/reports/report-fixture/takes"], ["/browse/reports/report-fixture/clip/c01", "/projects/reports/report-fixture/clip/c01"], ["/browse/reports/narration-review-fixture/narration", "/projects/reports/narration-review-fixture/narration"], ["/browse/reports/draft-review-fixture/review", "/projects/reports/draft-review-fixture/review"], ["/browse/reports/report-fixture?all=1¬e=n1", "/projects/reports/report-fixture?all=1¬e=n1"], ] as const) { test(`${old} lands on ${now}`, async ({ request }) => { const res = await request.get(old, { maxRedirects: 0 }); expect(res.status()).toBe(308); expect(parts(res.headers()["location"])).toEqual(parts(now)); expect((await request.get(old)).status()).toBe(200); }); } test("a page that did not move is not redirected", async ({ request }) => { // `/` is the Inbox unless the query has `from` (the hand-off row). for (const p of ["/", "/?hidden=1", "/work", "/tools", "/projects", "/sites/priv", "/articles/delta", "/create", "/create?make=song", "/settings", "/settings/generation", "/settings/system"]) { const res = await request.get(p, { maxRedirects: 0 }); expect(res.status(), p).toBe(200); } }); // --------------------------------------------------------------------------- // THE WORKSPACE'S STATES (umtool redesign L7b): the views a report video's workspace now holds answer with a 308 to // it (ProjectView, after the project resolves -- a project id is a path, so these cannot be rows of the table). // What the workspace does not hold yet stays where it is: the clip bench (the walk's every step is a bare // /clip/), the post and claim benches, the drafts review, Play's own page (`?cut=1` and every query), the // montage deck, the takes' compare and the trailer. // --------------------------------------------------------------------------- const W = "reports/play-cut-fixture"; for (const [old, now] of [ [urls.legacyPresentHref(W), urls.workspaceHref(W, { mode: "present" })], [urls.legacyPresentHref(W, { take: "short" }), urls.workspaceHref(W, { mode: "present", take: "short" })], [urls.takeWalkHref(W, "v1"), urls.workspaceHref(W, { mode: "review", take: "v1" })], [urls.takeWalkHref(W, "short", { all: true }), urls.workspaceHref(W, { mode: "review", take: "short", all: true })], [urls.takeWalkHref(W, "v1", { all: true, note: "n1" }), urls.workspaceHref(W, { mode: "review", take: "v1", all: true, note: "n1" })], [urls.barePlayHref(W), urls.workspaceHref(W)], // The workspace's own tab. [urls.projectHref(W, { tab: "workspace" }), urls.workspaceHref(W)], ] as const) { test(`L7b: ${old} → ${now} (308)`, async ({ request }) => { const res = await request.get(old, { maxRedirects: 0 }); expect(res.status(), old).toBe(308); expect(parts(res.headers()["location"]), old).toEqual(parts(now)); expect((await request.get(old)).status(), `${old} lands`).toBe(200); }); } test("L7b: what the workspace does not hold yet is not redirected", async ({ request }) => { for (const href of [ urls.playHref(W), urls.playHref(W, { take: "short" }), urls.playHref(W, { clip: "c02", at: 0.5 }), urls.clipBenchHref(W, "c01"), urls.clipBenchHref(W, "c01", { play: { at: 1 } }), urls.postBenchHref("reports/post-items-fixture", "p-txt"), urls.claimBenchHref("reports/bench-fixture", "k03"), urls.reviewHref("reports/draft-review-fixture"), urls.projectHref(W, { tab: "overview" }), urls.projectHref(W, { tab: "cut" }), urls.takesHref(W), urls.trailerHref(W), urls.clipDeckHref(W), ]) { const res = await request.get(href, { maxRedirects: 0 }); expect(res.status(), href).not.toBe(308); expect(res.status(), href).toBeLessThan(400); } }); // The tabs that folded into Deliver: a 307 (that content moves again), the rest of the query kept, note last. An // article piece keeps its own Build and Media tabs: its `?tab=build` is not redirected at all. for (const [old, now] of [ [urls.projectHref(W, { tab: "build" }), urls.projectHref(W, { tab: "deliver" })], [urls.projectHref(W, { tab: "media", note: "n1" }), urls.projectHref(W, { tab: "deliver", note: "n1" })], ] as const) { test(`L7b: ${old} → ${now} (307)`, async ({ request }) => { const res = await request.get(old, { maxRedirects: 0 }); expect(res.status(), old).toBe(307); expect(parts(res.headers()["location"]), old).toEqual(parts(now)); expect((await request.get(old)).status(), `${old} lands`).toBe(200); }); } test("L7b: an article piece's ?tab=build and ?tab=media are its own tabs, never redirected", async ({ request }) => { for (const tab of ["build", "media"]) { const href = urls.articleHref({ site: "articles", id: "zeta" }, { tab }); const res = await request.get(href, { maxRedirects: 0 }); expect(res.status(), href).toBe(200); } });