import assert from "node:assert/strict"; import { readFile, readdir, lstat } from "node:fs/promises"; import { Script } from "node:vm"; const root = new URL("../", import.meta.url); const site = new URL("website/", root); const pkg = JSON.parse(await readFile(new URL("package.json", root), "utf8")); const html = await readFile(new URL("index.html", site), "utf8"); // Only the public landing page is uploaded; workspace reports must never enter it. const files = await readdir(site); assert.deepEqual(files.sort(), [".nojekyll", "CNAME", "index.html"]); for (const file of files) assert.ok((await lstat(new URL(file, site))).isFile(), `Unexpected site object: ${file}`); const domain = (await readFile(new URL("CNAME", site), "utf8")).trim(); assert.equal(new URL(pkg.homepage).hostname, domain); assert.ok(html.includes(``), "Website version differs from package.json"); for (const version of html.match(/\bv\d+\.\d+\.\d+(?:-[\w.]+)?/g) || []) assert.equal(version, `v${pkg.version}`, "Visible website version is stale"); assert.ok(html.includes(``)); assert.ok(html.includes('')); assert.ok(!/<(?:script|img|iframe|link)\b[^>]*(?:src|href)=["'](?:https?:)?\/\//i.test( html.replace(/]*rel="canonical"[^>]*>/gi, "")), "The single-file site must not depend on remote assets"); const ids = [...html.matchAll(/\bid="([^"]+)"/g)].map(match => match[1]); assert.equal(new Set(ids).size, ids.length, "Duplicate page IDs"); for (const [, id] of html.matchAll(/href="#([^"]+)"/g)) assert.ok(ids.includes(id), `Broken page anchor: ${id}`); for (const [, id] of html.matchAll(/data-copy="([^"]+)"/g)) assert.ok(ids.includes(id), `Copy button target missing: ${id}`); for (const [, script] of html.matchAll(/