import { test } from "node:test"; import assert from "node:assert/strict"; import * as React from "react"; import { renderToString } from "react-dom/server"; import { syntheticReport, syntheticReportView } from "../../fixtures/report-site/synthetic"; import { validateReport } from "yt-dlp-transcript-common/lib/report/validate"; import { CLAIM_ARCHIVES_MAX } from "yt-dlp-transcript-common/lib/report/views"; import ReportArticle from "../components/reports/ReportArticle"; // A REPORT PAGE'S SIZE is bounded by what it cites, not by what it repeats. A // report citing one long document many times once carried that document — and // its hundreds of archive links — inside every citation of it, and rendered // them on every card and preview: a static host's per-file limit refused the // page. The synthetic report (fixtures/report-site/synthetic.ts: 400 citations, // 100 of them of ONE source with 300 archive links) holds the budget. (globalThis as { React?: typeof React }).React = React; const MB = 1024 * 1024; const report = syntheticReport(); const view = syntheticReportView(report); test("the synthetic report is sound and as large as it says", () => { assert.deepEqual(validateReport(report), []); const kinds = Object.values(view.citations).reduce>((n, c) => ((n[c.kind] = (n[c.kind] ?? 0) + 1), n), {}); assert.deepEqual(kinds, { source: 100, video: 200, post: 100 }); assert.equal(view.sources.s0.archives.length, 300); }); test("the page view is under 2 MB, and carries the document once", () => { const json = JSON.stringify(view, null, 2); assert.ok(Buffer.byteLength(json) < 2 * MB, `page.json is ${Buffer.byteLength(json)} bytes`); // every archive URL appears once in the document's entry, and otherwise only // in the claims it belongs to (at most CLAIM_ARCHIVES_MAX each) const first = view.sources.s0.archives[0].url; const claimsWith = view.sections.flatMap((s) => s.claims).filter((c) => c.archives?.some((a) => a.url === first)).length; assert.equal(json.split(first + '"').length - 1, 1 + claimsWith); for (const c of view.sections.flatMap((s) => s.claims)) assert.ok((c.archives?.length ?? 0) <= CLAIM_ARCHIVES_MAX); for (const c of Object.values(view.citations)) assert.ok(!("source" in c), "a source citation names its document by id"); }); test("the rendered report page is under 5 MB", () => { const html = renderToString(React.createElement(ReportArticle, { view })); assert.ok(Buffer.byteLength(html) < 5 * MB, `the page renders to ${Buffer.byteLength(html)} bytes`); // the document's full archive list is on the page once, collapsed assert.equal(html.match(/data-source-archives="300"/g)?.length, 1); assert.match(html, /
]*>]*>300 archive links<\/summary>/); });