// The public homepage build's audit (release 26 A4): builtHomepageProblem // (lib/builtExport.ts) over lib/builtHomepage.ts. Each refusal on a temp out/ // and article store; a clean public build passes, with articles or none. // // Run with: node_modules/.bin/tsx --test lib/builtHomepage.test.ts import { after, test } from "node:test"; import assert from "node:assert/strict"; import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; import { tmpdir } from "node:os"; import path from "node:path"; import { builtHomepageProblem } from "./builtExport"; import { homepageBuildAudience } from "./builtHomepage"; const ROOT = mkdtempSync(path.join(tmpdir(), "built-homepage-")); after(() => rmSync(ROOT, { recursive: true, force: true })); const put = (file: string, value: unknown) => { mkdirSync(path.dirname(file), { recursive: true }); writeFileSync(file, typeof value === "string" ? value : JSON.stringify(value)); }; const paths = { articlesDir: path.join(ROOT, "reports"), channelsDir: path.join(ROOT, "channels") }; put(path.join(paths.articlesDir, "open", "report.json"), { audience: "public" }); put(path.join(paths.articlesDir, "closed", "report.json"), { audience: "private" }); put(path.join(paths.articlesDir, "unsaid", "report.json"), {}); put(path.join(paths.channelsDir, "xchan", "config.json"), { sourceKind: "social", platform: "twitter" }); put(path.join(paths.channelsDir, "vids", "config.json"), { handling: "youtube" }); const X_PRIVATE = { social: { x: { visibility: "private" } } }; let n = 0; // A built out/ with the given extra files. function out(files: Record = {}): string { const dir = path.join(ROOT, `out-${n++}`); put(path.join(dir, "index.html"), "

home

"); put(path.join(dir, "homepage-build.json"), { format: "archilyzer-homepage-build", version: 1, audience: "public", articles: [] }); for (const [rel, v] of Object.entries(files)) put(path.join(dir, rel), v); return dir; } const moment = (...hrefs: string[]) => ({ format: "archilyzer-moment-page", citedIn: hrefs.map((href) => ({ href })) }); test("no build, then a clean public build with no articles, then one with a public article and its moment", () => { assert.match(builtHomepageProblem(path.join(ROOT, "nothing"), { paths }) ?? "", /holds no build/); assert.equal(builtHomepageProblem(out(), { paths, settings: X_PRIVATE }), null); const withOne = out({ "articles/open/page.json": {}, "m/vids/v1/1.00-2.00/moment.json": moment("/articles/open/#c1"), "media/posts/vids/p1/shot.png": "png", }); assert.equal(builtHomepageProblem(withOne, { paths, settings: X_PRIVATE }), null); }); test("a private build is refused by its stamp, with or without the store", () => { const dir = out({ "homepage-build.json": { audience: "private" } }); assert.equal(homepageBuildAudience(dir), "private"); for (const opts of [{}, { paths }]) { assert.match(builtHomepageProblem(dir, opts) ?? "", /holds a private homepage build .* which is never deployed/); } }); test("an article the store does not mark public is refused: private, unsaid (private by default), gone", () => { for (const id of ["closed", "unsaid", "gone"]) { const dir = out({ [`articles/${id}/page.json`]: {} }); assert.match( builtHomepageProblem(dir, { paths }) ?? "", new RegExp(`carries the article "${id}", which is not public`), id, ); assert.equal(builtHomepageProblem(dir), null, "without the store, the stamp alone is asked"); } }); test("a moment a private article cites, or one cited by no article, is refused", () => { assert.match( builtHomepageProblem(out({ "m/vids/v1/1.00-2.00/moment.json": moment("/articles/open/", "/articles/closed/#c2") }), { paths }) ?? "", /moment vids\/v1\/1\.00-2\.00 is cited by the article "closed", which is not public/, ); assert.match( builtHomepageProblem(out({ "m/vids/v1/1.00-2.00/moment.json": moment("/reports/some-site-report/") }), { paths }) ?? "", /cited by "\/reports\/some-site-report\/", which is no public article/, ); }); test("while X posts are private: no X post's moment and no X captures; public X posts pass", () => { const xMoment = out({ "m/xchan/123/moment.json": moment("/articles/open/") }); assert.match(builtHomepageProblem(xMoment, { paths, settings: X_PRIVATE }) ?? "", /moment xchan\/123 is an X post/); const xMedia = out({ "media/posts/xchan/123/shot.png": "png" }); assert.match(builtHomepageProblem(xMedia, { paths, settings: X_PRIVATE }) ?? "", /media\/posts\/xchan\/, an X channel's captures/); assert.equal(builtHomepageProblem(xMoment, { paths, settings: {} }), null); assert.equal(builtHomepageProblem(xMedia, { paths, settings: {} }), null); }); // INSTAGRAM (lane instagram): private unless social.instagram.visibility is // "public" — a homepage built while it was public is caught after the flip. test("while Instagram posts are private (the default): no Instagram post's moment and no Instagram captures; public ones pass", () => { put(path.join(paths.channelsDir, "igchan", "config.json"), { sourceKind: "social", platform: "instagram" }); const IG_PUBLIC = { social: { instagram: { visibility: "public" } } }; const igMoment = out({ "m/igchan/3500000000000000001/moment.json": moment("/articles/open/") }); assert.match(builtHomepageProblem(igMoment, { paths, settings: {} }) ?? "", /moment igchan\/3500000000000000001 is an Instagram post, and Instagram posts are private \(social\.instagram\.visibility\)/); const igMedia = out({ "media/posts/igchan/3500000000000000001/01-1.jpg": "jpg" }); assert.match(builtHomepageProblem(igMedia, { paths, settings: {} }) ?? "", /media\/posts\/igchan\/, an Instagram channel's captures/); assert.equal(builtHomepageProblem(igMoment, { paths, settings: IG_PUBLIC }), null); assert.equal(builtHomepageProblem(igMedia, { paths, settings: IG_PUBLIC }), null); // X's answers are what they were, whatever Instagram's setting. const xMoment = out({ "m/xchan/123/moment.json": moment("/articles/open/") }); assert.equal(builtHomepageProblem(xMoment, { paths, settings: {} }), null); assert.equal(builtHomepageProblem(xMoment, { paths, settings: IG_PUBLIC }), null); assert.match(builtHomepageProblem(xMoment, { paths, settings: { ...X_PRIVATE.social ? { social: { ...X_PRIVATE.social, instagram: { visibility: "public" } } } : {} } }) ?? "", /is an X post/); });