// Release 37 lane F: archive.today's answers read — its timemap, a copy's facts, // its check page, and a copy unwrapped so the extractors read it as they read a // raw Wayback body: lane C's synthetic tweet and Tumblr pages, wrapped the way // archive.today wraps a copy, give the SAME records. // // Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test lib/archives/archiveToday.test.ts import test from "node:test"; import assert from "node:assert/strict"; import { blockById, copyFactsFromHeaders, copyFactsFromHtml, isArchiveTodayChallenge, mapArchiveTodayMedia, nearestCapture, parseArchiveTodayTimemap, parseLinkFormat, unwrapArchiveTodayHtml, withinCaptureRange, } from "./archiveToday"; import { CHALLENGE_HTML, COPIES, wrapLikeArchiveToday, AT_ARTICLE_URL, AT_ARTICLE_ID, AT_ARTICLE_TS } from "../../testing/web/fakeArchiveToday.mjs"; import { extractPage } from "../waybackPages/extract"; import { captureOf, fixture } from "../waybackPages/extractors/__fixtures__/capture"; test("the timemap's copies, oldest first; URLs with commas survive; the original is rel=original", () => { const text = [ `; rel="original"`, `; rel="timegate"`, `; rel="self"; type="application/link-format"`, `; rel="last memento"; datetime="Wed, 01 Jan 2020 10:15:00 GMT"`, `; rel="first memento"; datetime="Sun, 12 May 2019 08:30:00 GMT"`, ].join(",\n"); assert.equal(parseLinkFormat(text).length, 5); assert.deepEqual(parseArchiveTodayTimemap(text, "https://ignored.example/"), [ { source: "archive.today", captureTs: "20190512083000", originalUrl: "https://journal.example/a,b.html", mementoUrl: "https://archive.ph/Ab3dE", status: "200", mimetype: "text/html" }, { source: "archive.today", captureTs: "20200101101500", originalUrl: "https://journal.example/a,b.html", mementoUrl: "https://archive.ph/Fg7hJ", status: "200", mimetype: "text/html" }, ]); assert.equal(withinCaptureRange("20190512083000", "2019", "2019"), true); assert.equal(withinCaptureRange("20200101101500", "2019", "2019"), false); assert.equal(withinCaptureRange("20190512083000", "201906"), false); const rows = parseArchiveTodayTimemap(text, ""); assert.equal(nearestCapture(rows, "20191201")?.mementoUrl, "https://archive.ph/Fg7hJ"); assert.equal(nearestCapture(rows, "2019")?.mementoUrl, "https://archive.ph/Ab3dE"); assert.equal(nearestCapture([], "2019"), null); }); test("a copy's facts: from its Memento headers, else from its header bar", () => { const h = new Headers({ "memento-datetime": "Sun, 12 May 2019 08:30:00 GMT", link: `<${AT_ARTICLE_URL}>; rel="original", ; rel="memento"; datetime="Sun, 12 May 2019 08:30:00 GMT"`, }); assert.deepEqual(copyFactsFromHeaders(h), { captureTs: "20190512083000", originalUrl: AT_ARTICLE_URL }); const wrapped = wrapLikeArchiveToday(COPIES[0].page(), { id: AT_ARTICLE_ID, original: AT_ARTICLE_URL, timestamp: AT_ARTICLE_TS }); assert.deepEqual(copyFactsFromHtml(wrapped), { originalUrl: AT_ARTICLE_URL, captureTs: AT_ARTICLE_TS }); assert.deepEqual(copyFactsFromHtml("

no bar

"), {}); }); test("a check page is told apart from a copy — and a copy OF a page with a captcha form is still a copy", () => { assert.equal(isArchiveTodayChallenge(CHALLENGE_HTML), true); assert.equal(isArchiveTodayChallenge("Just a moment...Checking your browser"), true); const page = wrapLikeArchiveToday(COPIES[0].page(), { id: AT_ARTICLE_ID, original: AT_ARTICLE_URL, timestamp: AT_ARTICLE_TS }); assert.equal(isArchiveTodayChallenge(page), false); const signup = wrapLikeArchiveToday( 'Sign up

Join us.

', { id: "Zz9yX", original: "https://club.example/signup", timestamp: "20180101000000" }, ); assert.equal(isArchiveTodayChallenge(signup), false); }); test("blockById matches its own element's close, not a nested one's, and not a longer id", () => { const html = '
no
in

x

after
'; const b = blockById(html, "CONTENT"); assert.equal(b?.inner, "
in

x

