/** * The two things standard.site reads out of a publication's HTML: the * well-known key naming the publication record, and the link tag naming a * post's document record. * * The absent cases are the ones worth pinning. An href with nothing behind it * is a claim a verifier follows, and CloudFront answers a genuinely missing * key with the app's index.html and a 200, so from outside the network a * wrong answer and a right one look the same. * * Run with `npm test`. */ import { test, after } from "node:test"; import assert from "node:assert/strict"; import { execFileSync } from "node:child_process"; import { existsSync, readFileSync, readdirSync, rmSync, writeFileSync, } from "node:fs"; import { join } from "node:path"; import { fileURLToPath } from "node:url"; const web = fileURLToPath(new URL("../", import.meta.url)); const WELL_KNOWN = join(web, "public/.well-known/site.standard.publication"); const POSTS = join(web, "src/content/blog"); // Nothing resolvable. A DID that looked real would be followed by the first // person who copied it out of here. const DOCUMENT = "at://did:plc:example/site.standard.document/fakerkey"; // A post that has been published, which the tree may or may not have one of on // any given day. Written for the build and taken away again. Under web/.astro, // which is gitignored and already the build's scratch - not os.tmpdir(), // because the last thing a build does is rename its output into place and a // rename across filesystems is EXDEV. const fixture = join(POSTS, "fixture-borborygmus.md"); const outDir = join(web, ".astro/standard-site"); writeFileSync( fixture, `--- title: Fixture borborygmus description: Fixture for the standard.site tests. Removed when they finish. publishDate: 2026-01-01 atUri: ${DOCUMENT} --- Borborygmus quincunx widdershins. `, ); // Which posts claim a record, read while the fixture is still on disk. Slugs // are filenames, which is what Astro's glob loader makes its ids from. Sequoia // writes the value quoted, so the quotes come off. const published = new Map( readdirSync(POSTS) .filter((file) => file.endsWith(".md")) .map((file) => [ file.replace(/\.md$/, ""), /^atUri:\s*["']?(at:\/\/\S+?)["']?\s*$/m.exec( readFileSync(join(POSTS, file), "utf8"), )?.[1], ]), ); try { execFileSync( join(web, "node_modules/.bin/astro"), ["build", "--outDir", outDir], { cwd: web, stdio: "pipe", }, ); } finally { rmSync(fixture, { force: true }); } after(() => rmSync(outDir, { recursive: true, force: true })); test("a post links to its record, and only if it has one", () => { const built = readdirSync(join(outDir, "blog"), { withFileTypes: true }) .filter((entry) => entry.isDirectory()) .map((entry) => entry.name); assert.ok(built.length > 1, "the fixture and at least one post should build"); for (const slug of built) { const html = readFileSync(join(outDir, "blog", slug, "index.html"), "utf8"); const atUri = published.get(slug); if (atUri) { assert.match( html, new RegExp(` { // `sequoia init` writes this file and the URI in sequoia.json in the same // step, and nothing rewrites either afterwards. They drift when one is // edited by hand, and the symptom is a publication nobody can verify. if (!existsSync(WELL_KNOWN)) return; // Trimmed: the end-of-file-fixer hook adds a newline to every file in the // repo, this one included, so the bytes on disk are never exactly the URI. const body = readFileSync(WELL_KNOWN, "utf8").trim(); assert.match( body, /^at:\/\/did:\S+\/site\.standard\.publication\/\S+$/, "the key must be one AT-URI and nothing else", ); assert.equal( body, JSON.parse(readFileSync(join(web, "sequoia.json"), "utf8")).publicationUri, ); assert.ok( existsSync(join(outDir, ".well-known/site.standard.publication")), "public/.well-known did not survive the build", ); });