Public: anyone can read this; the crew can change it.
The milestones page's Server-Timing names its phases: session, each read, render #3302
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3281-the-milestones-page-s-server-timing-name → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +72
−6
src/web/pages/milestones.ts +15 −6
| @@ -37,6 +37,7 @@ import { watchMilestone } from "../../actions/watches.ts"; | ||
| 37 | 37 | import { replanResult } from "../../actions/limb_replan.ts"; |
| 38 | 38 | import { given, pendingFor } from "../../core/limb_replan.ts"; |
| 39 | 39 | import type { Ctx } from "../../http/context.ts"; |
| 40 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 40 | 41 | import { askToLiveFor } from "../ask_to_live.ts"; |
| 41 | 42 | import { |
| 42 | 43 | crumbsFor, |
| @@ -196,13 +197,19 @@ function limbLine(base: string, limb: Limb, move: Html | null = null): Html { | ||
| 196 | 197 | |
| 197 | 198 | /** GET /:owner/:name/milestones — the plan, collapsed to its limbs. */ |
| 198 | 199 | export function milestonesPage(ctx: Ctx): Response { |
| 199 | const repo = loadRepo(ctx); | |
| 200 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 201 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); | |
| 200 | 202 | if (!repo) return notFoundPage(ctx); |
| 201 | const plan = readPlan(ctx.app.db, repo, { | |
| 202 | spend: canSeeOwnerFacts(ctx.app.db, repo, ctx.auth.user), | |
| 203 | }); | |
| 203 | const plan = timePhase(ctx.request, "plan", () => | |
| 204 | readPlan(ctx.app.db, repo, { | |
| 205 | spend: canSeeOwnerFacts(ctx.app.db, repo, ctx.auth.user), | |
| 206 | }), | |
| 207 | ); | |
| 204 | 208 | const base = repoBase(repo); |
| 205 | const move = moverFor(ctx.app.db, repo, ctx.auth.user, plan.read); | |
| 209 | const move = timePhase(ctx.request, "seats", () => | |
| 210 | moverFor(ctx.app.db, repo, ctx.auth.user, plan.read), | |
| 211 | ); | |
| 212 | const rendering = performance.now(); | |
| 206 | 213 | const body = html`${repoHeader(ctx, repo, "map")} |
| 207 | 214 | <div class="page-head mt"> |
| 208 | 215 | <h1>Milestones</h1> |
| @@ -224,7 +231,7 @@ export function milestonesPage(ctx: Ctx): Response { | ||
| 224 | 231 | )} |
| 225 | 232 | </div>`} |
| 226 | 233 | ${liveMount({ repo: base })}`; |
| 227 | return page({ | |
| 234 | const response = page({ | |
| 228 | 235 | ctx, |
| 229 | 236 | title: `Milestones · ${repo.name}`, |
| 230 | 237 | crumbs: crumbsFor(repo), |
| @@ -232,6 +239,8 @@ export function milestonesPage(ctx: Ctx): Response { | ||
| 232 | 239 | body, |
| 233 | 240 | scriptJs: liveClientJs, |
| 234 | 241 | }); |
| 242 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 243 | return response; | |
| 235 | 244 | } |
| 236 | 245 | |
| 237 | 246 | const STATE_TONE: Record<LeafState, "success" | "attn" | undefined> = { |
test/milestones-timing.test.ts added +57
| @@ -0,0 +1,57 @@ | ||
| 1 | /** `/:owner/:name/milestones` names session, repo, plan, seats and render in Server-Timing (#3281). */ | |
| 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 { createRepo } from "../src/actions/repos.ts"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { createUser } from "../src/core/users.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { proveAll } from "./helpers/verified.ts"; | |
| 11 | import { quietLogs } from "./helpers/globals.ts"; | |
| 12 | ||
| 13 | quietLogs(); | |
| 14 | ||
| 15 | let root = ""; | |
| 16 | let app: App; | |
| 17 | let servers: Servers; | |
| 18 | ||
| 19 | beforeAll(async () => { | |
| 20 | root = mkdtempSync(join(tmpdir(), "forge-milestones-timing-")); | |
| 21 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 22 | const u = await createUser(app.db, { | |
| 23 | origin: "seed", | |
| 24 | trusted: true, | |
| 25 | username: "alice", | |
| 26 | email: "[email protected]", | |
| 27 | password: "a-good-passphrase", | |
| 28 | adminIfFirst: true, | |
| 29 | }); | |
| 30 | if (!u.ok) throw new Error(u.error); | |
| 31 | proveAll(app); | |
| 32 | const made = await createRepo(app, { id: u.value.id, username: "alice" } as never, { name: "forge" }); | |
| 33 | if (!made.ok) throw new Error(made.error); | |
| 34 | servers = await serve(app); | |
| 35 | }); | |
| 36 | afterAll(() => { | |
| 37 | servers.stop(); | |
| 38 | app.close(); | |
| 39 | rmSync(root, { recursive: true, force: true }); | |
| 40 | }); | |
| 41 | ||
| 42 | test("GET /:owner/:name/milestones names its phases", async () => { | |
| 43 | const signin = await fetch(`${servers.url}/signin`, { | |
| 44 | method: "POST", | |
| 45 | headers: { origin: servers.url }, | |
| 46 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 47 | redirect: "manual", | |
| 48 | }); | |
| 49 | const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 50 | const res = await fetch(`${servers.url}/alice/forge/milestones`, { headers: { cookie } }); | |
| 51 | const body = await res.text(); | |
| 52 | expect(res.status).toBe(200); | |
| 53 | expect(body).toContain("<h1>Milestones</h1>"); | |
| 54 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 55 | for (const name of ["app", "session", "repo", "plan", "seats", "render"]) | |
| 56 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 57 | }); |
new above
offline
Check that #3281 is the issue this test is meant to cite.