import { test, expect } from "@playwright/test"; import { copyFileSync, existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { openPanel } from "./panels"; // --------------------------------------------------------------------------- // Preparing the walk (lib/report/benchPrep.mjs): the Cut tab's "Prepare clips // for the walk" runs, in the background, what the clip bench would do on a // clip's first open -- a long recording's excerpt, the waveform -- and the // bench then opens on the prepared files. // // Its own project, made here -- by the test, a moment after the server walked // the reports without it -- and removed after (the suite runs one spec file // at a time, so no other spec's project count sees it): r01 sits on a // "recording", a cached window whose NAME says 0–700 s (longer than the // bench's EXCERPT_OVER_S, so the bench is given an excerpt of it), and r02 on // an ordinary window. The bytes are report-fixture's nine seconds of tone. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/prep-fixture"; const DIR = path.join(FIXTURE, "reports", "prep-fixture"); const TONE = path.join(FIXTURE, "reports", "report-fixture", "out", "clips-raw", "vid1_0.00-9.00.mp4"); const EXCERPT = path.join(DIR, "out", "bench-excerpts", "vidp", "0.00-60.00.excerpt.mp4"); /** * The project, on disk. Made INSIDE the test, after the server has walked the * reports without it: whatever an earlier spec asked a moment ago (the walk is * memoised for a second, lib/projects.ts), a project made on disk is found * the moment it is asked for -- in a full run the spec before this one used to * leave a walk that did not have it, and the Cut tab 404'd. */ function makeProject() { rmSync(DIR, { recursive: true, force: true }); mkdirSync(path.join(DIR, "out", "clips-raw"), { recursive: true }); const clip = (id: string, video: string) => ({ type: "clip", id, video, start: 3, end: 6, cite: 3, section: 0, lock: true, quote: "and because" }); writeFileSync( path.join(DIR, "video.manifest.json"), `${JSON.stringify({ slug: "prep-fixture", title: "The Prep Fixture", provenance: { siteOrigin: "https://archive.example" }, timeline: [clip("r01", "vidp"), clip("r02", "vid1")] }, null, 2)}\n`, ); copyFileSync(TONE, path.join(DIR, "out", "clips-raw", "vidp_0.00-700.00.mp4")); copyFileSync(TONE, path.join(DIR, "out", "clips-raw", "vid1_0.00-9.00.mp4")); } test.beforeAll(() => { rmSync(DIR, { recursive: true, force: true }); }); test.afterAll(() => { rmSync(DIR, { recursive: true, force: true }); }); test("Prepare clips for the walk makes the excerpt and the waveforms, and the bench opens on them", async ({ page, request }) => { // The server walks the reports now, and finds no such project... expect((await request.get(`/api/report/prep?project=${encodeURIComponent(PROJECT)}`)).status()).toBe(404); // ...which is made a moment later, and opened at once. makeProject(); await page.goto(urls.section(PROJECT, "timeline")); await openPanel(page, "options", "cut"); await openPanel(page, "advanced", "cut"); const panel = page.locator("[data-bench-prep]"); await expect(panel.locator("[data-bench-prep-status]")).toHaveText("0 of 2 ready to open · 2 to prepare"); expect(existsSync(EXCERPT)).toBe(false); await panel.locator("[data-action=bench-prep]").click(); // The runner is its own process; the line follows it to the end. await expect(panel.locator("[data-bench-prep-status]")).toHaveText("2 of 2 ready to open", { timeout: 60_000 }); await expect(panel.locator("[data-action=bench-prep]")).toHaveCount(0); await expect(panel).toHaveAttribute("data-bench-prep-state", "ready"); // The excerpt the bench's excerptOf names: the clip ± 45 s, rounded out to 15 s. expect(existsSync(EXCERPT)).toBe(true); // The bench's own routes take it: the clip's window is the excerpt, and its // audio answers from it. const clip = await (await request.get(`/api/report/clip?project=${encodeURIComponent(PROJECT)}&clip=r01`)).json(); expect(clip.windows[0].name).toBe("0.00-60.00.excerpt.mp4"); const audio = await request.get( `/api/report/audio?project=${encodeURIComponent(PROJECT)}&clip=r01&file=0.00-60.00.excerpt.mp4&from=0&to=9`, ); expect(audio.status()).toBe(200); expect(audio.headers()["content-type"]).toBe("audio/wav"); // And the API says so too: nothing left, no runner. const state = await (await request.get(`/api/report/prep?project=${encodeURIComponent(PROJECT)}`)).json(); expect(state.counts).toMatchObject({ clips: 2, ready: 2, todo: 0, failed: 0 }); expect(state.running).toBe(false); });