diff --git a/docs/README.md b/docs/README.md index 71fab8387d9..b86cdb07636 100644 --- a/docs/README.md +++ b/docs/README.md @@ -134,7 +134,7 @@ Netlify runs `scripts/netlify-ignore-build.sh`, then `scripts/netlify-build.sh` - Production builds `next` when `docs/` changed since the last production build that passed, or when that build cannot be found. It leaves out the dev docs and the lines. - A deploy preview builds when its pull request changes `docs/`. -- `node scripts/smoke_deployed_site.mts [--commit ]` checks a deployed site for what only Netlify answers: redirects, markdown twins, a retired page's markdown twin, the migration-notes range, the 404 page, `/commit.txt`, and the API reference's network URLs, which must reach the folder `developer_version_config.json` maps each network to. It needs no install. +- `node scripts/smoke_deployed_site.mts [--commit ]` checks a deployed site for what only Netlify answers: redirects, markdown twins, a retired page's markdown twin, the migration-notes range, the 404 page, `/commit.txt`, and the API reference's network URLs, which must reach the folder `developer_version_config.json` maps each network to; a TypeScript folder's URL, with or without its slash, must reach the index page `scripts/split_typescript_api.mjs` writes into it. It needs no install. - A retired page's markdown twin (`.md`) follows the page's `netlify.toml` redirect: the markdown edge function sends it to the replacement's twin, or to the replacement when that has no twin. A served twin is never redirected. - `netlify/` holds the subscribe function and the markdown and migration-notes edge functions. `yarn dev:netlify` runs them locally; the subscribe function reads `BREVO_API_KEY` from a `.env` made from `.env.template`. - Failed production deploys post to the `#docs-alert` Slack channel. These are site owners' actions, in the Netlify UI: diff --git a/docs/scripts/__tests__/check_built_site.test.mts b/docs/scripts/__tests__/check_built_site.test.mts index 3e24a2bebce..a02739be502 100644 --- a/docs/scripts/__tests__/check_built_site.test.mts +++ b/docs/scripts/__tests__/check_built_site.test.mts @@ -136,6 +136,7 @@ function fixtureBuild(): { dir: string; write: (url: string, html: string) => vo write(`/operate/v5.2.0/${opPage}`, shell("") + config); for (const v of ["", "v5.2.0/"]) write(`/operate/${v}operators/solo-sequencer/install-toolchain`, shell("") + "v6.0.0"); for (const page of MATH_PAGES) write(`/developers/${page}`, shell("") + math); + write("/typescript-api/v6.0.0/index", ""); return { dir, write }; } const math = "

rollup

