import { test, expect } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // The video knobs (plans/video-knobs-ui.md): // - the clip editor's Marks box (was Count & stamp) on a clip with one mark: // Set at playhead (and Shift+S) writes claim.at, count / label / stamp // on-off write and Clear removes; a clip that carries the claim but does // not stamp it says where it stamps (marks.spec.ts: two marks and more) // - the Audio box: a sync nudge, the gain, Clear all // - an agent's token on a manifest-write route: right one writes, a wrong one is 401 // - the On-screen Markers editor: add, label, colour, align, re-order, the // layout -> render.chrome.deck.markers / markerLayout // - Deliver's Make variants (the encoder stubbed: e2e/fixtures/variants.e2e.mjs) // and the Sync table, its flagged clip linking to that clip's Audio box // Fixture: e2e/fixtures/knobs-fixture.mjs. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/knobs-fixture"; const DIR = path.join(FIXTURE, "reports", "knobs-fixture"); const DECK_PROJECT = "reports/knobs-deck-fixture"; const DECK_DIR = path.join(FIXTURE, "reports", "knobs-deck-fixture"); type Entry = { id: string; type: string; claim?: Record; audio?: Record }; type Manifest = { render: Record & { chrome?: { deck?: Record }; variants?: unknown }; timeline: Entry[] }; const readManifest = (dir = DIR): Manifest => JSON.parse(readFileSync(path.join(dir, "video.manifest.json"), "utf8")); const entry = (id: string, dir = DIR) => readManifest(dir).timeline.find((e) => e.id === id) ?? null; test("Count & stamp and Audio in the clip editor; an agent's token on the route", async ({ page, request }) => { test.setTimeout(150_000); await page.setViewportSize({ width: 1366, height: 900 }); await page.goto(urls.clipEditorHref(PROJECT, { clip: "r003", mode: "edit" })); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r003"); await expect(page.locator("[data-editor-player]")).not.toHaveAttribute("data-editor-player", "looking", { timeout: 15_000 }); const box = page.locator('[data-marks="r003"]'); await expect(box).toBeVisible(); // The defaults show where a key is absent: the cut's stamp seconds, a count of 1. await expect(box.locator('[data-knob="hold"]')).toHaveAttribute("placeholder", "3"); await expect(box.locator('[data-knob="count"]')).toHaveAttribute("placeholder", "1"); await expect(box.locator("[data-stamps-on]")).toHaveCount(0); // A word puts the playhead there; Set at playhead writes the source second. await page.locator('[data-word-t="7.2"]').click(); await box.locator("[data-claim-at-playhead]").click(); await expect.poll(() => entry("r003")?.claim?.at).toBe(7.2); // Shift+S does the same (S alone is Split here). await page.locator('[data-word-t="7.8"]').click(); await page.keyboard.press("Shift+S"); await expect.poll(() => entry("r003")?.claim?.at).toBe(7.8); expect(readManifest().timeline.filter((e) => e.type === "clip").map((e) => e.id)).toEqual(["r001", "r002", "r003"]); const count = box.locator('[data-knob="count"]'); await expect(async () => { await count.fill("2"); await count.press("Enter"); await expect.poll(() => entry("r003")?.claim?.count, { timeout: 2000 }).toBe(2); }).toPass({ timeout: 15_000 }); const label = box.locator('[data-knob="label"]'); await label.fill("2 SEIZURES"); await label.press("Enter"); await expect.poll(() => entry("r003")?.claim?.label).toBe("2 SEIZURES"); await box.locator('[data-knob="stamp"]').uncheck(); await expect.poll(() => entry("r003")?.claim?.stamp).toBe(false); await box.locator('[data-knob-clear="count"]').click(); await expect.poll(() => entry("r003")?.claim).toEqual({ id: "k1", verdict: "CONTRADICTED", at: 7.8, stamp: false, label: "2 SEIZURES" }); // Audio: a nudge, the gain, Clear all. const audio = page.locator('[data-audio-box="r003"]'); await audio.locator('[data-audio-nudge="-40"]').click(); await expect.poll(() => entry("r003")?.audio).toEqual({ offset: -40 }); const gain = audio.locator('[data-knob="gain"]'); await gain.fill("-3"); await gain.press("Enter"); await expect.poll(() => entry("r003")?.audio).toEqual({ offset: -40, gain: -3 }); await audio.locator("[data-audio-clear-all]").click(); await expect.poll(() => entry("r003")?.audio).toBeUndefined(); // r002 carries the claim but r003 stamps it: the box says so; r001 has none. await page.locator('[data-editor-row="r002"]').click(); await expect(page.locator('[data-marks="r002"] [data-stamps-on="r003"]')).toBeVisible(); await page.locator('[data-editor-row="r001"]').click(); await expect(page.locator('[data-marks="r001"]')).toHaveAttribute("data-mark-count", "0"); await expect(page.locator("[data-mark]")).toHaveCount(0); // An agent's token writes through the same route; a wrong one is refused. const view = await (await request.get(`/api/report/clip-editor?project=${encodeURIComponent(PROJECT)}`)).json(); const wrong = await request.post("/api/report/clip-editor", { headers: { authorization: "Bearer nope" }, data: { project: PROJECT, op: "claim", clip: "r003", knobs: { count: 3 }, token: view.token } }); expect(wrong.status()).toBe(401); const right = await request.post("/api/report/clip-editor", { headers: { authorization: "Bearer umtool-e2e-token" }, data: { project: PROJECT, op: "claim", clip: "r003", knobs: { count: 3 }, token: view.token } }); expect(right.ok(), await right.text()).toBe(true); expect(entry("r003")?.claim?.count).toBe(3); }); test("the Markers editor: add, label, colour, align, re-order, layout", async ({ page, request }) => { test.setTimeout(120_000); test.skip(!readManifest(DECK_DIR).render.fontRegular, "the deck refuses to draw without render.fontRegular/fontBold, and make-fixture.mjs found no font on this machine"); // From no markers, whatever an earlier run left. const token = (await (await request.get(`/api/report/chrome?project=${encodeURIComponent(DECK_PROJECT)}`)).json()).token; const reset = await request.put("/api/report/chrome", { data: { project: DECK_PROJECT, token, markers: [], markerLayout: null } }); expect(reset.ok(), await reset.text()).toBe(true); await page.goto(urls.section(DECK_PROJECT, "onscreen")); const ed = page.getByTestId("markers-editor"); await expect(ed).toBeVisible({ timeout: 30_000 }); await ed.getByTestId("markers-add").click(); await ed.getByTestId("markers-add").click(); await ed.getByTestId("marker-after-0").selectOption("c01"); await ed.getByTestId("marker-label-0").fill("Arrival"); await ed.getByTestId("marker-align-0").selectOption("left"); await ed.getByTestId("marker-after-1").selectOption("c02"); await ed.getByTestId("marker-label-1").fill("Rescue"); await ed.getByTestId("marker-color-1").fill("accent"); await ed.getByTestId("marker-down-0").click(); await ed.getByTestId("markers-layout").selectOption("truncate"); await ed.getByTestId("markers-save").click(); await expect.poll(() => readManifest(DECK_DIR).render.chrome?.deck?.markers).toEqual([ { after: "c02", label: "Rescue", color: "accent" }, { after: "c01", label: "Arrival", align: "left" }, ]); expect(readManifest(DECK_DIR).render.chrome?.deck?.markerLayout).toBe("truncate"); await page.reload(); await expect(page.getByTestId("marker-label-0")).toHaveValue("Rescue", { timeout: 30_000 }); await page.getByTestId("marker-remove-0").click(); await page.getByTestId("markers-layout").selectOption(""); await page.getByTestId("markers-save").click(); await expect.poll(() => readManifest(DECK_DIR).render.chrome?.deck?.markers).toEqual([{ after: "c01", label: "Arrival", align: "left" }]); expect(readManifest(DECK_DIR).render.chrome?.deck && "markerLayout" in readManifest(DECK_DIR).render.chrome!.deck!).toBe(false); }); test("Deliver: Make variants (stub encoder) lists them; Sync flags a clip and links to its Audio box", async ({ page, request }) => { test.setTimeout(120_000); // From the default ladder, whatever an earlier run left. const token = (await (await request.get(`/api/report/render?project=${encodeURIComponent(PROJECT)}`)).json()).token; const reset = await request.put("/api/report/render", { data: { project: PROJECT, token, variants: null } }); expect(reset.ok(), await reset.text()).toBe(true); await page.goto(urls.section(PROJECT, "deliver")); const panel = page.locator("[data-variants-panel]"); await expect(panel).toBeVisible({ timeout: 30_000 }); await expect(panel.locator('[data-variants-ladder="default"]')).toBeVisible(); // The ladder is a knob: one rung less, saved to render.variants. await panel.locator("[data-variants-edit]").click(); await panel.locator('[data-variant-field="3:name"]').locator("xpath=../..").getByRole("button", { name: "remove" }).click(); await panel.locator("[data-variants-save]").click(); await expect.poll(() => readManifest().render.variants).toEqual([{ name: "master" }, { name: "1080p", height: 1080, crf: 22 }, { name: "720p", height: 720, crf: 23 }]); await panel.locator("[data-variants-make]").click(); await expect(panel.locator('[data-variants-job="done"]')).toBeVisible({ timeout: 60_000 }); await expect(panel.locator("[data-variant]")).toHaveCount(3); expect(existsSync(path.join(DIR, "out", "knobs-fixture.720p.mp4"))).toBe(true); const href = await panel.locator('[data-variant-link="720p"]').getAttribute("href"); const got = await request.get(href!); expect(got.ok()).toBe(true); expect(got.headers()["content-type"]).toBe("video/mp4"); // Sync: r002's sound is 469 ms early, flagged; its link opens its Audio box. const row = panel.locator('[data-sync-row="r002"]'); await expect(row).toHaveAttribute("data-sync-flagged", ""); await expect(panel.locator('[data-sync-row="r001"]')).not.toHaveAttribute("data-sync-flagged", ""); await expect(row.locator("[data-sync-link]")).toHaveAttribute("href", `${urls.clipEditorHref(PROJECT, { clip: "r002", mode: "edit" })}#clip-audio`); await row.locator("[data-sync-link]").click(); await expect(page.locator("[data-clip-editor]")).toHaveAttribute("data-clip-editor", "r002", { timeout: 30_000 }); await expect(page.locator('[data-audio-box="r002"]')).toBeVisible(); });