import { test, expect } from "@playwright/test"; import { mkdirSync } from "node:fs"; import * as urls from "./urls"; // --------------------------------------------------------------------------- // A clip fetched PER KEPT PIECE (fetch-per-piece; pieced-consumers.test.mjs is // the unit half): no window holds its extent, the pieces do, and every surface // that asked for "the window holding the clip" reads them. // // Fixture: pieced-fixture (make-fixture.mjs), READ-ONLY. // pc01 pcvid 1-98 less the gap 8-91: both pieces on disk (raw windows 0-9, 90-99) // pc02 pcvid2 1-98, the same gap: only the first piece on disk // // - the Cut tab's pill: pc01 "cached" (data-fetched 1), pc02 "not fetched yet" // - the bench opens pc01 on ONE window on the source's clock (the pieces where // they were said, black filler between), plays it across the gap -- the // gap skipped as the cut will skip it, seven seconds of sound twice, not 97 // - pc02 is not offered as playable: it offers to fetch // - the walk (`ready N of M`) counts pc01 and not pc02 // --------------------------------------------------------------------------- const PROJECT = "reports/pieced-fixture"; const SHOTS = process.env.PIECED_SHOTS ?? ""; const shot = async (page: import("@playwright/test").Page, name: string) => { if (!SHOTS) return; mkdirSync(SHOTS, { recursive: true }); await page.screenshot({ path: `${SHOTS}/${name}.png`, fullPage: false }); }; test.beforeEach(() => { test.setTimeout(120_000); }); test("the Cut tab: a clip with every piece on disk is cached; one with a piece missing is not fetched yet", async ({ page }) => { await page.goto(urls.section(PROJECT, "timeline")); await expect(page.locator("[data-entry=pc01][data-kind]")).toHaveAttribute("data-fetched", "1"); await expect(page.locator("[data-entry=pc01][data-kind]")).toHaveAttribute("data-cached", "1"); await expect(page.locator("[data-entry=pc01][data-kind]")).not.toContainText("not fetched yet"); await expect(page.locator("[data-entry=pc02][data-kind]")).toHaveAttribute("data-fetched", "0"); await expect(page.locator("[data-entry=pc02][data-kind]")).toContainText("not fetched yet"); // The walk counts what can be watched end to end: pc01. await expect(page.locator("[data-ready-count]")).toHaveText("ready 1 of 2 needing judgement"); await shot(page, "cut-tab-pills"); }); test("the bench plays a clip fetched in pieces as one timeline: the gap is skipped, not played", async ({ page, request }) => { // The bench's window: one file on the source's clock, named for the pieces it is laid from. const clip = (await (await request.get(`/api/report/clip?project=${encodeURIComponent(PROJECT)}&clip=pc01`)).json()) as { windows?: { name: string; from: number; to: number }[]; }; const wins = clip.windows ?? []; expect(wins[0]?.name, JSON.stringify(wins)).toMatch(/\.pieces\.mp4$/); expect([wins[0].from, wins[0].to]).toEqual([0, 99]); await page.goto(urls.clipBenchHref(PROJECT, "pc01")); const playback = page.locator("[data-playback]"); await expect(playback).toHaveAttribute("data-audio-state", "ready", { timeout: 60_000 }); await expect(page.locator("[data-gap-band]")).toHaveCount(1); await expect(page.locator("[data-clip-unfetched]")).toHaveCount(0); await shot(page, "bench-pieced"); // Keyboard attached (hydration), then play. await expect(async () => { await page.locator("body").press("x"); await expect(page.locator("[data-reject-menu]")).toBeVisible({ timeout: 500 }); }).toPass({ timeout: 10_000 }); await page.locator("body").press("Escape"); await page.locator("body").press(" "); await expect(playback).toHaveAttribute("data-play-state", "playing", { timeout: 10_000 }); expect(await playback.getAttribute("data-play-engine")).toBe("webaudio"); const a = Number(await playback.getAttribute("data-play-ctx-start")); const b = Number(await playback.getAttribute("data-play-ctx-stop")); // 1-98 less the 83 s gap: 14 s of sound (7 + 7), not 97 (the window stays under the 120 s decode cap, else the bench plays through the element). expect(b - a).toBeCloseTo(14, 1); expect(Number(await playback.getAttribute("data-play-to"))).toBeCloseTo(98, 1); await shot(page, "bench-pieced-playing"); await page.locator("body").press(" "); }); test("a clip with a piece missing is not playable: the bench offers to fetch it", async ({ page }) => { await page.goto(urls.clipBenchHref(PROJECT, "pc02")); await expect(page.locator("[data-bench=pc02]")).toBeVisible(); await expect(page.locator("[data-clip-unfetched]")).toHaveCount(1); await shot(page, "bench-part-fetched"); });