/g) ?? []).length, 31);
- assert.match(
- coursework,
- /Advanced Linear Algebra.*Complex Analysis.*Financial Mathematics.*Mathematical Approaches to Financial Derivatives.*Mathematical Modeling.*Measure Theory.*Numerical Analysis.*Ordinary Differential Equations.*Partial Differential Equations.*Real Analysis.*Stochastic Differential Equations.*Stochastic Processes.*Topology/s,
- );
- assert.match(
- coursework,
- /Advanced Topics in Engineering Computing.*Algorithms.*Deep Learning.*Machine Learning.*Statistical Methodology.*Technology-Driven Quantitative Finance/s,
+ return result;
+}
+
+function extractAriaLabelledBy(html) {
+ const markup = html.replace(
+ /<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/giu,
+ " ",
);
- assert.match(
- coursework,
- /Corporate Finance.*Econometrics.*Financial Accounting.*Independent Study in Economics.*Macroeconomics.*Mathematical Analysis of Macroeconomics.*Microeconomics.*Venture Capital/s,
+ const result = [];
+
+ for (const [, tag, attributes] of markup.matchAll(
+ /<([a-z][\w:-]*)\b([^>]*)>/giu,
+ )) {
+ const value = attribute(attributes, "aria-labelledby");
+ if (value === undefined) continue;
+ result.push({
+ tag: tag.toLowerCase(),
+ role: attribute(attributes, "role") ?? null,
+ value,
+ });
+ }
+
+ return result;
+}
+
+function extractAriaAttributes(html) {
+ const markup = html.replace(
+ /<(script|style|template|noscript)\b[\s\S]*?<\/\1\s*>/giu,
+ " ",
);
- assert.match(
- coursework,
- /Ethics and Leadership.*Global China and Global Challenges.*Ocean and Coastal Law.*Space Law/s,
+ const result = [];
+
+ for (const [, tag, attributes] of markup.matchAll(
+ /<([a-z][\w:-]*)\b([^>]*)>/giu,
+ )) {
+ for (const name of ["aria-label", "aria-labelledby"]) {
+ const value = attribute(attributes, name);
+ if (value !== undefined) result.push({ tag: tag.toLowerCase(), name, value });
+ }
+ }
+
+ return result;
+}
+
+function extractCanonicalUrls(html) {
+ const result = [];
+ for (const [, attributes] of html.matchAll(/]*)>/giu)) {
+ const rel = (attribute(attributes, "rel") ?? "").toLowerCase().split(/\s+/u);
+ if (rel.includes("canonical")) result.push(attribute(attributes, "href"));
+ }
+ return result;
+}
+
+function extractOpenGraphUrls(html) {
+ const result = [];
+ for (const [, attributes] of html.matchAll(/]*)>/giu)) {
+ if ((attribute(attributes, "property") ?? "").toLowerCase() === "og:url") {
+ result.push(attribute(attributes, "content"));
+ }
+ }
+ return result;
+}
+
+function canonicalUrl(route) {
+ return new URL(route, SITE_ORIGIN).toString();
+}
+
+function recordMatches(expected, actual, tokenFields = new Set()) {
+ if (typeof expected !== "object" || expected === null) return actual === expected;
+ return Object.entries(expected).every(([key, value]) => {
+ if (tokenFields.has(key)) {
+ try {
+ assertTokenSubsequence(value, actual[key] ?? "", `${key} changed`);
+ return true;
+ } catch {
+ return false;
+ }
+ }
+ return actual[key] === value;
+ });
+}
+
+function assertRecordSubsequence(
+ expectedRecords,
+ actualRecords,
+ message,
+ tokenFields = new Set(),
+) {
+ let cursor = 0;
+ for (const expected of expectedRecords) {
+ while (
+ cursor < actualRecords.length &&
+ !recordMatches(expected, actualRecords[cursor], tokenFields)
+ ) {
+ cursor += 1;
+ }
+ if (cursor === actualRecords.length) {
+ assert.fail(`${message}: missing or reordered ${JSON.stringify(expected)}`);
+ }
+ cursor += 1;
+ }
+}
+
+async function routeHtml(route) {
+ if (!htmlCache.has(route)) {
+ const relative = route === "/" ? ["index.html"] : [
+ ...route.replace(/^\/+|\/+$/gu, "").split("/"),
+ "index.html",
+ ];
+ const file = path.join(OUT, ...relative);
+ htmlCache.set(route, await readFile(file, "utf8"));
+ }
+ return htmlCache.get(route);
+}
+
+function sha256(bytes) {
+ return createHash("sha256").update(bytes).digest("hex");
+}
+
+function pngDimensions(bytes) {
+ assert.equal(
+ bytes.subarray(1, 4).toString("ascii"),
+ "PNG",
+ "Expected a PNG source image",
);
- assert.doesNotMatch(coursework, /[^<]*(?:analysis|learning|finance)[^<]*<\/p>/i);
+ return { width: bytes.readUInt32BE(16), height: bytes.readUInt32BE(20) };
+}
- assert.match(
- css,
- /\.education-institution h2\s*{[^}]*font-size:\s*1\.55rem[^}]*font-weight:\s*620/s,
+async function walk(directory) {
+ const result = [];
+ for (const entry of await readdir(directory, { withFileTypes: true })) {
+ const absolute = path.join(directory, entry.name);
+ if (entry.isDirectory()) result.push(...(await walk(absolute)));
+ else result.push(absolute);
+ }
+ return result;
+}
+
+function localReference(reference, pageRoute) {
+ if (!reference || /^(?:data|mailto|tel|javascript):/iu.test(reference)) return null;
+ const url = new URL(reference, new URL(pageRoute, `${SITE_ORIGIN}/`));
+ if (!["http:", "https:"].includes(url.protocol)) return null;
+ if (!["www.theodoreoy.com", "theodoreoy.com"].includes(url.hostname)) return null;
+ return url;
+}
+
+function artifactCandidates(url) {
+ const pathname = decodeURIComponent(url.pathname);
+ const relative = pathname.replace(/^\/+/, "").split("/").filter(Boolean);
+
+ if (pathname === "/") return [path.join(OUT, "index.html")];
+ if (pathname.endsWith("/")) return [path.join(OUT, ...relative, "index.html")];
+
+ const direct = path.join(OUT, ...relative);
+ if (path.extname(pathname)) return [direct];
+ return [direct, path.join(direct, "index.html"), `${direct}.html`];
+}
+
+async function assertReferenceResolves(reference, pageRoute, source) {
+ const url = localReference(reference, pageRoute);
+ if (!url) return;
+
+ assert.notEqual(
+ url.pathname,
+ "/_next/image",
+ `${source} uses the runtime Next image optimizer, which cannot serve a static export`,
);
- assert.match(
- css,
- /\.education-degree\s*{[^}]*margin:\s*0 0 14px[^}]*font-size:\s*1\.38rem/s,
+
+ const candidates = artifactCandidates(url);
+ const resolved = candidates.find((candidate) => existsSync(candidate));
+ assert.ok(
+ resolved,
+ `${source} references ${reference}, but no exported artifact exists (${candidates.join(", ")})`,
);
- assert.match(
- css,
- /\.post-listing \.section-kicker\s*{[^}]*margin-bottom:\s*16px/s,
+
+ if (url.hash && resolved.endsWith(".html")) {
+ const targetHtml = await readFile(resolved, "utf8");
+ const targetId = decodeURIComponent(url.hash.slice(1));
+ assert.ok(
+ extractIds(targetHtml).includes(targetId),
+ `${source} references missing fragment #${targetId}`,
+ );
+ }
+}
+
+function htmlReferences(html) {
+ const references = [];
+ for (const match of html.matchAll(/<(a|link|img|script|source)\b([^>]*)>/giu)) {
+ const tag = match[1].toLowerCase();
+ const attributes = match[2];
+ for (const name of ["href", "src"]) {
+ const value = attribute(attributes, name);
+ if (value) references.push({ value, source: `<${tag} ${name}>` });
+ }
+ const srcset = attribute(attributes, "srcset");
+ if (srcset) {
+ for (const candidate of srcset.split(",")) {
+ const value = candidate.trim().split(/\s+/u)[0];
+ if (value) references.push({ value, source: `<${tag} srcset>` });
+ }
+ }
+ }
+
+ for (const [, attributes] of html.matchAll(/]*)>/giu)) {
+ const key = (
+ attribute(attributes, "property") ?? attribute(attributes, "name") ?? ""
+ ).toLowerCase();
+ if (["og:image", "twitter:image"].includes(key)) {
+ const value = attribute(attributes, "content");
+ if (value) references.push({ value, source: `` });
+ }
+ }
+
+ return references;
+}
+
+function elementsWithClass(html, tagName, className) {
+ const expression = new RegExp(
+ `<${tagName}\\b([^>]*)>([\\s\\S]*?)<\\/${tagName}\\s*>`,
+ "giu",
);
-});
+ return [...html.matchAll(expression)].filter((match) => hasClass(match[1], className));
+}
-test("uses restrained Apple-style materials and accessible motion", async () => {
- const css = await readFile(new URL("../app/globals.css", import.meta.url), "utf8");
-
- assert.match(css, /--ease-out:\s*cubic-bezier\(0\.23,\s*1,\s*0\.32,\s*1\)/);
- assert.match(css, /--radius-large:\s*28px/);
- assert.match(css, /\.topbar-inner\s*{[^}]*backdrop-filter:\s*blur\(24px\) saturate\(145%\)/s);
- assert.match(css, /\.profile-sidebar\s*{[^}]*border-radius:\s*var\(--radius-large\)/s);
- assert.match(css, /@media \(hover:\s*hover\) and \(pointer:\s*fine\)/);
- assert.match(css, /@media \(prefers-reduced-motion:\s*reduce\)/);
- assert.match(css, /@media \(prefers-reduced-transparency:\s*reduce\)/);
- assert.match(css, /@media \(prefers-contrast:\s*more\)/);
- assert.doesNotMatch(css, /transition:\s*all\b/);
- assert.doesNotMatch(
- css,
- /transition:[^;]*(?:padding|margin|width|height|top|right|bottom|left)[^;]*;/,
+function elementsWithAnyClass(html, tagName, classNames) {
+ const matches = classNames.flatMap((className) =>
+ elementsWithClass(html, tagName, className),
);
- assert.doesNotMatch(css, /@keyframes\b/);
- assert.doesNotMatch(css, /\.post-listing\s*{[^}]*transition:/s);
- assert.match(
- css,
- /\.post-listing h2 a\s*{[^}]*transition:[^;]*text-decoration-color/s,
+ return [...new Map(matches.map((match) => [match.index, match])).values()].sort(
+ (left, right) => left.index - right.index,
);
-});
+}
-test("past experience landing page links to five separate domain pages", async () => {
- const html = await (await render("/past-experience")).text();
+function normalizeRoute(value) {
+ const pathname = new URL(value, SITE_ORIGIN).pathname;
+ return pathname === "/" ? "/" : `${pathname.replace(/\/+$/u, "")}/`;
+}
- for (const { name, path } of domainPages) {
- assert.match(html, new RegExp(`href="${path}/"`));
- assert.match(html, new RegExp(escapeText(name)));
+async function exportedPublicRoutes() {
+ const routes = [];
+
+ for (const file of await walk(OUT)) {
+ if (path.basename(file) !== "index.html") continue;
+ const relativeDirectory = path
+ .relative(OUT, path.dirname(file))
+ .split(path.sep)
+ .filter(Boolean);
+ if (["404", "_not-found"].includes(relativeDirectory[0])) continue;
+ routes.push(relativeDirectory.length === 0 ? "/" : `/${relativeDirectory.join("/")}/`);
}
- assert.equal((html.match(/class="domain-directory-link"/g) ?? []).length, 5);
- assert.doesNotMatch(html, /domain-disclosure|path-invariant vertical time|LightGBM pairwise ranker/);
-});
+ return routes.sort();
+}
-test("each domain page contains only its own exact archive content", async () => {
- const source = await readFile(
- new URL(
- "../content/past-experience/archive-through-2026-06-30.md",
- import.meta.url,
- ),
- "utf8",
+async function sitemapRoutes() {
+ const sitemap = await readFile(path.join(OUT, "sitemap.xml"), "utf8");
+ return [...sitemap.matchAll(/([\s\S]*?)<\/loc>/giu)]
+ .map((match) => normalizeRoute(decodeHtml(match[1].trim())))
+ .sort();
+}
+
+test("the preservation fixture is immutable and covers exactly 11 public routes", () => {
+ assert.equal(baseline.schemaVersion, 1);
+ assert.equal(baseline.baselineCommit, "69d6e7134132da51f4961dbe5509fc6adb657284");
+ assert.equal(accessibleLabelBaseline.schemaVersion, 1);
+ assert.equal(
+ accessibleLabelBaseline.baselineCommit,
+ "69d6e7134132da51f4961dbe5509fc6adb657284",
);
- const domainSection = source.split("## Domain Experience")[1];
- assert.ok(domainSection, "Domain Experience must exist in the source archive");
+ assert.equal(accessibleLabelledByBaseline.schemaVersion, 1);
+ assert.equal(
+ accessibleLabelledByBaseline.baselineCommit,
+ "69d6e7134132da51f4961dbe5509fc6adb657284",
+ );
+ assert.equal(frozenBaselineRoutes.length, 11);
+ assert.deepEqual(frozenBaselineRoutes, [
+ "/",
+ "/education/",
+ "/now/",
+ "/past-experience/",
+ "/past-experience/artificial-intelligence/",
+ "/past-experience/data-science/",
+ "/past-experience/environmental-social-and-governance/",
+ "/past-experience/finance/",
+ "/past-experience/stem-academic-competitions-and-training/",
+ "/personal-posts/",
+ "/personal-posts/from-vision-and-instructions-to-robot-actions/",
+ ]);
+ assert.deepEqual(Object.keys(accessibleLabelBaseline.routes), frozenBaselineRoutes);
+
+ for (const [route, record] of Object.entries(baseline.routes)) {
+ const expectedFile = route === "/" ? "index.html" : `${route.slice(1)}index.html`;
+ assert.equal(record.file, expectedFile, `${route} baseline file mapping is inconsistent`);
+ const text = gunzipSync(Buffer.from(record.visibleTextGzipBase64, "base64")).toString(
+ "utf8",
+ );
+ assert.equal(
+ sha256(Buffer.from(text)),
+ record.visibleTextSha256,
+ `${route} baseline payload does not match its recorded hash`,
+ );
+ }
- const dateLines = domainSection.match(/^\*\*Dates:\*\*.*$/gm) ?? [];
- assert.equal(dateLines.length, 16);
- assert.ok(
- dateLines.every(
- (line) =>
- !/\b(?:Jan|Feb|Mar|Apr|Jun|Jul|Aug|Sep|Sept|Oct|Nov|Dec)\s+\d{4}\b/.test(
- line,
- ),
- ),
- "Past Experience month names must be written in full",
+ for (const domain of domainRoutes) {
+ const record = baseline.routes[domain.route];
+ assert.equal(record.headings[1]?.text, domain.name);
+ assert.equal(
+ record.title,
+ `${domain.name} | Past Experience | Theodore Ouyang`,
+ `${domain.route} baseline title does not match its route`,
+ );
+ }
+});
+
+test("the official Next export contains all public routes and the custom 404", async () => {
+ const output = await stat(OUT);
+ assert.ok(output.isDirectory(), "Run the official Next static build before the tests");
+
+ const currentRoutes = await exportedPublicRoutes();
+ assert.ok(currentRoutes.length >= frozenBaselineRoutes.length);
+ for (const route of currentRoutes) {
+ const html = await routeHtml(route);
+ assert.match(html, /^/iu, `${route} must be a complete static HTML document`);
+ assert.deepEqual(
+ extractCanonicalUrls(html),
+ [canonicalUrl(route)],
+ `${route} must have exactly one self-referencing canonical URL`,
+ );
+ assert.deepEqual(
+ extractOpenGraphUrls(html),
+ [canonicalUrl(route)],
+ `${route} must have exactly one matching Open Graph URL`,
+ );
+ }
+
+ const notFoundPath = [path.join(OUT, "404.html"), path.join(OUT, "404", "index.html")].find(
+ (candidate) => existsSync(candidate),
);
- assert.ok(dateLines.every((line) => line.includes(" – ")));
-
- const sourceDomains = domainSection
- .split(/^### /gm)
- .slice(1)
- .map((block) => {
- const [name, ...lines] = block.split(/\r?\n/);
- return {
- name: name.trim(),
- bullets: lines
- .filter((line) => line.startsWith("- "))
- .map((line) => line.slice(2)),
- };
- });
+ assert.ok(notFoundPath, "The export must include a static 404 page");
+ const notFoundText = visibleBodyText(await readFile(notFoundPath, "utf8"));
+ assert.match(notFoundText, /(?:\b404\b|page not found|not found)/iu);
+});
+test("every post-baseline route has an append-only published-copy snapshot", async () => {
+ const currentRoutes = await exportedPublicRoutes();
+ const snapshotRoutes = publishedCopySnapshots.map(({ file, snapshot }) => {
+ assert.equal(snapshot.schemaVersion, 1, `${file} has an unsupported schema`);
+ assert.equal(typeof snapshot.route, "string", `${file} must declare a route`);
+ return snapshot.route;
+ });
+
+ assert.equal(
+ new Set(snapshotRoutes).size,
+ snapshotRoutes.length,
+ "Published-copy snapshot routes must be unique",
+ );
assert.deepEqual(
- sourceDomains.map(({ name }) => name),
- domainPages.map(({ name }) => name),
+ [...snapshotRoutes].sort(),
+ currentRoutes.filter((route) => !frozenBaselineRoutes.includes(route)).sort(),
+ "Every route added after the frozen baseline must have exactly one snapshot",
);
- let exactBulletMatches = 0;
+ for (const { file, snapshot } of publishedCopySnapshots) {
+ const html = await routeHtml(snapshot.route);
+ const main = mainMarkup(html);
+ assertTokenSubsequence(
+ snapshot.mainText,
+ textContent(main),
+ `${file} published main copy changed`,
+ );
+ assert.equal(extractTitle(html), snapshot.title, `${file} title changed`);
+ assert.equal(
+ extractDescription(html),
+ snapshot.description,
+ `${file} description changed`,
+ );
+ assertRecordSubsequence(
+ snapshot.headings,
+ extractHeadings(main),
+ `${file} headings changed`,
+ new Set(["text"]),
+ );
+ assertRecordSubsequence(
+ snapshot.links,
+ extractLinks(main),
+ `${file} links changed`,
+ new Set(["label", "ariaLabel"]),
+ );
+ assertRecordSubsequence(
+ snapshot.images,
+ extractImages(main),
+ `${file} images changed`,
+ new Set(["alt"]),
+ );
+ assertRecordSubsequence(snapshot.ids, extractIds(main), `${file} IDs changed`);
+ assertRecordSubsequence(snapshot.times, extractTimes(main), `${file} times changed`);
+ assertRecordSubsequence(
+ snapshot.ariaAttributes,
+ extractAriaAttributes(main),
+ `${file} accessible names changed`,
+ new Set(["value"]),
+ );
+ }
+});
+
+test("no original rendered copy or public structure is deleted", async () => {
+ for (const [route, record] of Object.entries(baseline.routes)) {
+ const html = await routeHtml(route);
+ const oldText = gunzipSync(Buffer.from(record.visibleTextGzipBase64, "base64")).toString(
+ "utf8",
+ );
+
+ assertTokenSubsequence(oldText, visibleBodyText(html), `${route} rendered copy changed`);
+ assert.equal(extractTitle(html), record.title, `${route} title changed`);
+ assert.equal(extractDescription(html), record.description, `${route} description changed`);
- for (const [index, domain] of sourceDomains.entries()) {
- const page = domainPages[index];
- const html = await (await render(page.path)).text();
+ assertRecordSubsequence(
+ record.headings,
+ extractHeadings(html),
+ `${route} headings changed`,
+ new Set(["text"]),
+ );
+ assertRecordSubsequence(
+ record.links,
+ extractLinks(html),
+ `${route} link labels or destinations changed`,
+ new Set(["label", "ariaLabel"]),
+ );
+ assertRecordSubsequence(
+ record.images.map(({ alt }) => ({ alt })),
+ extractImages(html),
+ `${route} image alternative text changed`,
+ new Set(["alt"]),
+ );
+ assertRecordSubsequence(record.times, extractTimes(html), `${route} time metadata changed`);
+ assertRecordSubsequence(
+ accessibleLabelBaseline.routes[route],
+ extractAriaLabels(html),
+ `${route} accessible labels changed`,
+ new Set(["value"]),
+ );
+ assertRecordSubsequence(
+ accessibleLabelledByBaseline.routes[route] ?? [],
+ extractAriaLabelledBy(html),
+ `${route} accessible label references changed`,
+ new Set(["value"]),
+ );
- assert.match(html, new RegExp(`${escapeText(domain.name)}<\\/h1>`));
- assert.match(html, /href="\/past-experience\/"/);
- assert.match(html, /November 2025 – July 2026|Past Experience/);
- assert.doesNotMatch(html, /\bPresent\b/);
+ // _R_ was the obsolete Vinext bootstrap script ID, not authored page content.
+ const authoredIds = record.ids.filter((id) => id !== "_R_");
+ assertRecordSubsequence(authoredIds, extractIds(html), `${route} authored IDs changed`);
+ }
+});
- for (const otherPage of domainPages.filter((item) => item.path !== page.path)) {
- assert.doesNotMatch(html, new RegExp(`href="${otherPage.path}/"`));
+test("all internal links, image sources, scripts, styles, and responsive sources resolve", async () => {
+ const pages = await exportedPublicRoutes();
+ if (existsSync(path.join(OUT, "404.html"))) pages.push("/404.html");
+
+ for (const route of pages) {
+ const html =
+ route === "/404.html"
+ ? await readFile(path.join(OUT, "404.html"), "utf8")
+ : await routeHtml(route);
+ for (const reference of htmlReferences(html)) {
+ await assertReferenceResolves(reference.value, route, `${route} ${reference.source}`);
}
+ }
- for (const bullet of domain.bullets) {
- assert.ok(
- html.includes(escapeText(bullet)),
- `Rendered archive changed or omitted bullet: ${bullet}`,
- );
- exactBulletMatches += 1;
+ for (const file of (await walk(OUT)).filter((candidate) => candidate.endsWith(".css"))) {
+ const css = await readFile(file, "utf8");
+ const route = `/${path.relative(OUT, file).split(path.sep).join("/")}`;
+ for (const match of css.matchAll(/url\(\s*(?:"([^"]+)"|'([^']+)'|([^)'"\s]+))\s*\)/giu)) {
+ const reference = match[1] ?? match[2] ?? match[3];
+ await assertReferenceResolves(reference, route, `${route} CSS url()`);
}
}
+});
- assert.equal(exactBulletMatches, 92);
+test("the exported runtime is free of Vinext and Cloudflare scaffolding", async () => {
+ const textExtensions = new Set([
+ ".css",
+ ".html",
+ ".js",
+ ".json",
+ ".map",
+ ".mjs",
+ ".txt",
+ ".xml",
+ ]);
+ const forbiddenPath =
+ /(?:__VINEXT|_vinext|\bvinext\b|vite-rsc|\bcloudflare\b|\bwrangler\b)/iu;
+ const forbiddenContent =
+ /(?:__VINEXT|_vinext|\bvinext\b|vite-rsc|\bwrangler\b|@cloudflare\/vite-plugin)/iu;
+
+ for (const file of await walk(OUT)) {
+ const relative = path.relative(OUT, file).split(path.sep).join("/");
+ assert.doesNotMatch(relative, forbiddenPath, `Forbidden runtime artifact: ${relative}`);
+ if (!textExtensions.has(path.extname(file).toLowerCase())) continue;
+ assert.doesNotMatch(
+ await readFile(file, "utf8"),
+ forbiddenContent,
+ `Forbidden runtime reference in ${relative}`,
+ );
+ }
});
-test("publishes the July 2026 transition as a separate present-facing page", async () => {
- const html = await (await render("/now")).text();
+test("robots, sitemap, and exported HTML publish the same canonical route manifest", async () => {
+ const robotsPath = path.join(OUT, "robots.txt");
+ const sitemapPath = path.join(OUT, "sitemap.xml");
+ assert.ok(existsSync(robotsPath), "robots.txt must be part of the static export");
+ assert.ok(existsSync(sitemapPath), "sitemap.xml must be part of the static export");
- assert.match(html, /Current Chapter \| Theodore Ouyang<\/title>/);
- assert.match(html, /