import { test, expect, type APIRequestContext } from "@playwright/test"; import { existsSync, readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; // --------------------------------------------------------------------------- // THE STATS REGION (release 31, lane P3): a frame scan's running numbers drawn // over each clip, built and verified. // // stats-build-fixture made by make-fixture.mjs at 1920x1080 with the deck // on, `render.chrome.stats`, and a frame scan's // `frameScan.overlay` points for both clips (synthetic) // // The build runs offline, as the on-screen build's does: the renderer is the // fixture's stub (HYPERFRAMES_BIN), which writes the frame sequence each // region declares. The chain ends in verify-build, which holds the stats // region's frames to the cut and fails the job when one is missing -- so a // job that is `done` is a verified cut with the overlay laid over it. // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const PROJECT = "reports/stats-build-fixture"; const DIR = path.join(FIXTURE, "reports", "stats-build-fixture"); const VARIANT_OUT = path.join(DIR, "out", "sourced"); const FINAL = path.join(DIR, "out", "stats-build-fixture.mp4"); const INVOCATIONS = path.join(FIXTURE, "bin", "hyperframes.invocations"); type Job = { id: string; state: string; error: string | null; steps: { label: string; argv: string[] }[]; events: { ev: string; phase?: string; region?: string }[]; log?: string[]; }; async function waitForJob(request: APIRequestContext, id: string, ms = 240_000): Promise { const until = Date.now() + ms; while (Date.now() < until) { const j = (await (await request.get(`/api/report/build?job=${id}`)).json()) as Job; if (j.state !== "running") return j; await new Promise((r) => setTimeout(r, 400)); } throw new Error("the job never finished"); } const manifest = () => JSON.parse(readFileSync(path.join(DIR, "video.manifest.json"), "utf8")); test("a deck build lays the stats region over each clip, and verify-build holds it", async ({ request }) => { test.setTimeout(300_000); test.skip( !manifest().render.fontRegular, "the deck refuses to draw without render.fontRegular/fontBold, and make-fixture.mjs found no font on this machine", ); // The chain: the build, then verify-build. const dry = (await (await request.post("/api/report/build?dry=1", { data: { project: PROJECT, preset: "fast" } })).json()) as { steps: { argv: string[] }[]; }; expect(dry.steps.at(-1)!.argv.join(" ")).toContain("verify-build.mjs"); const start = await request.post("/api/report/build?replace=1", { data: { project: PROJECT, preset: "fast" } }); expect(start.ok(), await start.text()).toBeTruthy(); const job = await waitForJob(request, ((await start.json()) as { job: Job }).job.id); expect(job.state, `${job.error ?? ""}\n${job.log?.slice(-30).join("\n") ?? ""}`).toBe("done"); // The region was composed and rendered (by the stub), after the deck. const chrome = job.events.filter((e) => e.ev === "chrome"); expect(chrome.some((e) => e.phase === "compose" && e.region === "stats")).toBe(true); expect(chrome.some((e) => e.phase === "render" && e.region === "stats")).toBe(true); const renders = readFileSync(INVOCATIONS, "utf8").split("\n").filter((l) => l.includes("stats-build-fixture")); // A first render captures each distinct frame once into work-capture-stats-frames (compose-chrome.mjs reuseFrames). const chromeDir = path.join(VARIANT_OUT, "chrome"); expect(renders.some((l) => l.includes(`${chromeDir}/stats-frames`) || l.includes(`${chromeDir}/work-capture-stats-frames`))).toBe(true); // The schedule draws both clips, each number held from the scan's point. const schedule = JSON.parse(readFileSync(path.join(VARIANT_OUT, "schedule.json"), "utf8")) as { fps: number; total: number; stats: { position: string; clips: { segment: string; in: number; out: number; states: { at: number; values: Record }[] }[] }; }; expect(schedule.stats.position).toBe("bottom-left"); expect(schedule.stats.clips.map((c) => c.segment)).toEqual(["c01", "c02"]); expect(schedule.stats.clips[0].states.map((s) => s.values.stack)).toEqual([50000, 80000]); expect(schedule.stats.clips[1].states[0].values).toEqual({ stack: 170000, stackBB: 106.3, playersLeft: 45, level: 4 }); // The page the frames were rendered from shows the numbers. const page = readFileSync(path.join(VARIANT_OUT, "chrome", "stats", "index.html"), "utf8"); expect(page).toContain('
SYNTH MAIN
'); expect(page).toContain('
80,000
'); expect(page).toContain('
Left
45
'); // As long as the cut, pruned after the mux and recorded. const pruned = JSON.parse(readFileSync(path.join(VARIANT_OUT, "chrome", "pruned.json"), "utf8")) as { dirs: Record }; expect(pruned.dirs["stats-frames"].frames).toBe(Math.round(schedule.total * schedule.fps)); expect(pruned.dirs["stats-frames"].frames).toBe(pruned.dirs["deck-frames"].frames); expect(existsSync(FINAL)).toBe(true); });