import { test, expect } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE TAKE WALK'S OLD ADDRESSES (umtool redesign L3; was "walk a take": a draft take walked on the clip // bench, every edit landing in its patch). Every edit lands in the draft now: the take walk // (`…/takes//walk`) and a take's bench (`…/takes//clip/`) are the Open in draft page -- it asks, // saves the draft first, copies the take in -- then the DRAFT's bench; the take's take.json is never // written. The walk's data route and `umtool walk --take` still read a take. // // Fixture (fixtures/take-walk-fixture.mjs), written by this file alone: take-walk-fixture's master is one // clip, w01; its legacy draft take `tight` replaces the timeline with t01a (confirmed), t01b and t01c, all // inside the cached vid1 0-9 s window; and a saved version `v1` of the master (its frozen base). The tests // run in order, each leaving what the next reads. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const PROJECT = "reports/take-walk-fixture"; const TAKE = "tight"; const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "take-walk-fixture"); const manifestText = () => readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const takeText = () => readFileSync(path.join(DIR, "takes", TAKE, "take.json"), "utf8"); const draftClip = (id: string) => (JSON.parse(manifestText()).timeline as { id: string; verdict?: string }[]).find((e) => e.id === id); /** The bench's keys answer once it has hydrated. */ const keyboardLive = async (page: import("@playwright/test").Page) => { // Live once the bench's own keys answer: `x` opens Reject ▾'s reasons, Escape closes them unasked. const menu = page.locator("[data-reject-menu]"); await expect(async () => { await page.locator("body").press("x"); await expect(menu).toBeVisible({ timeout: 500 }); }).toPass({ timeout: 10_000 }); await page.locator("body").press("Escape"); await expect(menu).toHaveCount(0); }; let masterBefore = ""; let takeBefore = ""; test.beforeAll(() => { masterBefore = manifestText(); takeBefore = takeText(); }); test("the Takes page: the draft take and the saved version each Play and Open in draft -- no walk", async ({ page }) => { await page.goto(urls.takesHref(PROJECT)); const card = page.locator(`[data-take="${TAKE}"]`); await expect(card.locator(`[data-take-draft="${TAKE}"]`)).toContainText("draft — not rendered"); await expect(card.locator(`[data-take-open-draft="${TAKE}"]`)).toHaveAttribute("href", urls.openInDraftHref(PROJECT, TAKE)); await expect(card.locator('[data-play-link="take-actions"]')).toHaveAttribute("href", urls.playHref(PROJECT, { take: TAKE })); await expect(page.locator("[data-take-walk-link]")).toHaveCount(0); // Nothing rendered to use: the draft is made the cut, not "used". await expect(card.locator("[data-action=pick]")).toHaveCount(0); await expect(card.locator("[data-take-promote]")).toBeVisible(); await expect(page.locator('[data-take="v1"] [data-take-draft="v1"]')).toContainText("saved version — not rendered"); }); test("the bench's data is the draft's whatever a take is named: a take's clip is not benched (its take paths are gone, E1)", async ({ request }) => { // t01a is the take's, not the draft's: once the bench walked the take with `walkTake`; now it is a 404. const theirs = await request.get(`/api/report/bench?project=${encodeURIComponent(PROJECT)}&clip=t01a&walkTake=${TAKE}`); expect(theirs.status()).toBe(404); const ours = await request.get(`/api/report/bench?project=${encodeURIComponent(PROJECT)}&clip=w01&walkTake=${TAKE}&take=${TAKE}&from=play`); expect(ours.status()).toBe(200); const j = (await ours.json()) as { data: { take?: unknown; fromPlay: { take: string } }; top: { kind: string } }; expect(j.data.take).toBeUndefined(); expect(j.top.kind).toBe("Clip bench"); // `take` with from=play is only the take Play was on: Back keeps it, edits go to the draft. expect(j.data.fromPlay.take).toBe(TAKE); expect(manifestText()).toBe(masterBefore); }); test("the walk's old address is the take's review pass (L7b), whose Open in draft asks; the walk's data route still reads the take", async ({ page, request }) => { await page.goto(urls.takeWalkHref(PROJECT, TAKE)); // A 308 to the take's review pass: read-only, its Open in draft the page that asks. await expect(page.locator("[data-review-pass]")).toHaveAttribute("data-review-pass", TAKE, { timeout: 30_000 }); await expect(page.locator("[data-review-open-draft]")).toHaveAttribute("href", urls.openInDraftHref(PROJECT, TAKE)); await page.locator("[data-review-open-draft]").click(); const ask = page.locator(`[data-open-draft="${TAKE}"]`); await expect(ask).toContainText(`Open ${TAKE} in draft?`); // The draft (from v1, the master unchanged: no edits) has nothing to save. await expect(ask.locator("[data-open-draft-said]")).toContainText("no edits since v1 — nothing to save"); // The data route (and `umtool walk --take`): the same reading as before. const j = (await (await request.get(`/api/report/walk?project=${encodeURIComponent(PROJECT)}&take=${TAKE}`)).json()) as { first: string; take: { draft: boolean }; clips: { id: string; onWalk: boolean; fetched: boolean }[]; }; expect(j.first).toBe("t01b"); expect(j.take.draft).toBe(true); expect(j.clips.map((c) => [c.id, c.fetched, c.onWalk])).toEqual([ ["t01a", true, false], ["t01b", true, true], ["t01c", true, true], ]); expect(manifestText()).toBe(masterBefore); }); test("a take's old bench address: asked, opened, then the DRAFT's bench on the clip -- a verdict lands in the draft, take.json untouched", async ({ page }) => { await page.goto(urls.takeClipHref(PROJECT, TAKE, "t01b")); const ask = page.locator(`[data-open-draft="${TAKE}"]`); await expect(ask).toContainText("the bench opens on t01b"); await ask.locator("[data-open-draft-confirm]").click(); await expect(page).toHaveURL(/\/projects\/reports\/take-walk-fixture\/clip\/t01b$/); await expect(page.locator("[data-bench=t01b]")).toBeVisible({ timeout: 20_000 }); expect((JSON.parse(manifestText()).timeline as { id: string }[]).map((e) => e.id)).toEqual(["t01a", "t01b", "t01c"]); expect(takeText(), "the take is never written").toBe(takeBefore); await keyboardLive(page); await page.locator("body").press("y"); await expect(page.locator("[data-bench=t01c]")).toBeVisible(); await expect.poll(() => draftClip("t01b")?.verdict).toBe("confirmed"); expect(takeText()).toBe(takeBefore); }); test("the draft's own parent with no edits: the old bench address goes straight on (307)", async ({ request }) => { const r = await request.post("/api/report/takes/save", { data: { project: PROJECT } }); expect(await r.json()).toMatchObject({ saved: true, id: "v2" }); const res = await request.get(urls.takeClipHref(PROJECT, "v2", "t01c"), { maxRedirects: 0 }); expect(res.status()).toBe(307); expect(res.headers()["location"]).toMatch(/\/projects\/reports\/take-walk-fixture\/clip\/t01c$/); // A take that is not the parent still asks (its walk's old address is its review pass, whose Open in draft asks). const walk = await request.get(urls.takeWalkHref(PROJECT, TAKE), { maxRedirects: 0 }); expect(walk.status()).toBe(308); expect(walk.headers()["location"]).toBe(urls.versionReviewHref(PROJECT, TAKE)); const asks = await request.get(urls.openInDraftHref(PROJECT, TAKE), { maxRedirects: 0 }); expect(asks.status()).toBe(200); });