// The Captures tab of a Wayback pages channel (release 37 S2), end to end over // the fake Wayback (common/testing/web/fakeWayback.mjs, its scan listing), // named to the test server through E2E_WAYBACK_ORIGIN_FILE (e2e/servers.ts). // The real Wayback Machine is never contacted. // // Scan now runs a wayback-scan job (the CDX listing, no bodies) → the table → // filter by year → Import selected and Import all in range queue one // import-page job per row (S1's job: the capture fetched raw, a page record // written) → the rows read as imported and Import all in range skips them → // the automatic-import toggle writes wayback.auto. import { test, expect } from "@playwright/test"; import { mkdir, readFile, rm, writeFile } from "node:fs/promises"; import type { APIRequestContext } from "@playwright/test"; import path from "node:path"; import { startFakeWayback, SCAN_CAPTURES } from "yt-dlp-transcript-common/testing/web/fakeWayback.mjs"; import { baseUrl } from "./baseUrl"; import { resetData, resolvePath, testPaths } from "./helpers"; import { waybackOriginFile } from "./servers"; const AUTH = { authorization: "Bearer test-worker-token" }; const SLUG = "synth-pages"; type JobRow = { id: string; status: string }; // Every import-page job of the channel, once `n` exist and all have ended. async function importJobs(request: APIRequestContext, n: number): Promise { let rows: JobRow[] = []; await expect .poll( async () => { const res = await request.get(`${baseUrl}/api/ops/jobs?kind=import-page&slug=${SLUG}&limit=50`, { headers: AUTH }); rows = ((await res.json()) as { jobs: JobRow[] }).jobs; return rows.length === n && rows.every((r) => r.status === "done" || r.status === "failed"); }, { timeout: 90_000, intervals: [1_000] }, ) .toBe(true); return rows; } test("Captures: scan on the fake → the table → filter by year → Import selected and Import all in range queue one import each", async ({ page, request, }) => { test.setTimeout(180_000); await resetData("empty"); const transcripts = resolvePath(testPaths().transcriptsDir); const channelRoot = path.join(transcripts, "channels", SLUG); await mkdir(channelRoot, { recursive: true }); await writeFile( path.join(channelRoot, "config.json"), JSON.stringify( { handling: "transcribe", sourceKind: "social", platform: "webpage", socialHandle: "blog.example", name: "Synth Blog (Wayback)", url: "https://web.archive.org/web/*/blog.example*", wayback: { targets: [{ url: "blog.example", match: "host" }] }, }, null, 2, ), ); const wb = await startFakeWayback({ captures: SCAN_CAPTURES }); const originFile = waybackOriginFile(transcripts); await writeFile(originFile, wb.base); try { await page.goto(`/channels/${SLUG}/captures`); await expect(page.getByRole("link", { name: "Captures tab" })).toHaveAttribute("aria-current", "page"); await expect(page.getByLabel("captures status line")).toHaveText("Not scanned yet"); await page.getByRole("button", { name: "Scan now" }).click(); const status = page.getByLabel("captures status line"); await expect(status).toContainText("7 versions of 5 pages", { timeout: 30_000 }); await expect(status).toContainText("0 imported"); await expect(status).toContainText("complete"); // One listing, no bodies: matchType host, collapsed by digest, paged. const cdx = wb.requests.filter((r) => r.path.startsWith("/cdx/")); expect(cdx.length).toBe(1); const q = new URL(cdx[0].path, "http://x").searchParams; expect(q.get("matchType")).toBe("host"); expect(q.get("collapse")).toBe("digest"); expect(q.get("showResumeKey")).toBe("true"); expect(wb.requests.some((r) => r.path.startsWith("/web/"))).toBe(false); const table = page.getByRole("table", { name: "captures table" }); await expect(table.locator("tbody tr")).toHaveCount(7); const p101b = page.getByRole("row", { name: "capture /post/101/first-post P101B" }); await expect(p101b).toContainText("2015-04-05"); await expect(p101b).toContainText("2 of 2"); // Filter: the 2015 rows. await page.getByLabel("Year").selectOption("2015"); await page.getByRole("button", { name: "Filter" }).click(); await expect(page).toHaveURL(/year=2015/); await expect(table.locator("tbody tr")).toHaveCount(4); await expect(page.getByLabel("capture count")).toHaveText("4 rows match"); // Import selected: two rows → two import-page jobs, each the capture the // content was first listed at. await page.getByLabel("Select /post/101/first-post (2015-04-05)").check(); await page.getByLabel("Select /tagged/bread (2015-07-08)").check(); await page.getByRole("button", { name: "Import selected (2)" }).click(); await expect(page.getByLabel("import result")).toContainText("Queued 2 import jobs."); const first = await importJobs(request, 2); expect(first.map((j) => j.status)).toEqual(["done", "done"]); const fetched = wb.requests.filter((r) => /^\/web\/\d{14}id_\//.test(r.path)).map((r) => r.path).sort(); expect(fetched).toEqual([ "/web/20150405000000id_/https://blog.example/post/101/first-post", "/web/20150708000000id_/https://blog.example/tagged/bread", ]); // The two rows now read as imported; Import all in range takes the other two. await page.reload(); await expect(page.getByLabel("captures status line")).toContainText("2 imported"); await expect(page.getByRole("row", { name: "capture /post/101/first-post P101B" }).getByLabel(/^imported as /)).toBeVisible(); await expect(page.getByLabel("capture count")).toHaveText("4 rows match (2 not imported)"); await page.getByRole("button", { name: "Import all in range (2)" }).click(); await expect(page.getByLabel("import result")).toContainText("Queued 2 import jobs; 2 already imported."); expect((await importJobs(request, 4)).every((j) => j.status === "done")).toBe(true); await page.reload(); await expect(page.getByLabel("captures status line")).toContainText("4 imported"); await expect(page.getByRole("button", { name: "Import all in range (0)" })).toBeDisabled(); // The automatic-import toggle writes wayback.auto (and keeps the targets). const toggle = page.getByLabel("Import new captures automatically"); await expect(toggle).not.toBeChecked(); await toggle.check(); await expect .poll(async () => JSON.parse(await readFile(path.join(channelRoot, "config.json"), "utf8")).wayback) .toEqual({ targets: [{ url: "blog.example", match: "host" }], auto: true }); await page.reload(); await expect(page.getByLabel("Import new captures automatically")).toBeChecked(); // The same over HTTP, as a dry run: nothing queued. const res = await request.post(`${baseUrl}/api/ops/wayback-import`, { headers: AUTH, data: { slug: SLUG, prefix: "blog.example/post/", dryRun: true }, }); const body = (await res.json()) as { ok: boolean; chosen: number; queued: { url: string; jobId?: string }[]; skipped: unknown[] }; expect(res.status()).toBe(200); expect(body.chosen).toBe(4); expect(body.queued.map((x) => x.url)).toEqual([ "https://web.archive.org/web/20140203000000/https://blog.example/post/101/first-post", "https://web.archive.org/web/20140506000000/https://blog.example/post/102/second-post", ]); expect(body.queued.every((x) => x.jobId === undefined)).toBe(true); expect(body.skipped.length).toBe(2); await importJobs(request, 4); } finally { await rm(originFile, { force: true }); await wb.close(); } }); // Release 38 lane C: a target the Wayback Machine excludes (a CDX 403) is a // line of its own on the tab, and the scan goes on to the next target. test("Captures: an excluded target is marked, and the next target is scanned", async ({ page }) => { test.setTimeout(120_000); await resetData("empty"); const transcripts = resolvePath(testPaths().transcriptsDir); const slug = "synth-pages-excluded"; const channelRoot = path.join(transcripts, "channels", slug); await mkdir(channelRoot, { recursive: true }); const targets = [ { url: "gone.example", match: "host" }, { url: "blog.example", match: "host" }, ]; await writeFile( path.join(channelRoot, "config.json"), JSON.stringify({ handling: "transcribe", sourceKind: "social", platform: "webpage", socialHandle: "blog.example", name: "Synth Blog, one target excluded", url: "https://web.archive.org/web/*/blog.example*", wayback: { targets }, }), ); const wb = await startFakeWayback({ captures: SCAN_CAPTURES, excluded: ["gone.example"] }); const originFile = waybackOriginFile(transcripts); await writeFile(originFile, wb.base); try { await page.goto(`/channels/${slug}/captures`); await page.getByRole("button", { name: "Scan now" }).click(); const status = page.getByLabel("captures status line"); await expect(status).toContainText("7 versions of 5 pages", { timeout: 30_000 }); await expect(status).toContainText("complete"); const list = page.getByRole("list", { name: "scan targets" }); await expect(list.locator("li").filter({ hasText: "gone.example" }).locator("[data-scan-target-excluded]")).toHaveText( "excluded from the Wayback Machine (cause unknown)", ); await expect(list.locator("li").filter({ hasText: "blog.example" })).toContainText("complete"); } finally { await rm(originFile, { force: true }); await wb.close(); } });