import { test, expect } from "@playwright/test"; import { execFileSync } from "node:child_process"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The clip kit (lane clip-kit): the Look panel's QR corner and link, its Desktop clips and its Channel promo (saved, // read back, the card drawn); the clip editor's own QR, End card and promo portrait; and the batch of shorts -- // `umtool shorts`, run as ⌘K runs it (POST /api/cli, a queued step) -- each clip in both formats into shorts-kit/, // each ending on the channel's card. Fixture: e2e/fixtures/clip-editor-fixture.mjs as reports/clip-kit-fixture, // with a draft take `kit`. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/clip-kit-fixture"; const DIR = path.join(FIXTURE, "reports", "clip-kit-fixture"); const json = (name: string) => { try { return JSON.parse(readFileSync(path.join(DIR, name), "utf8")); } catch { return null; } }; const render = () => json("video.manifest.json")?.render ?? {}; const clip = (id: string) => (json("video.manifest.json")?.timeline ?? []).find((e: { id: string }) => e.id === id) ?? null; const probe = (file: string) => execFileSync("ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "stream=width,height:format=duration", "-of", "json", file], { encoding: "utf8" }); test("the look: the QR's corner and link, desktop clips and the channel promo saved and read back; the card drawn", async ({ page }) => { test.setTimeout(180_000); await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.section(PROJECT, "build")); await expect(page.locator("[data-look-panel]")).toHaveAttribute("data-look-panel", ""); // The QR: on (the fixture's default), in the top left, linking the source at each clip's second. await page.locator("[data-look-qr-corner]").selectOption("tl"); await page.locator("[data-look-qr-links]").selectOption("moment"); // Desktop clips: a code at the bottom left, the captions extra large. await page.locator("[data-look-desktop-qr]").selectOption("bl"); await page.locator("[data-look-desktop-size]").selectOption("xl"); // The channel promo. await page.locator("[data-look-promo-on]").check(); await page.locator("[data-look-promo-name1]").fill("Fixture"); await page.locator("[data-look-promo-name2]").fill("Channel"); await page.locator("[data-look-promo-url]").fill("https://kick.com/fixture"); await page.locator("[data-look-promo-lead]").fill("1"); await page.locator("[data-look-promo-fade]").fill("0.3"); await page.locator("[data-look-promo-hold]").fill("1"); await page.locator("[data-look-save]").click(); await expect(page.locator("[data-look-status]")).toHaveText("Saved — the next render uses it"); const r = render(); expect(r.qr).toEqual({ corner: "tl", links: "moment" }); expect(r.desktop).toEqual({ qr: { corner: "bl" }, captions: { size: "xl" } }); expect(r.promo).toEqual({ name: ["Fixture", "Channel"], url: "https://kick.com/fixture", lead: 1, fade: 0.3, hold: 1 }); await page.reload(); await expect(page.locator("[data-look-panel]")).toHaveAttribute("data-look-panel", ""); await expect(page.locator("[data-look-qr-corner]")).toHaveValue("tl"); await expect(page.locator("[data-look-qr-links]")).toHaveValue("moment"); await expect(page.locator("[data-look-desktop-qr]")).toHaveValue("bl"); await expect(page.locator("[data-look-desktop-size]")).toHaveValue("xl"); await expect(page.locator("[data-look-promo-on]")).toBeChecked(); await expect(page.locator("[data-look-promo-url]")).toHaveValue("https://kick.com/fixture"); await expect(page.locator("[data-look-promo-portrait]")).toContainText("No portrait yet"); // The card, drawn 9:16 and 16:9 by the build's own page. await page.locator("[data-look-promo-draw]").click(); for (const shape of ["v", "h"]) { const img = page.locator(`[data-look-promo-card='${shape}']`); await expect.poll(async () => img.evaluate((e) => (e as HTMLImageElement).naturalWidth), { timeout: 60_000 }).toBe(shape === "v" ? 1080 : 1920); } }); test("the clip editor: a clip's own QR corner, its end card off and back, the promo's portrait from the playhead", async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: "r001" })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r001"); await page.locator("[data-kit-qr='r001']").selectOption("tr"); await expect.poll(() => clip("r001")?.qr ?? null).toEqual({ corner: "tr" }); await page.locator("[data-kit-qr='r001']").selectOption("none"); await expect.poll(() => clip("r001")?.qr).toBe(false); await page.locator("[data-kit-qr='r001']").selectOption("cut"); await expect.poll(() => clip("r001") && "qr" in clip("r001")).toBe(false); await page.locator("[data-kit-promo='r001']").selectOption("off"); await expect.poll(() => clip("r001")?.promo).toBe(false); await page.locator("[data-kit-promo='r001']").selectOption("cut"); await expect.poll(() => clip("r001") && "promo" in clip("r001")).toBe(false); // A zoom at the playhead (slice F): added, its scale changed, taken off. await expect(page.locator("[data-editor-player]")).toHaveAttribute("data-editor-player", /^(?!looking|none)/, { timeout: 20_000 }); await page.locator("body").press("l"); await expect(page.locator("[data-zoom-add='r001']")).toBeEnabled(); await page.locator("[data-zoom-add='r001']").click(); await expect.poll(() => clip("r001")?.zooms?.length ?? 0).toBe(1); // The playhead is near the cut's end (1-3 s): the zoom is moved back and held as long as fits. expect(clip("r001").zooms[0]).toMatchObject({ at: 1.9, scale: 1.3, hold: 0.3 }); await page.locator("[data-zoom-scale='0']").selectOption("1.5"); await expect.poll(() => clip("r001")?.zooms?.[0]?.scale).toBe(1.5); await page.locator("[data-zoom-remove='0']").click(); await expect.poll(() => clip("r001") && "zooms" in clip("r001")).toBe(false); // Hidden regions (slice E): a box on every clip of this recording, taken off again; one on this clip alone. await page.locator("[data-censor-box='x']").fill("75"); await page.locator("[data-censor-box='y']").fill("0"); await page.locator("[data-censor-box='w']").fill("25"); await page.locator("[data-censor-box='h']").fill("100"); await page.locator("[data-censor-style]").selectOption("black"); await page.locator("[data-censor-add='r001']").click(); await expect.poll(() => render().censor ?? null).toEqual([{ video: "vid1", boxes: [[0.75, 0, 0.25, 1]], style: "black" }]); await page.locator("[data-censor-remove='r0']").click(); await expect.poll(() => render().censor ?? null).toBe(null); await page.locator("[data-censor-scope]").selectOption("clip"); await page.locator("[data-censor-add='r001']").click(); await expect.poll(() => clip("r001")?.censor ?? null).toEqual({ boxes: [[0.75, 0, 0.25, 1]], style: "black" }); // The player draws it over the picture (an editing surface): filled black, outlined, Peek OFF until pressed. const over = page.getByTestId("editor-censor"); await expect(over).toHaveAttribute("data-censor-overlay", "edit"); await expect(over.locator("[data-censor-region]")).toHaveCount(1); await expect(over.locator("[data-censor-region]")).toHaveCSS("background-color", "rgb(0, 0, 0)"); await expect(over.locator("[data-censor-peek]")).toHaveAttribute("aria-pressed", "false"); await over.locator("[data-censor-peek]").click(); await expect(over.locator("[data-censor-peek]")).toHaveAttribute("aria-pressed", "true"); await expect(over.locator("[data-censor-region]")).not.toHaveCSS("background-color", "rgb(0, 0, 0)"); await page.locator("[data-censor-remove='c0']").click(); await expect.poll(() => clip("r001") && "censor" in clip("r001")).toBe(false); await expect(over).toHaveCount(0); // The portrait: the player ready, the playhead moved (l: 2 s on), the frame there grabbed into shots/. await expect(page.locator("[data-editor-player]")).toHaveAttribute("data-editor-player", /^(?!looking|none)/, { timeout: 20_000 }); if (!render().promo) test.skip(true, "the look test sets the promo first"); await page.locator("body").press("l"); await expect(page.locator("[data-promo-portrait='r001']")).toBeEnabled(); await page.locator("[data-promo-portrait='r001']").click(); await expect(page.locator("[data-promo-portrait-set]")).toContainText("shots/still-r001-"); const portrait = render().promo?.portrait; expect(portrait?.file).toMatch(/^shots\/still-r001-.*\.png$/); expect(portrait?.from?.clip).toBe("r001"); expect(existsSync(path.join(DIR, portrait.file))).toBe(true); }); test("umtool shorts, as ⌘K runs it: each clip in both formats into shorts-kit/, named, recorded, ending on the card", async ({ page }) => { test.setTimeout(420_000); await page.goto(urls.homeHref()); const origin = new URL(page.url()).origin; if (!render().promo) test.skip(true, "the look test sets the promo first"); const r = await page.request.post("/api/cli", { data: { verb: "shorts", values: { project: PROJECT, "--take": "kit", "--items": "r001,r002", "--formats": "vertical,desktop", "--hook": "title" } }, headers: { origin } }); expect(r.status()).toBe(202); const { queued, line } = (await r.json()) as { queued: { qid: string }; line: string }; expect(line).toBe(`node umtool/bin/umtool.mjs shorts ${PROJECT} --take kit --items r001,r002 --formats vertical,desktop --hook title`); const stepOf = async () => (await (await page.request.get(`/api/cli?qid=${queued.qid}`)).json()) as { step: { state: string }; log: unknown }; await expect.poll(async () => ["queued", "running"].includes((await stepOf()).step.state), { timeout: 400_000, intervals: [2000] }).toBe(false); const step = await stepOf(); expect(step.step.state, Array.isArray(step.log) ? step.log.slice(-20).join("\n") : String(step.log)).toBe("done"); const folder = path.join(DIR, "shorts-kit"); const batch = JSON.parse(readFileSync(path.join(folder, "batch.json"), "utf8")); expect(batch.kind).toBe("shorts-batch"); expect(batch.clips.map((c: { id: string; name: string }) => [c.id, c.name])).toEqual([["r001", "r001"], ["r002", "r002"]]); for (const c of batch.clips) { expect(c.errors).toEqual({}); for (const [fmt, size] of [["vertical", [1080, 1920]], ["desktop", [1920, 1080]]] as const) { const file = path.join(folder, c.files[fmt]); const p = JSON.parse(probe(file)); expect([p.streams[0].width, p.streams[0].height]).toEqual(size); // The clip (about 2 s) and the card's silent second. expect(Number(p.format.duration)).toBeGreaterThan(2.5); const rec = JSON.parse(readFileSync(file.replace(/\.mp4$/, ".json"), "utf8")); expect(rec.layout).toBe(fmt === "vertical" ? "vertical" : "desktop"); } } // The card was drawn into the build's cards; the segment's record names it. const seg = JSON.parse(readFileSync(path.join(DIR, "takes", "kit", "out", "vertical-shorts-vertical", "segments", "r002.cut.json"), "utf8")); expect(seg.promo).toMatchObject({ lead: 1, fade: 0.3, hold: 1, captions: true }); // Not the clip editor's shorts/: its list has none of these. expect(existsSync(path.join(DIR, "shorts", "r001.vertical.mp4"))).toBe(false); });