import { test, expect, type Page } from "@playwright/test"; import { copyFileSync, existsSync, readFileSync, readdirSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // BEAT REELS (lane/beat-reels): "I want to be able to play and walk the // trailer the same as main, even if I need to have a rendered main first." // // reel-fixture takes/draft-1 with a synthesized rendered master (10.5 s, // six 2.0 s segments, 0.3 s dissolves) and its build // records; promo/trailer-beats.json c01 1–2.5, c03 5–6.5, // c05 9–10.4 (3.8 s); promo/teaser-beats.json c02 alone. // WRITES promo/, notes.json and a cut in draft-1/out: // each test starts from the fixture's. // reel-none-fixture its one take a draft with no master. // // The reel's Play (from the master, the crossfade, the clock against the // limit, a note on a beat), its walk -- the reel's own editor on the clip // bench's parts (lane/reel-bench): the master's waveform and zoom, nudges and // a drag held to what the master rendered, written in source seconds through // the one writer, tighten, an undo point per write, Confirm walks on, Back to // the reel -- a beat's gap (Alt + drag, Cut gap; Play skips it and counts kept // seconds), Cut the trailer as a job with the result's local path, and the // no-master state. Fixture: e2e/fixtures/reel-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "reel-fixture"); const PROJECT = "reports/reel-fixture"; const PROMO = path.join(DIR, "promo"); const OUT = path.join(DIR, "takes", "draft-1", "out"); const NOTES = path.join(DIR, "notes.json"); /** The reel's beats as written; `anchors` keeps what each was cut against (a walk's write anchors it to the take). */ const beatsOf = (reel = "trailer", { anchors = false } = {}) => { const d = JSON.parse(readFileSync(path.join(PROMO, `${reel}-beats.json`), "utf8")); const list = (Array.isArray(d) ? d : d.beats) as { id?: string; start?: number; end?: number; verdict?: string; anchor?: unknown }[]; return anchors ? list : list.map(({ anchor: _a, ...b }) => b); }; const root = (page: Page) => page.locator("[data-reel-play]"); const C03 = path.join(OUT, "sourced", "segments", "c03.cut.json"); test.beforeAll(() => { for (const f of ["trailer-beats.json", "teaser-beats.json"]) { const p = path.join(PROMO, f); if (!existsSync(`${p}.pristine`)) copyFileSync(p, `${p}.pristine`); } if (!existsSync(`${C03}.pristine`)) copyFileSync(C03, `${C03}.pristine`); }); test.beforeEach(() => { test.setTimeout(120_000); for (const f of readdirSync(PROMO)) { if (f.endsWith(".pristine")) copyFileSync(path.join(PROMO, f), path.join(PROMO, f.replace(/\.pristine$/, ""))); else if (!/^(trailer|teaser)-beats\.json$/.test(f)) rmSync(path.join(PROMO, f), { force: true }); } for (const f of readdirSync(OUT)) if (/\.(trailer|teaser)\.(mp4|json)$/.test(f) || f.endsWith(".trailer.json")) rmSync(path.join(OUT, f), { force: true }); rmSync(NOTES, { force: true }); copyFileSync(`${C03}.pristine`, C03); }); test("the Trailer page lists the reels; a reel plays from the take's rendered master, beat after beat, against the limit; a note lands on its beat", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.trailerHref(PROJECT)); await expect(page.locator("[data-reel-tab='trailer']")).toContainText("trailer (3)"); await expect(page.locator("[data-reel-tab='teaser']")).toContainText("teaser — The teaser (1)"); const panel = page.locator("[data-reel-cut-panel='trailer']"); await expect(panel).toContainText("(latest master)"); await expect(panel).toContainText("3 of 3 beats play from it · 0:03.8"); await panel.locator("[data-reel-play-link]").click(); await expect(root(page)).toHaveAttribute("data-reel-take", "draft-1"); await expect(root(page)).toHaveAttribute("data-reel-state", "paused"); await expect(page.locator("[data-reel-cell]")).toHaveCount(3); await expect(page.locator("[data-reel-clock]")).toHaveText("0:00.0 / 0:03.8"); await expect(page.locator("[data-reel-limit]")).toContainText("limit 2:20.0 · 136.2 s to spare · crossfade 0.3 s"); await expect(page.locator("[data-reel-master-path]")).toHaveText(path.join(OUT, "reel-fixture.mp4")); await expect(page.locator("[data-reel-now='1']")).toContainText("beat 1 · c01"); await expect(page.locator("[data-reel-now='1']")).toContainText("the words of c01"); // Plays through: beat 2 (into the crossfade), then 3, and stops at the reel's end. await page.locator("[data-reel-toggle]").click(); await expect(root(page)).toHaveAttribute("data-reel-state", "playing"); await expect(root(page)).toHaveAttribute("data-reel-beat", "2", { timeout: 15_000 }); await expect(root(page)).toHaveAttribute("data-reel-beat", "3", { timeout: 15_000 }); await expect(root(page)).toHaveAttribute("data-reel-state", "paused", { timeout: 15_000 }); expect(Number(await root(page).getAttribute("data-reel-t"))).toBeGreaterThan(3.6); // The keys: P back a beat, N on; M a note on the beat on screen. await page.keyboard.press("p"); await expect(root(page)).toHaveAttribute("data-reel-beat", "3"); await page.keyboard.press("p"); await expect(root(page)).toHaveAttribute("data-reel-beat", "2"); await page.keyboard.press("m"); await expect(page.locator("[data-reel-composer]")).toContainText("beat 2 · c03"); await page.getByTestId("reel-note-input").fill("end it on the word"); await page.locator("[data-reel-ask='trim']").click(); await page.getByTestId("reel-note-input").press("Enter"); await expect(page.locator("[data-reel-note-row]")).toHaveCount(1); await expect(page.locator("[data-reel-pin]")).toHaveCount(1); const notes = JSON.parse(readFileSync(NOTES, "utf8")).notes; expect(notes[0].anchor).toMatchObject({ kind: "reel", reel: "trailer", beat: 2, entry: "c03", take: "draft-1", ask: "trim" }); expect(notes[0].anchor.sourceT).toBeGreaterThanOrEqual(5); await page.screenshot({ path: test.info().outputPath("reel-play.png") }); // E: the walk on the beat on screen. await page.keyboard.press("e"); await expect(page).toHaveURL(/\/trailer\/walk\?take=draft-1&beat=2/); await expect(page.locator("[data-reel-walk]")).toHaveAttribute("data-reel-beat", "2"); }); test("the walk is the reel's own editor on the clip bench's parts: the master's waveform and zoom, nudges and a drag held to what the master rendered, saved in source seconds; tighten; undo; Confirm walks on; Back to the reel", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.reelWalkHref(PROJECT, { beat: 2 })); const walk = page.locator("[data-reel-walk]"); await expect(walk).toHaveAttribute("data-reel-beat", "2"); await expect(walk).toHaveAttribute("data-reel-dirty", "0"); await expect(page.locator("[data-reel-source-edges]")).toHaveText("source 0:05.00 – 0:06.50"); await expect(page.locator("[data-reel-beat-quote]")).toContainText("the words of c03"); await expect(page.locator("[data-reel-limits]")).toContainText("0:04.75–0:06.75"); // The master's waveform (its envelope, on the clip's source clock), over the seconds its segment plays. const box = page.locator("[data-wave-box]"); await expect(box).toHaveAttribute("data-wave-vis", "4.75-6.75"); await expect(page.locator("[data-reel-walk-video]")).toHaveAttribute("src", /\/api\/report\/file\?.*path=takes%2Fdraft-1%2Fout%2Freel-fixture\.mp4/); await expect(page.locator("[data-playback]")).toHaveAttribute("data-audio-state", "ready", { timeout: 15_000 }); // The zoom: z closer (the ruler and the overview), f back to the whole segment. await page.keyboard.press("z"); await expect(box).not.toHaveAttribute("data-wave-vis", "4.75-6.75"); await expect(page.locator("[data-zoom-overview]")).toHaveCount(1); await page.keyboard.press("f"); await expect(box).toHaveAttribute("data-wave-vis", "4.75-6.75"); // ] twice: the in edge 0.1 s later; . with Shift: the out edge 0.5 s later -- held to the segment (6.75), and said. await page.keyboard.press("]"); await page.keyboard.press("]"); await page.keyboard.press("Shift+."); await expect(walk).toHaveAttribute("data-reel-dirty", "1"); await expect(page.locator("[data-reel-source-edges]")).toHaveText("source 0:05.10 – 0:06.75"); await expect(page.locator("[data-reel-limit-hit='end']")).toContainText("the end of what the master rendered for c03"); await page.keyboard.press("Enter"); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 5.1, end: 6.75 }); await expect(walk).toHaveAttribute("data-reel-dirty", "0"); await expect(page.locator("[data-reel-msg]")).toContainText("saved beat 2: edges"); // The in handle dragged on the waveform past the segment's start: held at 4.75. const wb = (await box.boundingBox())!; const xOf = (t: number) => wb.x + ((t - 4.75) / 2) * wb.width; await page.mouse.move(xOf(5.1), wb.y + wb.height / 2); await page.mouse.down(); await page.mouse.move(wb.x - 20, wb.y + wb.height / 2, { steps: 6 }); await page.mouse.up(); await expect(page.locator("[data-reel-source-edges]")).toHaveText("source 0:04.75 – 0:06.75"); await page.locator("[data-reel-save]").click(); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 4.75, end: 6.75 }); await page.screenshot({ path: test.info().outputPath("reel-walk.png") }); // Tighten to the sentence is the clip bench's own button, over the clip's words: it says what it did. await page.locator("[data-tighten]").click(); await expect(page.locator("[data-reel-msg]")).toContainText(/tightened|already tight|not tightened/); // A tighten that moved the edges is a write of its own: U takes it back. await page.waitForTimeout(300); if (JSON.stringify(beatsOf()[1]) !== JSON.stringify({ id: "c03", start: 4.75, end: 6.75 })) await page.keyboard.press("u"); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 4.75, end: 6.75 }); // U: the last write undone, then the one before. await page.keyboard.press("u"); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 5.1, end: 6.75 }); await page.locator("[data-reel-undo]").click(); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 5, end: 6.5 }); await expect(page.locator("[data-reel-source-edges]")).toHaveText("source 0:05.00 – 0:06.50"); // Y: confirmed, and on to beat 3; B back to the reel's Play at that beat. await page.keyboard.press("y"); await expect(page).toHaveURL(/beat=3/); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 5, end: 6.5, verdict: "confirmed" }); await expect(page.locator("[data-reel-walk]")).toHaveAttribute("data-reel-beat", "3"); await page.keyboard.press("b"); await expect(page).toHaveURL(/\/trailer\/play\?.*beat=3/); await expect(root(page)).toHaveAttribute("data-reel-beat", "3"); await expect(page.locator("[data-reel-cell='2']")).toHaveClass(/border-b-2/); // The beats page says it too. await page.goto(urls.trailerHref(PROJECT)); await expect(page.getByTestId("trailer-confirmed")).toHaveText("1 confirmed on the walk"); await expect(page.locator("[data-beat='2'] [data-beat-verdict='confirmed']")).toHaveCount(1); }); test("a beat's gap: Alt + drag on the master's waveform, Cut gap writes it in source seconds, the reel's Play skips it and its clock counts kept seconds; undo takes it back", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.reelWalkHref(PROJECT, { beat: 2 })); const box = page.locator("[data-wave-box]"); await expect(box).toHaveAttribute("data-wave-vis", "4.75-6.75"); const wb = (await box.boundingBox())!; const xOf = (t: number) => wb.x + ((t - 4.75) / 2) * wb.width; const y = wb.y + wb.height / 2; await page.keyboard.down("Alt"); await page.mouse.move(xOf(5.5), y); await page.mouse.down(); await page.mouse.move(xOf(5.8), y, { steps: 5 }); await page.mouse.up(); await page.keyboard.up("Alt"); await expect(page.locator("[data-gap-cut]")).toBeVisible(); await page.keyboard.press("g"); await expect.poll(() => (beatsOf()[1] as { gaps?: { from: number; to: number }[] }).gaps?.length ?? 0).toBe(1); const g = (beatsOf()[1] as { gaps: { from: number; to: number }[] }).gaps[0]; expect(Math.abs(g.from - 5.5)).toBeLessThan(0.03); expect(Math.abs(g.to - 5.8)).toBeLessThan(0.03); await expect(page.locator("[data-reel-walk]")).toHaveAttribute("data-reel-gaps", `${g.from}-${g.to}`); await expect(page.locator("[data-gaps-summary]")).toContainText("1 gap"); await expect(page.locator("[data-reel-msg]")).toContainText("one beat of jump cuts"); // Play the reel: 3.8 s less the gap's seconds, and it plays through, skipping it. await page.goto(urls.reelPlayHref(PROJECT)); const cut = g.to - g.from; const total = 3.8 - cut; await expect(page.locator("[data-reel-clock]")).toHaveText(`0:00.0 / 0:0${total.toFixed(1)}`); await page.locator("[data-reel-toggle]").click(); await expect(root(page)).toHaveAttribute("data-reel-beat", "3", { timeout: 15_000 }); await expect(root(page)).toHaveAttribute("data-reel-state", "paused", { timeout: 15_000 }); expect(Number(await root(page).getAttribute("data-reel-t"))).toBeGreaterThan(total - 0.2); // Back on the walk, U takes the gap back. await page.goto(urls.reelWalkHref(PROJECT, { beat: 2 })); await page.keyboard.press("u"); await expect.poll(() => beatsOf()[1]).toEqual({ id: "c03", start: 5, end: 6.5 }); }); test("reels track their source: a beat anchored to the take, then its clip's end moved under it -- flagged, walked alone, clamped; the history says so", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.reelWalkHref(PROJECT, { beat: 2 })); await expect(page.locator("[data-reel-source-line]")).toHaveText("no beat is anchored yet"); await expect(page.locator("[data-reel-beat-state]")).toHaveAttribute("data-reel-beat-state", "unanchored"); await page.locator("[data-reel-anchor]").click(); await expect(page.locator("[data-reel-beat-state]")).toHaveAttribute("data-reel-beat-state", "unchanged"); expect((beatsOf("trailer", { anchors: true })[1] as { anchor?: { take: string; clip: { end: number } } }).anchor).toMatchObject({ take: "draft-1", clip: { start: 4.75, end: 6.75 } }); // The take's record for c03 now ends at 6.6 (as if the clip's edge moved and the take were rendered again): // beat 2 still fits -- its clip's edges moved; the reel says which beat. const rec = JSON.parse(readFileSync(C03, "utf8")); writeFileSync(C03, JSON.stringify({ ...rec, end: 6.6 })); await page.goto(urls.reelWalkHref(PROJECT, { beat: 1 })); await expect(page.locator("[data-reel-source-line]")).toHaveText("take draft-1 changes beat 2"); await page.locator("[data-reel-walk-filter='changed']").click(); await expect(page).toHaveURL(/beat=2.*changed=1|changed=1.*beat=2/); await expect(page.locator("[data-bench-pos]")).toHaveText("1 of 1 changed beats"); await expect(page.locator("[data-reel-beat-state]")).toHaveAttribute("data-reel-beat-state", "edges"); await expect(page.locator("[data-reel-beat-was]")).toHaveText("was 0:04.75–0:06.75 · now 0:04.75–0:06.60"); await page.screenshot({ path: test.info().outputPath("reel-changed.png") }); // Pulled in past the beat: clipped, and Clamp fits it back -- anchored to the take it was fixed against. writeFileSync(C03, JSON.stringify({ ...rec, end: 6.3 })); await page.reload(); await expect(page.locator("[data-reel-beat-state]")).toHaveAttribute("data-reel-beat-state", "clipped"); await page.locator("[data-reel-clamp]").click(); await expect.poll(() => (beatsOf()[1] as { end: number }).end).toBe(6.3); await expect(page.locator("[data-reel-beat-state]")).toHaveAttribute("data-reel-beat-state", "unchanged"); const hist = JSON.parse(readFileSync(path.join(PROMO, "trailer-beats.history.json"), "utf8")).entries as { what: string; take?: string }[]; expect(hist.map((e) => e.what)).toEqual(["anchor beat 2 to take draft-1", "beat 2: start, end"]); expect(hist[1].take).toBe("draft-1"); }); test("Cut the trailer: a job on the runner, its log, the result playing on the page with its local path; a new reel", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.trailerHref(PROJECT, { reel: "teaser" })); const panel = page.locator("[data-reel-cut-panel='teaser']"); await expect(panel.locator("[data-reel-cut]")).toBeEnabled(); await panel.locator("[data-reel-cut]").click(); await expect(panel.locator("[data-reel-job]")).toBeVisible(); await expect(panel.locator("[data-reel-job]")).toHaveAttribute("data-reel-job", "done", { timeout: 90_000 }); await expect(panel.locator("[data-reel-job-log]")).toContainText("trailer reports/reel-fixture --reel teaser --take draft-1"); const out = path.join(OUT, "reel-fixture.teaser.mp4"); await expect(panel.locator("[data-reel-result-path]")).toHaveText(out); expect(existsSync(out)).toBe(true); expect(existsSync(path.join(OUT, "reel-fixture.teaser.trailer.json"))).toBe(true); await expect(panel.locator("[data-reel-result-video]")).toHaveAttribute("src", /what=cut&reel=teaser/); // The trailer reel's file is untouched by the teaser's cut. expect(existsSync(path.join(OUT, "reel-fixture.trailer.mp4"))).toBe(false); // + New reel: a copy of the trailer, its own file, listed. await page.locator("[data-reel-new-open]").click(); await page.locator("[data-reel-new-name]").fill("x-first"); await page.locator("[data-reel-new-from]").selectOption("trailer"); await page.locator("[data-reel-new-make]").click(); await expect(page).toHaveURL(/reel=x-first/); await expect(page.locator("[data-reel-tab='x-first']")).toContainText("x-first (3)"); expect(beatsOf("x-first").map((b) => b.id)).toEqual(["c01", "c03", "c05"]); }); test("no rendered master: the reel says so and offers the render -- nothing renders from here", async ({ page }) => { await page.goto(urls.reelPlayHref("reports/reel-none-fixture")); await expect(page.locator("[data-reel-no-master-why]")).toContainText("no take has a finished master yet"); await expect(page.locator("[data-reel-render-link]")).toHaveAttribute("href", urls.takesHref("reports/reel-none-fixture")); await page.goto(urls.trailerHref("reports/reel-none-fixture")); await expect(page.locator("[data-reel-cut-panel] [data-reel-no-master]")).toContainText("render a take first"); await expect(page.locator("[data-reel-cut]")).toHaveCount(0); });