Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <base-url> [--commit <sha>]` 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 <base-url> [--commit <sha>]` 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 (`<page>.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:
Expand Down
2 changes: 2 additions & 0 deletions docs/scripts/__tests__/check_built_site.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -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("") + "<code>v6.0.0</code>");
for (const page of MATH_PAGES) write(`/developers/${page}`, shell("") + math);
write("/typescript-api/v6.0.0/index", "<!doctype html>");
return { dir, write };
}
const math = "<p>rollup <span class=katex><span class=katex-html aria-hidden=true>n</span></span></p>";
Expand Down Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions docs/scripts/__tests__/smoke_deployed_site.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ function apiRoutes(origin: string): Record<string, Handler> {
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", `<a href="/typescript-api/${folder}/llms.txt">llms.txt</a>`);
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)
Expand Down Expand Up @@ -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", "<html></html>") }));
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<string>();
const first = (key: string) => !seen.has(key) && Boolean(seen.add(key));
Expand Down
45 changes: 44 additions & 1 deletion docs/scripts/__tests__/split_typescript_api.test.mts
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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(`^<!doctype html>\\n<html lang="en">[\\s\\S]*<title>TypeScript API reference, ${folder}</title>`));
assert.match(html, /<meta name="color-scheme" content="light dark">/);
assert.match(html, />@aztec-labs\/aztec\.js<\/a>: Main SDK for building Aztec applications</);
} finally {
fs.rmSync(build, { recursive: true, force: true });
}
});

test("the index page escapes the text it is built from", () => {
const html = folderPage({ dir: "typescript-api/v1.0.0", version: "v1.0.0", packages: [{ file: "a.md", npmName: "@x/a", description: '<script>"&' }], summary: false });
assert.match(html, /: &lt;script&gt;&quot;&amp;<\/li>/);
assert.doesNotMatch(html, /<script>|llm-summary/);
});

test("packages are ours only under the documented scope", () => {
assert.equal(packages.npmName("aztec.js"), "@aztec-labs/aztec.js");
assert.ok(packages.isDocumentedPackage("@aztec-labs/stdlib"));
Expand Down
5 changes: 5 additions & 0 deletions docs/scripts/check_built_site.mts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ export function main(buildDir: string, model: Model, log: (line: string) => void
for (const dir of leaks) problems.push(`${dir}: served by production, which serves released docs only`);
}
problems.push(...mathProblems(buildDir));
const [developer] = networkDocs.docsInstances(model.configs.developer, model.configs.network, model.production);
for (const { kind, dir } of networkDocs.apiReferenceDirs(developer, model.cut.developer)) {
if (kind === "typescript" && !fs.existsSync(path.join(buildDir, dir, "index.html")))
problems.push(`/${dir}/: no index.html, so the folder's URL answers 404 (split_typescript_api.mjs writes it)`);
}

for (const problem of problems) log(problem);
const layout = model.production ? "production" : "non-production";
Expand Down
8 changes: 7 additions & 1 deletion docs/scripts/smoke_deployed_site.mts
Original file line number Diff line number Diff line change
Expand Up @@ -200,10 +200,16 @@ export const CHECKS: Check[] = [
problems.push(`${expected}: got ${page.status} ${page.type}, expected 200 ${type}`);
return undefined;
};
for (const network of folders.keys()) {
// The build writes each TypeScript folder's index.html; Netlify 301s the folder without its slash to it.
const indexPage = (page: Reply | undefined, folder: string) => {
if (page && !page.body.includes(`href="/typescript-api/${folder}/llms.txt"`)) problems.push(`${page.url.pathname}: not the folder's index page, which links its llms.txt`);
};
for (const [network, folder] of folders) {
await lands("aztec-nr-api", network, "/noir_aztec/index.html", "text/html");
await lands("typescript-api", network, "/llms.txt", "text/plain");
for (const rest of ["", "/"]) indexPage(await lands("typescript-api", network, rest, "text/html"), folder);
}
for (const folder of new Set(folders.values())) redirectTo(await get(`/typescript-api/${folder}`, BROWSER_ACCEPT), `/typescript-api/${folder}/`, problems);
await lands("aztec-nr-api", "mainnet", "", "text/html");
await lands("aztec-nr-api", "mainnet", "/", "text/html");
const twin = await lands("aztec-nr-api", "mainnet", `/${API_PAGE}.md`, "text/markdown");
Expand Down
44 changes: 38 additions & 6 deletions docs/scripts/split_typescript_api.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Splits each package file of the TypeScript API reference in a build (typescript-api/<folder>/<pkg>.md,
// up to 235 KB) into one page per exported name, <pkg>/<Name>.md, which an agent can fetch whole.
// up to 235 KB) into one page per exported name, <pkg>/<Name>.md, which an agent can fetch whole, and
// writes the folder's index.html, which the generator does not make.

import fs from "node:fs";
import { createRequire } from "node:module";
Expand Down Expand Up @@ -68,7 +69,36 @@ export function splitPackage(markdown, { pkg, npmName: npm, version, index }) {
});
}

