Browser tests and README: tops found by title, addresses named from titles

The browser tests find sections by their titles from the library root and open the
starter trees at /doc/<name made from the title>; a renamed document's address follows
its title. The README's addresses, text-format targets and /api/docs say the same.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Opus 5.5 committed 2026-11-16 23:43:58 -05:00
1 parent 44d2e437eb
commit 6c97772ec9
11 files changed
+68 -66

No files matched your search

+2 -2
View File
@@ -73,7 +73,7 @@ async function still(page: Page) {
}
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.goto("/doc/infinispand");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await expect(page.locator(".strip .pane")).toHaveCount(2);
@@ -92,7 +92,7 @@ async function tabTo(page: Page, words: string) {
/** The owner's screenshot: Two kinds of cell, with Eukaryote (opened from its link), Simple cells and Complex cells beside each other in the next column, and Bacteria opened from Eukaryote's text. */
async function cells(page: Page) {
await page.goto("/doc/the-eukaryotic-cell");
await page.goto("/doc/the-one-merger");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
await jump(page, "Two kinds of cell");
+15 -15
View File
@@ -77,34 +77,34 @@ export const writeReport = (name: string, report: unknown) => writeFileSync(`tes
interface Snap {
root: string;
nodes: Record<string, { id: string; parent: string | null; kind: string; title: string; body: string; slug?: string; ref?: unknown; anchors: { text: string }[]; children: string[] }>;
nodes: Record<string, { id: string; parent: string | null; kind: string; title: string; body: string; ref?: unknown; anchors: { text: string }[]; children: string[] }>;
}
const W = (title: string) => ({ kind: "wiki", title, lang: "en" });
/** Find a section by its document's slug and title path. */
function find(s: Snap, slug: string, ...path: string[]): string {
let at = s.nodes[s.root].children.find((c) => s.nodes[c].slug === slug)!;
for (const t of path) at = s.nodes[at].children.find((c) => s.nodes[c].kind === "section" && s.nodes[c].title === t)!;
if (!at) throw new Error(`no ${slug}/${path.join("/")}`);
/** Find a section by its titles from the library root. */
function find(s: Snap, ...path: string[]): string {
let at = s.root;
for (const t of path) at = s.nodes[at]?.children.find((c) => s.nodes[c].kind === "section" && s.nodes[c].title === t) as string;
if (!at) throw new Error(`no /${path.join("/")}`);
return at;
}
const noteOn = (s: Snap, parent: string, quote: string) => s.nodes[parent].children.find((c) => s.nodes[c].kind === "note" && s.nodes[c].anchors[0]?.text === quote)!;
export async function seedLinks(request: APIRequestContext) {
const s: Snap = await (await request.get("/api/tree")).json();
const recursion = find(s, "fixed-points", "Recursion without names");
const recursion = find(s, "Fixed points", "Recursion without names");
if (s.nodes[recursion].children.some((c) => s.nodes[c].ref)) return; // already seeded by an earlier test
const howY = find(s, "fixed-points", "Recursion without names", "How Y works");
const triple = find(s, "origin-of-the-elements", "Fusion in ordinary stars", "The triple-alpha process");
const separate = find(s, "octopus-minds", "A separate experiment");
const ancestor = find(s, "octopus-minds", "A separate experiment", "The common ancestor");
const programs = find(s, "what-a-proof-is", "Proof assistants", "Proofs as programs");
const kinds = find(s, "the-eukaryotic-cell", "Two kinds of cell");
const howY = find(s, "Fixed points", "Recursion without names", "How Y works");
const triple = find(s, "Where the elements come from", "Fusion in ordinary stars", "The triple-alpha process");
const separate = find(s, "Octopus minds", "A separate experiment");
const ancestor = find(s, "Octopus minds", "A separate experiment", "The common ancestor");
const programs = find(s, "What a proof is", "Proof assistants", "Proofs as programs");
const kinds = find(s, "The one merger", "Two kinds of cell");
const ops = [
{ op: "create", parent: recursion, kind: "note", quote: "fixed-point combinator", ref: W("Fixed-point combinator") },
{ op: "update", id: noteOn(s, recursion, "lambda calculus"), ref: W("Lambda calculus") },
{ op: "create", parent: recursion, kind: "note", quote: "Y combinator", ref: { kind: "node", id: howY, doc: "fixed-points", path: ["Recursion without names", "How Y works"] } },
{ op: "create", parent: recursion, kind: "note", quote: "Y combinator", ref: { kind: "node", id: howY, path: ["Fixed points", "Recursion without names", "How Y works"] } },
{ op: "create", parent: recursion, kind: "note", quote: "self-reference", ref: { kind: "url", url: "https://plato.stanford.edu/entries/self-reference/", title: "Self-Reference (Stanford Encyclopedia of Philosophy)" } },
{ op: "update", id: noteOn(s, triple, "an excited state at almost exactly the energy"), ref: W("Hoyle state") },
{ op: "create", parent: triple, kind: "note", quote: "Fred Hoyle", ref: W("Fred Hoyle") },
@@ -113,7 +113,7 @@ export async function seedLinks(request: APIRequestContext) {
// A link on words that already carry a note of their own: two notes on one span.
{ op: "create", parent: ancestor, kind: "note", quote: "The camera-like eye", ref: W("Cephalopod") },
{ op: "create", parent: programs, kind: "note", quote: "a function turning proofs", ref: W("Lambda calculus") },
{ op: "create", parent: programs, kind: "note", quote: "Several of the leading systems", ref: { kind: "node", id: recursion, doc: "fixed-points", path: ["Recursion without names"] } },
{ op: "create", parent: programs, kind: "note", quote: "Several of the leading systems", ref: { kind: "node", id: recursion, path: ["Fixed points", "Recursion without names"] } },
{ op: "create", parent: kinds, kind: "note", quote: "Eukaryotes", ref: W("Eukaryote") },
{ op: "create", parent: kinds, kind: "note", quote: "Bacteria", ref: W("Bacteria") },
];
+1 -1
View File
@@ -15,7 +15,7 @@ const titlesUnder = (page: Page, title: string) =>
/** The first document, opened in the column (hoisted, with the library one step out). */
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
await page.evaluate(() => document.fonts.ready);
}
+7 -7
View File
@@ -182,7 +182,7 @@ test("panes: Tab and Enter open an article in the next pane; its sections open a
});
test("a note that also links opens as one pane: its text above, the article in full beneath", async ({ page }) => {
await wide(page, "/doc/origin-of-the-elements");
await wide(page, "/doc/where-the-elements-come-from");
await inPane(page, "The triple-alpha process", "an excited state at almost exactly the energy");
await keys(page, "Enter");
const pane = panes(page).last();
@@ -221,14 +221,14 @@ test("a note that also links, clicked or entered, opens its article with the not
const words = "an excited state at almost exactly the energy";
const note = "It is called the Hoyle state";
// Panes, by click.
await wide(page, "/doc/origin-of-the-elements");
await wide(page, "/doc/where-the-elements-come-from");
await jump(page, "The triple-alpha process");
await keys(page, "l");
await panes(page).last().locator(".anchor", { hasText: words }).click();
await expect(panes(page).last()).toHaveClass(/note-pane/);
await expectCommentary(page, note, "Hoyle state", "excited, spin-0 resonant state");
// The column, by keyboard: Enter on the words opens the note as a page; h returns to the words.
await column(page, "/doc/origin-of-the-elements");
await column(page, "/doc/where-the-elements-come-from");
await jump(page, "The triple-alpha process");
await keys(page, "Enter i");
await tabTo(page, words);
@@ -323,7 +323,7 @@ test("Linked from and Mentioned in list what links here, reachable by j and Ente
});
test("linking by hand: the picker links to the library, to Wikipedia and to an address; it retargets; /unlink and D remove", async ({ page }) => {
await column(page, "/doc/tides");
await column(page, "/doc/the-tides");
await jump(page, "The tides");
const doc = await state(page, (s) => s.focus.node);
const linkCount = () => page.evaluate((d) => {
@@ -342,7 +342,7 @@ test("linking by hand: the picker links to the library, to Wikipedia and to an a
await expect(picker.locator(".choice.selected .t")).toHaveText("Octopus minds");
await keys(page, "Enter");
await expect(picker).toHaveCount(0);
expect(await linkCount()).toEqual([`${word}|node|`]);
expect(await linkCount()).toEqual([`${word}|node|Octopus minds`]); // its path: the titles from the library root
await expect(page.locator(".lnk.l-node", { hasText: word })).toBeVisible();
// The same picker on that link retargets it, here to Wikipedia: suggestions arrive under their own head.
await keys(page, "w");
@@ -385,7 +385,7 @@ test("linking by hand: the picker links to the library, to Wikipedia and to an a
});
test("a disambiguation page lists its senses as rows; a missing article, an unreachable Wikipedia and a slow one say so plainly", async ({ page }) => {
await wide(page, "/doc/tides");
await wide(page, "/doc/the-tides");
await jump(page, "The tides");
await keys(page, "i i");
await command(page, "/link w:Mercury");
@@ -474,7 +474,7 @@ test("a hostile article cannot run script or load anything from elsewhere, in a
let dialogs = 0;
page.on("dialog", (d) => (dialogs++, d.dismiss()));
for (const view of [wide, column]) {
await view(page, "/doc/tides");
await view(page, "/doc/the-tides");
await jump(page, "The tides");
await keys(page, "i i");
await command(page, "/link w:Hostile article");
+19 -18
View File
@@ -36,7 +36,7 @@ const menuList = async (page: Page) => {
await expect(page.locator(".panel.docs .filter")).not.toBeFocused();
await expect.poll(() => state(page, (s) => `${s.mode}/${s.menu.focus}`)).toBe("docs/list");
};
async function open(page: Page, path = "/doc/infinite-expand") {
async function open(page: Page, path = "/doc/infinispand") {
await page.goto(path);
await page.waitForSelector("article");
}
@@ -62,7 +62,7 @@ test("the library is the first page: its documents are its sections, and opening
await keys(page, "j Enter"); // the first document's row: it opens in place of the list
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await expect(page.locator(".crumbs")).toHaveText(/Library/);
await expect(page).toHaveURL(/\/doc\/infinite-expand$/);
await expect(page).toHaveURL(/\/doc\/infinispand$/);
await expect(page.locator(".docbar .doc-title .name")).toHaveText("Infinispand");
await keys(page, "h"); // stepping out of the document returns to the library, on its row
await expect(page.locator(".top h1")).toHaveText("Library");
@@ -113,12 +113,13 @@ test("import a .md file, then export it and get the same document back", async (
const again = page.waitForEvent("filechooser");
await command(page, "/import");
await (await again).setFiles({ name: "menu-fixture.md", mimeType: "text/markdown", buffer: Buffer.from(text) });
await expect(page).toHaveURL(/\/doc\/menu-fixture-2$/);
// A second top with the same name is addressed by its id as well.
await expect(page).toHaveURL(/\/doc\/menu-fixture\/[^/]+$/);
expect(await shape()).toBe(imported);
expect(await state(page, (s) => [s.currentDoc, ...s.snap.nodes[s.currentDoc].children].filter((id: string) => s.snap.nodes[id].by !== "llm").length)).toBe(0);
// Both are on the server, as sections of the library.
await synced(page);
expect((await (await page.request.get("/api/docs")).json()).map((d: any) => d.slug)).toEqual(expect.arrayContaining(["menu-fixture", "menu-fixture-2"]));
expect((await (await page.request.get("/api/docs")).json()).filter((d: any) => d.slug === "menu-fixture")).toHaveLength(2);
});
test("a file with a quote that is not in its text is refused, naming the section and the quote", async ({ page }) => {
@@ -151,7 +152,7 @@ test("filter and open; the address names the document and the node, and survives
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
expect(await state(page, (s) => s.focus.node)).toBe(section);
// A link to a document opens it; Back returns to the node; Back again to the library.
await open(page, "/doc/infinite-expand");
await open(page, "/doc/infinispand");
await expect(page.locator(".top h1")).toHaveText("Infinispand");
await page.goBack();
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
@@ -174,7 +175,7 @@ test("the jump box searches every document, says which one each match is in, and
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("The tides");
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("Amphidromes");
await expect(page).toHaveURL(/\/doc\/tides\/\d+%40\d+$/);
await expect(page).toHaveURL(/\/doc\/the-tides\/\d+%40\d+$/);
// Back to where the jump started.
await page.goBack();
await expect(page.locator(".top h1")).toHaveText("Infinispand");
@@ -202,7 +203,7 @@ test("the library opens from this browser without the network, and catches up wh
await page.reload();
await page.waitForSelector("article");
await expect(page.locator(".docbar .save-state")).toHaveText("saved", { timeout: 15_000 });
expect(JSON.stringify(await (await page.request.get("/api/docs/tides/tree")).json())).toContain("Renamed offline");
expect(JSON.stringify(await (await page.request.get("/api/docs/the-tides/tree")).json())).toContain("Renamed offline");
});
test("create, rename and duplicate from the menu", async ({ page }) => {
@@ -221,9 +222,9 @@ test("create, rename and duplicate from the menu", async ({ page }) => {
await page.keyboard.press("Enter");
await expect(page.locator(".top h1")).toHaveText("Scratch pad, renamed");
await expect(page.locator(".panel.docs .doc.current .title")).toHaveText("Scratch pad, renamed");
await expect(page).toHaveURL(/\/doc\/scratch-pad$/); // the slug, and so links, stay
await expect(page).toHaveURL(/\/doc\/scratch-pad-renamed$/); // the address follows the title; links go by node id
await synced(page);
const listed = await (await page.request.get("/api/docs/scratch-pad")).json();
const listed = await (await page.request.get("/api/docs/scratch-pad-renamed")).json();
expect(listed.title).toBe("Scratch pad, renamed");
await keys(page, "s");
@@ -234,8 +235,8 @@ test("create, rename and duplicate from the menu", async ({ page }) => {
await expect(page).toHaveURL(/\/doc\/scratch-copy$/);
// The copy sits after the original in the library, and is one commit in its history.
expect(await state(page, (s) => s.commits()[0].message)).toBe("Duplicate “Scratch pad, renamed” as “Scratch copy”");
const order = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c].slug));
expect(order.indexOf("scratch-copy")).toBe(order.indexOf("scratch-pad") + 1);
const order = await state(page, (s) => s.snap.nodes[s.snap.root].children.filter((c: string) => !s.snap.nodes[c].articles).map((c: string) => s.snap.nodes[c].title));
expect(order.indexOf("Scratch copy")).toBe(order.indexOf("Scratch pad, renamed") + 1);
});
test("delete asks first, and is an ordinary delete that u undoes", async ({ page }) => {
@@ -252,13 +253,13 @@ test("delete asks first, and is an ordinary delete that u undoes", async ({ page
await synced(page);
expect((await page.request.get("/api/docs/scratch-copy")).status()).toBe(404);
await keys(page, "Escape u");
await expect.poll(() => state(page, (s) => s.snap.nodes[s.snap.root].children.map((c: string) => s.snap.nodes[c].slug))).toContain("scratch-copy");
await expect.poll(() => state(page, (s) => s.snap.nodes[s.snap.root].children.map((c: string) => s.snap.nodes[c].title))).toContain("Scratch copy");
await synced(page);
expect((await page.request.get("/api/docs/scratch-copy")).status()).toBe(200);
});
test("a node moves from one document to another, and undo works wherever the last edit was", async ({ page }) => {
await open(page, "/doc/scratch-pad");
await open(page, "/doc/scratch-pad-renamed");
await keys(page, "a");
await page.keyboard.type("Only in the scratch pad");
await page.keyboard.press("Enter");
@@ -267,7 +268,7 @@ test("a node moves from one document to another, and undo works wherever the las
await expect(page.locator(".top h1")).toHaveText("Menu fixture");
expect(await titles(page)).not.toContain("Only in the scratch pad");
await expect
.poll(async () => JSON.stringify(await (await page.request.get("/api/docs/scratch-pad/tree")).json()))
.poll(async () => JSON.stringify(await (await page.request.get("/api/docs/scratch-pad-renamed/tree")).json()))
.toContain("Only in the scratch pad");
expect(JSON.stringify(await (await page.request.get("/api/docs/menu-fixture/tree")).json())).not.toContain("Only in the scratch pad");
// Undo is the library's too: u here takes back the edit made in the scratch pad.
@@ -280,7 +281,7 @@ test("a node moves from one document to another, and undo works wherever the las
await synced(page);
const tree = await (await page.request.get("/api/tree")).json();
const node = Object.values<any>(tree.nodes).find((n) => n.title === "Only in the scratch pad");
const target = Object.values<any>(tree.nodes).find((n) => n.slug === "menu-fixture");
const target = tree.nodes[tree.nodes[tree.root].children.find((c: string) => tree.nodes[c].title === "Menu fixture")];
const res = await page.request.post("/api/ops", { data: { author: "mover", message: "Move it across", ops: [{ op: "move", id: node.id, parent: target.id }] } });
expect(res.ok()).toBe(true);
await expect.poll(() => titles(page)).not.toContain("Only in the scratch pad");
@@ -302,7 +303,7 @@ test("a note being written in one document lands there after the reader has move
await expect(page.locator(".top h1")).toHaveText("Scratch pad, renamed");
await idle(page);
await expect(page.locator(".pending, .writing")).toHaveCount(0);
const notes = await state(page, (s) => s.snap.nodes[s.snap.nodes[s.snap.root].children.find((c: string) => s.snap.nodes[c].slug === "menu-fixture")].children.filter((c: string) => /mock/i.test(s.snap.nodes[c].body)).length);
const notes = await state(page, (s) => s.snap.nodes[s.snap.nodes[s.snap.root].children.find((c: string) => s.snap.nodes[c].title === "Menu fixture")].children.filter((c: string) => /mock/i.test(s.snap.nodes[c].body)).length);
expect(notes).toBe(1);
expect(await state(page, (s) => s.snap.nodes[s.focus.node].title)).not.toBe(where);
});
@@ -318,14 +319,14 @@ test("the : commands do the same", async ({ page }) => {
const download = page.waitForEvent("download");
await command(page, "/export");
expect(await (await download).suggestedFilename()).toBe("menu-fixture.md");
await command(page, "/open made-by-command");
await command(page, "/open renamed-by-command");
await expect(page.locator(".top h1")).toHaveText("Renamed by command");
});
test("the menu works in panes and at phone width", async ({ page }) => {
await page.setViewportSize({ width: 1920, height: 1080 });
await autoLayout(page);
await open(page, "/doc/infinite-expand");
await open(page, "/doc/infinispand");
await expect(page.locator(".strip .pane")).toHaveCount(2); // the library, and the document
await openByMenu(page, "menu fixture");
await expect(page.locator(".strip .pane.root h1")).toHaveText("Library");
+2 -2
View File
@@ -3,7 +3,7 @@ import { expect, test, type Page } from "@playwright/test";
import { idle, jump, keys, settle, state } from "./helpers";
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
}
@@ -121,7 +121,7 @@ test("an outside agent edits over HTTP with the same ops, and the open page foll
await open(page);
const tree = await (await request.get("/api/tree/main")).json();
// The tree is the whole library; its documents are the root's sections.
expect(Object.values<any>(tree.nodes).filter((n) => n.parent === tree.root).map((n) => n.slug)).toContain("infinite-expand");
expect(Object.values<any>(tree.nodes).filter((n) => n.parent === tree.root).map((n) => n.title)).toContain("Infinispand");
const target = Object.values<any>(tree.nodes).find((n) => n.title === "The first document");
expect(target).toBeTruthy();
const res = await request.post("/api/ops/main", {
+1 -1
View File
@@ -45,7 +45,7 @@ test.describe.configure({ mode: "serial" });
test.beforeAll(async ({ request }) => {
// A link on "simple ratio" (to the mock Wikipedia's Octopus), once.
const s = await (await request.get("/api/tree")).json();
const doc = s.nodes[s.root].children.find((c: string) => s.nodes[c].slug === "tuning-and-temperament");
const doc = s.nodes[s.root].children.find((c: string) => s.nodes[c].title === "Tuning and temperament");
const sec = s.nodes[doc].children.find((c: string) => s.nodes[c].title === "Why some intervals sound smooth");
if (s.nodes[sec].children.some((c: string) => s.nodes[c].ref)) return;
const res = await request.post("/api/ops", { data: { author: "mouse", message: "A link for the mouse tests", ops: [{ op: "create", parent: sec, kind: "note", quote: "simple ratio", ref: { kind: "wiki", title: "Octopus", lang: "en" } }] } });
+2 -2
View File
@@ -19,7 +19,7 @@ const paneTitles = async (page: Page) => (await panes(page)).map((p) => p.title)
const nodeId = (page: Page, title: string) => page.evaluate((t) => (Object.values((globalThis as any).__ie.snap.nodes) as any[]).find((n) => n.title === t).id as string, title);
async function open(page: Page) {
await page.goto("/doc/infinite-expand");
await page.goto("/doc/infinispand");
await page.waitForSelector(".strip .pane");
await page.evaluate(() => document.fonts.ready);
// The library pane and the document's; hoisting makes the document the first.
@@ -57,7 +57,7 @@ test("the library is the first pane, and a document opens in the next; reload an
await page.keyboard.press("Enter");
// From the menu a document opens in place of the one open, not beside it.
expect(await paneTitles(page)).toEqual(["Library", "Infinispand", "The tides"]);
await expect(page).toHaveURL(/\/doc\/tides$/);
await expect(page).toHaveURL(/\/doc\/the-tides$/);
await page.goBack();
await expect.poll(() => paneTitles(page)).toEqual(third);
await page.goForward();
+1 -1
View File
@@ -13,7 +13,7 @@ async function open(page: Page) {
(globalThis as any).__opened = [];
window.open = ((url: string) => ((globalThis as any).__opened.push(String(url)), null)) as typeof window.open;
});
await page.goto("/doc/infinite-expand");
await page.goto("/doc/infinispand");
await page.waitForSelector("article");
}
+1 -1
View File
@@ -187,7 +187,7 @@ test("when the model fails, nothing is linked unreviewed: everything is suggeste
test("a background job is reviewed as it goes, with the model's calls counted, and can be stopped; a finished one links what was approved", async ({ page }) => {
await column(page);
await page.goto("/doc/tides");
await page.goto("/doc/the-tides");
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await command(page, "/linkall");
await page.waitForFunction(() => (globalThis as any).__ie.links.job?.state === "running" && (globalThis as any).__ie.links.job.done > 0);