import { test, expect } from "@playwright/test"; import { spawnSync } from "node:child_process"; import { readFileSync, statSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // FAST FEEDBACK (lib/report/takePreview.mjs; umtool/docs/report-video.md, "Fast feedback: preview and // changes renders"): a take's PREVIEW (the whole take at 1280x720, veryfast) and its CHANGES REEL (only // what changed against the take it was made from, each piece labelled with its time in the full cut). // // 1. the CLI: t0 rendered whole; t1 drafted from it (m02 trimmed, m04 added); t1's changes reel has two // labelled pieces and changes.json lists them; t0's preview is 1280x720 and its full render's files // (preview.mp4, out/.mp4, render.json, take.json, out/sourced/schedule…) are untouched; // `take status --json` reports both // 2. the Takes page: the card's Preview render / Render changes, a queue step the app runs, the state // inline, the output's local path, Play of the file // // Fixture: preview-render-fixture (make-fixture.mjs), which this spec WRITES (takes/). // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/preview-render-fixture"; const DIR = path.join(FIXTURE, "reports", "preview-render-fixture"); const SLUG = "preview-render-fixture"; function cli(args: string[], base = "") { const r = spawnSync("node", ["bin/umtool.mjs", ...args], { cwd: path.join(HERE, ".."), encoding: "utf8", env: { ...process.env, REPORTS_DIR: FIXTURE, CHANNELS_DIR: path.join(FIXTURE, "channels"), UMTOOL_CACHE_DIR: path.join(FIXTURE, "cache"), UMTOOL_MEDIA_DIR: "", ...(base ? { UMTOOL_URL: base } : {}) }, timeout: 240_000, }); return { code: r.status, out: r.stdout, err: r.stderr }; } function size(file: string) { const r = spawnSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height", "-of", "csv=p=0", file], { encoding: "utf8" }); return r.stdout.trim(); } const clip = (id: string, start: number, end: number, quote: string) => ({ type: "clip", id, video: "vid1", start, end, cite: Math.floor(start), section: 0, lock: true, quote }); test.describe.configure({ mode: "serial" }); test("the CLI: a changes reel of two labelled pieces with changes.json; a 1280x720 preview beside the untouched full render", async () => { test.setTimeout(400_000); const t0 = cli(["take", PROJECT, "--id", "t0", "--label", "T0", "--full", "--force"]); expect(t0.code, t0.err + t0.out).toBe(0); const patch = { timeline: [clip("m01", 3, 4, "the first"), clip("m02", 4, 5.5, "and because"), clip("m03", 3.5, 5, "the last"), clip("m04", 5, 6, "one more")] }; const d = cli(["take", PROJECT, "--id", "t1", "--draft", "--from", "t0", "--force", "--patch-json", JSON.stringify(patch)]); expect(d.code, d.err).toBe(0); expect(JSON.parse(readFileSync(path.join(DIR, "takes", "t1", "take.json"), "utf8")).draftedFrom).toBe("t0"); // The changes reel: against t0 (the draft's own from), two pieces, each labelled with its full-cut time. const c = cli(["take", PROJECT, "--id", "t1", "--changes", "--json"]); expect(c.code, c.err + c.out).toBe(0); const list = JSON.parse(readFileSync(path.join(DIR, "takes", "t1", "changes.json"), "utf8")); expect(list.from).toBe("t0"); expect(list.tier).toBe("preview"); expect(list.items.map((x: { id: string; kinds: string[] }) => [x.id, x.kinds])).toEqual([["m02", ["media trim"]], ["m04", ["added clip"]]]); for (const it of list.items) expect(it.label).toMatch(new RegExp(`^\\d+:\\d\\d · ${it.id} · `)); // t0's segments measured its clock: the times are its, moved by m02's new length. expect(list.times.basis).toBe("measured"); expect(list.items[0].at).toBeGreaterThan(0.5); expect(list.items[1].at).toBeGreaterThan(list.items[0].at); const reel = path.join(DIR, "takes", "t1", "out", `${SLUG}.changes.mp4`); expect(size(reel)).toBe("1280,720"); expect(list.items[1].reel.to).toBeGreaterThan(list.items[0].reel.to); // The draft is still a draft: nothing of a full render was made for it. expect(() => statSync(path.join(DIR, "takes", "t1", "preview.mp4"))).toThrow(); // The preview of t0: 1280x720, its full render's files untouched. const full = ["preview.mp4", `out/${SLUG}.mp4`, "render.json", "take.json", "video.manifest.json", "out/sourced/segments/m02.mp4"].map((f) => path.join(DIR, "takes", "t0", f)); const before = full.map((f) => { const s = statSync(f); return `${s.size}:${s.mtimeMs}:${s.ino}`; }); const p = cli(["take", PROJECT, "--id", "t0", "--preview"]); expect(p.code, p.err + p.out).toBe(0); expect(size(path.join(DIR, "takes", "t0", "out", `${SLUG}.preview.mp4`))).toBe("1280,720"); expect(size(path.join(DIR, "takes", "t0", "preview.mp4"))).toBe("1920,1080"); expect(full.map((f) => { const s = statSync(f); return `${s.size}:${s.mtimeMs}:${s.ino}`; })).toEqual(before); // Its own record, in its own dir; the take's render record still the full render's. expect(JSON.parse(readFileSync(path.join(DIR, "takes", "t0", "out", "preview", "render.json"), "utf8")).state).toBe("done"); expect(JSON.parse(readFileSync(path.join(DIR, "takes", "t0", "render.json"), "utf8")).mp4).toBe("preview.mp4"); const s0 = cli(["take", "status", PROJECT, "--id", "t0", "--json"]); expect(s0.code).toBe(0); const j0 = JSON.parse(s0.out); expect(j0.state).toBe("done"); expect(j0.preview.state).toBe("done"); expect(j0.preview.mp4).toContain(`${SLUG}.preview.mp4`); const j1 = JSON.parse(cli(["take", "status", PROJECT, "--id", "t1", "--json"]).out); expect(j1.changes.items).toBe(2); expect(j1.changes.from).toBe("t0"); }); test("the Takes page: Preview render and Render changes are queue steps, their state and path inline, the file played", async ({ page, baseURL }) => { test.setTimeout(300_000); await page.goto(urls.takesHref(PROJECT)); const card0 = page.locator("[data-fast-renders='t0']"); await expect(card0.locator("[data-fast='preview']")).toHaveAttribute("data-fast-state", "done", { timeout: 30_000 }); await expect(card0.locator("[data-fast='preview'] [data-fast-path]")).toContainText(`${SLUG}.preview.mp4`); await card0.locator("[data-action='play-preview']").click(); await expect(card0.locator("[data-fast-video='preview']")).toBeVisible(); const served = await page.request.get(`/api/report/takes/fast?project=${encodeURIComponent(PROJECT)}&take=t0&file=preview`, { headers: { range: "bytes=0-99" } }); expect(served.status()).toBe(206); // Render changes on the draft: a step of the app's queue, run, its state inline. const card1 = page.locator("[data-fast-renders='t1']"); const before = statSync(path.join(DIR, "takes", "t1", "changes.json")).mtimeMs; await card1.locator("[data-action='render-changes']").click(); await expect(card1.locator("[data-fast-queued]")).toContainText(/queued as q\d+/); const qid = ((await card1.locator("[data-fast-queued]").textContent()) ?? "").match(/q\d+/)?.[0] ?? ""; const st = cli(["queue", "status", qid, "--json"], String(baseURL)); expect(JSON.parse(st.out).step?.argv ?? JSON.parse(st.out).argv).toEqual(["take", PROJECT, "--id", "t1", "--changes", "--from", "t0"]); await expect(card1.locator("[data-fast='changes']")).toHaveAttribute("data-fast-state", "done", { timeout: 240_000 }); expect(statSync(path.join(DIR, "takes", "t1", "changes.json")).mtimeMs).toBeGreaterThan(before); await expect(card1.locator("[data-fast='changes'] [data-fast-said]")).toContainText("2 piece(s) against t0"); });