import { mkdir, writeFile } from "node:fs/promises"; import { test, expect } from "@playwright/test"; import { baseUrl } from "./baseUrl"; import { channelStage, generateReport, readJson, resetData, resolvePath, testPaths, } from "./helpers"; // Release 32 R7: a full download may read the media URL the record stores, the // way the platform's player does. The UI-without-AI rule: the per-channel // setting is on the Configure form, and the video page's re-download offers it // when the record has a stored URL the allowlist trusts. Nothing here starts a // download — the stored URL's host is a real CDN and no test asks it anything // (the download itself is 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 CLAIM = "FAKE-TEST-VALUEFAKE-TEST-VALUE01234567"; async function invalidate() { await fetch(`${baseUrl}/api/test/invalidate-cache`).catch(() => {}); } test("configure: the stored media URL setting saves fallback/only and Never clears it", async ({ page }) => { await resetData(FIXTURE); await generateReport(page, CHANNEL); await page.goto(channelStage(CHANNEL, "configure")); const select = page.getByLabel("stored media URL downloads"); await expect(select).toHaveValue(""); await select.selectOption("only"); await page.getByRole("button", { name: /save changes/i }).click(); await expect .poll(async () => (await readJson<{ storedUrlDownloads?: string }>(`${ROOT}/config.json`)).storedUrlDownloads) .toBe("only"); await page.reload(); await expect(page.getByLabel("stored media URL downloads")).toHaveValue("only"); await page.getByLabel("stored media URL downloads").selectOption(""); await page.getByRole("button", { name: /save changes/i }).click(); await expect .poll(async () => "storedUrlDownloads" in (await readJson>(`${ROOT}/config.json`))) .toBe(false); }); test("video page: the re-download offers the stored media URL when the record has one", async ({ page }) => { await resetData(FIXTURE); const dir = resolvePath(`${ROOT}/data/${CLAIM}`); await mkdir(dir, { recursive: true }); await writeFile( `${dir}/metadata.info.json`, JSON.stringify({ id: CLAIM, extractor: "lbry", title: "A synthetic stream", webpage_url: `https://odysee.com/synthetic-stream:${CLAIM}`, duration: 60, formats: [ { url: `https://player.odycdn.com/v6/streams/${CLAIM}/a1b2c3.mp4`, protocol: "https", ext: "mp4" }, ], }), ); await invalidate(); await page.goto(`/channels/${CHANNEL}/videos/${CLAIM}`); const select = page.getByLabel("stored media URL", { exact: true }); await expect(select).toBeVisible(); await expect(select).toHaveValue(""); await expect(select.locator("option")).toHaveText([ "Inherit (channel: never)", "Never — the page", "Fallback — when the page is rate-limited", "Only — player.odycdn.com, no page request", ]); await select.selectOption("only"); await expect(select).toHaveValue("only"); // Both download modes carry it. await page.getByLabel("download mode").selectOption("whisper"); await expect(page.getByLabel("stored media URL", { exact: true })).toHaveValue("only"); await expect(page.getByRole("button", { name: "Audio + Whisper" })).toBeEnabled(); // A record whose stored URL the allowlist does not trust: no offer. await writeFile( `${dir}/metadata.info.json`, JSON.stringify({ id: CLAIM, webpage_url: `https://odysee.com/synthetic-stream:${CLAIM}`, formats: [{ url: "https://cdn.example/a.mp4", protocol: "https" }], }), ); await invalidate(); await page.reload(); await expect(page.getByLabel("download mode")).toBeVisible(); await expect(page.getByLabel("stored media URL", { exact: true })).toHaveCount(0); });