commit 09bd9767dd6c425191521bda1b0442a4363c4b8e
parent 05f635284e1d401e3db65559dbd15f68c5a73543
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Thu, 15 Oct 2026 06:55:06 -0400
common: release 29 test kit — a fake Bluesky (AppView, a bsky.app-shaped post page, images), a fake Wayback CDX, and a recording deleted on its platform with its availability.json
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
8 files changed, 377 insertions(+), 0 deletions(-)
diff --git a/common/testing/README.md b/common/testing/README.md
@@ -20,6 +20,9 @@ transcript, channel or person goes in these fixtures, ever.
| `archiveOrg/fakeArchiveOrg.mjs` | A fake archive.org on loopback: `/advancedsearch.php` (every word of `q` in an item's identifier, title or subject; `*` all) and `/metadata/<id>` over invented items (`ITEMS`: a show's episodes with an original, a derivative and a JSON file, a restricted item, an audio tape). `ia.fetch` sends `https://archive.org/…` to it, for `new ArchiveOrgClient({ fetch: ia.fetch })`; `busyTimes` answers 429 first. |
| `draft/manifests/full`, `flips` | Release 28: every media field a draft task writes, as the build accepts it today — per-entry `onscreen`, a narrated card, a teaser, `claim` verdicts, `render.chrome.threads` with a `thread` per clip (`full`), or `render.chrome.flips` (`flips`: one THEN/NOW pair over clips of different dates). Hand-written, not derived; `umtool/report-to-video/fixtures-r28.test.mjs` keeps them lint-clean. |
| `draft/reports/ruled.report.json` | Release 28: a synthetic fact-check whose claims carry verdicts standing for operator rulings — every verdict at least once, each cited quote a cue of the corpus. The verdict bench's tests read it. |
+| `social/fakeBluesky.mjs` | Release 29: a fake Bluesky on loopback — the public AppView (`resolveHandle`, `getPosts` answering only live posts, images as `embed.images[].fullsize`), a bsky.app-shaped post page (`pageUrl(handle, rkey)`: the post in `[data-testid="postThreadItem-by-<handle>"]` inside page chrome, "Post not found" for a deleted one) for a headless screenshot, and PNG images. `bsky.fetch` sends `https://public.api.bsky.app`, `https://bsky.app` and `https://cdn.bsky.app` to it; `busyTimes` answers 429 first. |
+| `web/fakeWayback.mjs` | Release 29: a fake Wayback Machine — the CDX API (`/cdx/search/cdx`, `output=json` with its header row, `[]` for none, `filter=statuscode:`, `limit`, `matchType=prefix`) and capture pages (`/web/<ts>[id_]/<url>`). `wb.fetch` sends `https://web.archive.org` to it; `busyTimes` 429s, `downTimes` 503s. |
+| `draft/corpus.mjs` `GONE_RECORD`, `GONE_AVAILABILITY` | Release 29: a recording deleted on its platform (`state: "deleted"`, cues kept; add it with `withRecords`) and the `availability.json` it carries on disk. The fake Wayback has one capture of its watch page. |
| `draft/runs/*.json` | One recorded run per generation task (release 27 S5): the model side, scripted — `turns` for the fake Anthropic (`sweep-agent`, `revise-report`, `revise-video`, `research`) or the fake ollama (`sweep-pipeline`, `narrate`; release 28's `flips`, `threads` and `youtube`, each with a `note` saying what it is run over and why its first answer is refused), with the question, channels or feedback it answers. `mcp/src/draftTasks.test.ts` runs each task over the synthetic corpus against them. |
| `draft/derive.ts`, `draft/regenerate.ts` | How the derived files are made. After a converter change: `cd common && pnpm exec tsx testing/draft/regenerate.ts`, review the diff, commit. `fakes.test.ts` fails until they match. |
diff --git a/common/testing/draft/corpus.d.mts b/common/testing/draft/corpus.d.mts
@@ -30,5 +30,13 @@ export function postHref(channel: string, id: string): string;
export function recordOf(channel: string, id: string): FixtureRecord | null;
export function cuesOf(channel: string, id: string): Promise<FixtureCue[] | null>;
export const LATE_RECORD: FixtureRecord;
+export const GONE_RECORD: FixtureRecord & { state: "deleted"; isDeleted: true };
+export const GONE_AVAILABILITY: {
+ checkedAt: string;
+ availability: "deleted";
+ error: string;
+ webpageUrl: string;
+ history: { availability: string; observedAt: string; source: "check" | "backfill" | "download" }[];
+};
export function withRecords(extra: FixtureRecord[]): FixtureChannel[];
export function writeDraftCorpus(dir: string, opts?: { channels?: FixtureChannel[] }): Promise<string>;
diff --git a/common/testing/draft/corpus.mjs b/common/testing/draft/corpus.mjs
@@ -162,6 +162,38 @@ export const LATE_RECORD = video("synth-kitchen", "Synth Kitchen", "contest-stre
"congratulations to the winner", // 10
]);
+// A recording deleted on its platform (release 29 S0): the archive kept its
+// cues, the platform no longer serves it (`state: "deleted"`, as a composed
+// record says it). Not in CHANNELS; add it with withRecords. On disk a gone
+// recording also carries `data/<id>/availability.json` — GONE_AVAILABILITY.
+// The fake Wayback (`web/fakeWayback.mjs`) has one capture of its watch page.
+export const GONE_RECORD = video(
+ "synth-kitchen",
+ "Synth Kitchen",
+ "gone-video-05",
+ "The old oven review",
+ "20260120",
+ [
+ "this is my honest review of the old oven", // 0
+ "the old oven never once burned a loaf", // 5
+ "I would buy the same oven again tomorrow", // 10
+ "that is the review thanks for watching", // 15
+ ],
+ { state: "deleted", isDeleted: true },
+);
+
+// The availability.json a gone recording carries (common/lib/availability.ts).
+export const GONE_AVAILABILITY = {
+ checkedAt: "2026-10-01T00:00:00.000Z",
+ availability: "deleted",
+ error: "Video unavailable. This video has been removed by the uploader",
+ webpageUrl: GONE_RECORD.webpageUrl,
+ history: [
+ { availability: "public", observedAt: "2026-01-21T00:00:00.000Z", source: "download" },
+ { availability: "deleted", observedAt: "2026-10-01T00:00:00.000Z", source: "check" },
+ ],
+};
+
// CHANNELS with `extra` records added to their channels (a later build).
export function withRecords(extra) {
return CHANNELS.map((c) => ({ ...c, records: [...c.records, ...extra.filter((r) => r.channelSlug === c.slug)] }));
diff --git a/common/testing/fakes.test.ts b/common/testing/fakes.test.ts
@@ -231,3 +231,61 @@ test("fixtures: the ruled fact-check (release 28) validates, carries every verdi
assert.equal(cue?.text, c.quote, id);
}
});
+
+// ─── Release 29: Bluesky, Wayback, a gone recording ───
+
+test("fake Bluesky: handle → DID, getPosts answers only live posts with fullsize images, the page and its images serve", async () => {
+ const { startFakeBluesky, ACCOUNTS, BSKY_POSTS } = await import("./social/fakeBluesky.mjs");
+ const bsky = await startFakeBluesky({ busyTimes: 1 });
+ try {
+ const [acct] = ACCOUNTS;
+ const resolve = `https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle?handle=${acct.handle}`;
+ assert.equal((await bsky.fetch(resolve)).status, 429);
+ assert.equal(((await (await bsky.fetch(resolve)).json()) as any).did, acct.did);
+ const uris = BSKY_POSTS.map((p) => `at://${acct.did}/app.bsky.feed.post/${p.rkey}`);
+ const q = new URLSearchParams();
+ for (const u of uris) q.append("uris", u);
+ const got = (await (await bsky.fetch(`https://public.api.bsky.app/xrpc/app.bsky.feed.getPosts?${q}`)).json()) as any;
+ assert.equal(got.posts.length, BSKY_POSTS.filter((p) => !p.deleted).length);
+ const withImages = got.posts.find((p: any) => p.embed?.images?.length);
+ const img = await bsky.fetch(withImages.embed.images[0].fullsize);
+ assert.equal(img.headers.get("content-type"), "image/png");
+ const page = await (await fetch(bsky.pageUrl(acct.handle, BSKY_POSTS[0].rkey))).text();
+ assert.match(page, new RegExp(`data-testid="postThreadItem-by-${acct.handle.replace(/\./g, "\\.")}"`));
+ const gone = BSKY_POSTS.find((p) => p.deleted)!;
+ assert.match(await (await fetch(bsky.pageUrl(acct.handle, gone.rkey))).text(), /Post not found/);
+ } finally {
+ await bsky.close();
+ }
+});
+
+test("fake Wayback: CDX json rows oldest first with a header, [] for none, a status filter, captures serve", async () => {
+ const { startFakeWayback } = await import("./web/fakeWayback.mjs");
+ const { GONE_RECORD } = await import("./draft/corpus.mjs");
+ const wb = await startFakeWayback({ busyTimes: 1 });
+ try {
+ const cdx = (url: string, extra = "") =>
+ wb.fetch(`https://web.archive.org/cdx/search/cdx?url=${encodeURIComponent(url)}&output=json${extra}`);
+ assert.equal((await cdx(GONE_RECORD.webpageUrl)).status, 429);
+ const rows = (await (await cdx(GONE_RECORD.webpageUrl)).json()) as string[][];
+ assert.equal(rows[0][1], "timestamp");
+ assert.equal(rows.length, 2);
+ const ts = rows[1][1];
+ assert.deepEqual(await (await cdx("https://video.example/watch?v=never")).json(), []);
+ const bread = (await (await cdx("https://video.example/watch?v=bread-day-01", "&filter=statuscode:200")).json()) as string[][];
+ assert.equal(bread.length, 2);
+ const cap = await wb.fetch(`https://web.archive.org/web/${ts}/${GONE_RECORD.webpageUrl}`);
+ assert.equal(cap.status, 200);
+ } finally {
+ await wb.close();
+ }
+});
+
+test("the gone recording: deleted on its platform, cues kept, an availability.json that isPermanentlyGone", async () => {
+ const { GONE_RECORD, GONE_AVAILABILITY, CHANNELS: base } = await import("./draft/corpus.mjs");
+ const { isPermanentlyGone } = await import("../lib/availability");
+ assert.equal(GONE_RECORD.state, "deleted");
+ assert.ok(GONE_RECORD.cues.length > 0);
+ assert.ok(!base.some((c) => c.records.some((r) => r.id === GONE_RECORD.id)));
+ assert.ok(isPermanentlyGone(GONE_AVAILABILITY.availability as any));
+});
diff --git a/common/testing/social/fakeBluesky.d.mts b/common/testing/social/fakeBluesky.d.mts
@@ -0,0 +1,24 @@
+export const PNG: Buffer;
+
+export type FakeBlueskyAccount = { handle: string; did: string; displayName: string };
+export type FakeBlueskyPost = {
+ handle: string;
+ rkey: string;
+ text: string;
+ createdAt: string;
+ images: { name: string; alt: string }[];
+ deleted?: boolean;
+};
+
+export const ACCOUNTS: FakeBlueskyAccount[];
+export const BSKY_POSTS: FakeBlueskyPost[];
+
+export type FakeBluesky = {
+ base: string;
+ requests: string[];
+ pageUrl(handle: string, rkey: string): string;
+ fetch(url: string | URL, init?: RequestInit): Promise<Response>;
+ close(): Promise<void>;
+};
+
+export function startFakeBluesky(opts?: { accounts?: FakeBlueskyAccount[]; posts?: FakeBlueskyPost[]; busyTimes?: number }): Promise<FakeBluesky>;
diff --git a/common/testing/social/fakeBluesky.mjs b/common/testing/social/fakeBluesky.mjs
@@ -0,0 +1,150 @@
+// A fake Bluesky on loopback (release 29 S0): the public AppView the fetcher
+// reads, a bsky.app-shaped post page a headless browser can screenshot, and the
+// CDN's images. No test reaches the real Bluesky.
+//
+// const bsky = await startFakeBluesky();
+// bsky.fetch a fetch that sends https://public.api.bsky.app/…,
+// https://bsky.app/… and https://cdn.bsky.app/… here
+// bsky.base the loopback origin (a browser goes here directly)
+// bsky.pageUrl(h, rkey) the post page on the fake (what bsky.app/profile/<h>/post/<rkey> is)
+// bsky.requests every request path, in order
+// await bsky.close()
+//
+// Routes:
+// GET /xrpc/com.atproto.identity.resolveHandle?handle=<h> { did }, 400 for an unknown handle
+// GET /xrpc/app.bsky.feed.getPosts?uris=<at-uri>… the live posts among the uris
+// (a deleted post is simply absent)
+// GET /profile/<handle>/post/<rkey> the post page: a thread item
+// `[data-testid="postThreadItem-by-<handle>"]`
+// holding the text and its images, inside
+// page chrome (a header, a side bar); a
+// deleted post renders "Post not found"
+// GET /img/<did>/<name> a small PNG
+// opts.busyTimes: the first N AppView requests answer 429 (Retry-After: 1).
+
+import http from "node:http";
+
+// A 2×2 PNG (opaque grey), enough for an <img> to load and a file to be written.
+export const PNG = Buffer.from(
+ "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAADklEQVR4nGNoAAMGCAUAKg4GARWeQtcAAAAASUVORK5CYII=",
+ "base64",
+);
+
+export const ACCOUNTS = [{ handle: "synthbaker.bsky.social", did: "did:plc:synthbaker0000000000000", displayName: "Synth Baker" }];
+
+// Invented posts. `deleted` posts exist for the page (it says so) and never in getPosts.
+export const BSKY_POSTS = [
+ {
+ handle: "synthbaker.bsky.social",
+ rkey: "3lsynthpost0001",
+ text: "The second shop opens in the spring. Small place, big oven.",
+ createdAt: "2026-03-02T15:00:00.000Z",
+ images: [
+ { name: "oven.png", alt: "The new oven" },
+ { name: "shop.png", alt: "The shop front" },
+ ],
+ },
+ {
+ handle: "synthbaker.bsky.social",
+ rkey: "3lsynthpost0002",
+ text: "No, I did not enter the pie contest. The judges are my friends.",
+ createdAt: "2026-02-11T20:00:00.000Z",
+ images: [],
+ },
+ {
+ handle: "synthbaker.bsky.social",
+ rkey: "3lsynthpost0003",
+ text: "This one was deleted.",
+ createdAt: "2026-02-12T09:00:00.000Z",
+ images: [],
+ deleted: true,
+ },
+];
+
+const esc = (s) => String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """);
+
+export async function startFakeBluesky(opts = {}) {
+ const accounts = opts.accounts ?? ACCOUNTS;
+ const posts = opts.posts ?? BSKY_POSTS;
+ const requests = [];
+ let busy = opts.busyTimes ?? 0;
+ let base = "";
+ const didOf = (handle) => accounts.find((a) => a.handle === handle)?.did ?? null;
+ const accountOf = (actor) => accounts.find((a) => a.handle === actor || a.did === actor) ?? null;
+ const imgUrl = (did, name) => `https://cdn.bsky.app/img/${did}/${name}`;
+
+ const view = (p) => {
+ const a = accountOf(p.handle);
+ const images = p.images.map((im) => ({ thumb: imgUrl(a.did, im.name), fullsize: imgUrl(a.did, im.name), alt: im.alt }));
+ return {
+ uri: `at://${a.did}/app.bsky.feed.post/${p.rkey}`,
+ cid: `bafy${p.rkey}`,
+ author: { did: a.did, handle: a.handle, displayName: a.displayName },
+ record: {
+ $type: "app.bsky.feed.post",
+ text: p.text,
+ createdAt: p.createdAt,
+ langs: ["en"],
+ ...(images.length ? { embed: { $type: "app.bsky.embed.images", images: p.images.map((im) => ({ alt: im.alt })) } } : {}),
+ },
+ ...(images.length ? { embed: { $type: "app.bsky.embed.images#view", images } } : {}),
+ replyCount: 1,
+ repostCount: 2,
+ likeCount: 3,
+ quoteCount: 0,
+ indexedAt: p.createdAt,
+ };
+ };
+
+ const page = (handle, rkey) => {
+ const p = posts.find((x) => x.handle === handle && x.rkey === rkey);
+ const a = accountOf(handle);
+ const chrome = (inner) => `<!doctype html><html><head><title>Bluesky</title>
+<style>body{margin:0;font-family:sans-serif;background:#fff}header{height:56px;background:#eef}aside{position:fixed;left:0;top:56px;width:200px;bottom:0;background:#f6f6f6}
+main{margin-left:220px;width:600px;padding:12px}[data-testid^="postThreadItem-by-"]{border:1px solid #ddd;padding:12px}
+img{width:200px;height:120px;display:inline-block;margin:4px}</style></head>
+<body><header>Bluesky</header><aside>Home · Search · Feeds</aside><main>${inner}</main></body></html>`;
+ if (!p || !a || p.deleted) return chrome(`<div data-testid="postThreadScreen"><p>Post not found</p></div>`);
+ const imgs = p.images.map((im) => `<img src="${base}/img/${a.did}/${esc(im.name)}" alt="${esc(im.alt)}">`).join("");
+ return chrome(`<div data-testid="postThreadScreen"><div data-testid="postThreadItem-by-${esc(handle)}">
+<div><b>${esc(a.displayName)}</b> @${esc(handle)}</div><p>${esc(p.text)}</p>${imgs}<div>${esc(p.createdAt)}</div></div>
+<div data-testid="postThreadItem-by-someone.else">a reply</div></div>`);
+ };
+
+ const server = http.createServer((req, res) => {
+ const u = new URL(req.url ?? "/", "http://fake");
+ requests.push(u.pathname + u.search);
+ const send = (status, type, body, headers = {}) => {
+ res.writeHead(status, { "content-type": type, ...headers });
+ res.end(body);
+ };
+ const json = (status, body, headers) => send(status, "application/json", JSON.stringify(body), headers);
+ if (u.pathname.startsWith("/xrpc/") && busy > 0) {
+ busy--;
+ return json(429, { error: "RateLimitExceeded" }, { "retry-after": "1" });
+ }
+ if (u.pathname === "/xrpc/com.atproto.identity.resolveHandle") {
+ const did = didOf(u.searchParams.get("handle") ?? "");
+ return did ? json(200, { did }) : json(400, { error: "InvalidRequest", message: "Unable to resolve handle" });
+ }
+ if (u.pathname === "/xrpc/app.bsky.feed.getPosts") {
+ const uris = u.searchParams.getAll("uris");
+ const live = posts.filter((p) => !p.deleted).map(view).filter((v) => uris.includes(v.uri));
+ return json(200, { posts: live });
+ }
+ const m = /^\/profile\/([^/]+)\/post\/([^/]+)$/.exec(u.pathname);
+ if (m) return send(200, "text/html; charset=utf-8", page(decodeURIComponent(m[1]), decodeURIComponent(m[2])));
+ if (/^\/img\/[^/]+\/[^/]+$/.test(u.pathname)) return send(200, "image/png", PNG);
+ return json(404, { error: "NotFound" });
+ });
+ await new Promise((r) => server.listen(0, "127.0.0.1", r));
+ base = `http://127.0.0.1:${server.address().port}`;
+ return {
+ base,
+ requests,
+ pageUrl: (handle, rkey) => `${base}/profile/${encodeURIComponent(handle)}/post/${encodeURIComponent(rkey)}`,
+ fetch: (url, init) =>
+ fetch(String(url).replace(/^https:\/\/(public\.api\.bsky\.app|bsky\.app|cdn\.bsky\.app)/, base), init),
+ close: () => new Promise((r) => server.close(() => r())),
+ };
+}
diff --git a/common/testing/web/fakeWayback.d.mts b/common/testing/web/fakeWayback.d.mts
@@ -0,0 +1,12 @@
+export type FakeWaybackCapture = { original: string; timestamp: string; statuscode: string; mimetype?: string };
+
+export const CAPTURES: FakeWaybackCapture[];
+
+export type FakeWayback = {
+ base: string;
+ requests: { path: string; at: number }[];
+ fetch(url: string | URL, init?: RequestInit): Promise<Response>;
+ close(): Promise<void>;
+};
+
+export function startFakeWayback(opts?: { captures?: FakeWaybackCapture[]; busyTimes?: number; downTimes?: number }): Promise<FakeWayback>;
diff --git a/common/testing/web/fakeWayback.mjs b/common/testing/web/fakeWayback.mjs
@@ -0,0 +1,90 @@
+// A fake Wayback Machine on loopback (release 29 S0): the CDX search API and
+// capture pages, for the deleted-video fallback's lookup. No test reaches the
+// real web.archive.org.
+//
+// const wb = await startFakeWayback();
+// wb.fetch a fetch that sends https://web.archive.org/… here
+// wb.base the loopback origin
+// wb.requests every request path, in order (pacing tests read the times in `at`)
+// await wb.close()
+//
+// Routes:
+// GET /cdx/search/cdx?url=<u>[&output=json][&limit=N][&filter=statuscode:200][&matchType=…]
+// output=json: a header row ["urlkey","timestamp","original","mimetype","statuscode","digest","length"]
+// then one row per capture of <u> (oldest first); no captures: `[]` (the real API's empty answer)
+// without output=json: the same rows space-separated, one per line
+// GET /web/<timestamp>[id_|if_]/<original> the capture (text/html), 404 for an unknown one
+// opts.busyTimes: the first N CDX requests answer 429 (Retry-After: 1); opts.downTimes: then 503s.
+
+import http from "node:http";
+
+const HEADER = ["urlkey", "timestamp", "original", "mimetype", "statuscode", "digest", "length"];
+
+// Invented captures. `bread-day-01`'s watch page was captured twice (one a
+// redirect), `gone-video-05` once; anything else has none.
+export const CAPTURES = [
+ { original: "https://video.example/watch?v=bread-day-01", timestamp: "20260106120000", statuscode: "200", mimetype: "text/html" },
+ { original: "https://video.example/watch?v=bread-day-01", timestamp: "20260301080000", statuscode: "302", mimetype: "text/html" },
+ { original: "https://video.example/watch?v=gone-video-05", timestamp: "20260125093000", statuscode: "200", mimetype: "text/html" },
+];
+
+const urlkey = (u) => {
+ try {
+ const x = new URL(u);
+ return `${x.hostname.split(".").reverse().join(",")})${x.pathname}${x.search}`.toLowerCase();
+ } catch {
+ return u;
+ }
+};
+
+export async function startFakeWayback(opts = {}) {
+ const captures = opts.captures ?? CAPTURES;
+ const requests = [];
+ let busy = opts.busyTimes ?? 0;
+ let down = opts.downTimes ?? 0;
+ const server = http.createServer((req, res) => {
+ const u = new URL(req.url ?? "/", "http://fake");
+ requests.push({ path: u.pathname + u.search, at: Date.now() });
+ const send = (status, type, body, headers = {}) => {
+ res.writeHead(status, { "content-type": type, ...headers });
+ res.end(body);
+ };
+ if (u.pathname === "/cdx/search/cdx") {
+ if (busy > 0) {
+ busy--;
+ return send(429, "text/plain", "Too Many Requests", { "retry-after": "1" });
+ }
+ if (down > 0) {
+ down--;
+ return send(503, "text/plain", "Service Unavailable");
+ }
+ const want = u.searchParams.get("url") ?? "";
+ const prefix = u.searchParams.get("matchType") === "prefix";
+ const status = /^statuscode:(\d+)$/.exec(u.searchParams.get("filter") ?? "")?.[1];
+ const limit = Number(u.searchParams.get("limit") ?? 0) || Infinity;
+ const rows = captures
+ .filter((c) => (prefix ? c.original.startsWith(want) : c.original === want))
+ .filter((c) => !status || c.statuscode === status)
+ .sort((a, b) => a.timestamp.localeCompare(b.timestamp))
+ .slice(0, limit)
+ .map((c) => [urlkey(c.original), c.timestamp, c.original, c.mimetype ?? "text/html", c.statuscode, `DIGEST${c.timestamp}`, "1234"]);
+ if (u.searchParams.get("output") === "json") return send(200, "application/json", JSON.stringify(rows.length ? [HEADER, ...rows] : []));
+ return send(200, "text/plain", rows.map((r) => r.join(" ")).join("\n") + (rows.length ? "\n" : ""));
+ }
+ const m = /^\/web\/(\d{14})(?:id_|if_)?\/(.+)$/.exec(u.pathname + u.search);
+ if (m) {
+ const c = captures.find((x) => x.timestamp === m[1] && x.original === m[2]);
+ if (!c) return send(404, "text/html", "<p>Wayback Machine has not archived that URL.</p>");
+ return send(200, "text/html; charset=utf-8", `<!doctype html><html><head><title>capture ${c.timestamp}</title></head><body><p>${c.original}</p></body></html>`);
+ }
+ return send(404, "text/plain", "not found");
+ });
+ await new Promise((r) => server.listen(0, "127.0.0.1", r));
+ const base = `http://127.0.0.1:${server.address().port}`;
+ return {
+ base,
+ requests,
+ fetch: (url, init) => fetch(String(url).replace(/^https?:\/\/web\.archive\.org/, base), init),
+ close: () => new Promise((r) => server.close(() => r())),
+ };
+}