import { expect, test, type Locator, type Page, type Request } from "@playwright/test"; import { execFileSync, spawnSync } from "node:child_process"; import { readFileSync, writeFileSync } from "node:fs"; import { expectModalOpen } from "./helpers"; import { installMissingSourceRoutes, makeWav, slugOf } from "./fixtures/missing-source"; // A CLIP OF THE VISITOR'S OWN COPY, CUT IN THE BROWSER (lane browser-clip). // A real media file, made here by ffmpeg (keyframes every 2.0 s), is picked // as the visitor's copy; the Clip in / Clip out marks are set from cue clicks; // "Clip my copy" says where the clip really starts BEFORE saving; the // download is checked with ffprobe — the source's codecs (a stream copy, not // a re-encode), the length from the keyframe to the out mark, and audio and // video starting within one audio frame of each other. // // A flash and a beep at one known moment catch an A/V shift; a stubbed // showSaveFilePicker (an in-memory writable in the page) runs the disk path // to the end. // // The file never leaves the browser: from the pick on, the page asks for // nothing but blob: URLs and, once a clip is asked for, the clipper's own // script chunk (a same-origin GET with no body) — and that chunk is not part // of the first load. The dev server registers no service worker, which is // asserted, so page.on("request") sees every request the page makes. function has(cmd: string): boolean { try { execFileSync(cmd, ["-version"], { stdio: "ignore" }); return true; } catch { return false; } } const FFMPEG = has("ffmpeg") && has("ffprobe"); // The engine's marker string (common/lib/localClipEngine.ts, CLIP_ENGINE_MARK): // how its lazy chunk is told apart, since a minifier strips licence headers. const ENGINE_MARK = "archilyzer-local-clip-engine"; const SLUG = slugOf("synthmem001"); const TITLE_BASE = "Synth-members-stream"; // Cues over the whole 12 s (the fixture's default four end at 6 s). const CUES = [ { start: 0, end: 2, text: "clip line zero" }, { start: 2, end: 4, text: "clip line two" }, { start: 4, end: 5, text: "clip line four" }, { start: 5, end: 7, text: "clip line five" }, { start: 7, end: 9, text: "clip line seven" }, { start: 9, end: 11, text: "clip line nine" }, { start: 11, end: 20, text: "clip line eleven" }, ]; const CODECS = { webm: { args: ["-c:v", "libvpx-vp9", "-g", "50", "-keyint_min", "50", "-deadline", "realtime", "-cpu-used", "8", "-b:v", "200k", "-c:a", "libopus", "-b:a", "48k"], mime: "video/webm", }, mp4: { args: ["-c:v", "libx264", "-profile:v", "main", "-bf", "2", "-g", "50", "-keyint_min", "50", "-sc_threshold", "0", "-pix_fmt", "yuv420p", "-c:a", "aac", "-b:a", "64k"], mime: "video/mp4", }, } as const; function makeMedia(path: string, kind: keyof typeof CODECS, opts: { seconds?: number; heavy?: boolean } = {}): void { const seconds = opts.seconds ?? 12; const video = opts.heavy ? ["-f", "lavfi", "-i", `testsrc2=size=320x180:rate=25:duration=${seconds}`] : ["-f", "lavfi", "-i", `testsrc2=size=160x90:rate=25:duration=${seconds}`]; // Noise makes a file too big to copy in a blink (the cancel case). const heavy = opts.heavy ? ["-vf", "noise=alls=80:allf=t", "-b:v", "4M", "-minrate", "4M", "-maxrate", "4M"] : []; execFileSync("ffmpeg", [ "-v", "error", "-y", ...video, "-f", "lavfi", "-i", `sine=frequency=440:sample_rate=48000:duration=${seconds}`, ...CODECS[kind].args, ...heavy, "-shortest", path, ]); } // Black video with ONE white frame at 6.00 s (content time), silence with ONE // 1 kHz beep from 6.00 s. `extra` goes to the output (e.g. a later start). function makeFlashBeep(path: string, kind: keyof typeof CODECS, extra: string[] = []): void { execFileSync("ffmpeg", [ "-v", "error", "-y", "-f", "lavfi", "-i", "color=c=black:s=160x90:r=25:d=12,drawbox=x=0:y=0:w=iw:h=ih:color=white:t=fill:enable='between(t,5.99,6.01)'", "-f", "lavfi", "-i", "aevalsrc='0.8*sin(2*PI*1000*t)*between(t,6,6.2)':s=48000:d=12", ...CODECS[kind].args, ...extra, "-shortest", path, ]); } // Where, on the clip's own clock, the first bright frame is and the beep starts. function flashAndBeep(path: string): { flash: number; beep: number } { const v = execFileSync("ffmpeg", ["-v", "error", "-i", path, "-an", "-vf", "signalstats,metadata=print:key=lavfi.signalstats.YAVG:file=-", "-f", "null", "-"], { encoding: "utf8", }); let flash = NaN; let pts = NaN; for (const line of v.split("\n")) { const t = /pts_time:([\d.]+)/.exec(line); if (t) pts = Number(t[1]); const y = /YAVG=([\d.]+)/.exec(line); if (y && Number(y[1]) > 128 && Number.isNaN(flash)) flash = pts; } const err = spawnSync("ffmpeg", ["-v", "info", "-nostats", "-i", path, "-vn", "-af", "silencedetect=n=-30dB:d=0.05", "-f", "null", "-"], { encoding: "utf8", }).stderr; const end = /silence_end: ([\d.]+)/.exec(err); return { flash, beep: end ? Number(end[1]) : NaN }; } // The flash and the beep land together, `at` seconds into the clip. function expectInStep(path: string, at: number) { const { flash, beep } = flashAndBeep(path); // One video frame is 40 ms; the beep's onset is within an audio frame. expect(Math.abs(flash - at), `flash at ${flash}`).toBeLessThanOrEqual(0.045); expect(Math.abs(beep - at), `beep at ${beep}`).toBeLessThanOrEqual(0.03); expect(Math.abs(flash - beep), `flash ${flash}, beep ${beep}`).toBeLessThanOrEqual(0.045); } type Probe = { streams: { codec_type: string; codec_name: string; start_time: string }[]; format: { duration: string } }; function ffprobe(path: string): Probe { return JSON.parse( execFileSync("ffprobe", ["-v", "error", "-show_entries", "stream=codec_type,codec_name,start_time:format=duration", "-of", "json", path], { encoding: "utf8", }), ); } function firstVideoFrameIsKey(path: string): boolean { const out = execFileSync( "ffprobe", ["-v", "error", "-select_streams", "v:0", "-show_entries", "frame=key_frame", "-read_intervals", "%+#1", "-of", "csv=p=0", path], { encoding: "utf8" }, ); return out.trim().split("\n")[0]?.trim() === "1"; } const video = (page: Page) => page.locator('video[aria-label="Your copy"]'); const clipGroup = (page: Page) => page.getByRole("group", { name: "Clip of your copy" }); // The ONE live region, mounted while a copy plays. const clipStatus = (page: Page) => page.getByTestId("local-clip-status"); const clipToggle = (page: Page) => page.getByRole("button", { name: "Clip my copy" }); // showSaveFilePicker, stubbed with a writable that keeps the file in the page. async function stubSavePicker(page: Page) { await page.addInitScript(() => { type Chunk = { type: "write"; data: Uint8Array; position: number }; const saved: { name: string | null; calls: string[]; bytes: Uint8Array | null } = { name: null, calls: [], bytes: null }; (window as unknown as { __saved: typeof saved }).__saved = saved; (window as unknown as { showSaveFilePicker: unknown }).showSaveFilePicker = async (opts: { suggestedName: string }) => { saved.name = opts.suggestedName; return { createWritable: async () => { let file = new Uint8Array(0); return new WritableStream({ write(chunk) { saved.calls.push("write"); const end = chunk.position + chunk.data.byteLength; if (end > file.byteLength) { const grown = new Uint8Array(end); grown.set(file); file = grown; } file.set(chunk.data, chunk.position); }, close() { saved.calls.push("close"); saved.bytes = file; }, abort() { saved.calls.push("abort"); }, }); }, }; }; }); } async function savedFile(page: Page): Promise<{ name: string | null; calls: string[]; bytes: Buffer | null }> { const r = await page.evaluate(() => { const s = (window as unknown as { __saved: { name: string | null; calls: string[]; bytes: Uint8Array | null } }).__saved; let b64: string | null = null; if (s.bytes) { let bin = ""; for (let i = 0; i < s.bytes.length; i += 0x8000) bin += String.fromCharCode(...s.bytes.subarray(i, i + 0x8000)); b64 = btoa(bin); } return { name: s.name, calls: s.calls, b64 }; }); return { name: r.name, calls: r.calls, bytes: r.b64 === null ? null : Buffer.from(r.b64, "base64") }; } // Every object URL the page revokes. async function spyRevokes(page: Page) { await page.addInitScript(() => { const revoked: string[] = []; (window as unknown as { __revoked: string[] }).__revoked = revoked; const orig = URL.revokeObjectURL.bind(URL); URL.revokeObjectURL = (u: string) => { revoked.push(u); orig(u); }; }); } const revoked = (page: Page) => page.evaluate(() => (window as unknown as { __revoked: string[] }).__revoked); // Playback is the browser's; what is tested is the copy. play() starts // nothing, so every currentTime is exactly where the page put it. async function stillPlayback(page: Page) { await page.addInitScript(() => { HTMLMediaElement.prototype.play = function () { return Promise.resolve(); }; }); } async function cue(page: Page, text: string) { await page.locator("li", { hasText: text }).getByRole("button").click(); } async function markClip(page: Page, inText: string, outText: string) { await cue(page, inText); await page.getByRole("button", { name: "Mark clip start at current time" }).click(); await cue(page, outText); await page.getByRole("button", { name: "Mark clip end at current time" }).click(); } // Every request from `from` on: what it was, and whether the clip path may make it. type Seen = { url: string; method: string; post: string | null; type: string }; function seen(r: Request): Seen { return { url: r.url(), method: r.method(), post: r.postData(), type: r.resourceType() }; } async function open(page: Page) { await installMissingSourceRoutes(page, { cues: CUES }); await stillPlayback(page); await page.goto(`/?v=${SLUG}`); await expectModalOpen(page); // The page has settled: the panel (it waits for the summaries) and the cues // (the transcript record) are in. await expect(page.getByTestId("source-missing").getByRole("button", { name: "Play your own copy" })).toBeVisible(); await expect(page.locator("li", { hasText: "clip line zero" })).toBeVisible(); } async function pick(page: Page, file: { name: string; mimeType: string; buffer: Buffer }) { await expect(page.getByRole("button", { name: "Play your own copy" })).toBeVisible(); await page.getByTestId("local-file-input").setInputFiles(file); await expect(video(page)).toHaveAttribute("src", /^blob:/); } async function noServiceWorker(page: Page) { const sw = await page.evaluate(async () => ({ controlled: navigator.serviceWorker?.controller != null, registrations: (await navigator.serviceWorker?.getRegistrations?.())?.length ?? 0, })); expect(sw).toEqual({ controlled: false, registrations: 0 }); } test.describe("export — clip your own copy in the browser", () => { test.skip(!FFMPEG, "ffmpeg/ffprobe not on PATH"); test("WebM: says where the clip starts, saves a stream copy in step, and sends the file nowhere", async ({ page }, info) => { const src = info.outputPath("synth-copy.webm"); makeMedia(src, "webm"); const FILE = { name: "my-synth-copy.webm", mimeType: CODECS.webm.mime, buffer: readFileSync(src) }; // The first load: every request, and every script's text. const firstLoad: Seen[] = []; const firstLoadScripts: Promise[] = []; let phase: "load" | "picked" | "clip" = "load"; const afterPick: Seen[] = []; const afterClip: Seen[] = []; const clipScripts: Promise<{ url: string; body: string }>[] = []; page.on("request", (r) => { if (phase === "load") firstLoad.push(seen(r)); else if (!r.url().startsWith("blob:")) (phase === "picked" ? afterPick : afterClip).push(seen(r)); }); page.on("response", (resp) => { if (resp.request().resourceType() !== "script") return; const body = resp.text().catch(() => ""); if (phase === "load") firstLoadScripts.push(body); else clipScripts.push(body.then((b) => ({ url: resp.url(), body: b }))); }); await spyRevokes(page); await open(page); phase = "picked"; await pick(page, FILE); await markClip(page, "clip line five", "clip line nine"); // Nothing went out between the pick and asking for a clip. expect(afterPick).toEqual([]); phase = "clip"; await page.getByRole("button", { name: "Clip my copy" }).click(); const group = clipGroup(page); await expect(group).toBeVisible(); // BEFORE saving: the range, the real start, the name. await expect(group.getByTestId("local-clip-start")).toHaveText("Starts 1.0 s earlier, at the nearest keyframe (0:00:04.0)."); await expect(group.getByTestId("local-clip-range")).toHaveText("From 0:00:05.0 to 0:00:09.0."); await expect(group.getByTestId("local-clip-end")).toHaveCount(0); // The live region says the same, once. await expect(clipStatus(page)).toContainText("Starts 1.0 s earlier, at the nearest keyframe (0:00:04.0)."); await expect(group.getByTestId("local-clip-name")).toHaveText(`${TITLE_BASE}_00h00m04s-00h00m09s.webm`); await expect(group).toContainText("Clipping uses Mediabunny 1.45.3 (MPL-2.0)"); const download = page.waitForEvent("download"); await group.getByRole("button", { name: "Save clip" }).click(); const d = await download; expect(d.suggestedFilename()).toBe(`${TITLE_BASE}_00h00m04s-00h00m09s.webm`); const out = info.outputPath("clip.webm"); await d.saveAs(out); await expect(group.getByTestId("local-clip-done")).toContainText(`Your browser is saving ${TITLE_BASE}_00h00m04s-00h00m09s.webm`); await expect(clipStatus(page)).toContainText(`Your browser is saving ${TITLE_BASE}_00h00m04s-00h00m09s.webm`); // Closing the panel leaves the download's URL alive; clearing the copy lets it go. const downloadUrl = d.url(); expect(downloadUrl).toMatch(/^blob:/); await group.getByRole("button", { name: "Close the clip" }).click(); await expect(clipGroup(page)).toHaveCount(0); expect(await revoked(page)).not.toContain(downloadUrl); // The clip: copied, from a key frame, 9.0 − 4.0 s long, audio and video in step. const probe = ffprobe(out); const v = probe.streams.find((s) => s.codec_type === "video")!; const a = probe.streams.find((s) => s.codec_type === "audio")!; expect([v.codec_name, a.codec_name]).toEqual(["vp9", "opus"]); expect(firstVideoFrameIsKey(out)).toBe(true); expect(Math.abs(Number(probe.format.duration) - 5)).toBeLessThan(0.12); // One Opus frame is 20 ms. expect(Math.abs(Number(v.start_time) - Number(a.start_time))).toBeLessThanOrEqual(0.0205); // The network, from the pick on: only the clipper's own chunk(s), asked // for after "Clip my copy", same-origin GETs with no body, none naming the file. const origin = new URL(page.url()).origin; expect(afterClip.length).toBeGreaterThan(0); for (const r of afterClip) { const u = new URL(r.url); expect(r.method, r.url).toBe("GET"); expect(r.post, r.url).toBeNull(); expect(u.origin, r.url).toBe(origin); expect(u.pathname.startsWith("/_next/"), r.url).toBe(true); expect(r.url).not.toContain("my-synth-copy"); } // The library arrived with the clip, not with the first load. const engineChunks = (await Promise.all(clipScripts)).filter((s) => s.body.includes(ENGINE_MARK)); expect(engineChunks.length).toBeGreaterThan(0); const firstUrls = new Set(firstLoad.map((r) => r.url)); for (const c of engineChunks) expect(firstUrls.has(c.url), c.url).toBe(false); for (const body of await Promise.all(firstLoadScripts)) expect(body.includes(ENGINE_MARK)).toBe(false); await noServiceWorker(page); await page.getByRole("button", { name: "Stop using my copy" }).click(); await expect.poll(() => revoked(page)).toContain(downloadUrl); }); test("an offset moves the marks onto the file's clock; on a keyframe the clip starts at the mark", async ({ page }, info) => { const src = info.outputPath("synth-copy.webm"); makeMedia(src, "webm"); await open(page); await pick(page, { name: "my-synth-copy.webm", mimeType: CODECS.webm.mime, buffer: readFileSync(src) }); await page.getByRole("button", { name: "Offset +1 second" }).click(); await markClip(page, "clip line five", "clip line nine"); await page.getByRole("button", { name: "Clip my copy" }).click(); const group = clipGroup(page); // Cue 0:05 + 1 s = 6.0 s into the file, a keyframe. await expect(group.getByTestId("local-clip-start")).toHaveText("Starts at your Clip in mark."); await expect(group).toContainText("From 0:00:05.0 to 0:00:09.0, with your offset +1.00 s applied."); await expect(group.getByTestId("local-clip-name")).toHaveText(`${TITLE_BASE}_00h00m05s-00h00m09s.webm`); const download = page.waitForEvent("download"); await group.getByRole("button", { name: "Save clip" }).click(); const out = info.outputPath("clip.webm"); await (await download).saveAs(out); const probe = ffprobe(out); expect(Math.abs(Number(probe.format.duration) - 4)).toBeLessThan(0.12); }); test("MP4 (H.264 with B-frames, AAC): a stream copy in step, whether or not this browser can play it", async ({ page }, info) => { const src = info.outputPath("synth-copy.mp4"); makeFlashBeep(src, "mp4"); await open(page); await pick(page, { name: "my-synth-copy.mp4", mimeType: CODECS.mp4.mime, buffer: readFileSync(src) }); await markClip(page, "clip line five", "clip line nine"); await page.getByRole("button", { name: "Clip my copy" }).click(); const group = clipGroup(page); await expect(group.getByTestId("local-clip-start")).toHaveText("Starts 1.0 s earlier, at the nearest keyframe (0:00:04.0)."); await expect(group.getByTestId("local-clip-name")).toHaveText(`${TITLE_BASE}_00h00m04s-00h00m09s.mp4`); const download = page.waitForEvent("download"); await group.getByRole("button", { name: "Save clip" }).click(); const out = info.outputPath("clip.mp4"); await (await download).saveAs(out); const probe = ffprobe(out); const v = probe.streams.find((s) => s.codec_type === "video")!; const a = probe.streams.find((s) => s.codec_type === "audio")!; expect([v.codec_name, a.codec_name]).toEqual(["h264", "aac"]); expect(firstVideoFrameIsKey(out)).toBe(true); expect(Math.abs(Number(probe.format.duration) - 5)).toBeLessThan(0.12); // One AAC frame is 1024 samples at 48 kHz, about 21.3 ms; start_time // already carries the container's edit-list offsets. expect(Math.abs(Number(v.start_time) - Number(a.start_time))).toBeLessThanOrEqual(0.0215); // The flash and the beep at 6.0 s land together, 2.0 s after the 4.0 s keyframe. expectInStep(out, 2); }); test("cancel stops the copy and offers nothing as finished", async ({ page }, info) => { // Two slow saves, each cancelled. test.setTimeout(90_000); const src = info.outputPath("synth-big.webm"); makeMedia(src, "webm", { seconds: 20, heavy: true }); // The file reads slowly here (100 ms per 64 KiB), so the copy is still // running when Cancel is pressed. await page.addInitScript(() => { const orig = Blob.prototype.stream; Blob.prototype.stream = function (this: Blob) { const reader = orig.call(this).getReader(); return new ReadableStream({ async pull(controller) { const { done, value } = await reader.read(); if (done) return controller.close(); await new Promise((r) => setTimeout(r, Math.ceil(value.byteLength / 65536) * 100)); controller.enqueue(value); }, cancel(reason) { return reader.cancel(reason); }, }); } as typeof Blob.prototype.stream; }); await open(page); await pick(page, { name: "my-synth-big.webm", mimeType: CODECS.webm.mime, buffer: readFileSync(src) }); await markClip(page, "clip line two", "clip line eleven"); await page.getByRole("button", { name: "Clip my copy" }).click(); const group = clipGroup(page); await expect(group.getByTestId("local-clip-start")).toBeVisible({ timeout: 30_000 }); let downloads = 0; page.on("download", () => downloads++); await group.getByRole("button", { name: "Save clip" }).click(); await expect(group.getByRole("progressbar", { name: "Saving clip" })).toBeVisible(); // Saving moves the focus to Cancel. const cancel = group.getByRole("button", { name: "Cancel the clip" }); await expect(cancel).toBeFocused(); await cancel.click(); await expect(group.getByTestId("local-clip-cancelled")).toHaveText("Cancelled; nothing was saved."); await expect(clipStatus(page)).toHaveText("Cancelled; nothing was saved."); // Cancel is gone, and the focus with it: it lands on "Clip my copy". await expect(clipToggle(page)).toBeFocused(); // Again, and this time "Clip my copy" is toggled off mid-save: the live // region, still there, says so. await group.getByRole("button", { name: "Close the clip" }).click(); await clipToggle(page).click(); await expect(clipGroup(page).getByTestId("local-clip-start")).toBeVisible({ timeout: 30_000 }); await clipGroup(page).getByRole("button", { name: "Save clip" }).click(); await expect(clipGroup(page).getByRole("progressbar", { name: "Saving clip" })).toBeVisible(); await clipToggle(page).click(); await expect(clipGroup(page)).toHaveCount(0); await expect(clipStatus(page)).toHaveText("Cancelled; nothing was saved."); await page.waitForTimeout(1500); expect(downloads).toBe(0); await noServiceWorker(page); }); test("to a file you choose: the disk path writes the whole clip, in step, and closes the file", async ({ page }, info) => { const src = info.outputPath("synth-copy.webm"); makeFlashBeep(src, "webm"); await stubSavePicker(page); await open(page); await pick(page, { name: "my-synth-copy.webm", mimeType: CODECS.webm.mime, buffer: readFileSync(src) }); await markClip(page, "clip line five", "clip line nine"); await clipToggle(page).click(); const group = clipGroup(page); const name = `${TITLE_BASE}_00h00m04s-00h00m09s.webm`; await expect(group.getByTestId("local-clip-name")).toHaveText(name); let downloads = 0; page.on("download", () => downloads++); await group.getByRole("button", { name: "Save the clip to a file you choose" }).click(); await expect(group.getByTestId("local-clip-done")).toHaveText(/^Saved Synth-members-stream_00h00m04s-00h00m09s\.webm \(\d+(\.\d)? (KB|MB)\)\.$/); await expect(clipStatus(page)).toContainText(`Saved ${name}`); // Cancel went with the save, and the focus went to "Clip my copy". await expect(clipToggle(page)).toBeFocused(); const saved = await savedFile(page); expect(saved.name).toBe(name); expect(saved.calls.at(-1)).toBe("close"); expect(saved.calls).not.toContain("abort"); expect(downloads).toBe(0); const out = info.outputPath("disk-clip.webm"); writeFileSync(out, saved.bytes!); const probe = ffprobe(out); expect(probe.streams.map((s) => s.codec_name).sort()).toEqual(["opus", "vp9"]); expect(firstVideoFrameIsKey(out)).toBe(true); expect(Math.abs(Number(probe.format.duration) - 5)).toBeLessThan(0.12); expectInStep(out, 2); }); test("a mark outside the copy: the page says where the clip really starts and ends, and the name agrees", async ({ page }, info) => { const src = info.outputPath("synth-copy.webm"); makeMedia(src, "webm"); await open(page); await pick(page, { name: "my-synth-copy.webm", mimeType: CODECS.webm.mime, buffer: readFileSync(src) }); // Marks at cue 0:00 and 0:09, then the offset to −2 s: the in mark is // before the copy begins (its 0.0 s is cue 0:02). await markClip(page, "clip line zero", "clip line nine"); await page.getByRole("button", { name: "Offset −1 second" }).click(); await page.getByRole("button", { name: "Offset −1 second" }).click(); await clipToggle(page).click(); const group = clipGroup(page); await expect(group.getByTestId("local-clip-start")).toHaveText( "Your copy begins at 0:00:02.0, after your Clip in mark; the clip starts there.", ); await expect(group.getByTestId("local-clip-range")).toHaveText("From 0:00:02.0 to 0:00:09.0, with your offset −2.00 s applied."); await expect(group.getByTestId("local-clip-end")).toHaveCount(0); await expect(group.getByTestId("local-clip-name")).toHaveText(`${TITLE_BASE}_00h00m02s-00h00m09s.webm`); let download = page.waitForEvent("download"); await group.getByRole("button", { name: "Save clip" }).click(); let out = info.outputPath("clamped-start.webm"); await (await download).saveAs(out); // File 0.0 → 7.0. expect(Math.abs(Number(ffprobe(out).format.duration) - 7)).toBeLessThan(0.12); await group.getByRole("button", { name: "Close the clip" }).click(); // Marks at cue 0:05 and 0:11, then the offset to +2 s: the out mark is // past the copy's end (its 12.0 s is cue 0:10). await markClip(page, "clip line five", "clip line eleven"); for (let i = 0; i < 4; i++) await page.getByRole("button", { name: "Offset +1 second" }).click(); await clipToggle(page).click(); await expect(group.getByTestId("local-clip-end")).toHaveText( "Your copy ends at 0:00:10.0, before your Clip out mark; the clip ends there.", ); await expect(group.getByTestId("local-clip-start")).toHaveText("Starts 1.0 s earlier, at the nearest keyframe (0:00:04.0)."); await expect(group.getByTestId("local-clip-range")).toHaveText("From 0:00:05.0 to 0:00:10.0, with your offset +2.00 s applied."); await expect(group.getByTestId("local-clip-name")).toHaveText(`${TITLE_BASE}_00h00m04s-00h00m10s.webm`); download = page.waitForEvent("download"); await group.getByRole("button", { name: "Save clip" }).click(); out = info.outputPath("clamped-end.webm"); await (await download).saveAs(out); // File 6.0 → 12.0. expect(Math.abs(Number(ffprobe(out).format.duration) - 6)).toBeLessThan(0.12); }); test("a copy whose first timestamp is 3 s: the page's times are the