/** Splits every documented package of each TypeScript folder `apiReferenceDirs` lists; returns the exit code. */
const escapeHtml = (text) => text.replace(/[&<>"]/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;" })[c]);

/**
* The landing page of a TypeScript API folder: its scoped index, the guide, each package file and the summary.
*
* @param {{dir: string, version: string, packages: {file: string, npmName: string, description: string}[], summary: boolean}} folder
* `dir` is the folder's path under the site root; `packages` the package files it holds, in order;
* `summary` whether it holds llm-summary.txt
* @returns {string}
*/
export function folderPage({ dir, version, packages, summary }) {
const link = (file, text) => `<a href="/${escapeHtml(dir)}/${escapeHtml(file)}">${escapeHtml(text)}</a>`;
return [
"<!doctype html>",
'<html lang="en">',
'<meta charset="utf-8">',
'<meta name="viewport" content="width=device-width, initial-scale=1">',
'<meta name="color-scheme" content="light dark">',
`<title>TypeScript API reference, ${escapeHtml(version)}</title>`,
`<h1>TypeScript API reference, ${escapeHtml(version)}</h1>`,
`<p>The Aztec TypeScript packages, one markdown file each. ${link(SCOPED_API_INDEX, "llms.txt")} links a page per exported name. The <a href="/developers/docs/aztec-js/typescript_api_reference">TypeScript API reference</a> guide explains the packages.</p>`,
"<ul>",
...packages.map((p) => `<li>${link(p.file, p.npmName)}: ${escapeHtml(p.description)}</li>`),
"</ul>",
...(summary ? [`<p>${link("llm-summary.txt", "llm-summary.txt")}: a summary of every package.</p>`] : []),
"",
].join("\n");
}

/** Splits every documented package of each TypeScript folder `apiReferenceDirs` lists and writes its index page; returns the exit code. */
export function main(buildDir, env = process.env) {
const config = (name) => JSON.parse(fs.readFileSync(new URL(`../${name}_version_config.json`, import.meta.url), "utf8"));
const [developer] = docsInstances(config("developer"), config("network"), env.CONTEXT === "production");
Expand All @@ -83,18 +113,20 @@ export function main(buildDir, env = process.env) {
continue;
}
const index = `${llmsSiteUrl(env)}/${dir}/${SCOPED_API_INDEX}`;
let packages = 0;
const listed = [];
let pages = 0;
for (const { name: pkg } of documentedPackages()) {
for (const { name: pkg, description } of documentedPackages()) {
const file = path.join(root, `${pkg}.md`);
if (!fs.existsSync(file)) continue;
const split = splitPackage(fs.readFileSync(file, "utf8"), { pkg, npmName: npmName(pkg), version, index });
fs.mkdirSync(path.join(root, pkg), { recursive: true });
for (const page of split) fs.writeFileSync(path.join(root, page.file), page.markdown);
packages++;
listed.push({ file: `${pkg}.md`, npmName: npmName(pkg), description });
pages += split.length;
}
console.log(`typescript split: ${dir}: ${packages} packages, ${pages} pages`);
const summary = fs.existsSync(path.join(root, "llm-summary.txt"));
fs.writeFileSync(path.join(root, "index.html"), folderPage({ dir, version, packages: listed, summary }));
console.log(`typescript split: ${dir}: ${listed.length} packages, ${pages} pages, index.html`);
}
return failed ? 1 : 0;
}
Expand Down
Loading