import { spawnSync } from "node:child_process"; import { cp, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import path from "node:path"; import { describe, expect, it } from "vitest"; const INPUTS = [ "README.md", "docs/accessibility/manual-checklist.md", "docs/architecture/review-ledger.json", "docs/architecture/review-evidence.md", ]; /** Runs verify:documentation on a copy of its inputs, `mutate` applied to README.md. */ async function verifyWithReadme(mutate: (readme: string) => string) { const root = await mkdtemp(path.join(tmpdir(), "documentation-readiness-")); try { for (const input of INPUTS) await cp(input, path.join(root, input), { recursive: true }); const readme = path.join(root, "README.md"); await writeFile(readme, mutate(await readFile(readme, "utf8"))); return spawnSync(process.execPath, [path.resolve("scripts/verify-documentation-readiness.ts")], { cwd: root, encoding: "utf8", }); } finally { await rm(root, { recursive: true, force: true }); } } // 1101/14-06. A route missing from a scope document used to fail with only // "canonical scoped-review evidence is incomplete", which points at the // diagram review instead of the document to fix. describe("verify:documentation failure output (1101/14-06)", () => { it("passes the documents as they are", async () => { const result = await verifyWithReadme((readme) => readme); expect(result.status, result.stderr).toBe(0); }); it("names the document and the route ID it is missing", async () => { const result = await verifyWithReadme((readme) => readme.replaceAll("`EXAMPLES_PLATFORM`", "")); expect(result.status).toBe(1); expect(result.stderr).toContain("README.md does not name route IDs: EXAMPLES_PLATFORM"); expect(result.stderr).toMatch(/FAIL_UNVERIFIED \(failed: route scope\)/u); expect(result.stderr).not.toContain("scoped-review evidence"); }); it("names every failed check", async () => { const result = await verifyWithReadme((readme) => readme.replaceAll("`EXAMPLES_PLATFORM`", "").replaceAll("`RELEASE_TARGET`", ""), ); expect(result.stderr).toContain("README.md does not name: RELEASE_TARGET"); expect(result.stderr).toMatch(/\(failed: route scope, runtime variables\)/u); }); });