import { test, expect, type Page } from "@playwright/test"; import { existsSync, mkdirSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE REVIEW PASS (umtool redesign L7b; workspace/ReviewPass.tsx, lib/report/reviewPass.mjs): the workspace's // `?mode=review` -- the inspector hidden, the viewer playing block by block, each block answered Keep · Fix · Note // (k f n), the verdict at the end, and the pass resuming where it stopped. // // review-pass-fixture (WRITES; make-fixture.mjs): workspace-fixture's cut -- c01 c02 p-5 k01 c03 c04, c04 ruled // wrong speaker in the bench -- and play-cut-fixture's version v1. The tests run in order, each leaving what the next reads. // // L7B_SHOTS (a directory): the pass's screenshots at 1366×768 go there too. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const P = "reports/review-pass-fixture"; const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "review-pass-fixture"); const json = (name: string) => JSON.parse(readFileSync(path.join(DIR, name), "utf8")); const verdictOf = (id: string) => (json("video.manifest.json").timeline as { id: string; verdict?: string; correction?: string }[]).find((e) => e.id === id); const pass = (page: Page) => page.locator("[data-review-pass]"); const SHOTS = process.env.L7B_SHOTS ?? ""; const shot = async (page: Page, name: string) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); await page.screenshot({ path: path.join(SHOTS, name) }); }; test.beforeEach(async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); }); test("Review pass: the inspector hidden, k keeps a clip (its walk verdict), f on a clip and on the post is \"needs work\" (a mark, never a verdict), n opens the composer on the card", async ({ page }) => { await page.goto(urls.workspaceHref(P)); await expect(page.locator("[data-ws-mode-edit]")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-ws-mode-review]")).toHaveAttribute("href", urls.workspaceHref(P, { mode: "review" })); await page.locator("[data-ws-mode-review]").click(); await expect(page).toHaveURL(/[?&]mode=review/); await expect(page.locator("[data-ws-mode]")).toHaveAttribute("data-ws-mode", "review"); // The inspector is the pass: no bench, no project panels. await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "review"); await expect(page.locator("[data-ws-project-panels]")).toHaveCount(0); await expect(pass(page)).toHaveAttribute("data-review-current", "c01", { timeout: 20_000 }); // c04 is answered already: the bench ruled it. await expect(pass(page)).toHaveAttribute("data-review-progress", "1/6"); await expect(page.locator("[data-review-count]")).toHaveText("1 / 6 reviewed"); // The viewer is on the block under review. await expect(page.locator('[data-ws-block="c01"]')).toHaveAttribute("aria-selected", "true"); await shot(page, "ws-review.png"); // k: c01 kept -- its walk verdict, the bench's writer -- and on to c02, playing. await page.keyboard.press("k"); await expect(pass(page)).toHaveAttribute("data-review-current", "c02"); await expect.poll(() => verdictOf("c01")?.verdict).toBe("confirmed"); await expect(page.locator('[data-ws-block="c01"]')).toHaveAttribute("data-ws-block-review", "keep"); await expect(page.locator("[data-ws-viewer]")).toHaveAttribute("data-play-item", "c02", { timeout: 20_000 }); // f on a clip: "needs work", a mark in review-pass.json -- its verdict untouched (never `incorrect`). await page.keyboard.press("f"); await expect(page.locator("[data-review-fix-text]")).toBeFocused(); await page.locator("[data-review-fix-text]").fill("trim the tail"); await page.locator("[data-review-fix-text]").press("Enter"); await expect(pass(page)).toHaveAttribute("data-review-current", "p-5"); await expect.poll(() => json("review-pass.json").marks.c02).toMatchObject({ mark: "fix", note: "trim the tail" }); expect(verdictOf("c02")?.verdict).toBeUndefined(); expect(verdictOf("c02")?.correction).toBeUndefined(); await expect(page.locator('[data-ws-block="c02"]')).toHaveAttribute("data-ws-block-review", "fix"); await expect(pass(page)).toHaveAttribute("data-review-progress", "3/6"); // f on the post: what needs fixing, then on. A post has no walk verdict: review-pass.json holds it. await page.keyboard.press("f"); const fix = page.locator("[data-review-fix-text]"); await expect(fix).toBeFocused(); await fix.fill("the crop cuts his face"); await fix.press("Enter"); await expect(pass(page)).toHaveAttribute("data-review-current", "k01"); await expect.poll(() => (existsSync(path.join(DIR, "review-pass.json")) ? json("review-pass.json").marks["p-5"] : null)).toMatchObject({ mark: "fix", note: "the crop cuts his face" }); await expect(page.locator('[data-ws-block="p-5"]')).toHaveAttribute("data-ws-block-review", "fix"); await expect(pass(page)).toHaveAttribute("data-review-progress", "4/6"); // n on the card: the notes composer, anchored to the block (notes.json). await page.keyboard.press("n"); const input = page.getByTestId("note-input-k01"); await expect(input).toBeFocused(); await input.fill("is this card needed at all?"); await input.press("Enter"); await expect .poll(() => (existsSync(path.join(DIR, "notes.json")) ? (json("notes.json").notes as { text: string; anchor: { kind: string; entry?: string } }[]).find((n) => n.text === "is this card needed at all?")?.anchor : null)) .toEqual({ kind: "entry", entry: "k01" }); // A note is not an answer: the card is still the block under review. await expect(pass(page)).toHaveAttribute("data-review-current", "k01"); await expect(pass(page)).toHaveAttribute("data-review-progress", "4/6"); }); test("a reload resumes at block 4; so does the pass entered afresh (the first block with no answer)", async ({ page }) => { await page.goto(urls.workspaceHref(P, { mode: "review", block: "k01" })); await expect(pass(page)).toHaveAttribute("data-review-current", "k01", { timeout: 20_000 }); await page.reload(); await expect(pass(page)).toHaveAttribute("data-review-current", "k01", { timeout: 20_000 }); await expect(page.locator("[data-review-count]")).toHaveText("4 / 6 reviewed"); await page.goto(urls.workspaceHref(P, { mode: "review" })); await expect(pass(page)).toHaveAttribute("data-review-current", "k01", { timeout: 20_000 }); // The answers so far, said on the strip. expect(await page.locator("[data-ws-block-review]").evaluateAll((els) => els.map((e) => `${e.getAttribute("data-ws-block")}:${e.getAttribute("data-ws-block-review")}`))).toEqual([ "c01:keep", "c02:fix", "p-5:fix", "k01:", "c03:", "c04:ruled", ]); // Under a modal (the Keys), k answers nothing -- even with the focus nowhere in it; a held k is one press. const manifestNow = readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const marksNow = readFileSync(path.join(DIR, "review-pass.json"), "utf8"); await page.keyboard.press("?"); await expect(page.locator("[data-ws-keys]")).toBeVisible(); await page.evaluate(() => (document.activeElement as HTMLElement | null)?.blur()); await page.keyboard.press("k"); await page.waitForTimeout(400); expect(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).toBe(manifestNow); expect(readFileSync(path.join(DIR, "review-pass.json"), "utf8")).toBe(marksNow); await expect(pass(page)).toHaveAttribute("data-review-current", "k01"); await page.keyboard.press("Escape"); await expect(page.locator("[data-ws-keys]")).toHaveCount(0); // The CLI twin reads the same answers. const { reviewPassCommand } = await import("../lib/report/reviewPass.mjs"); const out: string[] = []; await reviewPassCommand([P, "--json"], { resolve: async () => ({ id: P, dir: DIR }), log: (s: string) => out.push(s), err: (s: string) => out.push(s) }); expect(JSON.parse(out.join("\n"))).toMatchObject({ done: 4, total: 6, next: "k01" }); }); test("past the last block, the verdict: Like saves the draft as a version and writes verdicts.json (L4's writer); Done is back to Edit", async ({ page }) => { await page.goto(urls.workspaceHref(P, { mode: "review" })); await expect(pass(page)).toHaveAttribute("data-review-current", "k01", { timeout: 20_000 }); // → walks on without answering: k01, c03, c04, the end. for (const id of ["c03", "c04"]) { await page.keyboard.press("ArrowRight"); await expect(pass(page)).toHaveAttribute("data-review-current", id); } // c04, ruled wrong speaker in the bench: shown with its words, Keep off, k writes nothing; the Full bench changes it. await expect(page.locator('[data-review-bench="incorrect"]')).toContainText("it is the co-host speaking"); await expect(page.locator("[data-review-keep]")).toBeDisabled(); await expect(page.locator("[data-review-full-bench]")).toHaveAttribute("href", urls.clipBenchHref(P, "c04")); await page.keyboard.press("k"); await page.waitForTimeout(400); expect(verdictOf("c04")).toMatchObject({ verdict: "incorrect", correction: "it is the co-host speaking" }); await expect(pass(page)).toHaveAttribute("data-review-current", "c04"); await page.keyboard.press("ArrowRight"); await expect(pass(page)).toHaveAttribute("data-review-current", "end"); const end = page.locator("[data-review-end]"); await expect(end).toContainText("2 blocks not reviewed"); await shot(page, "ws-review-end.png"); await end.locator('[data-review-verdict="like"]').click(); const judged = end.locator("[data-review-verdict-take]"); await expect(judged).toBeVisible({ timeout: 20_000 }); const take = (await judged.getAttribute("data-review-verdict-take"))!; expect(take).toMatch(/^v\d+$/); await expect.poll(() => json(path.join("takes", "verdicts.json"))[take]?.verdict).toBe("like"); // The server said which: the parent when only review fields differ, else a version saved for it. await expect(end.locator("[data-review-judged]")).toHaveText(new RegExp(`^(Judged ${take}|Saved ${take} and judged it):$`)); await expect(end.locator('[data-play-verdict-button="like"]')).toHaveAttribute("aria-pressed", "true"); await end.locator("[data-review-done]").click(); await expect(page).not.toHaveURL(/mode=/); await expect(page.locator("[data-ws-mode-edit]")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-ws-inspector]")).not.toHaveAttribute("data-ws-inspector", "review"); // The browser's Back: the pass again. await page.goBack(); await expect(page.locator("[data-ws-mode]")).toHaveAttribute("data-ws-mode", "review"); }); test("by clicking, both ways: Versions ▾ → Review on v1 is v1's pass, where E, Ctrl+Z and k write nothing; Done is the draft in Edit, where k writes nothing", async ({ page }) => { const disk = () => [ readFileSync(path.join(DIR, "video.manifest.json"), "utf8"), readFileSync(path.join(DIR, "takes", "v1", "take.json"), "utf8"), existsSync(path.join(DIR, "review-pass.json")) ? readFileSync(path.join(DIR, "review-pass.json"), "utf8") : null, ]; await page.goto(urls.workspaceHref(P)); await expect(page.locator("[data-ws-mode]")).toHaveAttribute("data-ws-mode", "edit"); // A block selected in Edit first: the state a soft navigation must not carry over. await page.locator('[data-ws-block="c02"]').click(); await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "clip"); const before = disk(); await page.locator("[data-ws-versions] > summary").click(); await page.locator('[data-ws-version-review="v1"]').click(); await expect(page).toHaveURL(new RegExp(`${urls.versionReviewHref(P, "v1").replace(/[?]/g, "\\?")}`)); await expect(pass(page)).toHaveAttribute("data-review-pass", "v1", { timeout: 20_000 }); await expect(page.locator("[data-ws-mode]")).toHaveAttribute("data-ws-mode", "review"); await expect(page.locator("[data-workspace]")).toHaveAttribute("data-ws-read-only", ""); await page.locator("body").press("e"); await page.locator("body").press("Control+z"); await page.locator("body").press("k"); // The strip's writers too (L8b's, gated on the same flag): Alt+→ on a block, a drag onto another, its menu. await page.locator('[data-ws-block="c01"]').click(); await page.locator("body").press("Alt+ArrowRight"); await page.locator('[data-ws-block="c01"]').dragTo(page.locator('[data-ws-block="c02"]')); await page.locator('[data-ws-block="c02"]').click({ button: "right" }); await expect(page.locator('[role="menu"]')).toHaveCount(0); await page.waitForTimeout(600); await expect(page.locator("[data-cut-app-bench]")).toHaveCount(0); expect(disk()).toEqual(before); // "Done — back to Edit": the DRAFT, in Edit, writable again -- and k there is nothing. await page.locator("[data-review-next]").click(); for (let i = 0; i < 8 && !(await page.locator("[data-review-done]").isVisible()); i += 1) await page.locator("[data-review-next]").click(); await page.locator("[data-review-done]").click(); await expect(page).not.toHaveURL(/take=|mode=/); await expect(page.locator("[data-ws-mode]")).toHaveAttribute("data-ws-mode", "edit", { timeout: 20_000 }); await expect(page.locator("[data-ws-version-shown]")).toHaveCount(0); await expect(page.locator("[data-workspace]")).not.toHaveAttribute("data-ws-read-only", ""); await expect(page.locator("[data-ws-undo]")).toBeVisible(); await page.locator("body").press("k"); await page.waitForTimeout(600); expect(disk()).toEqual(before); }); test("a version's review pass is read-only: watched and noted, never marked -- Open in draft to change it; its verdict at the end", async ({ page }) => { await page.goto(urls.versionReviewHref(P, "v1")); await expect(pass(page)).toHaveAttribute("data-review-pass", "v1", { timeout: 20_000 }); await expect(page.locator("[data-ws-version-shown]")).toContainText("v1 · read-only"); await expect(page.locator("[data-review-keep]")).toBeDisabled(); await expect(page.locator("[data-review-fix]")).toBeDisabled(); await expect(page.locator("[data-review-open-draft]")).toHaveAttribute("href", urls.openInDraftHref(P, "v1")); // Nothing on the bar writes the draft: no Look, Render, Undo. await expect(page.locator("[data-ws-undo]")).toHaveCount(0); await expect(page.locator("[data-ws-look]")).toHaveCount(0); const before = readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); await page.keyboard.press("k"); await page.waitForTimeout(400); expect(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).toBe(before); // A note on a version's block records the version (`umtool notes` says which it was about). const block = await pass(page).getAttribute("data-review-current"); await page.keyboard.press("n"); const input = page.getByTestId(`note-input-${block}`); await expect(input).toBeFocused(); await input.fill("on v1 this ran long"); await input.press("Enter"); await expect .poll(() => (json("notes.json").notes as { text: string; anchor: Record }[]).find((n) => n.text === "on v1 this ran long")?.anchor) .toEqual({ kind: "entry", entry: block, take: "v1" }); // The take walk's old address is this pass (a 308). const res = await page.request.get(urls.takeWalkHref(P, "v1"), { maxRedirects: 0 }); expect(res.status()).toBe(308); expect(res.headers()["location"]).toBe(urls.versionReviewHref(P, "v1")); }); test("a version's address that selects the + (present mode keeps the inspector mounted) shows no adder: read-only", async ({ page }) => { await page.goto(urls.workspaceHref(P, { mode: "present", take: "v1", block: "+" })); await expect(page.locator("[data-workspace]")).toHaveAttribute("data-ws-read-only", "", { timeout: 20_000 }); await expect(page.locator("[data-ws-add-read-only]")).toHaveCount(1); await expect(page.locator("[data-ws-add]")).toHaveCount(0); }); test("the draft's review pass moves nothing: a block does not drag", async ({ page }) => { await page.goto(urls.workspaceHref(P, { mode: "review" })); await expect(pass(page)).toHaveAttribute("data-review-pass", "draft", { timeout: 20_000 }); const before = readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); await expect(page.locator('[data-ws-block="c01"]')).toHaveAttribute("draggable", "false"); await page.locator('[data-ws-block="c01"]').dragTo(page.locator('[data-ws-block="c02"]')); await page.waitForTimeout(600); expect(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")).toBe(before); }); test("on a phone (390 px) the pass is a sheet under the viewer, its answers in reach", async ({ page }) => { await page.setViewportSize({ width: 390, height: 844 }); await page.goto(urls.workspaceHref(P, { mode: "review" })); await expect(pass(page)).toHaveAttribute("data-review-current", "k01", { timeout: 20_000 }); await expect(page.locator("[data-review-keep]")).toBeInViewport(); await expect(page.locator("[data-review-note]")).toBeInViewport(); expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth)).toBe(true); await shot(page, "ws-review-phone.png"); }); test("a mark is of what was reviewed: c02's edge moved since its Fix -- \"changed since reviewed\", unanswered, the pass resumes there", async ({ page, request }) => { const tok = ((await (await request.get(`/api/report/clip?project=${encodeURIComponent(P)}&clip=c02`)).json()) as { token: string }).token; const w = await request.put("/api/report/window", { data: { project: P, clip: "c02", token: tok, end: 5.3 } }); expect(w.ok(), await w.text()).toBe(true); await page.goto(urls.workspaceHref(P, { mode: "review" })); await expect(pass(page)).toHaveAttribute("data-review-current", "c02", { timeout: 20_000 }); await expect(page.locator("[data-review-changed]")).toHaveText("changed since reviewed"); // What the stale Fix said is still shown, and the Fix form opens on it. await expect(page.locator("[data-review-stale-fix]")).toHaveText("it needed work: trim the tail"); await page.keyboard.press("f"); await expect(page.locator("[data-review-fix-text]")).toHaveValue("trim the tail"); await expect(page.locator('[data-ws-block="c02"]')).toHaveAttribute("data-ws-block-review", ""); // The mark is still on disk, with what it was of: the answer is gone, not the record. expect(json("review-pass.json").marks.c02).toMatchObject({ mark: "fix", note: "trim the tail" }); });