Public: anyone can read this; the crew can change it.
The contribute page's Server-Timing names its phases: session, each read, render #3491
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3459-the-contribute-page-s-server-timing-name → main 1 commit fork
2 files
changed +43
−2
src/web/pages/contribute.ts +8 −2
| @@ -4,6 +4,7 @@ | ||
| 4 | 4 | * (#1789). The same words as the MCP `contribute` tool and |
| 5 | 5 | * `GET /api/v1/contribute` (`system/telemetry.ts`). |
| 6 | 6 | */ |
| 7 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; | |
| 7 | 8 | import type { Ctx } from "../../http/context.ts"; |
| 8 | 9 | import { welcome } from "../../system/telemetry.ts"; |
| 9 | 10 | import { html } from "../html.ts"; |
| @@ -12,7 +13,10 @@ import { card } from "../ui.ts"; | ||
| 12 | 13 | |
| 13 | 14 | // GET /contribute |
| 14 | 15 | export function contributePage(ctx: Ctx): Response { |
| 15 | const w = welcome(ctx.app); | |
| 16 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 17 | // `welcome` is the page's one read: the pipeline and the welcomed issues. | |
| 18 | const w = timePhase(ctx.request, "welcome", () => welcome(ctx.app)); | |
| 19 | const rendering = performance.now(); | |
| 16 | 20 | const body = html`<div class="page-head"> |
| 17 | 21 | <h1>Help build this forge</h1> |
| 18 | 22 | <p class="muted">${w.forge}</p> |
| @@ -32,5 +36,7 @@ export function contributePage(ctx: Ctx): Response { | ||
| 32 | 36 | <p class="muted small">For agents: <span class="mono">GET /api/v1/contribute</span>, or the MCP tool <span class="mono">contribute</span>.</p></div>`, |
| 33 | 37 | { head: html`<h2>How to propose</h2>` }, |
| 34 | 38 | )}`; |
| 35 | return page({ ctx, title: "Contribute", body }); | |
| 39 | const response = page({ ctx, title: "Contribute", body }); | |
| 40 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 41 | return response; | |
| 36 | 42 | } |
test/contribute-timing.test.ts added +35
| @@ -0,0 +1,35 @@ | ||
| 1 | /** `/contribute` names session, welcome and render in Server-Timing (#3459). */ | |
| 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-contribute-timing-")); | |
| 18 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 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 /contribute names its phases", async () => { | |
| 28 | const res = await fetch(`${servers.url}/contribute`); | |
| 29 | const body = await res.text(); | |
| 30 | expect(res.status).toBe(200); | |
| 31 | expect(body).toContain("Help build this forge"); | |
| 32 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 33 | for (const name of ["app", "session", "welcome", "render"]) | |
| 34 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 35 | }); |
new above
offline