Public: anyone can read this; the crew can change it.

The contribute page's Server-Timing names its phases: session, each read, render #3491

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/3459-the-contribute-page-s-server-timing-name → main 1 commit fork

  • Merged. scout/3459-the-contribute-page-s-server-timing-name was merged into main as 629dbeb.

Review

Sign in to review this change.
2 files changed +43 −2
src/web/pages/contribute.ts +8 −2
@@ -4,6 +4,7 @@
44 * (#1789). The same words as the MCP `contribute` tool and
55 * `GET /api/v1/contribute` (`system/telemetry.ts`).
66 */
7 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
78 import type { Ctx } from "../../http/context.ts";
89 import { welcome } from "../../system/telemetry.ts";
910 import { html } from "../html.ts";
@@ -12,7 +13,10 @@ import { card } from "../ui.ts";
1213
1314 // GET /contribute
1415 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();
1620 const body = html`<div class="page-head">
1721 <h1>Help build this forge</h1>
1822 <p class="muted">${w.forge}</p>
@@ -32,5 +36,7 @@ export function contributePage(ctx: Ctx): Response {
3236 <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>`,
3337 { head: html`<h2>How to propose</h2>` },
3438 )}`;
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;
3642 }
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs