import { readFileSync } from "node:fs"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { test } from "node:test"; import assert from "node:assert/strict"; import { renderReportMarkdown } from "./docs"; import { renderCitationsMarkdown } from "../citations/docs"; import { claimSchema, reportSchema, sectionSchema } from "./schema"; import { CITATION_KINDS } from "../citations/schema"; import { VERDICTS } from "./verdicts"; // REPORT.md and CITATIONS.md are GENERATED from the schemas // (common/bin/file-schemas-docs.ts). A hand edit to either, or a schema change // without a regenerate, fails here. const REPO = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..", "..", ".."); for (const [name, render] of [ ["REPORT.md", renderReportMarkdown], ["CITATIONS.md", renderCitationsMarkdown], ] as const) { test(`${name} is what the schema generates`, () => { const committed = readFileSync(path.join(REPO, name), "utf8"); assert.equal( committed, render(), `${name} is stale: run pnpm --filter yt-dlp-transcript-common exec tsx bin/file-schemas-docs.ts`, ); }); } test("REPORT.md has a row for every key of the document, a section and a claim, and every verdict", () => { const md = renderReportMarkdown(); for (const shape of [reportSchema.shape, sectionSchema.shape, claimSchema.shape]) { for (const key of Object.keys(shape)) assert.ok(md.includes(`| \`${key}\` |`), key); } for (const v of VERDICTS) assert.ok(md.includes(`| \`${v}\` |`), v); }); test("CITATIONS.md documents every key of every kind", () => { const md = renderCitationsMarkdown(); for (const member of CITATION_KINDS) { assert.ok(md.includes(`#### \`"${member.shape.kind.value}"\``), member.shape.kind.value); for (const key of Object.keys(member.shape)) assert.ok(md.includes(`| \`${key}\` |`), key); } });