"; @@ -191,6 +192,7 @@ test("main passes a healthy build and names each regression it is for", () => { (b) => fs.rmSync(path.join(b.dir, `developers/${MATH_PAGES[1]}.html`)), /MATH_PAGES docs\/foundational-topics\/ethereum-aztec-messaging: no built page renders math there/, ], + ["TypeScript folder page gone", (b) => fs.rmSync(path.join(b.dir, "typescript-api/v6.0.0/index.html")), /\/typescript-api\/v6\.0\.0\/: no index\.html/], ]; for (const [name, breakIt, expected] of breaks) { const b = fixtureBuild(); diff --git a/docs/scripts/__tests__/smoke_deployed_site.test.mts b/docs/scripts/__tests__/smoke_deployed_site.test.mts index 09f0a474ef3..dab2e5b9aff 100644 --- a/docs/scripts/__tests__/smoke_deployed_site.test.mts +++ b/docs/scripts/__tests__/smoke_deployed_site.test.mts @@ -32,6 +32,9 @@ function apiRoutes(origin: string): Record { for (const rest of ["/noir_aztec/index.html", `/${fn}.md`, "", "/"]) routes[`/aztec-nr-api/${network}${rest}`] = redirect(`${origin}/aztec-nr-api/${folder}/${rest.replace(/^\//, "")}`, 302); routes[`/typescript-api/${network}/llms.txt`] = redirect(`${origin}/typescript-api/${folder}/llms.txt`, 302); + for (const rest of ["", "/"]) routes[`/typescript-api/${network}${rest}`] = redirect(`${origin}/typescript-api/${folder}/`, 302); + routes[`/typescript-api/${folder}`] = redirect(`${origin}/typescript-api/${folder}/`); + routes[`/typescript-api/${folder}/`] = send(200, "text/html; charset=utf-8", `llms.txt`); routes[`/aztec-nr-api/${network}/${fn}`] = (req, res) => req.headers.accept?.includes("text/markdown") ? send(200, "text/markdown; charset=utf-8", API_TWIN, { vary: "Accept" })(req, res) @@ -127,6 +130,20 @@ test("each broken behaviour fails its own check, and a redirect off the site is assert.deepEqual(elsewhere.hits, []); }); +test("a TypeScript folder that answers 404, or a page that is not its index, fails B8", async () => { + const folder = folderOf("mainnet"); + const missing = await serve((o) => ({ ...netlifyRoutes(o), [`/typescript-api/${folder}/`]: send(404, "text/html; charset=utf-8", "Page Not Found") })); + assert.match((await run([missing.origin])).out, new RegExp(`^FAIL B8 .*/typescript-api/${folder}/: got 404`, "m")); + const other = await serve((o) => ({ ...netlifyRoutes(o), [`/typescript-api/${folder}/`]: send(200, "text/html; charset=utf-8", "") })); + assert.match((await run([other.origin])).out, new RegExp(`^FAIL B8 .*/typescript-api/${folder}/: not the folder's index page`, "m")); + const testnet = folderOf("testnet"); + const gone = send(404, "text/html; charset=utf-8", "Page Not Found"); + const bare = await serve((o) => ({ ...netlifyRoutes(o), "/typescript-api/testnet": gone, [`/typescript-api/${testnet}`]: gone })); + const out = (await run([bare.origin])).out; + assert.match(out, /^FAIL B8 .*\/typescript-api\/testnet: expected 302, got 404/m); + assert.match(out, new RegExp(`^FAIL B8 .*/typescript-api/${testnet}: expected 301, got 404`, "m")); +}); + test("a request that gets no answer is retried once, and only its check's line says so", async () => { const seen = new Set(); const first = (key: string) => !seen.has(key) && Boolean(seen.add(key)); diff --git a/docs/scripts/__tests__/split_typescript_api.test.mts b/docs/scripts/__tests__/split_typescript_api.test.mts index 3faa4629f2a..c8f139bc75a 100644 --- a/docs/scripts/__tests__/split_typescript_api.test.mts +++ b/docs/scripts/__tests__/split_typescript_api.test.mts @@ -1,9 +1,11 @@ import assert from "node:assert/strict"; import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; import { test } from "node:test"; import networkDocs from "../../src/network_docs.js"; import packages from "../typescript_api_generation/packages.js"; -import { declarations, splitPackage } from "../split_typescript_api.mjs"; +import { declarations, folderPage, main, splitPackage } from "../split_typescript_api.mjs"; const pkg = [ "# @aztec/foundation", @@ -77,6 +79,47 @@ test("every declaration of the committed reference lands in exactly one page", ( } }); +test("each served folder gets an index page listing the package files it holds, its indexes and the guide", (t) => { + t.mock.method(console, "log", () => {}); + const json = (name: string) => JSON.parse(fs.readFileSync(new URL(`../../${name}.json`, import.meta.url), "utf8")); + const config = json("developer_version_config"); + const [developer] = networkDocs.docsInstances(config, json("network_version_config"), false); + const served = networkDocs.apiReferenceDirs(developer, json("developer_versions")).filter((d) => d.kind === "typescript"); + const folder = networkDocs.networkApiFolder(config, "mainnet"); + assert.ok(folder, "developer_version_config.json maps no mainnet version"); + const build = fs.mkdtempSync(path.join(os.tmpdir(), "ts-folder-page-")); + try { + for (const { dir } of served) { + fs.mkdirSync(path.join(build, dir), { recursive: true }); + fs.writeFileSync(path.join(build, dir, "aztec.js.md"), pkg); + } + const dir = path.join(build, "typescript-api", folder); + for (const file of ["foundation.md", "llm-summary.txt"]) fs.writeFileSync(path.join(dir, file), pkg); + assert.equal(main(build, {}), 0); + for (const { dir } of served) assert.ok(fs.existsSync(path.join(build, dir, "index.html")), dir); + const html = fs.readFileSync(path.join(dir, "index.html"), "utf8"); + const hrefs = [...html.matchAll(/href="([^"]+)"/g)].map((m) => m[1]); + assert.deepEqual(hrefs, [ + `/typescript-api/${folder}/llms.txt`, + "/developers/docs/aztec-js/typescript_api_reference", + `/typescript-api/${folder}/aztec.js.md`, + `/typescript-api/${folder}/foundation.md`, + `/typescript-api/${folder}/llm-summary.txt`, + ]); + assert.match(html, new RegExp(`^\\n[\\s\\S]*TypeScript API reference, ${folder}`)); + assert.match(html, //); + assert.match(html, />@aztec-labs\/aztec\.js<\/a>: Main SDK for building Aztec applications { + const html = folderPage({ dir: "typescript-api/v1.0.0", version: "v1.0.0", packages: [{ file: "a.md", npmName: "@x/a", description: '