"); }); test("unwrapped: the bar gone, links out restored to the original, images back to their originals with the cached copies kept", () => { const wrapped = wrapLikeArchiveToday(COPIES[0].page(), { id: AT_ARTICLE_ID, original: AT_ARTICLE_URL, timestamp: AT_ARTICLE_TS }); const un = unwrapArchiveTodayHtml(wrapped, `https://archive.ph/${AT_ARTICLE_ID}`); assert.equal(un.framed, true); assert.doesNotMatch(un.html, /webpage capture|id="HEADER"|archive\.ph\/o\//); assert.match(un.html, /Notes I Later Deleted \| Journal<\/title>/); assert.match(un.html, /property="og:title"/); assert.doesNotMatch(un.html, /og:url/); assert.match(un.html, /href="https:\/\/journal\.example\/2019\/05\/minutes\.html"/); assert.match(un.html, /href="https:\/\/other\.example\/account"/); assert.match(un.html, /src="https:\/\/journal\.example\/img\/whiteboard\.png"/); assert.doesNotMatch(un.html, /old-src/); const cached = un.images.get("https://journal.example/img/whiteboard.png"); assert.match(String(cached), /^https:\/\/archive\.ph\/Ab3dE\/[0-9a-f]{8}\.png$/); // The generic extractor reads it as the page it is, and the record's image // is archive.today's cached copy — never a Wayback URL it was not checked against. const res = extractPage({ html: un.html, capture: { ...captureOf(AT_ARTICLE_URL, AT_ARTICLE_TS), mimetype: "text/html" } }); assert.equal(res.extractor.name, "generic"); const [draft] = res.drafts; assert.equal(draft.title, "Notes I Later Deleted"); assert.equal(draft.author, "Sam Example"); assert.match(draft.text, /written down the same night/); assert.doesNotMatch(draft.text, /webpage capture|Saved from/); assert.deepEqual(draft.links, ["https://journal.example/2019/05/minutes.html", "https://other.example/account"]); assert.deepEqual(mapArchiveTodayMedia(draft.media, un.images), [{ kind: "image", url: cached, name: "The whiteboard after the meeting" }]); }); test("lane C's tweet and Tumblr pages, wrapped like archive.today, make the same records as raw", () => { const cases: [string, string, string, string][] = [ ["x-2016-status.html", "https://twitter.com/TeapotFan/status/697374449464250369", "20160211000000", "x"], ["tumblr-2012-classic-post.html", "http://teapot-notes.tumblr.com/post/20000000001/on-spouts", "20120601000000", "tumblr"], ["tumblr-2012-classic-index.html", "http://teapot-notes.tumblr.com/", "20120601000000", "tumblr"], ]; for (const [name, url, ts, extractor] of cases) { const raw = extractPage({ html: fixture(name), capture: captureOf(url, ts) }); assert.equal(raw.extractor.name, extractor, name); const wrapped = wrapLikeArchiveToday(fixture(name), { id: "Qr5sT", original: url, timestamp: ts }); const un = unwrapArchiveTodayHtml(wrapped, "https://archive.ph/Qr5sT"); const viaArchive = extractPage({ html: un.html, capture: { ...captureOf(url, ts), waybackUrl: "https://archive.ph/Qr5sT", rawUrl: "https://archive.ph/Qr5sT" } }); assert.equal(viaArchive.extractor.name, extractor, `${name}: the site extractor still claims it`); assert.equal(viaArchive.fallback, undefined, name); assert.deepEqual(viaArchive.drafts, raw.drafts, name); // Each image a record names becomes archive.today's cached copy. for (const d of viaArchive.drafts) { for (const m of mapArchiveTodayMedia(d.media, un.images) ?? []) { assert.match(m.url, /^https:\/\/archive\.ph\/Qr5sT\/|^https?:\/\/(?!web\.archive\.org)/, `${name}: ${m.url}`); } } } }); test("a body that is not archive.today's frame passes through, its links still restored", () => { const un = unwrapArchiveTodayHtml('<html><body><a href="https://archive.ph/o/Ab3dE/https://a.example/x">x</a></body></html>', "https://archive.ph/Ab3dE"); assert.equal(un.framed, false); assert.match(un.html, /href="https:\/\/a\.example\/x"/); }); test("media: a Wayback image form of an uncached original becomes the original", () => { assert.deepEqual( mapArchiveTodayMedia([{ kind: "image", url: "https://web.archive.org/web/2019im_/https://journal.example/a.png" }], new Map()), [{ kind: "image", url: "https://journal.example/a.png" }], ); });