Public: anyone can read this; the crew can change it.
Every page route has a distinct, non-empty <title> that names the page and the forge, proven by a walk #13612
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/13588-every-page-route-has-a-distinct-non-empt → main 2 commits fork 1 thread · 1 unresolved
5 files
changed +96
−4
src/web/pages/data.ts +1 −1
| @@ -61,7 +61,7 @@ export async function adminDataPage(ctx: Ctx): Promise<Response> { | ||
| 61 | 61 | if (!viewer) return signInFirst(ctx); |
| 62 | 62 | if (!viewer.isAdmin) return refuse(ctx); |
| 63 | 63 | const sources = listSources(ctx.app.db, ctx.app.config.dataDir, viewer).filter((s) => s.kind === "forge"); |
| 64 | return draw(ctx, { path: "/admin/data", sources, sqlWait: () => sqlWindow(ctx.app, viewer.id) }, "Data · forge", pageHead("Forge data", { sub: "Secrets are masked; queries are read-only." })); | |
| 64 | return draw(ctx, { path: "/admin/data", sources, sqlWait: () => sqlWindow(ctx.app, viewer.id) }, "Forge data", pageHead("Forge data", { sub: "Secrets are masked; queries are read-only." })); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // GET /:owner/:name/data — an app's databases, for its writers. |
src/web/pages/packs-settings.ts +1 −1
| @@ -47,7 +47,7 @@ function view(ctx: Ctx, problems: readonly string[], text: string, error?: strin | ||
| 47 | 47 | return page( |
| 48 | 48 | { |
| 49 | 49 | ctx, |
| 50 | title: "Packs", | |
| 50 | title: "Packs settings", | |
| 51 | 51 | body: html`${pageHead("Packs", { sub: "/packs lists the public repositories named here, each with a pack.json at its root, and no others." })}${settingsLayout(accountSections("packs", { admin: true }), body, "Account settings")}`, |
| 52 | 52 | }, |
| 53 | 53 | status, |
src/web/pages/security.ts +1 −1
| @@ -358,7 +358,7 @@ export function securityPage(ctx: Ctx): Response { | ||
| 358 | 358 | notePhase(ctx.request, "render", performance.now() - rendering); |
| 359 | 359 | return page({ |
| 360 | 360 | ctx, |
| 361 | title: "Security", | |
| 361 | title: "Security settings", | |
| 362 | 362 | body: html`<div class="page-head"><h1>Security</h1></div> |
| 363 | 363 | ${settingsLayout(accountSections("security", { admin: true }), body, "Account settings")}`, |
| 364 | 364 | }); |
src/web/pages/usage-tabs.ts +1 −1
| @@ -28,7 +28,7 @@ export function usageShell(ctx: Ctx, current: UsageTab, body: Html, status?: num | ||
| 28 | 28 | return page( |
| 29 | 29 | { |
| 30 | 30 | ctx, |
| 31 | title: "Usage", | |
| 31 | title: `${TABS.find((t) => t.id === current)?.label} · Usage`, | |
| 32 | 32 | scriptJs: liveRegionsJs, |
| 33 | 33 | body: html`<div class="page-head"><h1>Usage</h1></div> |
| 34 | 34 | ${settingsLayout( |
test/page-titles.test.ts added +92
| @@ -0,0 +1,92 @@ | ||
| 1 | /** | |
| 2 | * Every static page route has a distinct, non-empty <title> that names the | |
| 3 | * page and the forge (#13588). The routes come from the router itself: every | |
| 4 | * GET pattern with no parameter, asked as a signed-in owner and as a stranger; | |
| 5 | * where it answers 200 with HTML, its title must be non-empty, name the forge, | |
| 6 | * differ from every other page's, and not be a generic word. Several routes | |
| 7 | * may share one rendering only if the page says which it is in its title. | |
| 8 | */ | |
| 9 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 10 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 11 | import { tmpdir } from "node:os"; | |
| 12 | import { join } from "node:path"; | |
| 13 | import { createApp, type App } from "../src/app.ts"; | |
| 14 | import { createSession } from "../src/core/sessions.ts"; | |
| 15 | import { buildRouter, serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let dataDir = ""; | |
| 22 | let app: App, servers: Servers; | |
| 23 | let cookie = ""; | |
| 24 | ||
| 25 | beforeAll(async () => { | |
| 26 | dataDir = await mkdtemp(join(tmpdir(), "forge-titles-")); | |
| 27 | app = createApp({ dataDir, port: 0 }); | |
| 28 | servers = await serve(app); | |
| 29 | const admin = await seedAdmin(app, { username: "ada", email: "[email protected]", password: "correct-horse-battery" }); | |
| 30 | if (!admin.ok) throw new Error(admin.error); | |
| 31 | cookie = `forge_session=${createSession(app.db, admin.value.id).token}`; | |
| 32 | }, 30_000); | |
| 33 | ||
| 34 | afterAll(async () => { | |
| 35 | servers?.stop(); | |
| 36 | app?.close(); | |
| 37 | await rm(dataDir, { recursive: true, force: true }); | |
| 38 | }); | |
| 39 | ||
| 40 | const GENERIC = new Set(["", "forge", "page", "untitled", "title", "home", "app", "error", "not found"]); | |
| 41 | const entity = (s: string) => s.replace(/&/g, "&").replace(/'|'/g, "'").replace(/"/g, '"'); | |
| 42 | ||
| 43 | /** Routes that answer with another route's page, by design: they carry its title. */ | |
| 44 | const ALIASES = new Set(["/front"]); | |
| 45 | ||
| 46 | /** Static pages: GET, no parameter, not an asset or machine route. */ | |
| 47 | const patterns = (): string[] => | |
| 48 | buildRouter() | |
| 49 | .routes() | |
| 50 | .filter((r) => r.method === "GET" && !r.pattern.includes(":") && !r.pattern.includes("*")) | |
| 51 | .map((r) => r.pattern); | |
| 52 | ||
| 53 | async function walk(headers: Record<string, string>) { | |
| 54 | const titles = new Map<string, string[]>(); | |
| 55 | const bad: string[] = []; | |
| 56 | const all = [...new Set(patterns())]; | |
| 57 | for (let i = 0; i < all.length; i += 16) { | |
| 58 | await Promise.all( | |
| 59 | all.slice(i, i + 16).map(async (path) => { | |
| 60 | const res = await fetch(`${servers.url}${path}`, { headers, redirect: "manual" }); | |
| 61 | // Streams never end: only an HTML 200 is read, anything else is dropped unread. | |
| 62 | if (res.status !== 200 || !(res.headers.get("content-type") ?? "").includes("text/html")) { | |
| 63 | await res.body?.cancel(); | |
| 64 | return; | |
| 65 | } | |
| 66 | const body = await res.text(); | |
| 67 | const raw = /<title>([^<]*)<\/title>/.exec(body)?.[1]; | |
| 68 | // A fragment (a live region, a stream chunk) is not a page. | |
| 69 | if (raw === undefined) return void (/<html[\s>]/i.test(body) ? bad.push(`${path}: no <title>`) : undefined); | |
| 70 | const title = entity(raw).trim(); | |
| 71 | if (GENERIC.has(title.toLowerCase())) return void bad.push(`${path}: generic or empty title "${title}"`); | |
| 72 | if (!/forge/i.test(title)) bad.push(`${path}: "${title}" does not name the forge`); | |
| 73 | if (ALIASES.has(path)) return; | |
| 74 | titles.set(title, [...(titles.get(title) ?? []), path]); | |
| 75 | }), | |
| 76 | ); | |
| 77 | } | |
| 78 | for (const [title, paths] of titles) if (paths.length > 1) bad.push(`"${title}" repeated by ${paths.sort().join(", ")}`); | |
| 79 | return { bad: bad.sort(), count: [...titles.values()].flat().length }; | |
| 80 | } | |
| 81 | ||
| 82 | test("as a stranger, every static page has its own title naming the forge", async () => { | |
| 83 | const { bad, count } = await walk({}); | |
| 84 | expect(count).toBeGreaterThan(10); | |
| 85 | expect(bad).toEqual([]); | |
| 86 | }, 60_000); | |
| 87 | ||
| 88 | test("as a signed-in owner, every static page has its own title naming the forge", async () => { | |
| 89 | const { bad, count } = await walk({ cookie }); | |
| 90 | expect(count).toBeGreaterThan(10); | |
| 91 | expect(bad).toEqual([]); | |
| 92 | }, 60_000); |
new above
offline
Minor: the optional chain can print "undefined · Usage". Fall back to "Usage" when no tab matches.