The homepage opener led with a feature description instead of the pain the
visitor is searching for. Rewrite it to name the search ("symbolic regression
from a time series", "discover equations from data"), link the shipped
damped-oscillator sample above the fold, and show the actual CLI command so
the value is provable in the first screen instead of asserted.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
150 lines
7.2 KiB
JavaScript
150 lines
7.2 KiB
JavaScript
// Plain-ESM test for the static-site emitter (run directly by `node --test`,
|
|
// not compiled by tsc — it uses Node's fs/os which the pure-TS build excludes).
|
|
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtempSync, readFileSync, rmSync } from "node:fs";
|
|
import { join } from "node:path";
|
|
import { tmpdir } from "node:os";
|
|
|
|
import { buildDocsSite } from "../dist/src/content.js";
|
|
import { buildFullSite, emitStaticSite, renderStaticSite, SITE_CONFIGURATION } from "../render-static.mjs";
|
|
|
|
test("the landing first screen states the time-series pain and links the shipped sample", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "lawsynth-home-"));
|
|
try {
|
|
const site = buildDocsSite(SITE_CONFIGURATION);
|
|
emitStaticSite(site, dir);
|
|
const home = readFileSync(join(dir, "index.html"), "utf8");
|
|
const articleStart = home.indexOf('<main id="content">');
|
|
const articleEnd = home.indexOf("</article>");
|
|
const article = home.slice(articleStart, articleEnd);
|
|
assert.ok(article.includes("Find the equation in a time series"), "heading names the pain");
|
|
assert.ok(/time series/i.test(article), "opening copy says time series");
|
|
assert.ok(article.includes("symbolic regression from a time series"), "opening copy uses the search the product answers");
|
|
assert.ok(
|
|
article.includes('href="/examples/damped-oscillator"'),
|
|
"opening copy points at the shipped damped-oscillator sample",
|
|
);
|
|
assert.ok(article.includes('href="/examples"'), "opening copy points at the examples gallery");
|
|
const sampleAt = article.indexOf('href="/examples/damped-oscillator"');
|
|
const firstSection = article.indexOf("<h2");
|
|
assert.ok(sampleAt > 0 && firstSection > sampleAt, "the sample link is on the opening screen, before later sections");
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("emitStaticSite writes one index.html per page plus control files", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "lawsynth-site-"));
|
|
try {
|
|
const site = buildDocsSite(SITE_CONFIGURATION);
|
|
const written = emitStaticSite(site, dir);
|
|
|
|
assert.ok(written.includes(join(dir, "index.html")), "landing page at the root");
|
|
for (const page of site.pages) {
|
|
const file =
|
|
page.path === "/"
|
|
? join(dir, "index.html")
|
|
: join(dir, page.path.replace(/^\//, ""), "index.html");
|
|
assert.ok(written.includes(file), `page ${page.path} was emitted`);
|
|
assert.ok(readFileSync(file, "utf8").startsWith("<!doctype html>"), `${page.path} is a full HTML document`);
|
|
}
|
|
|
|
for (const name of ["sitemap.xml", "robots.txt", "llms.txt", "_headers", "_redirects", "_worker.js"]) {
|
|
assert.ok(written.includes(join(dir, name)), `${name} was written`);
|
|
}
|
|
assert.ok(
|
|
readFileSync(join(dir, "_worker.js"), "utf8").includes("env.ASSETS.fetch(request)"),
|
|
"Pages worker forwards apex and preview traffic to static assets",
|
|
);
|
|
assert.ok(readFileSync(join(dir, "sitemap.xml"), "utf8").includes("https://lawsynth.dev"), "sitemap origin");
|
|
assert.ok(
|
|
readFileSync(join(dir, "robots.txt"), "utf8").includes("Sitemap: https://lawsynth.dev/sitemap.xml"),
|
|
"robots points to the sitemap",
|
|
);
|
|
assert.ok(readFileSync(join(dir, "_headers"), "utf8").includes("X-Content-Type-Options: nosniff"), "security headers");
|
|
|
|
const llms = readFileSync(join(dir, "llms.txt"), "utf8");
|
|
assert.ok(llms.startsWith("# LawSynth"), "llms.txt identifies the product");
|
|
assert.ok(llms.includes("STLSQ means sequentially thresholded least squares"), "llms.txt defines STLSQ");
|
|
assert.ok(llms.includes("not proof of physical or causal truth"), "llms.txt states the model boundary");
|
|
const productionSitemap = buildFullSite(SITE_CONFIGURATION).sitemap;
|
|
for (const match of llms.matchAll(/\]\((https:\/\/lawsynth\.dev\/[^)]+)\)/gu)) {
|
|
const url = match[1];
|
|
if (url.endsWith("/sitemap.xml")) continue;
|
|
assert.ok(productionSitemap.includes(`<loc>${url}</loc>`), `${url} is canonical and listed in the sitemap`);
|
|
}
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("the rendered site publishes the repo docs/ tree under /docs with rewritten links", () => {
|
|
const dir = mkdtempSync(join(tmpdir(), "lawsynth-docs-"));
|
|
try {
|
|
renderStaticSite(dir);
|
|
|
|
// A representative page from several docs sections is emitted as full HTML.
|
|
const representative = [
|
|
"docs/index.html", // the /docs landing
|
|
"docs/guide/index.html", // a README -> directory index
|
|
"docs/guide/workflow/index.html", // a plain page
|
|
"docs/methods/causal/granger/index.html", // a nested methods page
|
|
"docs/reference/python/world/index.html", // a nested reference page
|
|
];
|
|
for (const relative of representative) {
|
|
const html = readFileSync(join(dir, relative), "utf8");
|
|
assert.ok(html.startsWith("<!doctype html>"), `${relative} is a full HTML document`);
|
|
}
|
|
|
|
// Internal .md links are rewritten to site paths...
|
|
const guide = readFileSync(join(dir, "docs/guide/index.html"), "utf8");
|
|
assert.ok(guide.includes('href="/docs/guide/workflow"'), "relative .md link rewritten to a site path");
|
|
// ...and no /docs href retains a `.md` suffix.
|
|
assert.ok(!/href="\/docs\/[^"]*\.md/u.test(guide), "no /docs href keeps a .md suffix");
|
|
|
|
// The sitemap and a sanity count cover the docs pages too.
|
|
const sitemap = readFileSync(join(dir, "sitemap.xml"), "utf8");
|
|
assert.ok(sitemap.includes("https://lawsynth.dev/docs/guide/workflow"), "sitemap lists docs pages");
|
|
|
|
const site = buildFullSite(SITE_CONFIGURATION);
|
|
const docsPages = site.pages.filter((page) => page.path.startsWith("/docs"));
|
|
assert.ok(docsPages.length > 200, `expected the full docs corpus (got ${docsPages.length})`);
|
|
|
|
const stlsq = readFileSync(join(dir, "docs/methods/sparse/stlsq/index.html"), "utf8");
|
|
assert.ok(
|
|
stlsq.includes("STLSQ: Sequentially Thresholded Least Squares"),
|
|
"STLSQ page expands the exact-query acronym in its search title",
|
|
);
|
|
assert.ok(
|
|
stlsq.includes("STLSQ means sequentially thresholded least squares"),
|
|
"STLSQ page answers the exact query in its search description",
|
|
);
|
|
assert.ok(stlsq.includes("--solver stlsq --threshold 0.05"), "STLSQ page includes a runnable example");
|
|
assert.ok(
|
|
stlsq.includes('href="/docs/guides/discovery/sparse"'),
|
|
"STLSQ page links to the sparse discovery guide",
|
|
);
|
|
} finally {
|
|
rmSync(dir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("the emitted tree is deterministic (byte-identical across two renders)", () => {
|
|
const a = mkdtempSync(join(tmpdir(), "lawsynth-site-a-"));
|
|
const b = mkdtempSync(join(tmpdir(), "lawsynth-site-b-"));
|
|
try {
|
|
const filesA = renderStaticSite(a);
|
|
const filesB = renderStaticSite(b);
|
|
assert.equal(filesA.length, filesB.length);
|
|
for (let i = 0; i < filesA.length; i += 1) {
|
|
assert.equal(filesA[i].slice(a.length), filesB[i].slice(b.length), "same relative paths in order");
|
|
assert.equal(readFileSync(filesA[i], "utf8"), readFileSync(filesB[i], "utf8"), "byte-identical content");
|
|
}
|
|
} finally {
|
|
rmSync(a, { recursive: true, force: true });
|
|
rmSync(b, { recursive: true, force: true });
|
|
}
|
|
});
|