import { test, expect, type Page } from "@playwright/test"; import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // THE WORKSPACE (umtool redesign L7a; components/projects/workspace/): a report video's own address is one // screen -- the top bar, the viewer (Play's player core), the strip of blocks, the inspector chosen by the // selected block -- and every edit made in it lands in THE DRAFT, never in a take, with one undo stack. // // workspace-fixture (WRITES; make-fixture.mjs): play-cut-fixture's cut on vid1 with a post item after c02 -- // c01 c02 p-5 k01 c03 c04 -- and its made take, takes/short/take.json, which nothing here may touch. The tests // run in order, each leaving what the next reads. // --------------------------------------------------------------------------- test.describe.configure({ mode: "serial" }); const P = "reports/workspace-fixture"; const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", ".e2e-song", "reports", "workspace-fixture"); const manifestText = () => readFileSync(path.join(DIR, "video.manifest.json"), "utf8"); const manifest = () => JSON.parse(manifestText()) as { timeline: { id: string; start?: number; end?: number }[] }; const order = () => manifest().timeline.map((e) => e.id).join(" "); const takeText = () => readFileSync(path.join(DIR, "takes", "short", "take.json"), "utf8"); const viewer = (page: Page) => page.locator("[data-ws-viewer]"); const blocks = (page: Page) => page.locator("[data-ws-block]"); const blockIds = (page: Page) => blocks(page).evaluateAll((els) => els.map((e) => e.getAttribute("data-ws-block"))); test.beforeEach(async ({ page }) => { test.setTimeout(120_000); await page.setViewportSize({ width: 1366, height: 768 }); }); test("one screen at 1366×768: the top bar, the viewer plays the draft, the strip's blocks, no page scroll", async ({ page }) => { expect(order()).toBe("c01 c02 p-5 k01 c03 c04"); await page.goto(urls.workspaceHref(P)); await expect(page.locator(`[data-workspace="${P}"]`)).toBeVisible(); await expect(page.locator("[data-ws-title]")).toHaveText("The Workspace Fixture"); await expect(page.locator("[data-ws-draft]")).toContainText("Draft"); await expect(page.locator("[data-ws-mode-edit]")).toHaveAttribute("aria-current", "page"); await expect(page.locator("[data-ws-mode-present]")).toHaveAttribute("href", urls.presentHref(P)); expect(await blockIds(page)).toEqual(["c01", "c02", "p-5", "k01", "c03", "c04"]); await expect(page.locator('[data-ws-block="c03"]')).toContainText("no media"); // Nothing selected: the project's own panels (L6). await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "project"); await expect(page.locator('[data-ws-project-panels] [data-inspector="title"]')).toBeVisible(); // The page itself never scrolls: only the inspector and the strip do. const fit = await page.evaluate(() => ({ h: document.documentElement.scrollHeight, w: document.documentElement.scrollWidth, ih: window.innerHeight, iw: window.innerWidth })); expect(fit.h).toBeLessThanOrEqual(fit.ih); expect(fit.w).toBeLessThanOrEqual(fit.iw); // The viewer: the draft, on Play's clock, from the cached window. await expect(viewer(page)).toHaveAttribute("data-play-state", "paused"); await expect(viewer(page)).toHaveAttribute("data-play-edges", "render", { timeout: 30_000 }); // The deck composes (the live preview's pages), as Play's does: no "the chrome did not compose". await expect(viewer(page)).toHaveAttribute("data-play-compose", "ready", { timeout: 60_000 }); await expect(page.locator("[data-ws-compose-error]")).toHaveCount(0); await expect(page.locator('[data-ws-viewer] [data-testid="play-deck"]')).toBeVisible(); await page.locator("[data-ws-play]").click(); await expect(viewer(page)).toHaveAttribute("data-play-item", "c01"); await expect.poll(async () => Number(await viewer(page).getAttribute("data-play-t")), { timeout: 20_000 }).toBeGreaterThan(0.5); await expect(page.locator('[data-ws-block="c01"]')).toHaveAttribute("data-ws-block-now", ""); // Space pauses (the workspace's key). await page.keyboard.press("Space"); await expect(viewer(page)).toHaveAttribute("data-play-state", "paused"); await page.screenshot({ path: path.join(process.env.WS_SHOTS ?? path.join(DIR, ".."), "ws-overview.png") }).catch(() => {}); }); test("a clip block: the inspector is the bench's window and word strip; a nudged edge lands in the draft, not the take; Undo and Redo", async ({ page }) => { const original = manifestText(); const take = takeText(); await page.goto(urls.workspaceHref(P)); await page.locator('[data-ws-block="c01"]').click(); await expect(page.locator('[data-ws-block="c01"]')).toHaveAttribute("aria-selected", "true"); await expect(page).toHaveURL(/[?&]block=c01/); await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "clip"); const bench = page.locator('[data-bench-layout="inspector"][data-bench="c01"]'); await expect(bench).toBeVisible({ timeout: 20_000 }); // The window row and the word strip (the cue rail), and no verdict bar. await expect(bench.locator("[data-save-window]")).toBeVisible(); await expect.poll(() => bench.locator("[data-cue]").count(), { timeout: 15_000 }).toBeGreaterThan(0); await page.screenshot({ path: path.join(process.env.WS_SHOTS ?? path.join(DIR, ".."), "ws-clip.png") }).catch(() => {}); // Nudge the end on (the bench's own `.`, its focus inside it), save the window. await bench.evaluate((el) => (el as HTMLElement).focus()); await page.keyboard.press("."); await expect(bench.locator("[data-save-window]")).toBeEnabled(); await expect(page.locator("[data-workspace]")).toHaveAttribute("data-ws-token", /./); const tokenBefore = await page.locator("[data-workspace]").getAttribute("data-ws-token"); await bench.locator("[data-save-window]").click(); await expect.poll(() => manifest().timeline.find((e) => e.id === "c01")?.end, { timeout: 15_000 }).not.toBe(3.0); const nudged = manifestText(); // The workspace has read the draft's new token (the save announced itself) before Undo is pressed: an Undo on a // stale token is refused, never retried. await expect(page.locator("[data-workspace]")).not.toHaveAttribute("data-ws-token", tokenBefore ?? ""); expect(takeText()).toBe(take); // One Undo restores the draft byte for byte; Redo puts the edit back; Undo again. await page.locator("[data-ws-undo]").click(); await expect.poll(manifestText, { timeout: 15_000 }).toBe(original); await expect(page.locator("[data-ws-undo-said]")).toContainText("Undone"); await expect(page.locator("[data-ws-redo]")).toBeEnabled(); await page.locator("[data-ws-redo]").click(); await expect.poll(manifestText, { timeout: 15_000 }).toBe(nudged); // The file is written before the page has read the redo back (it is busy until then, and a key pressed meanwhile is // dropped): wait for its word first. await expect(page.locator("[data-ws-undo-said]")).toContainText("Redone"); await page.locator("body").press("Control+z"); await expect.poll(manifestText, { timeout: 15_000 }).toBe(original); expect(takeText()).toBe(take); }); test("a post block: the L6 post item panel and the post bench in the inspector", async ({ page }) => { await page.goto(urls.workspaceHref(P, { block: "p-5" })); await expect(page.locator('[data-ws-block="p-5"]')).toHaveAttribute("aria-selected", "true"); await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "post"); // The address's block is where the viewer is, too. await expect(viewer(page)).toHaveAttribute("data-play-item", "p-5", { timeout: 20_000 }); await expect(page.locator('[data-ws-inspector] [data-inspector="post-item"]')).toBeVisible({ timeout: 20_000 }); await expect(page.locator('[data-ws-inspector] [data-post-bench-shape="inspector"]')).toBeVisible({ timeout: 20_000 }); await page.screenshot({ path: path.join(process.env.WS_SHOTS ?? path.join(DIR, ".."), "ws-post.png") }).catch(() => {}); // ← → walk the blocks; Esc lets go of the block (the project's panels). await page.locator("body").press("ArrowRight"); await expect(page.locator('[data-ws-block="k01"]')).toHaveAttribute("aria-selected", "true"); await page.locator("body").press("Escape"); await expect(page.locator("[data-ws-inspector]")).toHaveAttribute("data-ws-inspector", "project"); }); test("two blocks reordered by keys: one move in the draft, the take untouched", async ({ page }) => { const take = takeText(); await page.goto(urls.workspaceHref(P)); await expect(page.locator('[data-ws-block="c02"]')).toHaveAttribute("data-ws-block-at", "1"); await page.locator('[data-ws-block="c02"]').click(); await page.keyboard.press("Alt+ArrowRight"); await expect(page.locator("[data-ws-undo-said]")).toContainText("Moved c02"); await expect.poll(order, { timeout: 15_000 }).toBe("c01 p-5 c02 k01 c03 c04"); await expect.poll(() => blockIds(page)).toEqual(["c01", "p-5", "c02", "k01", "c03", "c04"]); await expect(page.locator('[data-ws-block="c02"]')).toHaveAttribute("aria-selected", "true"); expect(takeText()).toBe(take); }); test("Save version: the versions menu lists it; E opens the bench in place and Back returns", async ({ page }) => { await page.goto(urls.workspaceHref(P)); await page.locator("[data-ws-versions] > summary").click(); await expect(page.locator('[data-ws-version="v1"]')).toHaveCount(0); await page.locator("[data-ws-versions] [data-save-version]").click(); await expect(page.locator("[data-ws-versions] [data-save-version-said]")).toContainText("saved as v1"); await expect(page.locator('[data-ws-version="v1"]')).toBeVisible({ timeout: 15_000 }); await expect(page.locator('[data-ws-version-open="v1"]')).toHaveAttribute("href", urls.openInDraftHref(P, "v1")); await expect(page.locator("[data-ws-draft]")).toHaveAttribute("data-ws-draft", "v1"); await page.keyboard.press("Escape"); // E: the clip on the full bench, in place; the workspace stays mounted under it. await page.locator('[data-ws-block="c01"]').click(); await page.locator("body").press("e"); await expect(page.locator('[data-cut-app-bench="c01"] [data-bench-shell="clip"]')).toBeVisible({ timeout: 20_000 }); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "hidden"); await page.locator("[data-back-to-play]").click(); await expect(page.locator("[data-cut-app-play]")).toHaveAttribute("data-cut-app-play", "shown"); await expect(page).toHaveURL(new RegExp(`/projects/${P}(\\?|$)`)); }); test("the piece page's tabs stay at ?tab=; the Overview is written out", async ({ page }) => { await page.goto(urls.projectHref(P, { tab: "overview" })); await expect(page.locator("[data-workspace]")).toHaveCount(0); // The Overview is a view of the workspace's (L7b): its tab is lit, the view drawn. await expect(page.locator("[data-piece-tabs]")).toHaveAttribute("data-piece-tabs", "workspace"); await expect(page.locator("[data-piece-tab]")).toHaveAttribute("data-piece-tab", "overview"); // ...and the piece page's ⋯ More goes back to it. await page.getByRole("button", { name: "More" }).click(); await expect(page.locator("[data-primary-workspace]")).toHaveAttribute("href", urls.workspaceHref(P)); }); test("under ~900 px the inspector is a sheet at the bottom, folded and unfolded by its head", async ({ page }) => { await page.setViewportSize({ width: 820, height: 900 }); await page.goto(urls.workspaceHref(P, { block: "c02" })); const sheet = page.locator("aside[data-ws-inspector]"); await expect(sheet).toHaveAttribute("data-ws-sheet", "open"); expect(await sheet.evaluate((el) => getComputedStyle(el).position)).toBe("fixed"); await expect(page.locator("[data-ws-sheet-toggle]")).toContainText("c02"); await page.screenshot({ path: path.join(process.env.WS_SHOTS ?? path.join(DIR, ".."), "ws-sheet.png") }).catch(() => {}); await page.locator("[data-ws-sheet-toggle]").click(); await expect(sheet).toHaveAttribute("data-ws-sheet", "closed"); const fit = await page.evaluate(() => document.documentElement.scrollWidth - window.innerWidth); expect(fit).toBeLessThanOrEqual(0); }); test("a write since the undo ends the redo: Redo is refused and the write is kept", async ({ page, request }) => { await page.goto(urls.workspaceHref(P)); await expect(page.locator('[data-ws-block="c04"]')).toHaveAttribute("data-ws-block-at", /\d/); const before = order(); await page.locator('[data-ws-block="c04"]').click(); await page.keyboard.press("Alt+ArrowLeft"); await expect(page.locator("[data-ws-undo-said]")).toContainText("Moved c04"); await expect.poll(order).not.toBe(before); await page.locator("[data-ws-undo]").click(); await expect.poll(order, { timeout: 15_000 }).toBe(before); await expect(page.locator("[data-ws-redo]")).toBeEnabled(); // Another writer (an agent, the terminal) titles a clip -- a write that takes no undo point. const r = await request.put("/api/report/window", { data: { project: P, clip: "c01", title: "Titled since the undo" } }); expect(r.ok(), await r.text()).toBe(true); const titled = manifestText(); // The Redo's answer first (the page says nothing while it is out -- under load, longer than an expect's 5 s). const answered = page.waitForResponse((r) => r.url().includes("/api/report/timeline") && r.request().method() === "POST", { timeout: 60_000 }); await page.locator("[data-ws-redo]").click(); await answered; // Refused: on the page's token (the draft moved since it was read), never retried on a fresh one... await expect(page.locator("[data-ws-undo-said]")).toHaveAttribute("data-ws-undo-said", "error"); await expect(page.locator("[data-ws-undo-said]")).toContainText("changed since"); expect(manifestText()).toBe(titled); // ...and by the redo itself, asked with no token at all (the CLI's way): the draft is not as the undo left it. const again = await request.post("/api/report/timeline", { data: { project: P, op: "redo" } }); expect(again.ok()).toBe(false); expect(await again.text()).toContain("the draft changed since the undo"); expect(manifestText()).toBe(titled); expect(order()).toBe(before); await expect(page.locator("[data-ws-redo]")).toBeDisabled(); });