check an incremental render against a fresh one with shared names masked
Signed-off-by: dawn <90008@klbr.net>
9 unmodified lines10111213141415161718199 unmodified linesrepo may cost on disk.
what every page of a repo shows the same way, the sidebar, is stored once per content in`<repo>/_shared/<hash>.json` and isn't a page's own read, so a change to it re-rendersnothing.nothing. a page kept from an older render names an older copy, so check an incremental runagainst a fresh one of the same generation with
node verify.mjs <incremental out> <fresh out>
node --test123456789101112131415161718192021222324252627282930313233343536373839#!/usr/bin/env node// checks an incremental render against a fresh one of the same generation: every page both// kept reads the same once shared names are masked, and every shared file a page names is// in its repo's store// node verify.mjs <incremental out> <fresh out>import { existsSync, readdirSync, readFileSync, realpathSync } from "node:fs";import path from "node:path";import { gunzipSync } from "node:zlib";import { readJson } from "./common.mjs";import { maskShared, SHARED_DIR, sharedNamed } from "./shared.mjs";
const [incremental, fresh] = process.argv.slice(2);const html = (out, state, route) => { const dir = realpathSync(path.join(out, "site", state.did)); const file = route === state.prefix ? "index.html" : route.slice(state.prefix.length + 1) + ".html"; return maskShared(gunzipSync(readFileSync(path.join(dir, file + ".gz"))).toString());};
const result = { compared: 0, differ: [], only_incremental: 0, only_fresh: 0, missing_shared: [] };for (const name of readdirSync(path.join(incremental, "state"))) { const a = readJson(path.join(incremental, "state", name)); const b = readJson(path.join(fresh, "state", name)); if (!a?.pages || !b?.pages) continue; const dir = realpathSync(path.join(incremental, "site", a.did)); for (const hash of sharedNamed(a.pages)) { if (!existsSync(path.join(dir, SHARED_DIR, hash + ".json.gz"))) result.missing_shared.push(`${a.prefix} ${hash}`); } for (const route of Object.keys(a.pages)) { if (!(route in b.pages)) { result.only_incremental++; continue; } result.compared++; if (html(incremental, a, route) !== html(fresh, b, route)) result.differ.push(route); } result.only_fresh += Object.keys(b.pages).filter((route) => !(route in a.pages)).length;}console.log(JSON.stringify(result));process.exitCode = result.differ.length > 0 || result.missing_shared.length > 0 ? 1 : 0;