import { mkdir, writeFile } from "node:fs/promises"; import { test, expect } from "@playwright/test"; import { baseUrl } from "./baseUrl"; import { generateReport, resetData, resolvePath, testPaths } from "./helpers"; // Release 32 R8, the operator's ruling of 2026-10-17: a partial transcript is // marked, but the full audio comes first. A corrupt full source whose record // stores a trusted media URL is downloaded from it FULL_AUDIO_ATTEMPTS times // before a salvage transcript is made; the channel's line says which are still // waiting ("awaiting full audio") and how many attempts the salvaged ones had // ("salvaged — full audio attempts: n"), and the video page's salvaged // transcript notice says the same. Nothing here starts a download: the stored // URL's host is a real CDN and no test asks it anything (the downloads are // covered by common's unit tests against a fake CDN). const CHANNEL = "test-transcribe"; const FIXTURE = "one-transcribe-channel"; const ROOT = `${testPaths().transcriptsDir}/channels/${CHANNEL}`; const WAITING = "1111111111111111111111111111111111111111"; const SALVAGED = "2222222222222222222222222222222222222222"; const stored = { n: 1, kind: "stored-url-ranged", handling: "transcribe", usedCookies: false, ytdlpExitCode: 1 }; async function video(id: string, storedAttempts: number, salvaged: boolean) { const dir = resolvePath(`${ROOT}/data/${id}`); await mkdir(dir, { recursive: true }); const put = (name: string, body: unknown) => writeFile(`${dir}/${name}`, typeof body === "string" ? body : JSON.stringify(body)); await put("metadata.info.json", { id, extractor: "lbry", title: `A synthetic stream ${id.slice(0, 4)}`, webpage_url: `https://odysee.com/synthetic-stream:${id}`, duration: 600, formats: [{ url: `https://player.odycdn.com/v6/streams/${id}/a1b2c3.mp4`, protocol: "https", ext: "mp4" }], }); // The kept file in the channel's format (m4a), as the audio check keeps it. await put("audio.m4a", "kept malformed bytes"); await put("download-outcome.json", { videoId: id, status: "corrupt-full-source", startedAt: "2026-10-16T00:00:00.000Z", finishedAt: "2026-10-16T00:10:00.000Z", attempts: [ { n: 1, kind: "audio-checked-primary", handling: "transcribe", usedCookies: false, ytdlpExitCode: 0 }, ...Array.from({ length: storedAttempts }, () => stored), ], }); if (salvaged) { await put("transcript.json", { transcription: [{ offsets: { from: 0, to: 2000 }, text: " hello there" }] }); await put("transcribe-outcome.json", { videoId: id, transcribedAt: "2026-10-16T01:00:00.000Z", salvaged: { source: "audio.m4a", decodedSeconds: 300, totalSeconds: 600, gaps: [[300, 600]] }, }); } } test("the line names the corrupt full sources awaiting full audio, and the salvaged ones' attempts; the video page says it too", async ({ page }) => { await resetData(FIXTURE); await video(WAITING, 0, false); await video(SALVAGED, 1, true); await writeFile( resolvePath(`${ROOT}/playlist`), [WAITING, SALVAGED].map((id) => `https://odysee.com/synthetic-stream:${id}`).join("\n") + "\n", ); await fetch(`${baseUrl}/api/test/invalidate-cache`).catch(() => {}); await generateReport(page, CHANNEL); await page.goto(`/channels/${CHANNEL}`); const line = page.getByLabel("channel line"); await expect(line.getByLabel("awaiting full audio siding")).toContainText("1 awaiting full audio"); await expect(line.getByLabel("salvaged — full audio attempts: 1 siding")).toContainText( "1 salvaged — full audio attempts: 1", ); await page.goto(`/channels/${CHANNEL}/videos/${SALVAGED}`); const notice = page.getByRole("status", { name: "salvaged transcript" }); await expect(notice).toContainText("Salvaged transcript — 5:00 of 10:00 of audio.m4a decoded."); await expect(notice).toContainText("Full audio attempts: 1 of 2."); // The waiting one: Transcribe says the full audio comes first, and Salvage now // is there for a person who wants the partial transcript at once (not pressed: // nothing is transcribed here). await page.goto(`/channels/${CHANNEL}/videos/${WAITING}`); await expect(page.getByRole("status", { name: "full audio first" })).toContainText( "Full audio first: 0 of 2 downloads from the stored media URL made.", ); await expect(page.getByRole("button", { name: "Salvage now (audio.m4a)" })).toBeVisible(); await expect(page.getByRole("button", { name: "Transcribe audio.m4a" })).toBeVisible(); });