import { test, expect, type Page } from "@playwright/test"; import { copyFileSync, existsSync, readFileSync, rmSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The clip editor's edits on the cut (UI notes 2026-10-30, items 2 and 11): // // cut-flash-fixture the clip editor's three clips r001 r002 r003 on vid1 // (their words, their windows cached), the deck on with // a marker after r001 ("Two"), citeUrls, speakers, r002 // end-locked; draft-1.patch.json carries the marker. // WRITES its manifest, the patch, promo/ and revisions/. // // Flash-forward selection… copies a span of r002 to the start of the cut with // its attribution and locks, as a repeat of r002; "move" takes it out of the // clip; Add to trailer writes a beat; a split keeps r001's section boundary. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const DIR = path.join(HERE, "..", ".e2e-song", "reports", "cut-flash-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const PATCH = path.join(DIR, "draft-1.patch.json"); const BEATS = path.join(DIR, "promo", "trailer-beats.json"); const PROJECT = "reports/cut-flash-fixture"; type Clip = Record & { id: string }; const read = (file: string) => JSON.parse(readFileSync(file, "utf8")); const clips = () => read(MANIFEST).timeline as Clip[]; const clip = (id: string) => clips().find((c) => c.id === id) ?? null; test.beforeAll(() => { for (const f of [MANIFEST, PATCH]) if (!existsSync(`${f}.pristine`)) copyFileSync(f, `${f}.pristine`); }); test.beforeEach(() => { for (const f of [MANIFEST, PATCH]) copyFileSync(`${f}.pristine`, f); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); rmSync(path.join(DIR, "promo"), { recursive: true, force: true }); rmSync(path.join(DIR, "montage-rulings.json"), { force: true }); }); async function openOn(page: Page, id: string) { await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: id })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", id); await expect(page.locator("[data-editor-words]")).toHaveAttribute("data-editor-words", "words", { timeout: 15_000 }); } /** Drag a selection on the strip from source second `a` to `b`. */ async function select(page: Page, a: number, b: number) { const strip = page.locator("[data-strip]").first(); const [from, to] = String(await strip.getAttribute("data-strip")).split("-").map(Number); const box = (await strip.boundingBox())!; const x = (t: number) => box.x + ((t - from) / (to - from)) * box.width; const y = box.y + box.height * 0.8; await page.mouse.move(x(a), y); await page.mouse.down(); await page.mouse.move((x(a) + x(b)) / 2, y, { steps: 4 }); await page.mouse.move(x(b), y, { steps: 4 }); await page.mouse.up(); } test("Flash-forward selection… copies the span earlier with its attribution and locks, as a repeat", async ({ page }) => { test.setTimeout(90_000); await openOn(page, "r002"); await expect(page.locator('[data-action="flash-forward"]')).toBeDisabled(); await select(page, 4.5, 5.8); await expect(page.locator('[data-action="flash-forward"]')).toBeEnabled(); await page.locator('[data-action="flash-forward"]').click(); const form = page.getByTestId("flash-forward-form"); await expect(form).toBeVisible(); // Its default: the start of r002's own section (§1, after r001's boundary). await expect(page.getByTestId("ff-where-section")).toBeChecked(); await expect(page.getByTestId("ff-section")).toHaveValue("1"); await page.getByTestId("ff-go").click(); await expect.poll(() => clips().map((c) => c.id)).toEqual(["r001", "r002t", "r002", "r003"]); const t = clip("r002t")!; expect(t.repeatOf).toBe("r002"); expect(t.start).toBeGreaterThanOrEqual(4.4); expect(t.end).toBeLessThanOrEqual(5.9); expect(t.cutStart).toBe(t.start); expect(t.title).toBe("The Fixture Stream"); expect(t.date).toBe("2026-10-27"); expect(t.speakers).toEqual(["Subject"]); expect(t.lockEnd).toBe(true); expect(String(t.citeUrl)).toMatch(new RegExp(`t=${Math.floor(Number(t.start))}$`)); expect(String(t.quote).length).toBeGreaterThan(0); expect(t.quote).not.toBe(clip("r002")!.quote); // The marker stays after r001: the copy opens §1. expect(read(MANIFEST).render.chrome.deck.markers[0].after).toBe("r001"); expect(clip("r002")!.cutStart).toBe(4); }); test("move it out: the span leaves the clip, which keeps the rest", async ({ page }) => { test.setTimeout(90_000); await openOn(page, "r003"); await select(page, 7.4, 8.5); await page.locator('[data-action="flash-forward"]').click(); // The sections have come back (the form's default is the start of r003's section). await expect(page.getByTestId("ff-where-section")).toBeChecked(); await page.getByTestId("ff-where-after").check(); await page.getByTestId("ff-after").selectOption(""); await page.getByTestId("ff-move").check(); await page.getByTestId("ff-go").click(); await expect.poll(() => clips()[0]?.id).toBe("r003t"); expect(clip("r003t")!.repeatOf).toBeUndefined(); expect(Number(clip("r003")!.cutEnd)).toBeLessThanOrEqual(7.5); expect(Number(clip("r003")!.cutStart)).toBe(6.5); }); test("Add to trailer writes the selection (else the cut) as a beat", async ({ page }) => { test.setTimeout(90_000); await openOn(page, "r002"); await page.locator('[data-action="add-to-trailer"]').click(); await expect(page.locator("[data-editor-status]")).toContainText("Added to the trailer as beat 1"); expect(read(BEATS)).toEqual([{ id: "r002", start: 4, end: 6 }]); await page.keyboard.press("ArrowLeft"); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r001"); await select(page, 1.2, 2.6); await page.locator('[data-action="add-to-trailer"]').click(); await expect.poll(() => read(BEATS).length).toBe(2); expect(read(BEATS)[0].id).toBe("r001"); }); test("a split keeps its section: the marker after r001 follows its second half, in the patch too", async ({ page }) => { test.setTimeout(90_000); await openOn(page, "r001"); await page.locator('[data-word-t="2.4"]').click(); await page.locator('[data-action="split"]').click(); await expect.poll(() => clip("r001-2")?.cutStart).toBe(2.4); expect(read(MANIFEST).render.chrome.deck.markers[0].after).toBe("r001-2"); expect(read(PATCH).render.chrome.deck.markers[0].after).toBe("r001-2"); expect(String(clip("r001-2")!.citeUrl)).toMatch(/t=2$/); });