import { test, expect } from "@playwright/test"; import { mkdir, writeFile } from "node:fs/promises"; import { join } from "node:path"; import { resetData, testPaths } from "./helpers"; // Release 31, lane C: a gone video whose audio find-copy's scope mode fetched // from a copy says so on its page — "Audio from a copy:" and the copy, in the // slot (and under the label) of that source's own provenance line, which a // record that IS a copy keeps. Synthetic records only: the sidecars as // fetch-copies writes them (controller/fetchCopies.ts). const SLUG = "test-youtube"; const WB_ID = "goneWayback"; const IA_ID = "goneMirror1"; const COPY_ID = "isACopy0001"; const watch = (id: string) => `https://www.youtube.com/watch?v=${id}`; const WB_URL = `https://web.archive.org/web/20240102030405/${watch(WB_ID)}`; const IA_URL = `https://archive.org/download/youtube-${IA_ID}/An%20upload-${IA_ID}.mp4`; async function goneVideo(id: string, files: Record) { const dir = join(testPaths().transcriptsDir, "channels", SLUG, "data", id); await mkdir(dir, { recursive: true }); await writeFile( join(dir, "metadata.info.json"), JSON.stringify({ id, title: `The original ${id}`, webpage_url: watch(id), extractor_key: "Youtube", duration: 300, upload_date: "20240101" }), ); await writeFile( join(dir, "availability.json"), JSON.stringify({ checkedAt: "2026-10-01T00:00:00.000Z", availability: "deleted", webpageUrl: watch(id), history: [] }), ); await writeFile(join(dir, "audio.mp3"), "synthetic audio"); for (const [name, body] of Object.entries(files)) await writeFile(join(dir, name), JSON.stringify(body)); } const waybackJson = (id: string, ts: string) => ({ originalUrl: watch(id), captureTs: ts, waybackUrl: `https://web.archive.org/web/${ts}/${watch(id)}`, rawUrl: `https://web.archive.org/web/${ts}id_/${watch(id)}`, }); test("a gone video's audio from a copy: the copy's line; a record that is a copy keeps its own", async ({ page }) => { await resetData("one-youtube-channel-with-data"); await goneVideo(WB_ID, { "wayback.json": waybackJson(WB_ID, "20240102030405"), "copy-attempts.json": { failed: [], attempts: [ { at: "2026-10-10T00:00:00.000Z", outcome: "none-found", detail: "wayback none; archive.org none" }, { at: "2026-10-16T00:00:00.000Z", outcome: "fetched", source: "wayback", url: WB_URL, captureTs: "20240102030405", audioFile: "audio.mp3" }, ], }, }); await goneVideo(IA_ID, { "archiveorg.json": { version: 1, identifier: `youtube-${IA_ID}`, file: `An upload-${IA_ID}.mp4`, itemUrl: `https://archive.org/details/youtube-${IA_ID}`, item: { title: `An upload ${IA_ID}`, collections: [] }, fetchedAt: "2026-10-16T00:00:00.000Z", }, "copy-attempts.json": { failed: [], attempts: [ { at: "2026-10-16T00:00:00.000Z", outcome: "fetched", source: "archive.org", url: IA_URL, identifier: `youtube-${IA_ID}`, file: `An upload-${IA_ID}.mp4`, audioFile: "audio.mp3" }, ], }, }); // A record imported FROM a Wayback capture, no copy attempt: its own line. await goneVideo(COPY_ID, { "wayback.json": waybackJson(COPY_ID, "20230506070809") }); await page.goto(`/channels/${SLUG}/videos/${WB_ID}`); const wb = page.getByLabel("Wayback provenance"); await expect(wb).toHaveText("Audio from a copy: Wayback Machine, 2024-01-02"); await expect(wb.getByRole("link", { name: "Wayback Machine, 2024-01-02" })).toHaveAttribute("href", WB_URL); await expect(page.getByText("Archived copy (")).toHaveCount(0); await page.goto(`/channels/${SLUG}/videos/${IA_ID}`); const ia = page.getByLabel("archive.org provenance"); await expect(ia).toHaveText(`Audio from a copy: archive.org youtube-${IA_ID}`); await expect(ia.getByRole("link", { name: `archive.org youtube-${IA_ID}` })).toHaveAttribute("href", IA_URL); await expect(page.getByText("Archived on archive.org:")).toHaveCount(0); await page.goto(`/channels/${SLUG}/videos/${COPY_ID}`); await expect(page.getByLabel("Wayback provenance")).toContainText("Archived copy (Wayback Machine, 2023-05-06) of"); await expect(page.getByText("Audio from a copy:")).toHaveCount(0); });