Archilyzer · Source

archilyzer

Archilyzer
git clone https://archilyzer.pages.dev/source/archilyzer.git
Log | Files | Refs | README | LICENSE

commit d06fbe31050155acfcf2e825c2640c6ebbbeddf5
parent 4f289f08ed24b0b58f656a69161aa4f44b3df39a
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date:   Wed, 11 Nov 2026 20:30:53 -0500

umtool: e2e for record -> filter -> preview (record-filter.spec.ts, its fixture; the stub's convert waits one poll at the heavy slot); the Filter job says the waits it went through; leaving a post drops its preview once, a double mount does not

Co-Authored-By: Claude <noreply@anthropic.com>

Diffstat:
Mumtool/app/api/report/post-narration/record/route.ts | 5++++-
Mumtool/components/projects/RecordFilter.tsx | 6+++++-
Mumtool/components/projects/RecordSession.tsx | 23++++++++++++++++-------
Mumtool/e2e/fixtures/editor-stub.mjs | 4+++-
Mumtool/e2e/fixtures/make-fixture.mjs | 3+++
Aumtool/e2e/fixtures/record-filter-fixture.mjs | 32++++++++++++++++++++++++++++++++
Aumtool/e2e/record-filter.spec.ts | 293+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 356 insertions(+), 10 deletions(-)

diff --git a/umtool/app/api/report/post-narration/record/route.ts b/umtool/app/api/report/post-narration/record/route.ts @@ -77,6 +77,7 @@ const TYPES: Record<string, string> = { webm: "audio/webm", ogg: "audio/ogg", wa const filterKind = (project: string, id: string) => `record-filter ${project} ${id}`; type Stage = { stage?: string; state?: string; message?: string; line?: string }; +const WAITS = ["queued", "memory", "slot"]; /** * The Filter job as the record page reads it: its state, the STAGE it is at (the chain's last `stage` event: * recordPreview.mjs runPreview), every stage's last word, and whether it is WAITING -- `queued` behind the editor's @@ -91,7 +92,9 @@ function filterJobView(job: Job) { return { id: job.id, state: job.state, startedAt: job.startedAt, endedAt: job.endedAt, stage: at?.stage ?? null, stageState: at?.state ?? null, message: at?.message ?? null, - waiting: at && job.state === "running" && ["queued", "memory", "slot"].includes(String(at.state)) ? at.state : null, + waiting: at && job.state === "running" && WAITS.includes(String(at.state)) ? at.state : null, + // Every wait it went through, in order (said after the fact too: "waited for memory"). + waited: [...new Set(stages.filter((x) => WAITS.includes(String(x.state))).map((x) => String(x.state)))], stages: last, // A failure in the CLI's own words (its last line), not "exited 1". error: failed ? (job.log.filter((l) => !l.startsWith("**") && !l.startsWith("$ ") && !l.startsWith("---")).at(-1) ?? job.error) : null, diff --git a/umtool/components/projects/RecordFilter.tsx b/umtool/components/projects/RecordFilter.tsx @@ -41,6 +41,7 @@ export type FilterJob = { stageState: string | null; message: string | null; waiting: "queued" | "memory" | "slot" | null; + waited: string[]; stages: Record<string, { state?: string; message?: string }>; error: string | null; }; @@ -154,7 +155,7 @@ export const waitText = (w: FilterJob["waiting"]) => export function FilterProgress({ job, now, onCancel }: { job: FilterJob; now: number; onCancel: () => void }) { const running = job.state === "running"; return ( - <div className="space-y-1 rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-2 text-[12.5px]" data-record-filter-job={job.state} data-record-filter-stage={job.stage ?? ""} data-record-filter-waiting={job.waiting ?? ""}> + <div className="space-y-1 rounded border border-[var(--color-line)] bg-[var(--color-panel)] p-2 text-[12.5px]" data-record-filter-job={job.state} data-record-filter-stage={job.stage ?? ""} data-record-filter-waiting={job.waiting ?? ""} data-record-filter-waited={(job.waited ?? []).join(" ")}> <div className="flex flex-wrap items-center gap-2"> {STAGES.map(([key, label]) => { const st = job.stages[key]?.state; @@ -190,6 +191,9 @@ export function FilterProgress({ job, now, onCancel }: { job: FilterJob; now: nu </div> )} {running && !job.waiting && <div className="text-text-2">{job.message ?? "starting…"} — a short read takes two or three minutes here.</div>} + {job.state === "done" && (job.waited ?? []).some((w) => w !== "queued") && ( + <div className="text-text-2">it waited at the heavy slot ({(job.waited ?? []).filter((w) => w !== "queued").map((w) => (w === "memory" ? "for memory" : "for another heavy job")).join(", ")}) on the way: the gate, not a fault</div> + )} {job.state === "failed" && ( <div className="text-[var(--color-blocking,#c33)]" data-record-filter-error=""> the Filter did not finish: {job.error ?? "it failed"} diff --git a/umtool/components/projects/RecordSession.tsx b/umtool/components/projects/RecordSession.tsx @@ -178,19 +178,28 @@ export default function RecordSession({ project, items: initial, start, box }: { // LEAVING the post (another one, the page closed): its scratch dir goes -- unless its Filter is still running. const running = useRef(false); running.current = fjob?.state === "running"; + const leaving = useRef<{ id: string; timer: ReturnType<typeof setTimeout> } | null>(null); useEffect(() => { + // The same post again at once (a development build mounts an effect twice): it was not left. + if (leaving.current?.id === item.id) clearTimeout(leaving.current.timer); + leaving.current = null; + const id = item.id; + const wasRunning = () => running.current; const drop = () => { - if (running.current) return; try { - navigator.sendBeacon(RECORD_API, new Blob([JSON.stringify({ project, id: item.id, op: "discard-preview" })], { type: "application/json" })); + navigator.sendBeacon(RECORD_API, new Blob([JSON.stringify({ project, id, op: "discard-preview" })], { type: "application/json" })); } catch { // no beacon here: the scratch dir is removed a day later (recordPreview.mjs) } }; - window.addEventListener("pagehide", drop); + const onHide = () => { + if (!wasRunning()) drop(); + }; + window.addEventListener("pagehide", onHide); return () => { - window.removeEventListener("pagehide", drop); - drop(); + window.removeEventListener("pagehide", onHide); + if (wasRunning()) return; + leaving.current = { id, timer: setTimeout(drop, 150) }; }; }, [project, item.id]); // The post's session: what was kept before (a reload resumes at the first part not kept). @@ -328,7 +337,7 @@ export default function RecordSession({ project, items: initial, start, box }: { }, [phase, mic, parts, cur, project, item.id, finish, review]); // A sound file for the current part (a recording made elsewhere: a phone's recorder, the LAN where the mic is off). - const useFile = useCallback( + const takeFile = useCallback( async (file: File) => { if (phase !== "idle" || !parts[cur]) return; setError(null); @@ -917,7 +926,7 @@ export default function RecordSession({ project, items: initial, start, box }: { onChange={(e) => { const f = e.target.files?.[0]; e.target.value = ""; - if (f) void useFile(f); + if (f) void takeFile(f); }} data-record-file="" /> diff --git a/umtool/e2e/fixtures/editor-stub.mjs b/umtool/e2e/fixtures/editor-stub.mjs @@ -1441,7 +1441,9 @@ const server = http.createServer((req, res) => { return json(res, 200, { ok: true, job: { id: opsJob[1], kind: j.kind ?? "tts-file", status }, - ...(tail ? { tail: ["tts: synthesizing (stub)", `${j.marker ?? "@@tts-result "}${JSON.stringify(j.result)}`] } : {}), + // A voice-convert that is still running is at the machine's heavy slot, and says so as the editor's job does + // (scripts/queue-lock.mjs): the record page's Filter shows it as a wait, not an error. + ...(tail ? { tail: status === "running" && j.kind === "voice-convert" ? ["heavy: waiting for memory — 4100 MB available, the floor is 6000 MB"] : ["tts: synthesizing (stub)", `${j.marker ?? "@@tts-result "}${JSON.stringify(j.result)}`] } : {}), }); } diff --git a/umtool/e2e/fixtures/make-fixture.mjs b/umtool/e2e/fixtures/make-fixture.mjs @@ -38,6 +38,7 @@ import { makeTakeWalkFixture } from "./take-walk-fixture.mjs"; import { makeCutIntegrityFixture } from "./cut-integrity-fixture.mjs"; import { makeUiOpsFixture } from "./ui-ops-fixture.mjs"; import { makeVoicesFixture } from "./voices-fixture.mjs"; +import { makeRecordFilterFixture } from "./record-filter-fixture.mjs"; import { makeYoutubeFixture } from "./youtube-fixture.mjs"; import { makeBoardFixture, makeResearchFixture } from "./research-fixture.mjs"; import { makeCaseStagesFixture } from "./case-stages-fixture.mjs"; @@ -1922,6 +1923,8 @@ makeCutIntegrityFixture({ reports, manifest, cachedWindow: path.join(REPORT, "ou makeUiOpsFixture({ reports, channels: CHANNELS, manifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4"), ff }); // The Voices page (voices.spec.ts): Host's clips (the real voice) and post items by @hostman and @guest. makeVoicesFixture({ reports, channels: CHANNELS, manifest, ff }); +// Record -> filter -> preview on the record page (record-filter.spec.ts): three one-part post items, no cast. +makeRecordFilterFixture({ reports, manifest }); // Release 28 M6: the YouTube text, previewed and built (media-draft-e.spec.ts). makeYoutubeFixture({ reports, manifest, cachedWindow: path.join(REPORT, "out", "clips-raw", "vid1_0.00-9.00.mp4") }); // Release 36 lane D: the assistant's labels, Suggest, Ask and Apply in the clip editor (clips-suggest.spec.ts). diff --git a/umtool/e2e/fixtures/record-filter-fixture.mjs b/umtool/e2e/fixtures/record-filter-fixture.mjs @@ -0,0 +1,32 @@ +// RECORD -> FILTER -> PREVIEW (record-filter.spec.ts; components/projects/RecordSession.tsx, lib/report/ +// recordPreview.mjs): a posts cut of three items, each a one-part read -- +// +// reports/record-filter-fixture/ +// p-1 @savvy "Savvy's first line, read aloud." the spec gives @savvy a character of this video's own +// p-2 @savvy "Savvy's second line." (narration/characters.json: seed-vc, contour +2, a direction) +// p-3 @stranger "A stranger says a thing." nobody's: no character, and the fixture has no cast +// +// No take, no character and no cast of its own: the spec writes this video's characters and removes what it made. The +// editor is the suite's stub (voice-enhance: not installed; voice-convert: copies, after one poll at the heavy slot). +// Synthetic, like every fixture. +import { mkdirSync, writeFileSync } from "node:fs"; +import path from "node:path"; + +export const RECORD_FILTER = "record-filter-fixture"; + +/** @param {{ reports: string, manifest: Function }} o */ +export function makeRecordFilterFixture({ reports, manifest }) { + const dir = path.join(reports, RECORD_FILTER); + mkdirSync(dir, { recursive: true }); + const post = (id, handle, author, text) => ({ + type: "post", id: `p-${id}`, post: `recordfilter-x/${id}`, platform: "x", author, handle, date: `2026-11-0${id}T10:00:00.000Z`, text, + url: `https://x.com/${handle}/status/${id}`, engagement: { likes: 1 }, section: 0, narration: { script: text }, + }); + const timeline = [ + post("1", "savvy", "Madam Savvy", "Savvy's first line, read aloud."), + post("2", "savvy", "Madam Savvy", "Savvy's second line."), + post("3", "stranger", "A Stranger", "A stranger says a thing."), + ]; + writeFileSync(path.join(dir, "video.manifest.json"), `${JSON.stringify(manifest(RECORD_FILTER, "The Record Filter Fixture", { siteOrigin: "https://archive.example", channelSlug: "recordfilter" }, timeline), null, 2)}\n`); + return dir; +} diff --git a/umtool/e2e/record-filter.spec.ts b/umtool/e2e/record-filter.spec.ts @@ -0,0 +1,293 @@ +import { test, expect, type Page } from "@playwright/test"; +import { execFileSync } from "node:child_process"; +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"; + +// --------------------------------------------------------------------------- +// RECORD -> FILTER -> PREVIEW on the record page (components/projects/RecordSession.tsx, RecordFilter.tsx; +// /api/report/post-narration/record; lib/report/recordPreview.mjs). Fixture: e2e/fixtures/record-filter-fixture.mjs +// -- p-1 and p-2 by @savvy (the spec gives her a character of this video's own: seed-vc, contour +2, a direction), +// p-3 by @stranger (nobody's). The editor is the suite's stub: voice-enhance is not installed, voice-convert copies +// after one poll at the heavy slot ("waiting for memory"). +// +// Filter -> the preview (no take), the wait at the heavy slot a state, raw and filtered side by side -> another +// pitch asks for the convert again -> Save to character -> Keep: the takes from the preview's files, the next post +// Again; nobody's post: nothing to convert, Keep in this video only, the recording kept alone +// the microphone off (a page opened over http from the LAN): said, and a sound file filtered and kept all the same +// +// RECORD_FILTER_SHOTS=<dir> screenshots there +// --------------------------------------------------------------------------- + +const HERE = path.dirname(fileURLToPath(import.meta.url)); +const FIXTURE = path.join(HERE, "..", ".e2e-song"); +const P = "reports/record-filter-fixture"; +const DIR = path.join(FIXTURE, "reports", "record-filter-fixture"); +const MANIFEST = path.join(DIR, "video.manifest.json"); +const NARRATION = path.join(DIR, "narration"); +const CHARACTERS = path.join(NARRATION, "characters.json"); +const SCRATCH = (post: string) => path.join(NARRATION, ".record-preview", `${post}.operator`); +const REQUESTS = path.join(FIXTURE, "editor-stub.requests.json"); +const SHOTS = process.env.RECORD_FILTER_SHOTS ?? null; +/** A voice for the fake microphone (and the file chosen where there is none): a 1 kHz tone, two seconds. */ +const MIC_WAV = path.join(FIXTURE, "record-filter-mic.wav"); + +type Take = { file: string; engine?: string; voice?: string; note?: string; seconds: number; source?: { kind: string; from?: string }; steps?: { op: string; engine?: string; voice?: string; pitch?: string; semitones?: number }[] }; +type Entry = { id: string; narration?: { script?: string; takes?: Take[]; pick?: number; approved?: boolean } }; +const narr = (id: string) => (JSON.parse(readFileSync(MANIFEST, "utf8")) as { timeline: Entry[] }).timeline.find((e) => e.id === id)!.narration!; +const converts = () => (JSON.parse(readFileSync(REQUESTS, "utf8")) as { route?: string; engine?: string; voice?: string; pitch?: string; semitones?: number; file?: string; out?: string }[]).filter((r) => r.route === "voice-convert"); +const characters = () => (JSON.parse(readFileSync(CHARACTERS, "utf8")) as { characters: { id: string; handles?: string[]; recorded?: { convert?: { engine?: string; voice?: string; pitch?: string; semitones?: number } } }[] }).characters; +const shot = async (page: Page, name: string) => { + if (!SHOTS) return; + mkdirSync(SHOTS, { recursive: true }); + await page.screenshot({ path: path.join(SHOTS, `${name}.png`), fullPage: true }); +}; + +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 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`); +}); +const reset = () => { + copyFileSync(`${MANIFEST}.pristine`, MANIFEST); + rmSync(NARRATION, { recursive: true, force: true }); + rmSync(path.join(DIR, "revisions"), { recursive: true, force: true }); +}; +/** @savvy's character of this video's own: converted by seed-vc to a stock voice, contour +2, a direction to read by. */ +const giveSavvy = () => { + mkdirSync(NARRATION, { recursive: true }); + writeFileSync(CHARACTERS, `${JSON.stringify({ + format: "umtool-project-characters", version: 1, + characters: [{ id: "madam-savvy", name: "Madam Savvy", handles: ["savvy"], synthetic: { voice: "kokoro:af_bella" }, recorded: { convert: { engine: "seed-vc", pitch: "contour", semitones: 2 }, direction: "higher, brisk, amused" } }], + }, null, 2)}\n`); +}; +test.beforeEach(async ({ page }) => { + test.setTimeout(180_000); + reset(); + // "Filter before keeping" as the page decides it (on for a post whose character converts), whatever a test before left. + await page.addInitScript(() => { + try { + window.localStorage.removeItem("umtool.record.filter-first"); + window.localStorage.setItem("umtool.record.count-in", "0"); + } catch { + // no storage here + } + }); +}); +test.afterAll(reset); + +const s = (page: Page) => page.locator("[data-record-session]"); +/** Space, a second of the fake microphone, Space: the part is on disk. */ +const recordPart = async (page: Page) => { + await page.keyboard.press("Space"); + await expect(s(page)).toHaveAttribute("data-record-phase", "recording", { timeout: 15_000 }); + await page.waitForTimeout(1200); + await page.keyboard.press("Space"); + await expect(s(page)).toHaveAttribute("data-record-phase", "idle", { timeout: 15_000 }); +}; +const filterDone = async (page: Page) => { + await expect(page.locator("[data-record-filter-job]")).toHaveAttribute("data-record-filter-job", "done", { timeout: 90_000 }); +}; + +test("Filter runs the character's recorded preset as one job into a preview (no take); raw and filtered side by side; another pitch; Save to character; Keep makes the takes and opens the next post", async ({ page }) => { + giveSavvy(); + await page.setViewportSize({ width: 1366, height: 1100 }); + await page.goto(urls.narrationRecordHref(P, { post: "p-1" })); + await expect(s(page)).toHaveAttribute("data-record-session", "p-1"); + // Who it is read as, above the record button: the character, its direction, its stock voice to hear. + const who = page.locator("[data-record-character]"); + await expect(who).toHaveAttribute("data-record-character", "madam-savvy"); + await expect(who).toHaveAttribute("data-record-character-layer", "project"); + await expect(page.locator("[data-record-character-name]")).toHaveText("Madam Savvy"); + await expect(page.locator("[data-record-direction]")).toContainText("higher, brisk, amused"); + await expect(page.locator("[data-record-stock]")).toContainText("kokoro:af_bella reads it"); + // Her character converts: the post waits to be filtered. The microphone is here (localhost): no note. + await expect(page.locator("[data-record-review]")).toBeChecked(); + await expect(page.locator("[data-record-no-mic]")).toHaveCount(0); + await expect(page.locator("[data-record-review-panel]")).toHaveCount(0); + + // Record it: NO take is made -- the waveform with its two cut marks, the pitch from the preset. + await recordPart(page); + const panel = page.locator("[data-record-review-panel]"); + await expect(panel).toBeVisible(); + await expect(page.locator('[data-record-wave="1"]')).toBeVisible({ timeout: 20_000 }); + expect(narr("p-1").takes ?? []).toHaveLength(0); + await expect(page.locator("[data-record-pitch]")).toHaveValue("contour"); + await expect(page.locator("[data-record-semitones]")).toHaveValue("2"); + await expect(page.locator("[data-record-keep]")).toHaveAttribute("data-record-keep-what", "recording"); + // A cut mark moved (a keyboard click at the start): four presses of the arrow, 0.2 s in. + const from = page.locator('[data-record-mark="from"]'); + await expect(from).toHaveAttribute("data-record-mark-at", "0"); + await from.focus(); + for (let i = 0; i < 4; i += 1) await page.keyboard.press("ArrowRight"); + await expect(from).toHaveAttribute("data-record-mark-at", "0.2"); + await shot(page, "record-filter-marks"); + + // FILTER (f): one job -- the clean skipped (the stub has no enhance engine), cut, converted; its wait at the heavy + // slot was a state on the way, and nothing failed. + await page.locator("[data-record-teleprompter]").click({ position: { x: 2, y: 2 } }); + await page.keyboard.press("f"); + await expect(page.locator("[data-record-filter-job]")).toBeVisible({ timeout: 15_000 }); + await filterDone(page); + const job = page.locator("[data-record-filter-job]"); + await expect(job).toHaveAttribute("data-record-filter-waited", /memory/); + await expect(job.locator('[data-record-filter-step="clean"]')).toHaveAttribute("data-record-filter-step-state", "skipped"); + await expect(job.locator('[data-record-filter-step="trim"]')).toHaveAttribute("data-record-filter-step-state", "done"); + await expect(job.locator('[data-record-filter-step="convert"]')).toHaveAttribute("data-record-filter-step-state", "done"); + await expect(page.locator("[data-record-filter-error]")).toHaveCount(0); + // The preview, in the scratch dir; still no take. + expect(existsSync(path.join(SCRATCH("1"), "raw.wav"))).toBe(true); + expect(existsSync(path.join(SCRATCH("1"), "filtered.wav"))).toBe(true); + expect(narr("p-1").takes ?? []).toHaveLength(0); + const asked = converts().at(-1)!; + expect(asked).toMatchObject({ engine: "seed-vc", voice: "kokoro:af_bella", pitch: "contour", semitones: 2 }); + expect(asked.file).toBe(path.join(SCRATCH("1"), "raw.wav")); + await expect(panel).toHaveAttribute("data-record-preview-current", "1"); + await expect(page.locator("[data-record-preview-note]").first()).toContainText("not cleaned"); + // Raw and filtered, side by side. + await expect(page.locator("[data-record-compare-what]")).toContainText("converted to kokoro:af_bella by seed-vc · pitch contour +2 st · both at one loudness"); + const player = page.locator("[data-record-player]"); + await page.locator("[data-record-play-raw]").click(); + await expect(player).toHaveAttribute("src", /preview&file=raw/); + await page.locator("[data-record-play-filtered]").click(); + await expect(player).toHaveAttribute("src", /preview&file=filtered/); + await shot(page, "record-filter-preview"); + + // Another pitch: the preview is not of it any more; Filter again asks for the convert, at that pitch. + const before = converts().length; + await page.locator("[data-record-pitch]").selectOption("source"); + await expect(panel).toHaveAttribute("data-record-preview-current", "0"); + await expect(page.locator("[data-record-preview-stale]")).toBeVisible(); + await page.locator("[data-record-filter]").click(); + await expect(panel).toHaveAttribute("data-record-preview-current", "1", { timeout: 90_000 }); + expect(converts()).toHaveLength(before + 1); + expect(converts().at(-1)).toMatchObject({ pitch: "source", semitones: 2, voice: "kokoro:af_bella" }); + await expect(page.locator('[data-record-filter-step="trim"]')).toHaveAttribute("data-record-filter-step-state", "cached"); + // Save to character: this video's own character keeps the pitch. + await page.locator("[data-record-save-character]").click(); + await expect(page.locator("[data-record-saved]")).toContainText("saved to Madam Savvy (this video's own)"); + expect(characters().find((c) => c.id === "madam-savvy")!.recorded!.convert).toMatchObject({ engine: "seed-vc", pitch: "source", semitones: 2 }); + await expect(page.locator("[data-record-save-character]")).toBeDisabled(); + + // KEEP (Enter): the takes from the preview's files -- nothing converted again -- the last picked, awaiting approval; + // the scratch dir and the session are gone; the next post not recorded is open. + const convertsBefore = converts().length; + await page.locator("[data-record-teleprompter]").click({ position: { x: 2, y: 2 } }); + await page.keyboard.press("Enter"); + await expect(s(page)).toHaveAttribute("data-record-session", "p-2", { timeout: 30_000 }); + await expect(page.locator("[data-record-last-kept]")).toContainText("kept post 1: recorded (take-1.recorded-operator.wav), converted to kokoro:af_bella (pitch: source +2 st) (take-2.convert-seed-vc.wav)"); + const n = narr("p-1"); + expect(n.takes).toHaveLength(2); + expect(n.pick).toBe(1); + expect(n.approved).not.toBe(true); + expect(n.takes![0]).toMatchObject({ file: "narration/posts/1/take-1.recorded-operator.wav", engine: "recorded", voice: "operator", note: "recorded for Madam Savvy" }); + expect(n.takes![1]).toMatchObject({ file: "narration/posts/1/take-2.convert-seed-vc.wav", engine: "derived", voice: "af_bella", source: { kind: "take", from: "take-1.recorded-operator" } }); + expect(n.takes![1].steps![0]).toMatchObject({ op: "convert", engine: "seed-vc", voice: "kokoro:af_bella", pitch: "source", semitones: 2 }); + for (const t of n.takes!) expect(existsSync(path.join(DIR, t.file))).toBe(true); + // The mark held: 0.2 s off the start of what was recorded. + expect(converts()).toHaveLength(convertsBefore); + expect(existsSync(SCRATCH("1"))).toBe(false); + expect(existsSync(path.join(NARRATION, "posts", "1", ".recording-operator"))).toBe(false); + await expect(page.locator('[data-record-jump="p-1"]')).toHaveAttribute("data-record-state", "recorded"); + await expect(page.locator("[data-record-progress]")).toHaveAttribute("data-record-progress", "1"); + // The next post reads as her too, at the pitch just saved. + await expect(page.locator("[data-record-character]")).toHaveAttribute("data-record-character", "madam-savvy"); + await shot(page, "record-filter-kept"); +}); + +test("Again drops the preview and records the part again; nobody's post has nothing to convert: Keep in this video only, and the recording kept alone", async ({ page }) => { + await page.setViewportSize({ width: 1366, height: 1100 }); + await page.goto(urls.narrationRecordHref(P, { post: "p-3" })); + await expect(s(page)).toHaveAttribute("data-record-session", "p-3"); + await expect(page.locator("[data-record-no-character]")).toContainText("no character reads @stranger"); + // Nobody converts it: the last part would make the take at once -- until a person asks to filter first. + await expect(page.locator("[data-record-review]")).not.toBeChecked(); + await page.locator("[data-record-review]").check(); + await page.locator("[data-record-teleprompter]").click({ position: { x: 2, y: 2 } }); + await recordPart(page); + const panel = page.locator("[data-record-review-panel]"); + await expect(page.locator('[data-record-wave="1"]')).toBeVisible({ timeout: 20_000 }); + await expect(page.locator("[data-record-pitch-row]")).toHaveCount(0); + expect(existsSync(path.join(SCRATCH("3"), "p01.raw.wav"))).toBe(true); + // Filter: no clean engine, no character -- it says so, and nothing failed. + await page.locator("[data-record-filter]").click(); + await filterDone(page); + await expect(page.locator('[data-record-filter-step="convert"]')).toHaveAttribute("data-record-filter-step-state", "skipped"); + await expect(page.locator("[data-record-nothing-filtered]")).toBeVisible(); + await expect(page.locator("[data-record-filter-error]")).toHaveCount(0); + const first = readFileSync(path.join(NARRATION, "posts", "3", ".recording-operator", "session.json"), "utf8"); + + // AGAIN (Backspace): the preview dropped, the part recorded again -- still no take. + await page.keyboard.press("Backspace"); + await expect(s(page)).toHaveAttribute("data-record-phase", "recording", { timeout: 15_000 }); + expect(existsSync(SCRATCH("3"))).toBe(false); + await page.waitForTimeout(1200); + await page.keyboard.press("Space"); + await expect(s(page)).toHaveAttribute("data-record-phase", "idle", { timeout: 15_000 }); + await expect(page.locator('[data-record-wave="1"]')).toBeVisible({ timeout: 20_000 }); + await expect(page.locator("[data-record-filter-job]")).toHaveCount(0); + expect(readFileSync(path.join(NARRATION, "posts", "3", ".recording-operator", "session.json"), "utf8")).not.toBe(first); + expect(narr("p-3").takes ?? []).toHaveLength(0); + + // Keep in this video only: @stranger gets a character of this video's own. + await page.locator("[data-record-keep-in-video]").click(); + await expect(page.locator("[data-record-character]")).toHaveAttribute("data-record-character-layer", "project", { timeout: 20_000 }); + const made = characters().find((c) => (c.handles ?? []).includes("stranger")); + expect(made).toBeTruthy(); + await expect(page.locator("[data-record-character]")).toHaveAttribute("data-record-character", made!.id); + await expect(page.locator("[data-record-keep-in-video]")).toHaveCount(0); + + // Not filtered: Keep keeps the recording alone -- one recorded take, picked -- and moves on. + await expect(panel).toHaveAttribute("data-record-preview-current", "0"); + await expect(page.locator("[data-record-keep]")).toHaveAttribute("data-record-keep-what", "recording"); + await page.locator("[data-record-keep]").click(); + await expect(s(page)).toHaveAttribute("data-record-session", "p-1", { timeout: 30_000 }); + const n = narr("p-3"); + expect(n.takes).toHaveLength(1); + expect(n.takes![0]).toMatchObject({ file: "narration/posts/3/take-1.recorded-operator.wav", engine: "recorded" }); + expect(n.pick).toBe(0); + expect(existsSync(SCRATCH("3"))).toBe(false); + expect(existsSync(path.join(NARRATION, "posts", "3", ".recording-operator"))).toBe(false); +}); + +test("opened over http from the LAN the microphone is off, and the page says so; a sound file is filtered and kept all the same; with the filter off the last part makes the take at once", async ({ page }) => { + giveSavvy(); + // What a browser gives a page opened over plain http from another machine: no secure context, no microphone. + await page.addInitScript(() => Object.defineProperty(window, "isSecureContext", { get: () => false })); + await page.setViewportSize({ width: 1366, height: 1100 }); + await page.goto(urls.narrationRecordHref(P, { post: "p-1" })); + await expect(page.locator("[data-record-no-mic]")).toContainText("The microphone is off on this page"); + await expect(page.locator("[data-record-no-mic]")).toContainText("localhost"); + await expect(page.locator("[data-record-toggle]")).toBeDisabled(); + // Space does not try the microphone. + await page.keyboard.press("Space"); + await expect(s(page)).toHaveAttribute("data-record-phase", "idle"); + await expect(page.locator("[data-record-error]")).toHaveCount(0); + // A sound file for the part: filtered, previewed and kept as a recording made here would be. + await page.locator("[data-record-file]").setInputFiles(MIC_WAV); + await expect(page.locator('[data-record-wave="1"]')).toBeVisible({ timeout: 20_000 }); + await page.locator("[data-record-filter]").click(); + await filterDone(page); + await expect(page.locator("[data-record-review-panel]")).toHaveAttribute("data-record-preview-current", "1"); + await page.locator("[data-record-play-filtered]").click(); + await expect(page.locator("[data-record-player]")).toHaveAttribute("src", /preview&file=filtered/); + await page.locator("[data-record-keep]").click(); + await expect(s(page)).toHaveAttribute("data-record-session", "p-2", { timeout: 30_000 }); + expect(narr("p-1").takes!.map((t) => t.engine)).toEqual(["recorded", "derived"]); + await shot(page, "record-filter-lan"); + + // "Filter before keeping" off: the last part makes the recorded take at once, as before. + await page.locator("[data-record-review]").uncheck(); + await page.locator("[data-record-file]").setInputFiles(MIC_WAV); + await expect(page.locator("[data-record-status]")).toContainText("take-1.recorded-operator.wav", { timeout: 30_000 }); + await expect(page.locator("[data-record-review-panel]")).toHaveCount(0); + expect(narr("p-2").takes).toHaveLength(1); + expect(existsSync(path.join(NARRATION, ".record-preview", "2.operator"))).toBe(false); +});