Web pages: a page without headings is arranged by itself, and a typed address becomes a titled link

A page cut into parts by length is now arranged into titled sections by a
model when it is first read, through the same gates as s (a model, the
daily budget, the plan's limits, one request per text), once per text per
server run. EX_PAGES_ARRANGE=manual keeps it to s. The pane shows the
parts at once, says that it is arranging or why it did not, and swaps the
sections in when they arrive.

A bare http(s) address typed into a node's text is linked when the edit
ends, then replaced by the page's title once that is read; u brings the
address back. A node whose whole text is one address becomes a section
that is only a link. See docs/pages.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014yB6q4BHMwptTX3YFtkRab
This commit is contained in:
thalladaandClaude Fable 5.2 committed 2026-11-18 14:19:21 -05:00
1 parent f8c6576ea1
commit 57b605e13c
19 files changed
+1095 -92

No files matched your search

+111
View File
@@ -0,0 +1,111 @@
/**
* A bare address typed into a node's text becomes a titled link once the edit is finished
* (src/core/bareLinks.ts, Store.typedAddresses), against the mock web (EX_PAGES=mock) and the mock
* model: linked as typed, then the page's title in place of the address; u brings the address back,
* still linked, and it is not converted again; a page that cannot be read leaves the address linked
* as typed and the status line says why; a Wikipedia address becomes a link to the article; a
* section whose whole text is an address becomes a section that is only the link; several in one
* edit all convert, at most five pages read; a page with no headings is arranged in the background,
* so opening it later is immediate. The browser's own requests elsewhere are refused.
*/
import { expect, test, type Page } from "@playwright/test";
import { WEB, addTop, keys, pageCalls, settle, state, visit } from "./helpers";
const status = (page: Page) => page.locator(".status .message");
const body = (page: Page) => state(page, (s) => s.snap.nodes[s.focus.node].body as string);
/** The links on the focused node's text: their words and targets. */
const linksHere = (page: Page) =>
state(page, (s) =>
s.snap.nodes[s.focus.node].children
.map((c: string) => s.snap.nodes[c])
.filter((n: any) => n.kind === "note" && n.ref)
.map((n: any) => ({ words: n.anchors[0]?.text, ref: n.ref })),
);
test.beforeEach(async ({ context }) => {
await context.route((u) => /(^|\.)(wikipedia\.org|wikimedia\.org|example\.(org|com|net))$/.test(u.hostname), (r) => r.abort());
});
test.afterEach(({ page }) => settle(page));
test("an address typed into the text is linked, then titled from its page; u brings the address back, linked, and it is not converted again", async ({ page }) => {
await addTop(page, "Reading the trace", `Start with ${WEB.tracing}, then the rest.`);
await expect.poll(() => body(page)).toBe("Start with Following one request through the stack, then the rest.");
expect(await linksHere(page)).toEqual([{ words: "Following one request through the stack", ref: { kind: "url", url: WEB.tracing, title: "Following one request through the stack" } }]);
await expect(status(page)).toContainText("Linked as “Following one request through the stack”, the page's title. u brings the address back.");
// Two commits of their own, after the edit: the link as typed, then the title (newest first).
const history: string[] = await state(page, (s) => s.commits().slice(0, 8).map((c: any) => c.message));
const titled = history.findIndex((m) => /^Title the link “https:\/\/tracing\.example\.org.*”: “Following one request through the stack”$/.test(m));
const linked = history.findIndex((m) => /^Link “https:\/\/tracing\.example\.org.*” to Following one request|^Link “https:\/\/tracing\.example\.org/.test(m));
expect(titled).toBeGreaterThanOrEqual(0);
expect(linked).toBeGreaterThan(titled);
await keys(page, "u");
await expect.poll(() => body(page)).toBe(`Start with ${WEB.tracing}, then the rest.`);
expect(await linksHere(page)).toEqual([{ words: WEB.tracing, ref: { kind: "url", url: WEB.tracing } }]);
// Edited again, the address is not new: it stays as it is.
await keys(page, "c End");
await page.keyboard.type(" More.");
await page.keyboard.press("Escape");
await expect.poll(() => body(page)).toBe(`Start with ${WEB.tracing}, then the rest. More.`);
await page.waitForTimeout(300);
expect(await body(page)).toBe(`Start with ${WEB.tracing}, then the rest. More.`);
expect(await linksHere(page)).toEqual([{ words: WEB.tracing, ref: { kind: "url", url: WEB.tracing } }]);
});
test("a page that cannot be read leaves its address as typed, linked, and the status line says why", async ({ page }) => {
await addTop(page, "Tides asked", `The answer is at ${WEB.robots}.`);
await expect(status(page)).toContainText(`No title for ${WEB.robots}: qa.example.com asks programs like this one not to read this page (robots.txt).`);
await expect(status(page)).toContainText("The address stays as typed, linked.");
expect(await body(page)).toBe(`The answer is at ${WEB.robots}.`);
expect(await linksHere(page)).toEqual([{ words: WEB.robots, ref: { kind: "url", url: WEB.robots } }]);
});
test("a Wikipedia article's address becomes a link to the article, titled with its title", async ({ page }) => {
await addTop(page, "Eight arms", "Read https://en.wikipedia.org/wiki/Octopus first. Not `https://code.example.org/x` though.");
await expect.poll(() => body(page)).toBe("Read Octopus first. Not `https://code.example.org/x` though.");
expect(await linksHere(page)).toEqual([{ words: "Octopus", ref: { kind: "wiki", title: "Octopus", lang: "en" } }]);
});
test("several addresses in one edit all convert, at most five pages read; one with no headings is arranged in the background, so opening it is immediate", async ({ page }) => {
const calls = pageCalls();
const urls = [WEB.essay, WEB.letters, WEB.rules, WEB.phare, WEB.figures, WEB.videos];
await addTop(page, "Six addresses", urls.join(" and "));
await expect.poll(() => body(page)).not.toContain(WEB.figures);
await expect.poll(() => body(page)).not.toMatch(new RegExp(urls.slice(0, 5).map((u) => u.replace(/[.?/]/g, "\\$&")).join("|")));
const titles = await Promise.all(urls.slice(0, 5).map((u) => titleOf(page, u)));
expect(titles.slice(0, 3)).toEqual(["A Hundred Small Maps", "On maps", "Twelve rules for a small team – Notes on Software"]);
expect(await body(page)).toBe([...titles, WEB.videos].join(" and "));
expect((await linksHere(page)).map((l: any) => l.ref.url)).toEqual(urls);
expect(await state(page, (s) => s.log.map((l: any) => l.text))).toContain("Linked 6 addresses; reading the page titles… 1 more is linked as typed, without reading its page (at most 5 are read from one edit).");
// The essay has no headings: the server arranged it by itself, with no pane open on it.
await expect.poll(pageCalls).toBe(calls + 1);
const opened = await (await page.request.get(`/api/page/article?url=${encodeURIComponent(WEB.essay)}`)).json();
expect(opened).toMatchObject({ cached: true, article: { outline: "model" } });
});
test("a section whose whole text is an address becomes a section that is only the link, named after its page", async ({ page }) => {
const root = (await (await page.request.get("/api/tree")).json()).root as string;
const made = await page.request.post("/api/ops", { data: { author: "tester", message: "Add a holder", ops: [{ op: "create", parent: root, title: "Address holder", body: "" }, { op: "create", parent: "$0", title: "", body: "" }] } });
expect(made.ok()).toBe(true);
const tree = await (await page.request.get("/api/tree")).json();
const holder = Object.values(tree.nodes as Record<string, { title: string; children: string[] }>).find((n) => n.title === "Address holder")!;
const id = holder.children[0];
await visit(page, `/n/${encodeURIComponent(id)}`);
await page.waitForFunction(() => (globalThis as any).__ie?.ready);
await page.evaluate((i) => (globalThis as any).__ie.setFocus({ node: i, grain: "node" }), id);
await keys(page, "c");
await page.keyboard.type(WEB.letters);
await page.keyboard.press("Escape");
await expect.poll(() => state(page, (s) => s.snap.nodes[s.focus.node].title)).toBe("On maps");
const n = await state(page, (s) => s.snap.nodes[s.focus.node]);
expect(n.id).toBe(id);
expect(n.body).toBe("");
expect(n.ref).toEqual({ kind: "url", url: WEB.letters, title: "On maps" });
expect(await state(page, (s) => s.linkOnly(s.focus.node))).toBe(true);
});
/** A page's title as the server keeps it. */
async function titleOf(page: Page, url: string): Promise<string> {
return (await (await page.request.get(`/api/page/summary?url=${encodeURIComponent(url)}&cached=1`)).json()).summary.title;
}
+12 -1
View File
@@ -7,7 +7,8 @@
* words, links on the screenshot's cells; the articles are the mock
* Wikipedia's fixtures in server/wikiMock.ts).
*/
import { writeFileSync } from "node:fs";
import { existsSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
import { inflateSync } from "node:zlib";
import { expect, type APIRequestContext, type Page } from "@playwright/test";
@@ -261,6 +262,10 @@ export async function seedLinks(request: APIRequestContext) {
export const WEB = {
tracing: "https://tracing.example.org/posts/following-a-request",
essay: "https://essays.example.com/hundred.html",
/** Headingless, and the mock model fails to arrange it ("mockfail" in its title). */
drift: "https://notes.example.net/field/unsorted",
/** Headingless, and the mock model takes 1.5 s to arrange it ("mockslow"). */
slow: "https://tides.example.net/slow-water",
letters: "https://letters.example.net/p/on-maps",
rules: "https://software.example.com/2003/10/twelve-rules/",
phare: "https://encyclopedie.example.org/fr/Phare_de_la_Pointe",
@@ -299,6 +304,12 @@ export async function seedWeb(request: APIRequestContext) {
if (!res.ok()) throw new Error(`seeding web links failed: ${res.status()} ${await res.text()}`);
}
/** Model calls made today to arrange pages, as the e2e server counts them (<EX_DATA>/page-calls.json). */
export function pageCalls(): number {
const file = join(process.env.EX_E2E_DATA ?? "", "page-calls.json");
return existsSync(file) ? (JSON.parse(readFileSync(file, "utf8")) as { used: number }).used : 0;
}
/** A screenshot's pixels (a PNG of 8-bit RGB or RGBA, as Playwright writes them): px(x, y) is [r, g, b]. */
export function pixels(buf: Buffer): { w: number; h: number; px: (x: number, y: number) => [number, number, number] } {
let at = 8;
+63 -20
View File
@@ -4,15 +4,16 @@
* its sections as rows that open as panes, and where it is from at its foot; each outline the
* server makes (headings, pseudo-headings, parts by length); a page that cannot be shown says why
* and offers the original; figures come through the app's media route; a reload keeps the panes;
* a hostile page runs nothing and loads nothing from elsewhere; s has the mock model arrange a page
* and R reads one again; a link's card shows what the server's cache knows of its page, and the
* a hostile page runs nothing and loads nothing from elsewhere; a page with no headings is arranged
* by the mock model by itself, once (or says why not), s has it arrange or summarise one, and R
* reads one again; a link's card shows what the server's cache knows of its page, and the
* link picker keeps an address's title; a section that is only a link is shown as its page or
* article at once (its pane reads as the article's; in the column, under its row), and L opens a
* section's target to the right of its pane. Nothing here touches the network:
* the server's fetch is the mock's, and the browser's requests elsewhere are refused.
*/
import { expect, test, type Page } from "@playwright/test";
import { WEB, command, jump, keys, noFaults, pane, seedLinks, seedWeb, settle, state, still, visit, wide } from "./helpers";
import { WEB, command, jump, keys, noFaults, pageCalls, pane, seedLinks, seedWeb, settle, state, still, visit, wide } from "./helpers";
/** The panes' refs, left to right, as short names: a node's title, W:article, U:host/path#section. */
const trail = (page: Page) =>
@@ -109,7 +110,7 @@ test("panes: a link to a web page opens it in the next pane: its site, title and
await keys(page, "Escape Escape");
});
test("each outline the server makes: pseudo-headings, strong headings with a byline class, parts by length, junk sections left out", async ({ page }) => {
test("each outline the server makes: pseudo-headings, strong headings with a byline class, parts by length (arranged by a model by itself, or not), junk sections left out", async ({ page }) => {
await wide(page, "Error-correcting codes");
await follow(page, WEB.letters);
let web = page.locator(".wiki-pane.web").last();
@@ -124,11 +125,19 @@ test("each outline the server makes: pseudo-headings, strong headings with a byl
await expect(web.locator(".web-byline")).toHaveText("Jo Calloway · Notes on Software · 9 Oct 2003");
await expect(web.locator(".wrow").first()).toContainText("1. Do you keep a list of bugs?");
// No headings: divided by length, and arranged by the model by itself. No metadata at all: the byline is the site alone.
await follow(page, WEB.essay);
web = page.locator(".wiki-pane.web").last();
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "chunks");
// No metadata at all: the byline is the site alone, and each part is named by its first words.
await expect(web.locator(".web-byline")).toHaveText("essays.example.com");
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "model");
await expect(web.locator(".web-auto")).toHaveCount(0);
// One the model cannot arrange keeps its parts, each named by its first words, and says why in one quiet line.
await follow(page, WEB.drift);
web = page.locator(".wiki-pane.web").last();
await expect(web.locator(".web-auto")).toHaveAttribute("data-auto", "skipped");
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "chunks");
await expect(web.locator(".web-auto")).toHaveText(/^Kept in parts by length: The model call failed: .* s tries again\.$/);
expect((await web.locator(".wrow > .row .title").allTextContents()).every((t) => t.endsWith("…"))).toBe(true);
await expect(web.locator(".wiki > .wattr")).toContainText("divided into parts by length");
@@ -377,39 +386,54 @@ async function posted(page: Page, key: string, route: "arrange" | "reload"): Pro
return (await res).json();
}
test("s: the model arranges a page divided by length; a pane on an old part closes; the summary is shown, labelled; a second s makes no call; a page with headings gains only the summary", async ({ page }) => {
test("a page with no headings is arranged by itself, once: “arranging…” meanwhile; a pane on a part by length closes when the sections arrive; the summary is shown, labelled; s then makes no call; a page with headings gains only the summary", async ({ page }) => {
await wide(page, "Error-correcting codes");
await follow(page, WEB.essay);
const calls = pageCalls();
// The mock model takes 1.5 s over this page: it shows its parts by length meanwhile, and says so.
await follow(page, WEB.slow);
const web = page.locator(".wiki-pane.web").last();
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "chunks");
await expect(web.locator(".web-auto")).toHaveText("Arranging into sections with a model…");
await expect(web.locator(".web-model")).toHaveCount(0);
// A part by length open as the next pane.
// A part by length open as the next pane, while the model works.
await keys(page, "j l");
expect((await trail(page)).at(-1)).toBe("U:essays.example.com/hundred.html#c1");
const first = await posted(page, "s", "arrange");
expect(first).toMatchObject({ ok: true, called: true, arranged: "sections" });
expect((await trail(page)).at(-1)).toBe("U:tides.example.net/slow-water#c1");
// The sections arrive: the page swaps to them, and the pane on the old part closes, the status line saying so.
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "model");
await expect(web.locator(".wrow > .row .title")).toHaveText(["Mock part one", "Mock part two", "Mock part three"]);
// The pane on the old part is closed, and the status line says so.
await expect(status(page)).toContainText("Arranged by the model into 3 sections");
await expect(status(page)).toContainText("A pane on one of its old parts is closed.");
expect((await trail(page)).at(-1)).toBe("U:essays.example.com/hundred.html");
await expect(web.locator(".web-auto")).toHaveCount(0);
await expect(status(page)).toContainText("A model has arranged this page into sections; the pane on one of its parts by length is closed.");
expect((await trail(page)).at(-1)).toBe("U:tides.example.net/slow-water");
expect(pageCalls()).toBe(calls + 1);
// The summary above the page's own opening, marked as the model's; the foot says what the model did.
const summary = web.locator(".web-model");
await expect(summary.locator(".web-model-label")).toContainText("Summary written by a model (mock)");
await expect(summary.locator(".web-model-text")).toContainText("Mock summary of “A Hundred Small Maps”");
await expect(web.locator(".wiki > .wiki-text")).toContainText("A Hundred Small Maps");
await expect(summary.locator(".web-model-text")).toContainText("Mock summary of “Slow water (mockslow)”");
await expect(web.locator(".web-arranged")).toContainText("Sections arranged by a model");
const foot = web.locator(".wiki > .wattr");
await expect(foot).toContainText("sections arranged by a model; summary written by a model");
await expect(foot).not.toContainText("divided into parts by length");
// A section of the model's opens as a pane like any other.
await keys(page, "j l");
expect((await trail(page)).at(-1)).toBe("U:essays.example.com/hundred.html#m1");
expect((await trail(page)).at(-1)).toBe("U:tides.example.net/slow-water#m1");
await keys(page, "h");
// Again: the kept result, no call.
// s: the kept result, no call. Opened again, or read again unchanged: no call either.
expect(await posted(page, "s", "arrange")).toMatchObject({ ok: true, called: false, arranged: "sections" });
await expect(status(page)).toContainText("no new call");
expect(await posted(page, "R", "reload")).toMatchObject({ ok: true, article: { outline: "model" } });
await follow(page, WEB.letters);
await follow(page, WEB.slow);
await expect(page.locator(".wiki-pane.web").last().locator(".wiki")).toHaveAttribute("data-outline", "model");
expect(pageCalls()).toBe(calls + 1);
// One the model failed on, by itself: s tries again (a call), and says why it failed again.
await follow(page, WEB.drift);
const drift = page.locator(".wiki-pane.web").last();
await expect(drift.locator(".web-auto")).toHaveAttribute("data-auto", "skipped");
const before = pageCalls();
expect(await posted(page, "s", "arrange")).toMatchObject({ ok: false, reason: "failed" });
await expect(status(page)).toContainText("Not arranged: The model call failed");
expect(pageCalls()).toBe(before + 1);
// A page with headings of its own keeps them, and gains the summary only.
await follow(page, WEB.tracing);
@@ -429,6 +453,25 @@ test("s: the model arranges a page divided by length; a pane on an old part clos
await page.keyboard.press("Escape");
});
test("when the day's budget is spent, a page with no headings keeps its parts with one quiet line saying so, and s says it again", async ({ page }) => {
// The server's own refusal is tested in tests/pageArrange.test.ts; here the browser is given it, as
// a server with its budget spent would send it, so the shared server's budget is left alone.
const spent = "Today's 20 model calls for arranging pages are used up on this server (EX_PAGE_CALLS); it starts again tomorrow (UTC).";
await page.route((u) => u.pathname === "/api/page/article" && u.searchParams.get("url") === WEB.drift, async (route) => {
const res = await route.fetch();
const body = await res.json();
await route.fulfill({ response: res, json: { ...body, article: { ...body.article, auto: { state: "skipped", reason: "budget", message: spent } } } });
});
await page.route((u) => u.pathname === "/api/page/arrange", (route) => route.fulfill({ status: 429, json: { ok: false, reason: "budget", message: spent } }));
await wide(page, "Error-correcting codes");
await follow(page, WEB.drift);
const web = page.locator(".wiki-pane.web").last();
await expect(web.locator(".web-auto")).toHaveText(`Kept in parts by length: ${spent} s tries again.`);
await expect(web.locator(".wiki")).toHaveAttribute("data-outline", "chunks");
expect(await posted(page, "s", "arrange")).toMatchObject({ ok: false, reason: "budget" });
await expect(status(page)).toContainText(`Not arranged: ${spent}`);
});
test("R reads a page again: unchanged text keeps the model's sections; a page that no longer answers keeps the copy read before, marked stale", async ({ page }) => {
// The essay read and arranged (as the test before leaves it, when it ran).
await page.request.get(`/api/page/article?url=${encodeURIComponent(WEB.essay)}`);