Public: anyone can read this; the crew can change it.
The first-admin page's Server-Timing names its phases: session, each read, render #3545
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3527-the-first-admin-page-s-server-timing-nam → main 1 commit fork
2 files
changed +41
−1
src/web/pages/first-admin.ts +6 −1
| @@ -15,6 +15,7 @@ import { clientAddress } from "../../http/peer.ts"; | ||
| 15 | 15 | import { boundedBody, json, str } from "../../http/respond.ts"; |
| 16 | 16 | import { FIRST_ADMIN_WORDS, firstAdminProblem, redeemFirstAdmin } from "../../actions/first_admin.ts"; |
| 17 | 17 | import { addPasskey } from "../../core/passkeys.ts"; |
| 18 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 18 | 19 | import { createSession } from "../../core/sessions.ts"; |
| 19 | 20 | import { pageHead } from "../chrome.ts"; |
| 20 | 21 | import { field, readForm } from "../form.ts"; |
| @@ -110,8 +111,12 @@ function errorsOf(error: keyof typeof FIRST_ADMIN_WORDS): Errors { | ||
| 110 | 111 | } |
| 111 | 112 | |
| 112 | 113 | // GET /first-admin — the form; the code is in the fragment, so nothing is known or spent here. |
| 114 | // It reads no data, so its Server-Timing names the session and the render only. | |
| 113 | 115 | export function firstAdminPage(ctx: Ctx): Response { |
| 114 | return page({ ctx, title: TITLE, body: form({}, {}), scriptJs: fragmentJs + passkeyJs }); | |
| 116 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 117 | return timePhase(ctx.request, "render", () => | |
| 118 | page({ ctx, title: TITLE, body: form({}, {}), scriptJs: fragmentJs + passkeyJs }), | |
| 119 | ); | |
| 115 | 120 | } |
| 116 | 121 | |
| 117 | 122 | /** The status a refusal answers with: the throttle, a code, or the form. */ |
test/first-admin-timing.test.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** `/first-admin` names session and render in Server-Timing; it reads no data, so names no read (#3527). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | import { quietLogs } from "./helpers/globals.ts"; | |
| 9 | ||
| 10 | quietLogs(); | |
| 11 | ||
| 12 | let root = ""; | |
| 13 | let app: App; | |
| 14 | let servers: Servers; | |
| 15 | ||
| 16 | beforeAll(async () => { | |
| 17 | root = mkdtempSync(join(tmpdir(), "forge-first-admin-timing-")); | |
| 18 | app = createApp({ dataDir: root, port: 0 }); | |
| 19 | servers = await serve(app); | |
| 20 | }); | |
| 21 | afterAll(() => { | |
| 22 | servers.stop(); | |
| 23 | app.close(); | |
| 24 | rmSync(root, { recursive: true, force: true }); | |
| 25 | }); | |
| 26 | ||
| 27 | test("GET /first-admin names its phases", async () => { | |
| 28 | const res = await fetch(`${servers.url}/first-admin`); | |
| 29 | const body = await res.text(); | |
| 30 | expect(res.status).toBe(200); | |
| 31 | expect(body).toContain("Make this forge's first admin"); | |
| 32 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 33 | for (const name of ["app", "session", "render"]) | |
| 34 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 35 | }); |
new above
offline