// archive.today copies as page records (release 37 lane F), end to end over the // fake archive.today (common/testing/web/fakeArchiveToday.mjs) and the fake // Wayback Machine, named to the test server through E2E_ARCHIVE_TODAY_ORIGIN_FILE // and E2E_WAYBACK_ORIGIN_FILE (e2e/servers.ts). Neither real service is ever // contacted, and no archive-session browser opens under the fake. // // The New channel form makes an "Archived pages" channel of an archive.today // copy's URL (its target on archive.today); Import a capture takes a copy's URL // and, with a date, the copy nearest it on archive.today; the copy is stored // as served with its source; Look up a page lists each source's copies — the // Wayback Machine's exclusion said in its words; a copy behind a check is // refused with its code, and Connect archive session is offered (never // clicked here: it opens a window). import { test, expect, type APIRequestContext } from "@playwright/test"; import { readFile, rm, writeFile } from "node:fs/promises"; import path from "node:path"; import { startFakeArchiveToday, AT_ARTICLE_ID, AT_ARTICLE_LATER_ID, AT_ARTICLE_LATER_TS, AT_ARTICLE_TS, AT_ARTICLE_URL, AT_CHECKED_ID, } from "yt-dlp-transcript-common/testing/web/fakeArchiveToday.mjs"; import { startFakeWayback } from "yt-dlp-transcript-common/testing/web/fakeWayback.mjs"; import { pageRecordId } from "yt-dlp-transcript-common/lib/waybackPages/types"; import { baseUrl } from "./baseUrl"; import { generateReport, pathExists, readJson, resetData, resolvePath, testPaths, writeSettings } from "./helpers"; import { archiveTodayOriginFile, waybackOriginFile } from "./servers"; const AUTH = { authorization: "Bearer test-worker-token" }; const SLUG = "deleted-journal"; async function waitForJob(request: APIRequestContext, jobId: string): Promise<{ status: string; tail: string[] }> { let last = { status: "", tail: [] as string[] }; await expect .poll( async () => { const res = await request.get(`${baseUrl}/api/ops/job/${jobId}?tail=40`, { headers: AUTH }); const body = (await res.json()) as { job: { status: string }; tail?: string[] }; last = { status: body.job.status, tail: body.tail ?? [] }; return last.status; }, { timeout: 90_000, intervals: [1_000] }, ) .toMatch(/^(done|failed|cancelled)$/); return last; } test("an Archived pages channel from an archive.today copy, its copies imported, looked up and refused at a check", async ({ page, request }) => { test.setTimeout(240_000); await resetData("empty"); // archive.today's least gap (4 s): the spec's few requests stay paced. await writeSettings({ minFreeDiskGB: 0, archives: { archiveTodayGapSeconds: 4, archiveTodayBrowser: true } }); await generateReport(page, "new"); await page.goto("/channels/new"); await page.locator('input[name="url"]').fill(`https://archive.ph/newest/${AT_ARTICLE_URL}`); // Offline: an archive.today copy of a page is an Archived pages channel. await expect(page.locator('select[name="platform"]')).toHaveValue("webpage"); await expect(page.locator('select[name="platform"] option[value="webpage"]')).toHaveText(/Archived pages/); await expect(page.getByLabel("target 1 URL")).toHaveValue(AT_ARTICLE_URL); await expect(page.getByLabel("target 1 match")).toHaveValue("exact"); await expect(page.getByLabel("target 1 sources")).toHaveValue("archive.today"); // Widen it: the whole journal, on both archives. await page.getByLabel("target 1 URL").fill("journal.example/"); await page.getByLabel("target 1 match").selectOption("prefix"); await page.getByLabel("target 1 sources").selectOption("both"); await page.locator('input[name="name"]').fill("Deleted journal"); await page.locator('input[name="slug"]').fill(SLUG); await page.getByRole("button", { name: /create|add channel|save/i }).first().click(); const configFile = `${testPaths().transcriptsDir}/channels/${SLUG}/config.json`; await expect .poll(async () => ((await pathExists(configFile)) ? await readJson(configFile) : null), { timeout: 15_000 }) .toMatchObject({ sourceKind: "social", platform: "webpage", wayback: { targets: [{ url: "journal.example/", match: "prefix", sources: ["wayback", "archive.today"] }] }, }); const at = await startFakeArchiveToday({ challenge: [AT_CHECKED_ID] }); const wb = await startFakeWayback({ excluded: [AT_ARTICLE_URL] }); const atFile = archiveTodayOriginFile(resolvePath(testPaths().transcriptsDir)); const wbFile = waybackOriginFile(resolvePath(testPaths().transcriptsDir)); await writeFile(atFile, at.base); await writeFile(wbFile, wb.base); try { await page.goto(`/channels/${SLUG}`); const pages = page.getByRole("region", { name: "Wayback pages" }); await expect(pages.getByLabel("pages held")).toHaveText("0 records from 0 captures"); await expect(page.getByRole("button", { name: "Connect archive session" })).toBeVisible(); // One copy by its short id (on another of archive.today's names). await page.getByLabel("capture URL").fill(`https://archive.is/${AT_ARTICLE_ID}`); await expect(page.getByLabel("capture source")).toBeDisabled(); await page.getByRole("button", { name: "Import capture" }).click(); await expect(page.getByRole("log", { name: `Import a capture into ${SLUG} output` })).toContainText('"ok":true', { timeout: 60_000 }); const id = pageRecordId(AT_ARTICLE_TS, AT_ARTICLE_URL); const channelRoot = resolvePath(`${testPaths().transcriptsDir}/channels/${SLUG}`); const capture = JSON.parse(await readFile(path.join(channelRoot, "pages", id, "capture.json"), "utf8")) as Record; expect(capture).toMatchObject({ originalUrl: AT_ARTICLE_URL, captureTs: AT_ARTICLE_TS, source: "archive.today", mementoUrl: `https://archive.ph/${AT_ARTICLE_ID}`, extractor: "generic", }); expect(at.requests.map((r) => r.path)).toEqual([`/${AT_ARTICLE_ID}`]); await page.reload(); await expect(pages.getByLabel("pages held")).toHaveText("1 record from 1 capture"); const row = page.locator(`[data-page-record="${id}"]`); await expect(row.getByRole("link", { name: "Notes I Later Deleted" })).toHaveAttribute("href", AT_ARTICLE_URL); await expect(row.getByRole("link", { name: "2019-05-12" })).toHaveAttribute("href", `https://archive.ph/${AT_ARTICLE_ID}`); await expect(row).toContainText("archive.today"); // The copy nearest a date, on archive.today (one timemap request). await page.getByLabel("capture URL").fill(AT_ARTICLE_URL); await page.getByLabel("capture date").fill("2019-12-01"); await page.getByLabel("capture source").selectOption("archive.today"); await page.getByRole("button", { name: "Import capture" }).click(); await expect(page.getByRole("log", { name: `Import a capture into ${SLUG} output` })).toContainText(`"captureTs":"${AT_ARTICLE_LATER_TS}"`, { timeout: 60_000, }); expect(at.requests.map((r) => r.path).slice(1)).toEqual([`/timemap/${AT_ARTICLE_URL}`, `/${AT_ARTICLE_LATER_ID}`]); await page.reload(); await expect(pages.getByLabel("pages held")).toHaveText("2 records from 2 captures"); // Look up a page across sources: the Wayback Machine excludes it (its // words), archive.today lists its two copies — each importable. await page.getByLabel("page URL").fill(AT_ARTICLE_URL); await page.getByRole("button", { name: "Look up" }).click(); await expect(page.getByLabel("Wayback Machine copies")).toContainText("excluded from the Wayback Machine (cause unknown)", { timeout: 60_000 }); await expect(page.getByLabel("archive.today copies")).toHaveText("archive.today: 2 copies"); await expect(page.getByRole("button", { name: `import archive.today ${AT_ARTICLE_TS}` })).toBeVisible(); // The ops door: the same lookup; a copy behind a check refused with its code. const look = await request.post(`${baseUrl}/api/ops/archive-lookup`, { headers: AUTH, data: { url: AT_ARTICLE_URL } }); const lookBody = (await look.json()) as { ok: boolean; found: number; sources: { source: string; ok: boolean; refusal?: string }[] }; expect(lookBody).toMatchObject({ ok: true, found: 2 }); expect(lookBody.sources.map((s) => [s.source, s.ok, s.refusal ?? null])).toEqual([ ["wayback", false, "excluded"], ["archive.today", true, null], ]); const wl = await request.post(`${baseUrl}/api/ops/wayback-lookup`, { headers: AUTH, data: { url: AT_ARTICLE_URL } }); expect(wl.status()).toBe(403); expect(await wl.json()).toMatchObject({ ok: false, refusal: "excluded" }); const dry = await request.post(`${baseUrl}/api/ops/import-page`, { headers: AUTH, data: { slug: SLUG, url: `https://archive.ph/${AT_ARTICLE_ID}`, dryRun: true }, }); expect(await dry.json()).toMatchObject({ ok: true, dryRun: true, already: true, source: "archive.today" }); const checked = await request.post(`${baseUrl}/api/ops/import-page`, { headers: AUTH, data: { slug: SLUG, url: `https://archive.ph/${AT_CHECKED_ID}` } }); const checkedBody = (await checked.json()) as { jobId?: string; error?: string }; expect(checked.status(), checkedBody.error).toBe(200); const job = await waitForJob(request, checkedBody.jobId!); expect(job.status).toBe("failed"); const tail = job.tail.join("\n"); expect(tail).toContain('"refusal":"challenge"'); expect(tail).toContain("Connect archive session"); // Nothing of the checked copy was stored. await page.reload(); await expect(pages.getByLabel("pages held")).toHaveText("2 records from 2 captures"); } finally { await rm(atFile, { force: true }); await rm(wbFile, { force: true }); await at.close(); await wb.close(); } });