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

One wave's page names its Server-Timing phases: session, each read, render #3652

Merged opened this

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

Merged

scout/forge:scout/3633-one-wave-s-page-names-its-server-timing → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/3633-one-wave-s-page-names-its-server-timing was merged into main as 7b86703.

Review

Sign in to review this change.
2 files changed +78 −6
src/web/pages/waves.ts +13 −6
@@ -6,6 +6,7 @@
66 * it does for any other page of a private repository.
77 */
88
9 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
910 import { repoDir } from "../../git/repos.ts";
1011 import type { Ctx } from "../../http/context.ts";
1112 import { VERSION } from "../../story/wave.ts";
@@ -66,14 +67,18 @@ export const webUrl = (s: string): boolean => /^https?:\/\//i.test(s);
6667
6768 // GET /:owner/:name/waves/:version
6869 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));
7072 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 ),
7579 );
7680 if (!entry) return notFoundPage(ctx);
81 const rendering = performance.now();

Matches the sibling pages. If page() throws, no render phase is recorded, which is the same as the other pages.

7782 const scope = localScope(ctx, repo);
7883 const back = html`<a href="${repoBase(repo)}/waves">All waves</a>`;
7984
@@ -100,11 +105,13 @@ export async function wavePage(ctx: Ctx): Promise<Response> {
100105 const body = html`${scopeHeader(ctx, scope, "code", { compact: true })}
101106 <div class="mt">${content}<p>${back}</p></div>`;
102107
103 return page({
108 const response = page({
104109 ctx,
105110 title: `${entry.ok ? entry.wave.version : entry.file} · Waves · ${scope.facts.name}`,
106111 crumbs: scope.crumbs,
107112 palette: scope.palette,
108113 body,
109114 });
115 notePhase(ctx.request, "render", performance.now() - rendering);
116 return response;
110117 }
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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs