import { test, expect, type Page } from "@playwright/test"; import { execFileSync } from "node:child_process"; import { createHash } from "node:crypto"; import { copyFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import * as urls from "./urls"; import { resetPostNarrationFiles } from "./fixtures/post-narration-fixture.mjs"; // --------------------------------------------------------------------------- // NARRATED POST ITEMS (report-to-video/post-narration.mjs; knobs.md, "A narrated // post item"). Fixture: e2e/fixtures/post-narration-fixture.mjs -- p-11 a 4 s // video narrated by a 2 s take (muffled 0-2.7 s, the ramp to 3.5 s, clean after; // the item 0.4 + 2 + 0.3 + 1.8 = 4.5 s), p-12 four pictures un-narrated, p-13 // words and a script, no take. The editor is the suite's stub (its tts op // writes a tone where `out` says). // // POST_NARRATION_SHOTS= screenshots there // --------------------------------------------------------------------------- const HERE = path.dirname(fileURLToPath(import.meta.url)); const FIXTURE = path.join(HERE, "..", ".e2e-song"); const DIR = path.join(FIXTURE, "reports", "post-narration-fixture"); const MANIFEST = path.join(DIR, "video.manifest.json"); const PROJECT = "reports/post-narration-fixture"; const SHOTS = process.env.POST_NARRATION_SHOTS ?? null; /** A voice for the fake microphone: a 1 kHz tone, two seconds. */ const MIC_WAV = path.join(FIXTURE, "post-narration-mic.wav"); type Take = { file: string; engine?: string; voice?: string; note?: string; seconds: number }; type Entry = { id: string; narration?: { script?: string; takes?: Take[]; pick?: number; approved?: boolean } }; const timeline = () => (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Entry[] }).timeline; const narr = (id: string) => timeline().find((e) => e.id === id)!.narration!; if (!existsSync(MIC_WAV)) { mkdirSync(FIXTURE, { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "sine=frequency=1000:sample_rate=48000:duration=2", "-ac", "1", MIC_WAV]); } // A fake microphone (the recording session) and audio that may start without a gesture, for the whole file. test.use({ launchOptions: { args: ["--use-fake-ui-for-media-stream", "--use-fake-device-for-media-stream", `--use-file-for-fake-audio-capture=${MIC_WAV}`, "--autoplay-policy=no-user-gesture-required"] } }); test.beforeAll(() => { if (!existsSync(`${MANIFEST}.pristine`)) copyFileSync(MANIFEST, `${MANIFEST}.pristine`); }); test.beforeEach(() => { test.setTimeout(120_000); copyFileSync(`${MANIFEST}.pristine`, MANIFEST); rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); rmSync(path.join(DIR, "notes.json"), { force: true }); // narration/ back to the fixture's own two files: this test's takes, parts, the parts cache a re-voice's phrase // lands in, .trash and .recording-* -- and ANOTHER spec's (long-reads leaves a take-7 of p-11, and a new take is // numbered past every take-N on disk, so the run order used to decide this spec's take numbers). resetPostNarrationFiles(DIR); }); const root = (page: Page) => page.locator("[data-play-cut]"); test("Play plays the take over the attachment, muffled under the read, then opens up clean", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-11" })); await expect(root(page)).toHaveAttribute("data-play-item", "p-11"); const player = page.locator('[data-post-play="p-11"]'); await expect(player).toHaveAttribute("data-post-narrated", "1"); // The video beside the card from the item's first frame; the muffle on. await expect(player).toHaveAttribute("data-post-step", "video"); await expect(player).toHaveAttribute("data-post-mix-phase", "muffled"); await expect(player).toHaveAttribute("data-post-wet", "0.3"); await expect(player).toHaveAttribute("data-post-dry", "0"); await expect(page.locator("[data-post-narration-audio]")).toHaveAttribute("data-post-narration-audio", "narration/posts/11/take-1.orpheus-zac.wav"); await page.locator("[data-play-toggle]").click(); await expect(player).toHaveAttribute("data-post-narration-playing", "1", { timeout: 15_000 }); await expect.poll(async () => page.locator("[data-post-narration-audio]").evaluate((a: HTMLAudioElement) => a.currentTime), { timeout: 10_000 }).toBeGreaterThan(0.3); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-narration-play-muffled.png") }); // Past the words and the tail: the ramp, then clean. await expect(player).toHaveAttribute("data-post-mix-phase", /ramp|clean/, { timeout: 15_000 }); await expect(player).toHaveAttribute("data-post-narration-playing", "0"); await page.locator("[data-play-toggle]").click(); }); /** Over `ms` of wall time inside the page: how far the item's clock, its video and its voice moved, and how often the video seeked. */ /** Playing for real before a speed is sampled: no "loading…" on the transport. (Not a wait on the post's clock: a * sample that starts late runs past a short read's end, and the voice reads slow.) */ const steadyPlay = async (page: Page, _id: string) => { await expect(page.locator("[data-play-waiting]")).toHaveCount(0, { timeout: 15_000 }); }; const sampleSpeed = (page: Page, id: string, ms: number) => page.evaluate(async ({ id, ms }) => { const p = document.querySelector(`[data-post-play="${id}"]`)!; const v = p.querySelector("video[data-post-video]") as HTMLVideoElement; const a = document.querySelector("[data-post-narration-audio]") as HTMLAudioElement; let seeks = 0; const on = () => (seeks += 1); v.addEventListener("seeking", on); const s0 = Number(p.getAttribute("data-post-s")), v0 = v.currentTime, a0 = a.currentTime, w0 = performance.now(); await new Promise((r) => setTimeout(r, ms)); v.removeEventListener("seeking", on); return { ds: Number(p.getAttribute("data-post-s")) - s0, dv: v.currentTime - v0, da: a.currentTime - a0, dw: (performance.now() - w0) / 1000, seeks, vr: v.playbackRate, ar: a.playbackRate }; }, { id, ms }); test("FAST-FORWARD SPEEDS A POST ITEM UP (operator, 3 Nov: \"it's just skipping rather than actual speeding up\"): at 2x the clock, the video and the voice all run at 2x, no seeks", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-11" })); await expect(root(page)).toHaveAttribute("data-play-item", "p-11"); // The deck composed first, as the read's-rate test below waits: its frame mounts the player afresh, and a sample // across that reads a player gone (the clock "moving" at 0.08x). await expect(root(page)).toHaveAttribute("data-play-compose", "ready", { timeout: 60_000 }); const player = page.locator('[data-post-play="p-11"]'); await expect(player).toHaveAttribute("data-post-step", "video"); await page.locator("[data-play-rate]").selectOption("2"); await page.locator("[data-play-toggle]").click(); await expect(player).toHaveAttribute("data-post-narration-playing", "1", { timeout: 15_000 }); await expect(page.locator("video[data-post-video]")).toHaveAttribute("data-post-video-rate", "2"); await expect(page.locator("[data-post-narration-audio]")).toHaveAttribute("data-post-narration-rate", "2"); // Sampled once it plays steadily: a window that opens on the media still loading measures the load, not the rate. await steadyPlay(page, "p-11"); const r = await sampleSpeed(page, "p-11", 600); // The clock at ~2x wall time; the video and the voice moving with it (played, not jumped); no re-seek. expect(r.ds / r.dw).toBeGreaterThan(1.6); expect(r.ds / r.dw).toBeLessThan(2.4); expect(r.vr).toBe(2); expect(r.ar).toBe(2); expect(r.dv / r.ds).toBeGreaterThan(0.75); expect(r.dv / r.ds).toBeLessThan(1.25); expect(r.da / r.ds).toBeGreaterThan(0.75); expect(r.da / r.ds).toBeLessThan(1.25); expect(r.seeks).toBeLessThanOrEqual(1); await page.locator("[data-play-toggle]").click(); }); test("THE READ's RATE in Play: render.postNarration.rate 1.25 plays the voice at 1.25x on a 1x clock, the read 1.6 s of the item, the attachment at 1x", async ({ page }) => { const m = JSON.parse(readFileSync(MANIFEST, "utf8")); m.render = { ...(m.render ?? {}), postNarration: { ...(m.render?.postNarration ?? {}), rate: 1.25 } }; writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-11" })); await expect(root(page)).toHaveAttribute("data-play-item", "p-11"); // The deck composed first: its frame mounts the player afresh, and a sample across that would read a player gone. await expect(root(page)).toHaveAttribute("data-play-compose", "ready", { timeout: 60_000 }); const player = page.locator('[data-post-play="p-11"]'); await page.locator("[data-play-toggle]").click(); await expect(player).toHaveAttribute("data-post-narration-playing", "1", { timeout: 15_000 }); await expect(page.locator("[data-post-narration-audio]")).toHaveAttribute("data-post-narration-rate", "1.25"); await expect(page.locator("video[data-post-video]")).toHaveAttribute("data-post-video-rate", "1"); // Sampled once it plays steadily: a window that opens on the media still loading measures the load, not the rate. await steadyPlay(page, "p-11"); const r = await sampleSpeed(page, "p-11", 600); expect(r.ar).toBe(1.25); expect(r.vr).toBe(1); expect(r.da / r.ds).toBeGreaterThan(1.25 * 0.8); expect(r.da / r.ds).toBeLessThan(1.25 * 1.2); // The 2 s take reads in 1.6 s: the voice stops at 0.4 + 1.6 = 2.0 s of the item, the muffle ends 0.3 s later. // Read in the page the moment it stops (a poll from here would land late). const sAtStop = await player.evaluate((el) => new Promise((resolve) => { const done = () => el.getAttribute("data-post-narration-playing") === "0" && (resolve(Number(el.getAttribute("data-post-s"))), true); if (done()) return; const mo = new MutationObserver(() => done() && mo.disconnect()); mo.observe(el, { attributes: true, attributeFilter: ["data-post-narration-playing"] }); })); expect(sAtStop).toBeGreaterThan(1.9); expect(sAtStop).toBeLessThan(2.3); await page.locator("[data-play-toggle]").click(); }); test("four pictures cycle beside the card while it is read; the words stay up the whole item", async ({ page }) => { await page.setViewportSize({ width: 1366, height: 1000 }); await page.goto(urls.postBenchHref(PROJECT, "p-12")); await expect(page.locator('[data-post-bench="p-12"]')).toBeVisible(); const player = page.locator('[data-post-play="p-12"]'); await expect(player).toHaveAttribute("data-post-layout", "side"); const scrub = page.locator("[data-post-bench-scrub]"); const seen: string[] = []; for (const [k, at] of [0.2, 2, 4.5].entries()) { await scrub.fill(String(at)); await expect(player).toHaveAttribute("data-post-step", "image"); await expect(page.frameLocator('[data-post-card-frame="read"]').locator("[data-post-words]")).toContainText("Four pictures of the thing"); seen.push(String(await page.locator("[data-post-image]").first().getAttribute("src"))); await expect.poll(() => page.locator("[data-post-image]").first().evaluate((i: HTMLImageElement) => i.complete && i.naturalWidth > 0)).toBe(true); if (SHOTS) await page.waitForTimeout(400); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, `post-narration-pictures-${k + 1}.png`) }); } expect(new Set(seen).size).toBe(3); }); test("the post bench: the lanes, a re-take with direction (the editor's tts job), Pick and Approve", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 1400 }); await page.goto(urls.postBenchHref(PROJECT, "p-11")); const panel = page.locator('[data-post-narration="p-11"]'); await expect(panel).toBeVisible(); await expect(panel.locator('[data-post-lane="attachment"]')).toBeVisible(); await expect(panel.locator('[data-post-lane="read"]')).toBeVisible(); await expect(panel.locator("[data-post-lane-muffle]")).toBeVisible(); await expect(panel.locator("[data-post-take]")).toHaveCount(1); await expect(panel.locator('[data-post-take="1"]')).toHaveAttribute("data-post-take-picked", "1"); // A take plays: its file is served as audio. const res = await page.request.get(`/api/report/file?project=${encodeURIComponent(PROJECT)}&path=${encodeURIComponent("narration/posts/11/take-1.orpheus-zac.wav")}`); expect(res.status()).toBe(200); expect(res.headers()["content-type"]).toBe("audio/wav"); await expect(panel.locator("[data-post-progress-recorded]")).toHaveText("0"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-narration-bench.png"), fullPage: true }); // Re-take with direction: queued on the editor, kept when done, picked, its note with it. await panel.locator("[data-post-retake-note]").fill("slower, a sigh first"); await panel.locator("[data-post-script]").fill(" The video speaks for itself."); await panel.locator("[data-post-retake]").click(); await expect(panel.locator("[data-post-take]")).toHaveCount(2, { timeout: 20_000 }); const n = narr("p-11"); expect(n.takes![1]).toMatchObject({ file: "narration/posts/11/take-2.orpheus-zac.wav", engine: "orpheus", voice: "zac", note: "slower, a sigh first" }); expect(n.pick).toBe(1); expect(n.script).toBe(" The video speaks for itself."); await expect(page.locator('[data-post-narration="p-11"] [data-post-take="2"]')).toHaveAttribute("data-post-take-picked", "1"); // Pick the first back; approve it. await page.locator('[data-post-take-pick="1"]').click(); await expect(page.locator('[data-post-take="1"]')).toHaveAttribute("data-post-take-picked", "1"); expect(narr("p-11").pick).toBe(0); await page.locator("[data-post-approve]").click(); await expect(page.locator("[data-post-approve]")).toBeChecked(); await expect.poll(() => narr("p-11").approved).toBe(true); // An operator's note on the post: shown on its bench, counted in the walk. await page.locator("[data-post-note-text]").fill("read it angrier"); await page.locator("[data-post-note-add]").click(); await expect(page.locator("[data-post-note]")).toContainText("read it angrier"); await page.goto(urls.postBenchHref(PROJECT, "p-12")); await expect(page.locator("[data-post-with-notes]")).toHaveAttribute("data-post-with-notes", "1"); await expect(page.locator("[data-post-next-with-note]")).toHaveAttribute("data-post-next-with-note", "p-11"); await page.goto(urls.postBenchHref(PROJECT, "p-11")); // The mix: a knob is one write. await page.locator('[data-post-mix="wet"]').fill("0.2"); await page.locator('[data-post-mix="wet"]').blur(); await expect.poll(() => (timeline().find((e) => e.id === "p-11")!.narration as Record).wet).toBe(0.2); // Run AI on a take: the stub editor has no voice ops -- "not installed", said plainly, nothing written. await page.locator("[data-post-derive-op]").selectOption("enhance"); await page.locator("[data-post-derive-run]").click(); await expect(page.locator("[data-post-derive-not-installed]")).toContainText("not installed"); expect(narr("p-11").takes).toHaveLength(2); // Delete, softly: the take out of the list, its file in .trash/. page.once("dialog", (d) => void d.accept()); await page.locator('[data-post-take-delete="2"]').click(); await expect(page.locator("[data-post-take]")).toHaveCount(1); expect(existsSync(path.join(DIR, "narration", "posts", "11", "take-2.orpheus-zac.wav"))).toBe(false); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-narration-bench-takes.png"), fullPage: true }); // Run AI on take #1, converted onto a stock voice (the editor's voice-convert, stubbed): a NEW take derived from // it, the original kept, the step naming the engine the editor ran and the voice it landed on. await page.locator("[data-post-derive-op]").selectOption("convert"); await page.locator("[data-post-derive-voice]").fill("zac"); await page.locator("[data-post-derive-run]").click(); await expect(page.locator("[data-post-take]")).toHaveCount(2, { timeout: 20_000 }); const d = narr("p-11").takes![1] as Take & { source?: unknown; steps?: Record[] }; expect(d).toMatchObject({ engine: "derived", voice: "zac", source: { kind: "take", from: "take-1.orpheus-zac" } }); expect(d.file).toMatch(/^narration\/posts\/11\/take-\d+\.convert-zac\.wav$/); expect(d.steps![0]).toMatchObject({ op: "convert", engine: "openvoice", voice: "zac" }); expect(existsSync(path.join(DIR, d.file))).toBe(true); expect(narr("p-11").takes![0].file).toBe("narration/posts/11/take-1.orpheus-zac.wav"); const asked = (JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")) as { route?: string; voice?: string; file?: string; out?: string }[]).filter((r) => r.route === "voice-convert").at(-1)!; expect(asked.voice).toBe("zac"); expect(asked.file).toMatch(/narration\/posts\/11\/take-1\.orpheus-zac\.wav$/); // The tree: the derived take under its source, its step said. await expect(page.locator('[data-post-take="2"]')).toContainText("convert"); await expect(page.locator('[data-post-take="2"]')).toContainText("zac"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-narration-bench-derived.png"), fullPage: true }); }); test("ANOTHER READING, TUNED (lane orpheus-tuning): the take op sends a tuning and a reading to the editor's tts op, refuses one out of range in its words, and the take records what the editor says it was made with -- the card's own words untouched", async ({ page }) => { const api = "/api/report/post-narration"; const shownBefore = JSON.stringify((timeline().find((e) => e.id === "p-11") as Record).text); const takesBefore = narr("p-11").takes!.length; const bad = await page.request.post(api, { data: { project: PROJECT, op: "take", id: "p-11", reading: -1 } }); expect(bad.status()).toBe(400); expect((await bad.json()).error).toMatch(/^"reading" must be a whole number from 0 to 99999/); const badT = await page.request.post(api, { data: { project: PROJECT, op: "take", id: "p-11", tuning: { temperature: 3 } } }); expect(badT.status()).toBe(400); expect((await badT.json()).error).toBe('"tuning.temperature" must be a number from 0.1 to 1.5 (got 3)'); expect(narr("p-11").takes).toHaveLength(takesBefore); const res = await page.request.post(api, { data: { project: PROJECT, op: "take", id: "p-11", tuning: { temperature: 0.7, top_k: 40 }, reading: 2 } }); expect(res.ok()).toBe(true); const { jobId, file } = (await res.json()) as { jobId: string; file: string }; // What the editor was asked: the tuning and the reading, as given. const asked = (JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")) as { route?: string; out?: string; tuning?: unknown; reading?: unknown; engine?: string }[]) .filter((r) => r.route === "tts").at(-1)!; expect(asked).toMatchObject({ engine: "orpheus", tuning: { temperature: 0.7, top_k: 40 }, reading: 2 }); const q = `${api}?project=${encodeURIComponent(PROJECT)}&id=p-11&job=${encodeURIComponent(jobId)}&file=${encodeURIComponent(file)}`; await expect.poll(async () => ((await (await page.request.get(q)).json()) as { state?: string }).state, { timeout: 20_000 }).toBe("done"); const t = narr("p-11").takes!.at(-1) as Take & { tuning?: Record; reading?: number }; expect(t.file).toBe(file); // Every value it was made with, the defaults included, and its reading: enough to make it again. expect(t.tuning).toEqual({ temperature: 0.7, top_p: 0.85, top_k: 40, min_p: 0, repeat_penalty: 1.2, takes: 3 }); expect(t.reading).toBe(2); expect(JSON.stringify((timeline().find((e) => e.id === "p-11") as Record).text)).toBe(shownBefore); // An engine that ignores them (Kokoro): the answer does not claim a tuning or a reading, the take records none, and // the editor's note comes back with the kept take so the bench can say it was ignored. const k = await page.request.post(api, { data: { project: PROJECT, op: "take", id: "p-11", engine: "kokoro", voice: "af_heart", tuning: { temperature: 0.7 }, reading: 1 } }); expect(k.ok()).toBe(true); const kj = (await k.json()) as { jobId: string; file: string; engine: string; tuning?: unknown; reading?: unknown }; expect(kj.engine).toBe("kokoro"); expect("tuning" in kj).toBe(false); expect("reading" in kj).toBe(false); const kq = `${api}?project=${encodeURIComponent(PROJECT)}&id=p-11&job=${encodeURIComponent(kj.jobId)}&file=${encodeURIComponent(kj.file)}`; let done: { state?: string; note?: string } = {}; await expect.poll(async () => (done = (await (await page.request.get(kq)).json()) as typeof done).state, { timeout: 20_000 }).toBe("done"); expect(done.note).toMatch(/has no sampler or seed: the tuning and reading were ignored/); const kt = narr("p-11").takes!.at(-1) as Take & { tuning?: unknown; reading?: unknown }; expect(kt.file).toBe(kj.file); expect(kt.tuning).toBeUndefined(); expect(kt.reading).toBeUndefined(); }); test.describe("the recording session", () => { test("record a long script part by part, play it back, Keep: a recorded take, picked, and it plays", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 1400 }); await page.goto(urls.postBenchHref(PROJECT, "p-11")); const rec = page.locator("[data-post-record]"); await expect(rec.locator("[data-post-part]")).toHaveCount(2); await expect(rec.locator('[data-post-part="1"]')).toHaveAttribute("data-post-part-current", "1"); await rec.locator("[data-post-record-start]").click(); await expect(rec).toHaveAttribute("data-post-record-phase", "recording", { timeout: 10_000 }); await expect(rec.locator("[data-post-recording]")).toBeVisible(); await page.waitForTimeout(1200); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-narration-recording.png"), fullPage: true }); await rec.locator("[data-post-record-stop]").click(); // Auto-advanced to the second part; the first is recorded and plays back. await expect(rec.locator('[data-post-part="2"]')).toHaveAttribute("data-post-part-current", "1"); await expect(rec.locator('[data-post-part="1"]')).toHaveAttribute("data-post-part-recorded", "1"); await rec.locator("[data-post-record-start]").click(); await expect(rec).toHaveAttribute("data-post-record-phase", "recording", { timeout: 10_000 }); await page.waitForTimeout(1000); await rec.locator("[data-post-record-stop]").click(); await expect(rec.locator('[data-post-part="2"]')).toHaveAttribute("data-post-part-recorded", "1"); await rec.locator("[data-post-record-keep]").click(); const panel = page.locator('[data-post-narration="p-11"]'); await expect(panel.locator("[data-post-take]")).toHaveCount(2, { timeout: 30_000 }); await expect(panel.locator('[data-post-take="2"]')).toHaveAttribute("data-post-take-engine", "recorded"); await expect(panel.locator('[data-post-take="2"]')).toHaveAttribute("data-post-take-picked", "1"); await expect(panel).toHaveAttribute("data-post-narration-plays", "recorded"); const n = narr("p-11"); expect(n.takes![1]).toMatchObject({ file: "narration/posts/11/take-2.recorded-operator.wav", engine: "recorded", voice: "operator" }); expect((n.takes![1] as unknown as { parts: unknown[] }).parts).toHaveLength(2); // The bench's player plays it, as the render will. await expect(page.locator("[data-post-narration-audio]")).toHaveAttribute("data-post-narration-audio", "narration/posts/11/take-2.recorded-operator.wav"); await expect(panel.locator("[data-post-progress-recorded]")).toHaveText("1"); }); }); test("A WORD ZOOM: Get word timings (the editor's transcription), click a word -> Zoom here -> saved; Play pushes the card in on it at its time", async ({ page }) => { await page.setViewportSize({ width: 1500, height: 1100 }); await page.goto(urls.postBenchHref(PROJECT, "p-11")); const panel = page.locator('[data-post-zoom-panel="p-11"]'); await expect(panel.locator("[data-post-zoom-words-state]")).toHaveText(/no word timings/); // The take's word timings: the editor's transcribe op (the stub "hears" the take), aligned to its script. await panel.locator("[data-post-zoom-get-words]").click(); await expect(panel.locator("[data-post-zoom-words-state]")).toHaveText(/the take is timed \(5 words\)/, { timeout: 20_000 }); const t0 = (narr("p-11") as { takes: Array }> }).takes[0]; expect(t0.words?.[2]).toEqual({ w: "speaks", start: 0.75, end: 1.1 }); // Click "speaks" and zoom on it. await panel.locator('[data-post-zoom-word="2"]').click(); await expect(panel.locator("[data-post-zoom-sel]")).toHaveText("“speaks”"); await panel.locator("[data-post-zoom-here]").click(); await expect(panel.locator('[data-post-zoom-fx="0"]')).toBeVisible(); expect((timeline().find((e) => e.id === "p-11") as { fx?: unknown[] }).fx).toEqual([{ kind: "word-zoom", match: "speaks" }]); // Its time: the read's lead 0.4 + the word's 0.75 s in the take. await expect(panel.locator("[data-post-zoom-at]")).toHaveAttribute("data-post-zoom-at", "1.15"); await expect(page.locator('[data-post-bench-zoom-mark="0"]')).toBeVisible(); await expect(page.locator('[data-post-lane-zoom="0"]')).toBeVisible(); // A knob: scale 3, one write. const scale = panel.locator('[data-post-zoom-knob="scale"]'); await scale.fill("3"); await scale.blur(); await expect.poll(() => (timeline().find((e) => e.id === "p-11") as { fx?: Array<{ scale?: number }> }).fx?.[0]?.scale).toBe(3); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-word-zoom-bench.png") }); // Play the cut: at the word's time the card's contents are pushed in, on the render's curve. await page.goto(urls.playHref(PROJECT, { bare: true, clip: "p-11" })); const player = page.locator('[data-post-play="p-11"]'); await expect(player).toHaveAttribute("data-post-zooms", "1", { timeout: 15_000 }); await expect(player).toHaveAttribute("data-post-zoom", "1"); await page.locator("[data-play-toggle]").click(); // Fully in from 1.15 s to 2.35 s: scale 3. await expect(player).toHaveAttribute("data-post-zoom", "3", { timeout: 15_000 }); await expect(player).toHaveAttribute("data-post-zoom-fx", "0"); const transform = await page.frameLocator('[data-post-card-frame="read"]').locator("[data-post-words]").evaluate((el) => (el as HTMLElement).style.transform); expect(transform).toMatch(/scale\(3\)/); const lit = await page.frameLocator('[data-post-card-frame="read"]').locator('[data-w="post:2"]').evaluate((el) => (el as HTMLElement).style.background); expect(lit).toMatch(/rgba\(255, 216, 77/); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-word-zoom-play.png") }); // And back out after it. await expect(player).toHaveAttribute("data-post-zoom", "1", { timeout: 15_000 }); await page.locator("[data-play-toggle]").click(); }); test("PAUSE AFTER (operator, 5 Nov: a countdown read in one breath): Get word timings, then Options -> Re-join the read: pause after speaks=0.5, Preview writes nothing, Apply makes a new take, picked, its later words 0.5 s on", async ({ page }) => { await page.setViewportSize({ width: 1500, height: 1100 }); await page.goto(urls.postBenchHref(PROJECT, "p-11")); const zoom = page.locator('[data-post-zoom-panel="p-11"]'); await zoom.locator("[data-post-zoom-get-words]").click(); await expect(zoom.locator("[data-post-zoom-words-state]")).toHaveText(/the take is timed \(5 words\)/, { timeout: 20_000 }); await page.reload(); const opts = page.locator('[data-panel-id="post-reread"]'); await opts.locator("summary").click(); const row = opts.locator("[data-post-reread-pause-row]"); await expect(row.locator("[data-post-reread-pause-needs-words]")).toHaveCount(0); await row.locator("[data-post-reread-pause]").fill("speaks=0.5"); await row.locator("[data-post-reread-pause-preview]").click(); const status = page.locator("[data-post-narration-status]"); await expect(status).toContainText('would pause after "speaks" (word 3'); expect(narr("p-11").takes).toHaveLength(1); await row.locator("[data-post-reread-pause-go]").click(); await expect(status).toContainText("a new take, picked", { timeout: 20_000 }); const n = narr("p-11") as { takes: Array; steps?: Array<{ op: string }> }>; pick?: number }; expect(n.takes).toHaveLength(2); expect(n.pick).toBe(1); expect(n.takes[1].file).toMatch(/take-2\.pause-orpheus\.wav$/); expect(n.takes[1].steps?.[0]?.op).toBe("pause"); expect(n.takes[1].seconds).toBeGreaterThan(2.4); expect(n.takes[1].words?.[3].start).toBeCloseTo((n.takes[0].words?.[3].start ?? 0) + 0.5, 2); expect(n.takes[1].words?.[2].start).toBe(n.takes[0].words?.[2].start); }); test("RE-VOICE A PHRASE (operator, 5 Nov: the countdown gabbled, pauses cut into it choppy): Get word timings, then Options -> Re-join the read: re-voice speaks as \"talks loudly\", Preview asks no TTS, Apply asks the editor for the phrase only and makes a new take, picked, its later words moved by the length change", async ({ page }) => { await page.setViewportSize({ width: 1500, height: 1100 }); await page.goto(urls.postBenchHref(PROJECT, "p-11")); const zoom = page.locator('[data-post-zoom-panel="p-11"]'); await zoom.locator("[data-post-zoom-get-words]").click(); await expect(zoom.locator("[data-post-zoom-words-state]")).toHaveText(/the take is timed \(5 words\)/, { timeout: 20_000 }); await page.reload(); const opts = page.locator('[data-panel-id="post-reread"]'); await opts.locator("summary").click(); const row = opts.locator("[data-post-reread-revoice-row]"); await expect(row).toContainText("TTS for the phrase only"); await expect(row.locator("[data-post-reread-revoice-needs-words]")).toHaveCount(0); await row.locator("[data-post-reread-revoice]").fill("speaks"); await row.locator("[data-post-reread-revoice-say]").fill("talks loudly"); const ttsAsked = () => (JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")) as { route?: string; text?: string; voice?: string; engine?: string }[]).filter((r) => r.route === "tts" && r.text === "talks loudly"); const before = ttsAsked().length; await row.locator("[data-post-reread-revoice-preview]").click(); const status = page.locator("[data-post-narration-status]"); await expect(status).toContainText('would re-voice "speaks" (words 3-3'); await expect(status).toContainText("not synthesized yet"); expect(narr("p-11").takes).toHaveLength(1); expect(ttsAsked()).toHaveLength(before); await row.locator("[data-post-reread-revoice-go]").click(); await expect(status).toContainText("a new take, picked", { timeout: 30_000 }); expect(ttsAsked().slice(before).map((r) => [r.voice, r.engine])).toEqual([["zac", "orpheus"]]); const n = narr("p-11") as { takes: Array; steps?: Array<{ op: string; revoice?: { from: number; to: number; seconds: number } }> }>; pick?: number }; expect(n.takes).toHaveLength(2); expect(n.pick).toBe(1); expect(n.takes[1].file).toMatch(/take-2\.revoice-orpheus\.wav$/); const st = n.takes[1].steps?.[0]; expect(st?.op).toBe("revoice"); expect(n.takes[1].words?.map((w) => w.w)).toEqual(["The", "video", "talks", "loudly", "for", "itself."]); expect(n.takes[1].words?.[2].estimated).toBe(true); const delta = (st?.revoice?.seconds ?? 0) - ((st?.revoice?.to ?? 0) - (st?.revoice?.from ?? 0)); expect(n.takes[1].words?.[4].start).toBeCloseTo((n.takes[0].words?.[3].start ?? 0) + delta, 2); expect(n.takes[1].words?.[1].start).toBe(n.takes[0].words?.[1].start); expect(n.takes[1].seconds).toBeCloseTo(n.takes[0].seconds + delta, 1); }); test("THE TAKE-ONLY BENCH IS RETIRED (L3): an old ?inTake= address is the draft's bench -- the re-voice lands in the draft, the take's take.json untouched", async ({ page }) => { // p-11's take timed (as Get word timings leaves it), then a draft take of the cut with no patch yet. const original = readFileSync(MANIFEST, "utf8"); const doc = JSON.parse(original) as { timeline: Array } }> }; const words = [["The", 0.1, 0.3], ["video", 0.35, 0.7], ["speaks", 0.75, 1.1], ["for", 1.15, 1.3], ["itself.", 1.35, 1.8]].map(([w, start, end]) => ({ w, start, end })); doc.timeline.find((e) => e.id === "p-11")!.narration!.takes![0].words = words; writeFileSync(MANIFEST, JSON.stringify(doc, null, 2)); const projectText = readFileSync(MANIFEST, "utf8"); const takes = path.join(DIR, "takes"); rmSync(takes, { recursive: true, force: true }); mkdirSync(path.join(takes, "t1"), { recursive: true }); writeFileSync(path.join(takes, "t1", "take.json"), JSON.stringify({ id: "t1", group: "takes", order: 1, label: "Take one", kind: "different", summary: "", changes: [], preview: "preview.mp4", seconds: null, builtAt: null, style: null, patch: null, window: null, draft: true, draftedAt: "2026-11-05T00:00:00.000Z", baseHash: createHash("sha256").update(projectText).digest("hex"), }, null, 2) + "\n"); const takeText = readFileSync(path.join(takes, "t1", "take.json"), "utf8"); try { await page.setViewportSize({ width: 1500, height: 1100 }); await page.goto(`${urls.postBenchHref(PROJECT, "p-11")}?inTake=t1`); await expect(page.locator('[data-post-bench-scope="cut"]')).toContainText("the draft"); await expect(page.locator("[data-post-narration-in-take]")).toHaveCount(0); } finally { expect(readFileSync(path.join(takes, "t1", "take.json"), "utf8")).toBe(takeText); writeFileSync(MANIFEST, original); rmSync(takes, { recursive: true, force: true }); } }); test("READ-FOLLOW (operator, 3 Nov: \"highlight the current paragraph and panning down as needed\"): a long post read part by part -- the second block brightens at its part's start, the others dim, and the card pans so a late block is in view; the bench shows the block map", async ({ page }) => { // p-13 made long: ten paragraphs, a take read paragraph by paragraph (a part every 2 s of the take). const para = (i: number) => `Paragraph ${i + 1} begins here and it goes on for a while, ${"saying the same kind of thing again and again, ".repeat(3)}until it ends with mark ${i + 1}.`; const paras = Array.from({ length: 10 }, (_, i) => para(i)); const m = JSON.parse(readFileSync(MANIFEST, "utf8")); const e = m.timeline.find((x: { id: string }) => x.id === "p-13"); e.text = paras.join("\n\n"); e.narration = { script: e.text, takes: [{ file: "narration/posts/11/take-1.orpheus-zac.wav", engine: "orpheus", voice: "zac", seconds: 20, script: e.text, parts: paras.map((text, i) => ({ n: i + 1, para: i, text, start: i * 2, seconds: 1.8 })) }], pick: 0, }; writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); await page.setViewportSize({ width: 1500, height: 1100 }); await page.goto(urls.postBenchHref(PROJECT, "p-13")); const panel = page.locator("[data-post-follow-panel]"); await expect(panel.locator("[data-post-follow-summary]")).toHaveText(/10 blocks, 10 read \(the take's parts\)/); await expect(panel.locator("[data-post-follow-row]")).toHaveCount(10); const player = page.locator('[data-post-play="p-13"]'); const frame = page.frameLocator('[data-post-card-frame="read"]'); await expect(frame.locator("body")).toHaveAttribute("data-post-follow", "10", { timeout: 15_000 }); const op = (k: number) => frame.locator(`[data-post-block="${k}"]`).evaluate((el) => (el as HTMLElement).style.opacity); const scrub = page.locator("[data-post-bench-scrub]"); // Before the second part: the first block lit, the second dimmed. await scrub.fill("1"); await expect(player).toHaveAttribute("data-post-follow-block", "0"); await expect.poll(() => op(0)).toBe(""); await expect.poll(() => op(1)).toBe("0.65"); // The second part starts at lead 0.4 + 2 s: past its ease (0.125 s) it is lit and the first is dimmed. await scrub.fill("2.6"); await expect(player).toHaveAttribute("data-post-follow-block", "1"); await expect.poll(() => op(1)).toBe(""); await expect.poll(() => op(0)).toBe("0.65"); await expect(panel.locator('[data-post-follow-row="1"]')).toHaveAttribute("data-current", "1"); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-follow-second-block.png") }); // The words are taller than the card: a late block is panned into view. await expect(player).toHaveAttribute("data-post-follow-pans", /^[1-9]/); await scrub.fill("17.2"); await expect(player).toHaveAttribute("data-post-follow-block", "8"); await expect.poll(async () => Number(await player.getAttribute("data-post-follow-offset"))).toBeGreaterThan(0); const view = await frame.locator("[data-post-words]").evaluate((w) => { const r = w.getBoundingClientRect(); const b = (w.querySelector('[data-post-block="8"]') as HTMLElement).getBoundingClientRect(); return { top: r.top, bottom: r.bottom, bTop: b.top, bBottom: b.bottom, flow: (w.querySelector("[data-post-flow]") as HTMLElement).style.transform }; }); expect(view.flow).toMatch(/translateY\(-\d/); expect(view.bTop).toBeGreaterThanOrEqual(view.top - 1); expect(view.bBottom).toBeLessThanOrEqual(view.bottom + 1); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "post-follow-panned.png") }); // A row of the map puts the playhead at its block's start. await panel.locator('[data-post-follow-row="3"] button').click(); await expect(page.locator("[data-post-bench-clock]")).toHaveText(/^6\.4 \//); // Off on this post: the card shows its words as they are (no blocks lit, no pan). await panel.locator("[data-post-follow-mode]").selectOption("off"); await expect(panel).toContainText("off: the card shows its words as they are"); }); test("THE RECORDING SESSION: part by part, a reload resumes, redo one, the last part makes the recorded take and picks it", async ({ page }) => { await page.setViewportSize({ width: 1440, height: 1200 }); await page.goto(urls.projectHref(PROJECT, { tab: "cut" })); await expect(page.locator("[data-record-narration-link]")).toHaveAttribute("href", urls.narrationRecordHref(PROJECT)); await page.goto(urls.narrationRecordHref(PROJECT, { post: "p-11" })); const s = page.locator("[data-record-session]"); await expect(s).toHaveAttribute("data-record-session", "p-11"); await expect(page.locator("[data-record-jump]")).toHaveCount(3); await expect(page.locator('[data-record-jump="p-11"]')).toHaveAttribute("data-record-state", "placeholder"); await expect(page.locator("[data-record-progress]")).toHaveAttribute("data-record-progress", "0"); // Two paragraphs: two parts, the first current. await expect(page.locator("[data-record-prompt]")).toHaveCount(2); await expect(page.locator('[data-record-prompt="1"]')).toHaveAttribute("data-record-prompt-current", "1"); await page.locator("[data-record-count-in]").uncheck(); // Space records, Space stops: part 1 is on disk, part 2 is next. await page.keyboard.press("Space"); await expect(s).toHaveAttribute("data-record-phase", "recording", { timeout: 10_000 }); await page.waitForTimeout(900); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "record-session-recording.png"), fullPage: true }); await page.keyboard.press("Space"); await expect(page.locator('[data-record-prompt="1"]')).toHaveAttribute("data-record-prompt-kept", "1"); await expect(page.locator('[data-record-prompt="2"]')).toHaveAttribute("data-record-prompt-current", "1"); expect(existsSync(path.join(DIR, "narration", "posts", "11", ".recording-operator", "session.json"))).toBe(true); // A reload resumes: part 1 kept, part 2 current. await page.reload(); await expect(page.locator('[data-record-prompt="1"]')).toHaveAttribute("data-record-prompt-kept", "1"); await expect(page.locator('[data-record-prompt="2"]')).toHaveAttribute("data-record-prompt-current", "1"); await expect(page.locator('[data-record-play-placeholder="2"]')).toBeVisible(); // Redo part 1 (r): recorded again, still kept; the next unkept part is current. await page.locator('[data-record-prompt="1"]').click(); await page.locator("[data-record-count-in]").uncheck(); await page.keyboard.press("r"); await expect(s).toHaveAttribute("data-record-phase", "recording", { timeout: 10_000 }); await page.waitForTimeout(700); await page.keyboard.press("Space"); await expect(page.locator('[data-record-prompt="2"]')).toHaveAttribute("data-record-prompt-current", "1"); await expect(page.locator('[data-record-play-part="1"]')).toHaveCount(0); // The last part: the take is made, picked, and the post is recorded. await page.keyboard.press("Space"); await expect(s).toHaveAttribute("data-record-phase", "recording", { timeout: 10_000 }); await page.waitForTimeout(700); await page.keyboard.press("Space"); await expect(page.locator("[data-record-status]")).toContainText("take-2.recorded-operator.wav", { timeout: 30_000 }); await expect(page.locator('[data-record-jump="p-11"]')).toHaveAttribute("data-record-state", "recorded"); await expect(page.locator("[data-record-progress]")).toHaveAttribute("data-record-progress", "1"); const n = narr("p-11"); expect(n.pick).toBe(1); expect(n.takes![1]).toMatchObject({ file: "narration/posts/11/take-2.recorded-operator.wav", engine: "recorded", voice: "operator" }); expect((n.takes![1] as unknown as { parts: unknown[] }).parts).toHaveLength(2); expect(existsSync(path.join(DIR, "narration", "posts", "11", ".recording-operator"))).toBe(false); if (SHOTS) await page.screenshot({ path: path.join(SHOTS, "record-session-done.png"), fullPage: true }); // Enter: on to the next post. await page.keyboard.press("Enter"); await expect(s).toHaveAttribute("data-record-session", "p-12"); }); // --------------------------------------------------------------------------- // READ AGAIN (lane line-rerun, S3 of the Orpheus re-tune plan): from the post bench a line is read again, heard as it // lands, and picked, with no agent -- and what the card DRAWS never changes. An item of this test's own, p-31 (written // into the manifest here, so the specs that share p-11 and p-13 never see it): a two-paragraph post, its script its // words as drafted, one take; a screenshot on it read line by line. // --------------------------------------------------------------------------- const OWN_TEXT = "The ferry runs at noon.\n\nBring a coat for the crossing."; const OWN_TAKE = "narration/posts/31/take-1.orpheus-zac.wav"; function addOwnItem() { const m = JSON.parse(readFileSync(MANIFEST, "utf8")); const base = m.timeline.find((x: { id: string }) => x.id === "p-13"); m.timeline.push({ ...base, id: "p-31", post: "narrchan-x/31", url: "https://x.com/narrsubject/status/31", text: OWN_TEXT, media: [{ src: "posts-media/narrchan-x/12/12_1.png", kind: "image", width: 320, height: 180 }], screens: [{ id: "s1", media: 0, kind: "dm", read: "none", lines: [{ who: "ferryfan", text: "Is it the BRT dock?" }, { who: "narrsubject", text: "Yes, pier four." }] }], narration: { script: OWN_TEXT, takes: [{ file: OWN_TAKE, engine: "orpheus", voice: "zac", seconds: 2, script: OWN_TEXT, at: "2026-11-02T00:00:00.000Z" }], pick: 0 }, }); writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); mkdirSync(path.join(DIR, "narration", "posts", "31"), { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "sine=frequency=300:sample_rate=48000:duration=2", "-ac", "1", "-c:a", "pcm_s16le", path.join(DIR, OWN_TAKE)]); } /** What the bench's card frame DRAWS of the item: its words, its blocks (their keys and words), its tiles' modes. */ async function drawnCard(page: Page) { const frame = page.frameLocator('[data-post-card-frame="read"]'); await expect(frame.locator("[data-post-words]")).toContainText("ferry", { timeout: 15_000 }); return frame.locator("body").evaluate((b) => ({ words: b.querySelector("[data-post-words]")?.textContent ?? null, blocks: [...b.querySelectorAll("[data-post-block]")].map((x) => [x.getAttribute("data-post-block"), x.textContent]), tiles: [...b.querySelectorAll("[data-thread-tile]")].map((x) => [x.getAttribute("data-thread-tile"), x.getAttribute("data-thread-mode")]), follow: b.getAttribute("data-post-follow"), })); } test("READ AGAIN (lane line-rerun): the next reading unpicked and heard as it lands, the edited text read, Pick -- and the card draws exactly what it drew", async ({ page }) => { addOwnItem(); // Every play the page starts, recorded (a new read plays as it lands). await page.addInitScript(() => { const w = window as unknown as { __played: string[] }; w.__played = []; const play = HTMLMediaElement.prototype.play; HTMLMediaElement.prototype.play = function (this: HTMLMediaElement) { w.__played.push(this.src); return play.call(this).catch(() => undefined) as Promise; }; }); await page.setViewportSize({ width: 1440, height: 1400 }); await page.goto(urls.postBenchHref(PROJECT, "p-31")); const panel = page.locator('[data-post-narration="p-31"]'); await expect(panel.locator("[data-post-take]")).toHaveCount(1); // Every new control, by its name. for (const label of ["Read again", "Read the edited text", "Tune this line only", "Read again with this tuning", "Tuning back to the defaults", "Play new reads when they land", "temperature, this line only", "top p, this line only", "top k, this line only", "min p, this line only", "repeat penalty, this line only", "takes, this line only", "Pick take 1"]) { await expect(panel.locator(`[aria-label="${label}"]`), label).toHaveCount(1); } const before = await drawnCard(page); // READ AGAIN: reading 1, a new take NOT picked, marked new, played as it lands. await expect(panel.locator('[aria-label="Read the edited text"]')).toBeDisabled(); // A DOUBLE PRESS is one read (review 1, finding 4): one ask of the editor, one take. const asks31 = () => (JSON.parse(readFileSync(path.join(FIXTURE, "editor-stub.requests.json"), "utf8")) as { route?: string; out?: string }[]).filter((r) => r.route === "tts" && String(r.out ?? "").includes("/narration/posts/31/")).length; const asked0 = asks31(); await panel.locator('[aria-label="Read again"]').dblclick(); await expect(panel.locator("[data-post-take]")).toHaveCount(2, { timeout: 20_000 }); expect(asks31()).toBe(asked0 + 1); expect(narr("p-31").takes![1]).toMatchObject({ file: "narration/posts/31/take-2.orpheus-zac.wav", script: OWN_TEXT, reading: 1 }); expect(narr("p-31").pick).toBe(0); await expect(panel.locator('[data-post-take-new="2"]')).toBeVisible(); await expect(panel.locator('[data-post-take-made="2"]')).toHaveText("reading 1"); await expect.poll(() => page.evaluate(() => (window as unknown as { __played: string[] }).__played.some((u) => u.includes(encodeURIComponent("take-2.orpheus-zac.wav"))))).toBe(true); // Again, tuned for this line only: reading 2, the tuning sent and recorded. await panel.locator('[data-read-tune] summary').click(); await panel.locator('[aria-label="temperature, this line only"]').fill("0.7"); await panel.locator('[aria-label="Read again with this tuning"]').click(); await expect(panel.locator("[data-post-take]")).toHaveCount(3, { timeout: 20_000 }); expect(narr("p-31").takes![2]).toMatchObject({ reading: 2, tuning: { temperature: 0.7 } }); expect(narr("p-31").pick).toBe(0); // The take list says each take's words. await expect(panel.locator('[data-post-take-text="3"]')).toContainText("The ferry runs at noon."); // READ EDITED TEXT: the words changed for reading only -- saved (marked for reading), then read (reading 0). const spoken = "The ferry runs at twelve noon. Bring a warm coat for the crossing."; await panel.locator("[data-post-script]").fill(spoken); await panel.locator('[aria-label="Read the edited text"]').click(); await expect(panel.locator("[data-post-take]")).toHaveCount(4, { timeout: 20_000 }); const n = timeline().find((e) => e.id === "p-31")!.narration as Record & { takes: Array> }; expect(n.script).toBe(spoken); expect(n.forReading).toBe(true); expect(n.takes[3]).toMatchObject({ script: spoken }); expect(n.takes[3].reading ?? 0).toBe(0); expect(n.pick).toBe(0); // PICK the edited read: it plays now -- and the card draws exactly what it drew before any of this. await panel.locator('[aria-label="Pick take 4"]').click(); await expect(panel.locator('[data-post-take="4"]')).toHaveAttribute("data-post-take-picked", "1"); expect(narr("p-31").pick).toBe(3); await page.reload(); expect(await drawnCard(page)).toEqual(before); // The previous pick, one press away. await page.locator('[data-post-narration="p-31"] [aria-label="Pick take 1"]').click(); await expect.poll(() => narr("p-31").pick).toBe(0); // A READ WHOSE JOB CANNOT BE FOLLOWED fails in place, never "reading…" for ever (review 1, finding 5). await page.route(/\/api\/report\/post-narration\?.*[?&]job=/, (route) => route.abort()); await page.locator('[data-post-narration="p-31"] [aria-label="Read again"]').click(); await expect(page.locator('[data-post-narration="p-31"] [data-post-take-failed]')).toContainText("did not answer", { timeout: 20_000 }); await expect(page.locator('[data-post-narration="p-31"] [aria-label="Read again"]')).toBeEnabled(); // The bench back: Check again lands the take the editor made meanwhile (review 2, finding 2) -- nothing lost. await page.unroute(/\/api\/report\/post-narration\?.*[?&]job=/); const had = narr("p-31").takes!.length; await page.locator('[data-post-narration="p-31"] [aria-label="Check again"]').click(); await expect.poll(() => narr("p-31").takes!.length, { timeout: 20_000 }).toBe(had + 1); // A lost read is found again on load too: its marker is gone once its take is kept. expect(existsSync(path.join(DIR, "narration", "posts", "31", ".reading.json"))).toBe(false); }); test("READ A SCREEN LINE AGAIN (lane line-rerun): said as, read again alone, its readings listed and picked -- the controls by name; the narration page's too", async ({ page }) => { addOwnItem(); const m = JSON.parse(readFileSync(MANIFEST, "utf8")); const e = m.timeline.find((x: { id: string }) => x.id === "p-31"); e.screens[0].read = "all"; e.screens[0].saidAs = { 0: "Is it the B R T dock?" }; writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); await page.setViewportSize({ width: 1440, height: 1400 }); await page.goto(urls.postBenchHref(PROJECT, "p-31")); const line = page.locator('[data-post-screen-line="0"]'); for (const label of ["said as, line 0", "Read line 0 again", "Read line 0 as edited", "Tune line 0 only"]) await expect(line.locator(`[aria-label="${label}"]`), label).toHaveCount(1); await expect(line.locator('[aria-label="said as, line 0"]')).toHaveValue("Is it the B R T dock?"); // The first read with the screens: made, picked (the bench's Make the read). await page.locator("[data-post-screens-make-read]").click(); await expect.poll(() => (narr("p-31").takes ?? []).length, { timeout: 60_000 }).toBe(2); const first = narr("p-31").takes![1] as Take & { parts?: Array<{ role?: string; text?: string; reading?: number }> }; expect(first.parts!.find((p) => p.role === "screen:s1:0")!.text).toContain("B R T"); await page.reload(); // Line 0 again: only it is read anew (reading 1), a new take unpicked. await page.locator('[data-post-screen-line="0"] [aria-label="Read line 0 again"]').click(); await expect.poll(() => (narr("p-31").takes ?? []).length, { timeout: 60_000 }).toBe(3); const again = narr("p-31").takes![2] as Take & { parts?: Array<{ role?: string; reading?: number }>; read?: { tuned?: Record } }; expect(again.parts!.find((p) => p.role === "screen:s1:0")!.reading).toBe(1); expect(again.parts!.find((p) => p.role === "screen:s1:1")!.reading).toBeUndefined(); expect(again.read!.tuned!["screen:s1:0"].reading).toBe(1); expect(narr("p-31").pick).toBe(1); await expect(page.locator('[data-post-screen-reading-pick="0:3"]')).toBeVisible({ timeout: 15_000 }); await page.locator('[aria-label="Pick take 3 for line 0"]').click(); await expect.poll(() => narr("p-31").pick).toBe(2); // ONE "play when ready" for every line on the page (review 1, finding 9): off on the post's, off on the line's. const postAuto = page.locator('[data-post-narration="p-31"] [aria-label="Play new reads when they land"]'); const lineAuto = page.locator('[data-post-screen-line="0"] [aria-label="Play new reads when they land"]'); await expect(lineAuto).toBeChecked(); await postAuto.uncheck(); await expect(lineAuto).not.toBeChecked(); await lineAuto.check(); await expect(postAuto).toBeChecked(); }); test("READ THE THREAD AGAIN (lane line-rerun): its controls by name on a threaded item, and one press makes a new thread read, unpicked, every synthesized piece one reading on", async ({ page }) => { // p-32 of this test's own: a reply, its thread read (the post it answers, then his words) picked. const m = JSON.parse(readFileSync(MANIFEST, "utf8")); const base = m.timeline.find((x: { id: string }) => x.id === "p-13"); const file = "narration/posts/32/take-1.orpheus-thread.wav"; m.timeline.push({ ...base, id: "p-32", post: "narrchan-x/32", url: "https://x.com/narrsubject/status/32", text: "Yes, every morning at nine.", date: "2026-10-30T11:00:00.000Z", parents: [{ id: "3201", handle: "ferryfan", author: "Ferry Fan", text: "Does the early boat still run?", date: "2026-10-30T10:30:00.000Z" }], narration: { script: "Yes, every morning at nine.", pick: 0, takes: [{ file, engine: "orpheus", voice: "leo+zac", seconds: 4, script: "Does the early boat still run?\n\nYes, every morning at nine.", read: { kind: "thread", parents: "0" }, parts: [ { n: 1, para: 0, text: "Does the early boat still run?", voice: "leo", role: "parent:0", start: 0, seconds: 1.8 }, { n: 2, para: 100, text: "Yes, every morning at nine.", voice: "zac", role: "post", start: 2.6, seconds: 1.4 }, ] }], }, }); writeFileSync(MANIFEST, JSON.stringify(m, null, 2) + "\n"); mkdirSync(path.join(DIR, "narration", "posts", "32"), { recursive: true }); execFileSync("ffmpeg", ["-v", "error", "-y", "-f", "lavfi", "-i", "sine=frequency=300:sample_rate=48000:duration=4", "-ac", "1", "-c:a", "pcm_s16le", path.join(DIR, file)]); await page.setViewportSize({ width: 1440, height: 1400 }); await page.goto(urls.postBenchHref(PROJECT, "p-32")); const thread = page.locator("[data-post-thread-panel]"); for (const label of ["Read the thread again", "Tune the thread only", "Read the thread again with this tuning", "Play new reads when they land"]) await expect(thread.locator(`[aria-label="${label}"]`), label).toHaveCount(1); await thread.locator('[aria-label="Read the thread again"]').click(); await expect(thread.locator("[data-read-note]")).toContainText("take 2 made, not picked", { timeout: 60_000 }); const t2 = narr("p-32").takes![1] as Take & { parts?: Array<{ role?: string; reading?: number }>; read?: { kind?: string } }; expect(t2.read?.kind).toBe("thread"); expect(t2.parts!.map((p) => [p.role, p.reading])).toEqual([["parent:0", 1], ["post", 1]]); expect(narr("p-32").pick).toBe(0); }); test("THE NARRATION PAGE's cards carry the same controls, by name", async ({ page }) => { await page.goto(urls.section("reports/narration-review-fixture", "narration")); await page.locator("[data-narration-link]").click(); for (const label of ["Read the card again", "Read the card as edited", "Tune the card only"]) await expect(page.locator(`[aria-label="${label}"]`).first(), label).toBeVisible(); });