commit 482b91ee7be86cd3811e1d73b96f48a51829983b
parent 262ea20b22f9f37dbc1ba6206788e566b6e5b774
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Sun, 11 Oct 2026 14:50:07 -0400
homepage: the private build and the public build's audit
Release 26 A4. `archilyzer build homepage --private` composes every
published article (stamped audience "private") and builds into
homepage/out-private (HOMEPAGE_DIST_DIR → next.config distDir), never
homepage/out; afterwards its articles are taken out of homepage/public again.
Served locally with `pnpm --filter homepage start:private`
(HOMEPAGE_PRIVATE_PORT, 3032 on main); never deployed.
lib/builtHomepage.ts audits a homepage build: a private stamp is never
deployed; with the article store, no article that is not public now, no
moment a non-public article cites (its page names the citing article), and
while social.x.visibility is private no X post moment or capture.
builtHomepageProblem asks it, so the deploy stage, its status and the public
build (which now fails on a problem) all refuse what it refuses. Tests for
each refusal, the deploy refusal, and both builds through seams.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Diffstat:
14 files changed, 444 insertions(+), 23 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -159,6 +159,7 @@ yarn-error.log*
/homepage/test-results/
/homepage/playwright-report/
/homepage/out/
+/homepage/out-private/
# the e2e's synthetic summary, and a killed run's temp copy (homepage/e2e/fixture-summary.ts)
/homepage/e2e/.e2e-summary.json*
# the e2e's settings.json (social links only), and its temp copy (homepage/e2e/fixture-social.ts)
diff --git a/COMMANDS.md b/COMMANDS.md
@@ -16,7 +16,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer build archives` | | warm the shared archive-zip cache for every enabled site's channels, once |
| `archilyzer compose site` | `<id> [--allow-missing-media]` | compose one site's export/public (default: SITE\_ID); --allow-missing-media lets a report citation with no prepared media through |
| `archilyzer compose hub` | | compose the hub's export/public (hub-sites.json, corpus.json, …) |
-| `archilyzer compose homepage` | | compose homepage/public (whole-pool stats + landing summary) |
+| `archilyzer compose homepage` | `[--private] [--allow-missing-media]` | compose homepage/public (whole-pool stats + landing summary, and the articles under /articles/: the public ones, or with --private every published one) |
| `archilyzer publish index` | | update the index: the LMDB index, the stats datasets and the chart templates in one child (8 GB heap), then the index stamp every build reads |
| `archilyzer publish build` | `<id\|all> [--runner local\|docker\|auto] [--force] [--skip-archives] [--allow-missing-media] [--out <dir>]` | build a site (or every stale one) into its bundle <exportBuildsDir>/<id>/out from the current index; --runner docker builds every site in containers (host only); a fresh site is a no-op without --force; --allow-missing-media lets a report citation with no prepared media through compose; --out <dir> then lays the site's bundle out in <dir> for a server that is not Pages (hard links where it can, else copies; emptied first and guarded as a local deploy's destination; not a deploy, nothing recorded) |
| `archilyzer publish deploy` | `<id\|all> [--preview <branch>] [--to local] [--force]` | ship a site's bundle to its Pages project (a preview with --preview), or with --to local into ARCHILYZER\_SITE\_OUT; a bundle already deployed there is a no-op without --force |
@@ -28,7 +28,7 @@ Run from the repo root (in the container: `docker compose exec editor pnpm archi
| `archilyzer build site` | `<id> [--nodata] [--skip-archives] [--allow-missing-media]` | alias: publish index (not with --nodata) + publish build <id> --force (default id: SITE\_ID) |
| `archilyzer build all` | `[--skip-archives]` | alias: publish index + publish build all --runner auto (containers when an engine answers, else serially on the host) |
| `archilyzer build hub` | | compose:hub + INSTANCE\_MODE=hub next build into export/out — a raw build, unstamped; to deploy the hub build it with `publish hub` |
-| `archilyzer build homepage` | `[--no-source]` | compose + source publish + next build in homepage/ (reads the index as it stands); --no-source removes the published source instead |
+| `archilyzer build homepage` | `[--no-source] [--private]` | compose + source publish + next build in homepage/ (reads the index as it stands), then the public build's audit (no private article, moment or X post); --no-source removes the published source instead; --private builds every published article into homepage/out-private instead (serve it with `pnpm --filter homepage start:private`; never deployed) |
| `archilyzer reports prepare` | `<id> \| --article <articleId>` | cut every clip and copy every post capture the site's published reports cite into its report-media cache, before its build, then export the reports as files (reports export) when nothing is missing (exit 1 when a citation lacks media or an export fails; default id: SITE\_ID); --article: the articles' cache (transcripts/reports/), every published article plus that one |
| `archilyzer reports export` | `<id> [--report <reportId>] \| --article <articleId>` | \[--formats html,pdf,md,slides,slides-pdf,zip\] \[--allow-missing-media\] write the site's published reports as files (report.html, report.pdf, report.md, slides.html, slides.pdf, evidence-pack.zip) into its report-exports staging, where compose publishes them from (exit 1 on a problem; a PDF skipped for want of a browser is a note; default id: SITE\_ID); --article: one article (transcripts/reports/), published or a draft |
| `archilyzer reports check` | `<id> [--reports <a,b>] \| --article <articleId>` | \[--allow-missing-media\] what compose would say about the site's reports, with no build: each report validated, every cited quote checked against its record, every cited moment's prepared media present and current, the report video under the publish limit (exit 1 with the list; --reports checks those, drafts included; default id: SITE\_ID); --article: one article (transcripts/reports/), published or a draft, as the homepage's compose would |
diff --git a/common/bin/archilyzer.ts b/common/bin/archilyzer.ts
@@ -70,9 +70,14 @@ export const COMMANDS: Command[] = [
},
{
path: ["compose", "homepage"],
- usage: "compose homepage/public (whole-pool stats + landing summary)",
- run: async () => {
- await (await import("./compose-homepage")).main();
+ usage:
+ "[--private] [--allow-missing-media] compose homepage/public (whole-pool stats + landing summary, and the articles under /articles/: the public ones, or with --private every published one)",
+ flags: { private: "boolean", "allow-missing-media": "boolean" },
+ run: async ({ flags }) => {
+ await (await import("./compose-homepage")).main({
+ audience: flags.private === true ? "private" : "public",
+ allowMissingMedia: flags["allow-missing-media"] === true,
+ });
return 0;
},
},
@@ -248,13 +253,14 @@ export const COMMANDS: Command[] = [
{
path: ["build", "homepage"],
usage:
- "[--no-source] compose + source publish + next build in homepage/ (reads the index as it stands); --no-source removes the published source instead",
- flags: { "no-source": "boolean" },
+ "[--no-source] [--private] compose + source publish + next build in homepage/ (reads the index as it stands), then the public build's audit (no private article, moment or X post); --no-source removes the published source instead; --private builds every published article into homepage/out-private instead (serve it with `pnpm --filter homepage start:private`; never deployed)",
+ flags: { "no-source": "boolean", private: "boolean" },
run: async ({ flags }) => {
const { buildHomepage } = await import("../publish/build");
const code = await buildHomepage({
signal: interrupted(),
skipSource: flags["no-source"] === true,
+ private: flags.private === true,
});
if (code !== 0) console.error(`build homepage: failed (exit ${code})`);
return code;
diff --git a/common/lib/builtExport.ts b/common/lib/builtExport.ts
@@ -17,6 +17,7 @@ import { existsSync, readdirSync, readFileSync, statSync, type Dirent } from "no
import path from "node:path";
import { isCitedOnlyChannel, isCitedSite } from "./siteSchema";
import { REPORT_HISTORY_REPO_FILE_RE } from "./report/revisions";
+import { homepageAudienceProblem, type HomepageAuditOptions } from "./builtHomepage";
import {
MOMENTS_INDEX_PATH,
REPORTS_INDEX_PATH,
@@ -682,11 +683,15 @@ export function hubReportDataIn(outDir: string, limit = 5): string[] {
* the deploy stage checks inside its job, so the refusal an operator gets before
* the job and the one the job would give agree on what "built" means.
*/
-export function builtHomepageProblem(outDir: string): string | null {
+//
+// A build that is there is then held to the audience audit (./builtHomepage.ts,
+// release 26 A4): no private build, and — with `paths` — no private article,
+// no moment a private article cites, no X post while X posts are private.
+export function builtHomepageProblem(outDir: string, opts: HomepageAuditOptions = {}): string | null {
if (!existsSync(path.join(outDir, "index.html"))) {
return "homepage/out holds no build — build the homepage first";
}
- return null;
+ return homepageAudienceProblem(outDir, opts);
}
/**
diff --git a/common/lib/builtHomepage.test.ts b/common/lib/builtHomepage.test.ts
@@ -0,0 +1,92 @@
+// 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, unknown> = {}): string {
+ const dir = path.join(ROOT, `out-${n++}`);
+ put(path.join(dir, "index.html"), "<p>home</p>");
+ 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);
+});
diff --git a/common/lib/builtHomepage.ts b/common/lib/builtHomepage.ts
@@ -0,0 +1,131 @@
+// WHAT A PUBLIC HOMEPAGE BUILD MAY NOT HOLD (release 26 A4,
+// plans/reports-on-homepage.md, "Two homepage builds").
+//
+// The homepage builds twice from one source: the PUBLIC build carries the
+// published articles whose report.json says `audience: "public"`, the PRIVATE
+// one (`archilyzer build homepage --private`, homepage/out-private) every
+// published article, and is never deployed. compose stamps each build in
+// `homepage-build.json` (bin/compose-homepage.ts). This audit is the second
+// line, asked of homepage/out by the build, the deploy stage and the status
+// (lib/builtExport.ts builtHomepageProblem):
+//
+// - a build stamped `audience: "private"` is never deployed;
+// - an article under out/articles/<id>/ must be one the article store marks
+// public now (report.json `audience`, absent = private) — one made private,
+// or gone, since the build is refused until the homepage is rebuilt;
+// - a moment under out/m/ may be cited only by such articles (its page names
+// every citing article: a private one's title would leak through it);
+// - while `social.x.visibility` is "private", no X channel's post — its
+// moment page or its captured media — is in the build, as a public site's
+// never is (lib/postsVisibility.ts).
+//
+// The store and the channel configs are read only when the caller passes the
+// paths; without them the stamp alone is checked. Synchronous: a status page
+// asks it.
+
+import { existsSync, readdirSync, readFileSync } from "node:fs";
+import path from "node:path";
+import type { Paths } from "./paths";
+import { isXPostsChannel, xPostsVisibility } from "./postsVisibility";
+import { ARTICLES_BASE, reportBaseDir } from "./report/routes";
+
+export const HOMEPAGE_BUILD_STAMP = "homepage-build.json";
+
+export type HomepageAuditOptions = {
+ paths?: Pick<Paths, "articlesDir" | "channelsDir">;
+ // `social.x.visibility`; asked only with `paths`.
+ settings?: { social?: { x?: { visibility?: unknown } } };
+};
+
+const readJson = (file: string): unknown => {
+ try {
+ return JSON.parse(readFileSync(file, "utf8"));
+ } catch {
+ return null;
+ }
+};
+
+const dirs = (dir: string): string[] => {
+ try {
+ return readdirSync(dir, { withFileTypes: true })
+ .filter((e) => e.isDirectory())
+ .map((e) => e.name)
+ .sort();
+ } catch {
+ return [];
+ }
+};
+
+// Every moment.json under out/m/, by key.
+function momentFiles(outDir: string): { key: string; file: string }[] {
+ const out: { key: string; file: string }[] = [];
+ const walk = (dir: string, rel: string[]) => {
+ if (existsSync(path.join(dir, "moment.json"))) out.push({ key: rel.join("/"), file: path.join(dir, "moment.json") });
+ for (const d of dirs(dir)) walk(path.join(dir, d), [...rel, d]);
+ };
+ walk(path.join(outDir, "m"), []);
+ return out;
+}
+
+// The stamp's audience, when the build carries one.
+export function homepageBuildAudience(outDir: string): string | null {
+ const stamp = readJson(path.join(outDir, HOMEPAGE_BUILD_STAMP)) as { audience?: unknown } | null;
+ return typeof stamp?.audience === "string" ? stamp.audience : null;
+}
+
+// The first reason `outDir` may not be deployed as the public homepage, or null.
+export function homepageAudienceProblem(outDir: string, opts: HomepageAuditOptions = {}): string | null {
+ if (homepageBuildAudience(outDir) === "private") {
+ return `${outDir} holds a private homepage build (its ${HOMEPAGE_BUILD_STAMP} says "audience": "private"), which is never deployed`;
+ }
+ const paths = opts.paths;
+ if (!paths) return null;
+
+ const articlesDir = path.join(outDir, reportBaseDir(ARTICLES_BASE));
+ const built = dirs(articlesDir).filter((id) => existsSync(path.join(articlesDir, id, "page.json")));
+ const isPublic = new Map<string, boolean>();
+ const publicNow = (id: string) => {
+ if (!isPublic.has(id)) {
+ const doc = readJson(path.join(paths.articlesDir, id, "report.json")) as { audience?: unknown } | null;
+ // lib/report/registry.ts articleAudience: absent = private.
+ isPublic.set(id, doc?.audience === "public");
+ }
+ return isPublic.get(id)!;
+ };
+ for (const id of built) {
+ if (!publicNow(id)) {
+ return `the homepage build carries the article "${id}", which is not public (its report.json's audience) — rebuild the homepage`;
+ }
+ }
+
+ const xPrivate = xPostsVisibility(opts.settings ?? {}) === "private";
+ const configs = new Map<string, boolean>();
+ const isX = (slug: string) => {
+ if (!configs.has(slug)) {
+ configs.set(slug, isXPostsChannel(readJson(path.join(paths.channelsDir, slug, "config.json")) as never));
+ }
+ return configs.get(slug)!;
+ };
+ const articlePrefix = ARTICLES_BASE;
+ for (const m of momentFiles(outDir)) {
+ const view = readJson(m.file) as { citedIn?: { href?: unknown }[] } | null;
+ for (const c of view?.citedIn ?? []) {
+ const href = typeof c.href === "string" ? c.href : "";
+ const id = href.startsWith(articlePrefix) ? href.slice(articlePrefix.length).split(/[/#]/)[0] : "";
+ if (!id || !publicNow(id)) {
+ return `the homepage build's moment ${m.key} is cited by ${id ? `the article "${id}", which is not public` : `"${href}", which is no public article`} — rebuild the homepage`;
+ }
+ }
+ if (xPrivate && isX(m.key.split("/")[0])) {
+ return `the homepage build's moment ${m.key} is an X post, and X posts are private (social.x.visibility) — rebuild the homepage`;
+ }
+ }
+ if (xPrivate) {
+ for (const slug of dirs(path.join(outDir, "media", "posts"))) {
+ if (isX(slug)) {
+ return `the homepage build carries media/posts/${slug}/, an X channel's captures, and X posts are private (social.x.visibility) — rebuild the homepage`;
+ }
+ }
+ }
+ return null;
+}
diff --git a/common/lib/ports.mjs b/common/lib/ports.mjs
@@ -40,6 +40,7 @@ export const PORTS = Object.freeze({
OLLAMA_STUB_PORT: { base: 11435, what: "digest-lane stub server in the editor e2e suite" },
HOMEPAGE_DEV_PORT: { base: 3030, what: "homepage real dev (`pnpm dev:homepage`)" },
HOMEPAGE_PORT: { base: 3031, what: "homepage static `serve out` (start:homepage)" },
+ HOMEPAGE_PRIVATE_PORT: { base: 3032, what: "the private homepage build, `serve out-private` (start:private)" },
HOMEPAGE_E2E_PORT: { base: 3040, what: "homepage's own Playwright suite" },
HUB_PORT: { base: 3041, what: "export's hub Playwright suite (e2e:hub)" },
REPORT_SITE_E2E_PORT: { base: 3042, what: "export's cited report-site Playwright suite (e2e:report)" },
diff --git a/common/publish/build.test.ts b/common/publish/build.test.ts
@@ -5,6 +5,7 @@ import {
existsSync,
mkdirSync,
mkdtempSync,
+ readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
@@ -272,3 +273,69 @@ test("buildHomepage: the source step sits between compose and next build; a refu
rmSync(root, { recursive: true, force: true });
}
});
+
+// The two homepage builds (release 26 A4), over a temp checkout whose compose
+// and next build are seams: the private one writes homepage/out-private (never
+// homepage/out), checks its stamp and takes its articles back out of public/;
+// the public one is audited and refused when it carries a private article.
+test("buildHomepage: --private builds into out-private and leaves public/ without articles; a public build carrying a private article is refused", async () => {
+ const root = mkdtempSync(path.join(os.tmpdir(), "build-homepage-private-"));
+ const savedPublic = process.env.HOMEPAGE_PUBLIC_DIR;
+ delete process.env.HOMEPAGE_PUBLIC_DIR;
+ try {
+ const home = path.join(root, "homepage");
+ const pub = path.join(home, "public");
+ const articlesDir = path.join(root, "transcripts", "reports");
+ const fakePaths = { monorepoRoot: root, articlesDir, channelsDir: path.join(root, "transcripts", "channels") } as Paths;
+ const put = (file: string, text: string) => {
+ mkdirSync(path.dirname(file), { recursive: true });
+ writeFileSync(file, text);
+ };
+ put(path.join(articlesDir, "pub-one", "report.json"), JSON.stringify({ audience: "public" }));
+ put(path.join(articlesDir, "priv-one", "report.json"), JSON.stringify({ audience: "private" }));
+ // homepage/out holds the deployable public build; it must not move.
+ put(path.join(home, "out", "index.html"), "<p>public</p>");
+
+ const envs: NodeJS.ProcessEnv[] = [];
+ // compose: the articles and the stamp it would write.
+ const compose = async (o: { private: boolean }) => {
+ for (const id of o.private ? ["pub-one", "priv-one"] : ["pub-one"]) put(path.join(pub, "articles", id, "page.json"), "{}");
+ put(path.join(pub, "homepage-build.json"), JSON.stringify({ audience: o.private ? "private" : "public" }));
+ return 0;
+ };
+ // next build: public/ copied into the out dir HOMEPAGE_DIST_DIR names.
+ const nextBuild = async (o: { env: NodeJS.ProcessEnv }) => {
+ envs.push(o.env);
+ const out = path.join(home, o.env.HOMEPAGE_DIST_DIR ?? "out");
+ rmSync(out, { recursive: true, force: true });
+ put(path.join(out, "index.html"), "<p>built</p>");
+ const { cpSync } = await import("node:fs");
+ cpSync(pub, out, { recursive: true });
+ return 0;
+ };
+ const logs: string[] = [];
+ const run = (o: Parameters<typeof buildHomepage>[0]) =>
+ buildHomepage({ paths: fakePaths, onLog: (l) => logs.push(l), compose, nextBuild, skipSource: true, clearSource: async () => {}, ...o });
+
+ assert.equal(await run({ private: true }), 0, logs.join("\n"));
+ assert.equal(envs[0].HOMEPAGE_DIST_DIR, "out-private");
+ assert.ok(existsSync(path.join(home, "out-private", "articles", "priv-one", "page.json")));
+ assert.equal(readFileSync(path.join(home, "out", "index.html"), "utf8"), "<p>public</p>", "homepage/out untouched");
+ for (const e of ["articles", "homepage-build.json"]) assert.ok(!existsSync(path.join(pub, e)), `public/${e} cleared`);
+
+ // The public build: clean, then one that carries a private article.
+ assert.equal(await run({}), 0, logs.join("\n"));
+ assert.equal(envs[1].HOMEPAGE_DIST_DIR, undefined);
+ put(path.join(pub, "articles", "priv-one", "page.json"), "{}");
+ const leaky = async () => {
+ put(path.join(pub, "homepage-build.json"), JSON.stringify({ audience: "public" }));
+ return 0;
+ };
+ logs.length = 0;
+ assert.equal(await run({ compose: leaky }), 1);
+ assert.match(logs.join("\n"), /refused: the homepage build carries the article "priv-one", which is not public/);
+ } finally {
+ if (savedPublic !== undefined) process.env.HOMEPAGE_PUBLIC_DIR = savedPublic;
+ rmSync(root, { recursive: true, force: true });
+ }
+});
diff --git a/common/publish/build.ts b/common/publish/build.ts
@@ -667,11 +667,21 @@ export function homepageOutDir(paths: Paths): string {
return path.join(homepageDir(paths), "out");
}
-function homepageEnv(paths: Paths): NodeJS.ProcessEnv {
+// The PRIVATE homepage build's out dir (release 26 A4): every published
+// article, served locally (`pnpm --filter homepage start:private`), never
+// deployed — nothing ships it, and its stamp refuses it if anything tried.
+export const HOMEPAGE_PRIVATE_OUT = "out-private";
+
+export function homepagePrivateOutDir(paths: Paths): string {
+ return path.join(homepageDir(paths), HOMEPAGE_PRIVATE_OUT);
+}
+
+function homepageEnv(paths: Paths, extra: Record<string, string> = {}): NodeJS.ProcessEnv {
return {
...process.env,
NODE_ENV: "production",
TRANSCRIPTS_DIR: paths.transcriptsDir,
+ ...extra,
};
}
@@ -680,10 +690,15 @@ function homepageEnv(paths: Paths): NodeJS.ProcessEnv {
* summary), as a child. Reads the LMDB index as it stands: run `archilyzer
* index` first when it is stale. Returns the exit code.
*/
-export async function composeHomepage(opts: PublishOpts = {}): Promise<number> {
+export async function composeHomepage(opts: PublishOpts & { private?: boolean } = {}): Promise<number> {
const { paths, onLog, signal } = resolved(opts);
return runSteps(onLog, signal, [
- { command: "pnpm", args: ["run", "compose"], cwd: homepageDir(paths), env: homepageEnv(paths) },
+ {
+ command: "pnpm",
+ args: ["run", "compose", ...(opts.private ? ["--", "--private"] : [])],
+ cwd: homepageDir(paths),
+ env: homepageEnv(paths),
+ },
]);
}
@@ -706,15 +721,42 @@ export async function composeHomepage(opts: PublishOpts = {}): Promise<number> {
* install) builds with the empty state too. `publishSource` / `clearSource`
* are the test's seams.
*/
+//
+// THE PUBLIC BUILD IS AUDITED (release 26 A4): after `next build`,
+// homepage/out is held to builtHomepageProblem with the article store and the
+// channel configs — no private build, no private article, no moment a private
+// article cites, no X post while X posts are private — and the build fails on
+// a problem, as a site's does.
+//
+// `private` is the PRIVATE build: compose carries every published article
+// (`compose homepage --private`, stamped `audience: "private"`), the source is
+// left as it is, and `next build` writes homepage/out-private
+// (HOMEPAGE_DIST_DIR, homepage/next.config.ts) — homepage/out, the bundle a
+// deploy ships, is never touched. Afterwards the private articles are taken
+// out of homepage/public again, so no later build of the tree (a
+// `build:nodata`) can pick them up.
export async function buildHomepage(
opts: PublishOpts & {
skipSource?: boolean;
+ private?: boolean;
publishSource?: (o: PublishOpts & { noRepository?: "refuse" | "empty" }) => Promise<number>;
clearSource?: (o: PublishOpts) => Promise<void>;
+ // The next build step; default `pnpm exec next build` in homepage/, through
+ // the heavy slot. The test's seam, as `compose` is (default composeHomepage).
+ nextBuild?: (o: { env: NodeJS.ProcessEnv; onLog: (line: string) => void; signal: AbortSignal }) => Promise<number>;
+ compose?: (o: { private: boolean }) => Promise<number>;
} = {},
): Promise<number> {
const { paths, onLog, signal } = resolved(opts);
- const code = await composeHomepage({ paths, onLog, signal });
+ const nextBuild =
+ opts.nextBuild ??
+ ((o: { env: NodeJS.ProcessEnv; onLog: (line: string) => void; signal: AbortSignal }) =>
+ runSteps(o.onLog, o.signal, [
+ heavyGated(paths, { command: "pnpm", args: ["exec", "next", "build"], cwd: homepageDir(paths), env: o.env }),
+ ]));
+ const compose = opts.compose ?? ((o: { private: boolean }) => composeHomepage({ paths, onLog, signal, private: o.private }));
+ if (opts.private) return buildPrivateHomepage(paths, onLog, signal, nextBuild, compose);
+ const code = await compose({ private: false });
if (code !== 0) return code;
// Loaded lazily: the source step pulls nothing the other publish entry
// points need, and it imports this module's types.
@@ -729,14 +771,52 @@ export async function buildHomepage(
return sourceCode || 1;
}
}
- return runSteps(onLog, signal, [
- heavyGated(paths, {
- command: "pnpm",
- args: ["exec", "next", "build"],
- cwd: homepageDir(paths),
- env: homepageEnv(paths),
- }),
- ]);
+ const built = await nextBuild({ env: homepageEnv(paths), onLog, signal });
+ if (built !== 0) return built;
+ const { homepageAudienceProblem } = await import("../lib/builtHomepage");
+ const problem = homepageAudienceProblem(homepageOutDir(paths), { paths, settings: getSettings() });
+ if (problem) {
+ onLog(`[homepage] refused: ${problem}\n`);
+ return 1;
+ }
+ return 0;
+}
+
+// The private homepage build (buildHomepage's `private`).
+async function buildPrivateHomepage(
+ paths: Paths,
+ onLog: (line: string) => void,
+ signal: AbortSignal,
+ nextBuild: (o: { env: NodeJS.ProcessEnv; onLog: (line: string) => void; signal: AbortSignal }) => Promise<number>,
+ compose: (o: { private: boolean }) => Promise<number>,
+): Promise<number> {
+ try {
+ const code = await compose({ private: true });
+ if (code !== 0) return code;
+ const built = await nextBuild({ env: homepageEnv(paths, { HOMEPAGE_DIST_DIR: HOMEPAGE_PRIVATE_OUT }), onLog, signal });
+ if (built !== 0) return built;
+ const { homepageBuildAudience } = await import("../lib/builtHomepage");
+ if (homepageBuildAudience(homepagePrivateOutDir(paths)) !== "private") {
+ onLog(`[homepage] the private build in ${homepagePrivateOutDir(paths)} carries no private stamp\n`);
+ return 1;
+ }
+ onLog(`[homepage] private build in ${homepagePrivateOutDir(paths)} — serve it with \`pnpm --filter homepage start:private\`; it is never deployed.\n`);
+ return 0;
+ } finally {
+ await clearHomepageArticles(paths);
+ }
+}
+
+// The articles compose wrote into homepage/public (and its stamp): removed
+// after a private build. A public build composes them again.
+export async function clearHomepageArticles(paths: Paths): Promise<void> {
+ const { reportPublicEntries } = await import("./composeReports");
+ const { ARTICLES_BASE } = await import("../lib/report/routes");
+ const { HOMEPAGE_BUILD_STAMP } = await import("../lib/builtHomepage");
+ const pub = process.env.HOMEPAGE_PUBLIC_DIR ?? path.join(homepageDir(paths), "public");
+ for (const entry of [...reportPublicEntries(ARTICLES_BASE), HOMEPAGE_BUILD_STAMP]) {
+ await rm(path.join(pub, entry), { recursive: true, force: true });
+ }
}
// The last build's copy of the source, out of homepage/out: a refused source
diff --git a/common/publish/deployStage.test.ts b/common/publish/deployStage.test.ts
@@ -56,6 +56,8 @@ function fixture(): Fixture {
monorepoRoot: root,
// Never the checkout's corpus: the local-destination guard resolves it.
transcriptsDir: path.join(root, "transcripts"),
+ articlesDir: path.join(root, "transcripts", "reports"),
+ channelsDir: path.join(root, "transcripts", "channels"),
exportDir: path.join(root, "export"),
exportBuildsDir: path.join(root, "builds"),
sitesDir,
@@ -622,6 +624,34 @@ test("the homepage's local deploy copies homepage/out into ARCHILYZER_HOMEPAGE_O
}
});
+// Release 26 A4: a homepage build stamped private (`build homepage --private`)
+// is never shipped, and nor is a public one carrying a private article.
+test("the homepage's deploy refuses a private build, and a public one carrying a private article", async () => {
+ const fx = fixture();
+ try {
+ const out = path.join(fx.root, "homepage", "out");
+ mkdirSync(path.join(out, "source"), { recursive: true });
+ writeFileSync(path.join(out, "index.html"), "<!doctype html>");
+ writeFileSync(path.join(out, "source", "index.html"), "<!doctype html>");
+ writeJson(path.join(fx.paths.exportBuildsDir, "_homepage", "built.json"), {
+ ...stampFields("_homepage", "homepage"),
+ stampId: "home-2",
+ corpusGeneratedAt: null,
+ });
+ const req: DeployStageRequest = { kind: "deploy-homepage", target: "_homepage", to: "local" };
+ const env = { ARCHILYZER_HOMEPAGE_OUT: path.join(fx.root, "homepage-out") };
+ writeJson(path.join(out, "homepage-build.json"), { audience: "private" });
+ await refused(runDeployStage(ctx(fx, env), req), 3, /holds a private homepage build .* never deployed/);
+ writeJson(path.join(out, "homepage-build.json"), { audience: "public" });
+ writeJson(path.join(out, "articles", "secret", "page.json"), {});
+ writeJson(path.join(fx.paths.articlesDir, "secret", "report.json"), { audience: "private" });
+ await refused(runDeployStage(ctx(fx, env), req), 3, /carries the article "secret", which is not public/);
+ assert.equal(existsSync(env.ARCHILYZER_HOMEPAGE_OUT), false);
+ } finally {
+ fx.cleanup();
+ }
+});
+
test("the hub: its project, its bundle, and every tombstone probed plain and busted", async () => {
const fx = fixture();
try {
diff --git a/common/publish/deployStage.ts b/common/publish/deployStage.ts
@@ -45,6 +45,7 @@
// the sentence the log already ends on, word for word, and stageRun.ts does
// not print it again.
+import { getSettings } from "../lib/settings";
import os from "node:os";
import path from "node:path";
import { existsSync, readdirSync, readFileSync } from "node:fs";
@@ -460,7 +461,8 @@ export async function runDeployStage(
if (problem) refuse(`${problem.replace(/^export\/out/, outDir)}.`, 3);
} else {
const problem =
- builtHomepageProblem(outDir) ?? (await (await import("./source")).publishedSourceProblem(paths, outDir));
+ builtHomepageProblem(outDir, { paths, settings: getSettings() }) ??
+ (await (await import("./source")).publishedSourceProblem(paths, outDir));
if (problem) refuse(problem, 3);
}
diff --git a/common/publish/stageBodies.ts b/common/publish/stageBodies.ts
@@ -166,7 +166,7 @@ export async function readNeedsInput(
deployed: await readDeployedFile(paths, HOMEPAGE_TARGET),
changedChannels: [],
configChangedAt: null,
- bundleProblem: homeBuilt ? builtHomepageProblem(homepageOutDir(paths)) : null,
+ bundleProblem: homeBuilt ? builtHomepageProblem(homepageOutDir(paths), { paths, settings: getSettings() }) : null,
mainHead: opts.mainHead ? await mainHeadOf(paths) : null,
},
};
diff --git a/homepage/next.config.ts b/homepage/next.config.ts
@@ -23,6 +23,11 @@ const nextConfig: NextConfig = {
// this app also uses.
turbopack: { root: path.join(__dirname, "..") },
output: "export",
+ // The PRIVATE build (release 26 A4: `archilyzer build homepage --private`)
+ // writes its export to homepage/out-private, never homepage/out — the bundle
+ // a deploy ships. With output "export", Next takes a custom distDir as the
+ // export directory and keeps its build files in .next.
+ ...(process.env.HOMEPAGE_DIST_DIR ? { distDir: process.env.HOMEPAGE_DIST_DIR } : {}),
trailingSlash: true,
images: { unoptimized: true },
staticPageGenerationTimeout: 600, // Increase timeout to 600 seconds
diff --git a/homepage/package.json b/homepage/package.json
@@ -12,6 +12,7 @@
"build": "next build",
"build:nodata": "next build",
"start": "serve out -l ${HOMEPAGE_PORT:-3031}",
+ "start:private": "serve out-private -l ${HOMEPAGE_PRIVATE_PORT:-3032}",
"lint": "eslint",
"test": "tsx --test \"app/**/*.test.ts\"",
"e2e": "node ../scripts/queue-lock.mjs --name e2e-homepage --estimate 1500 --ports HOMEPAGE_E2E_PORT:3040 -- playwright test",