Public: anyone can read this; the crew can change it.
One wave's page names its Server-Timing phases: session, each read, render #3652
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3633-one-wave-s-page-names-its-server-timing → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +78
−6
src/web/pages/waves.ts +13 −6
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * it does for any other page of a private repository. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts"; | |
| 9 | 10 | import { repoDir } from "../../git/repos.ts"; |
| 10 | 11 | import type { Ctx } from "../../http/context.ts"; |
| 11 | 12 | import { VERSION } from "../../story/wave.ts"; |
| @@ -66,14 +67,18 @@ export const webUrl = (s: string): boolean => /^https?:\/\//i.test(s); | ||
| 66 | 67 | |
| 67 | 68 | // GET /:owner/:name/waves/:version |
| 68 | 69 | export async function wavePage(ctx: Ctx): Promise<Response> { |
| 69 | const repo = loadRepo(ctx); | |
| 70 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 71 | const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx)); | |
| 70 | 72 | if (!repo) return notFoundPage(ctx); |
| 71 | const entry = await readWave( | |
| 72 | repoDir(ctx.app.reposRoot, repo.ownerName, repo.name), | |
| 73 | repo.defaultBranch, | |
| 74 | ctx.params.version ?? "", | |
| 73 | const entry = await timePhaseAsync(ctx.request, "wave", () => | |
| 74 | readWave( | |
| 75 | repoDir(ctx.app.reposRoot, repo.ownerName, repo.name), | |
| 76 | repo.defaultBranch, | |
| 77 | ctx.params.version ?? "", | |
| 78 | ), | |
| 75 | 79 | ); |
| 76 | 80 | if (!entry) return notFoundPage(ctx); |
| 81 | const rendering = performance.now(); | |
| 77 | 82 | const scope = localScope(ctx, repo); |
| 78 | 83 | const back = html`<a href="${repoBase(repo)}/waves">All waves</a>`; |
| 79 | 84 | |
| @@ -100,11 +105,13 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 100 | 105 | const body = html`${scopeHeader(ctx, scope, "code", { compact: true })} |
| 101 | 106 | <div class="mt">${content}<p>${back}</p></div>`; |
| 102 | 107 | |
| 103 | return page({ | |
| 108 | const response = page({ | |
| 104 | 109 | ctx, |
| 105 | 110 | title: `${entry.ok ? entry.wave.version : entry.file} · Waves · ${scope.facts.name}`, |
| 106 | 111 | crumbs: scope.crumbs, |
| 107 | 112 | palette: scope.palette, |
| 108 | 113 | body, |
| 109 | 114 | }); |
| 115 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 116 | return response; | |
| 110 | 117 | } |
test/wave-page-timing.test.ts added +65
| @@ -0,0 +1,65 @@ | ||
| 1 | /** `/:owner/:name/waves/:version` names session, repo, wave and render in Server-Timing (#3633). */ | |
| 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 { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 7 | import { createApp, type App } from "../src/app.ts"; | |
| 8 | import { createSession } from "../src/core/sessions.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { writeWave } from "../src/story/wave.ts"; | |
| 12 | import { quietLogs } from "./helpers/globals.ts"; | |
| 13 | ||
| 14 | quietLogs(); | |
| 15 | ||
| 16 | let root = ""; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | let cookie = ""; | |
| 20 | ||
| 21 | beforeAll(async () => { | |
| 22 | root = mkdtempSync(join(tmpdir(), "forge-wave-page-timing-")); | |
| 23 | app = createApp({ dataDir: root, port: 0 }); | |
| 24 | servers = await serve(app); | |
| 25 | const u = await createUser(app.db, { | |
| 26 | origin: "seed", | |
| 27 | trusted: true, | |
| 28 | username: "keeper", | |
| 29 | email: "[email protected]", | |
| 30 | password: "a-good-passphrase", | |
| 31 | adminIfFirst: true, | |
| 32 | }); | |
| 33 | if (!u.ok) throw new Error(u.error); | |
| 34 | cookie = `forge_session=${createSession(app.db, u.value.id).token}; forge_mode=dev`; | |
| 35 | const made = await createRepo(app, u.value, { name: "alpha", visibility: "public" }); | |
| 36 | if (!made.ok) throw new Error(String(made.error)); | |
| 37 | const w = writeWave({ | |
| 38 | version: "0.1.0", | |
| 39 | date: "2026-01-01", | |
| 40 | headline: "First", | |
| 41 | highlights: [1, 2, 3].map((n) => ({ title: `Thing ${n}`, why: "because" })), | |
| 42 | pulls: [{ title: "#1 A pull", url: "https://forge.example/o/r/pulls/1" }], | |
| 43 | }); | |
| 44 | if (!w.ok) throw w.error; | |
| 45 | const c = await commitToBranch(app, u.value, made.value, { | |
| 46 | message: "wave", | |
| 47 | files: [{ path: "waves/0.1.0.md", content: w.value }], | |
| 48 | }); | |
| 49 | if (!c.ok) throw new Error(JSON.stringify(c.error)); | |
| 50 | }, 30_000); | |
| 51 | afterAll(() => { | |
| 52 | servers.stop(); | |
| 53 | app.close(); | |
| 54 | rmSync(root, { recursive: true, force: true }); | |
| 55 | }); | |
| 56 | ||
| 57 | test("GET a wave page names its phases", async () => { | |
| 58 | const res = await fetch(`${servers.url}/keeper/alpha/waves/0.1.0`, { headers: { cookie } }); | |
| 59 | const body = await res.text(); | |
| 60 | expect(res.status).toBe(200); | |
| 61 | expect(body).toContain("<h1>First</h1>"); | |
| 62 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 63 | for (const name of ["app", "session", "repo", "wave", "render"]) | |
| 64 | expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/); | |
| 65 | }); |
new above
offline
Matches the sibling pages. If page() throws, no render phase is recorded, which is the same as the other pages.