Public: anyone can read this; the crew can change it.
A run's page Server-Timing names its phases: session, log, looks, render #3251
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/3249-a-run-s-page-server-timing-names-its-pha → main 1 commit fork 1 thread · 1 unresolved
2 files
changed +66
−1
src/web/pages/runs.ts +10 −1
| @@ -29,6 +29,7 @@ import { | ||
| 29 | 29 | import { getRun, type Run, type RunKind } from "../../core/runs.ts"; |
| 30 | 30 | import { getUsage, issueUsage } from "../../core/usage.ts"; |
| 31 | 31 | import { getUsersByIds, type User } from "../../core/users.ts"; |
| 32 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; | |
| 32 | 33 | import type { Ctx } from "../../http/context.ts"; |
| 33 | 34 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| 34 | 35 | import { field, readForm } from "../form.ts"; |
| @@ -302,11 +303,19 @@ export async function runsList(ctx: Ctx): Promise<Response> { | ||
| 302 | 303 | export async function runPage(ctx: Ctx): Promise<Response> { |
| 303 | 304 | const repo = loadRepo(ctx); |
| 304 | 305 | if (!repo) return notFoundPage(ctx); |
| 306 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 307 | const reading = performance.now(); | |
| 305 | 308 | const found = runLog(ctx.app, ctx.auth.user, repo, ctx.params.id ?? ""); |
| 309 | notePhase(ctx.request, "log", performance.now() - reading); | |
| 306 | 310 | if (!found.ok) return notFoundPage(ctx); |
| 307 | 311 | const { run, lines, truncated, logHidden } = found.value; |
| 312 | const looking = performance.now(); | |
| 308 | 313 | const looks = logHidden ? [] : readLooks(ctx.app.config.dataDir, run); |
| 309 | return await runView(ctx, repo, run, lines, truncated, logHidden, looks); | |
| 314 | notePhase(ctx.request, "looks", performance.now() - looking); | |
| 315 | const rendering = performance.now(); | |
| 316 | const view = await runView(ctx, repo, run, lines, truncated, logHidden, looks); | |
| 317 | notePhase(ctx.request, "render", performance.now() - rendering); | |
| 318 | return view; | |
| 310 | 319 | } |
| 311 | 320 | |
| 312 | 321 | // POST /:owner/:name/runs/:id/steer { text } |
test/run-page-timing.test.ts added +56
| @@ -0,0 +1,56 @@ | ||
| 1 | /** A run's page names its phases in Server-Timing (#3249). */ | |
| 2 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createRun, finishRun } from "../src/core/runs.ts"; | |
| 9 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 10 | import { seedAdmin } from "./helpers/admin.ts"; | |
| 11 | ||
| 12 | let dataDir = ""; | |
| 13 | let app: App, servers: Servers, bearer = "", runId = ""; | |
| 14 | ||
| 15 | beforeAll(async () => { | |
| 16 | dataDir = await mkdtemp(join(tmpdir(), "forge-rtime-")); | |
| 17 | app = createApp({ dataDir, port: 0 }); | |
| 18 | servers = await serve(app); | |
| 19 | const admin = await seedAdmin(app, { username: "alice", email: "[email protected]", password: "correct-horse-battery" }); | |
| 20 | if (!admin.ok) throw new Error(admin.error); | |
| 21 | const made = await createRepo(app, admin.value, { name: "notes", visibility: "public", description: "" }); | |
| 22 | if (!made.ok) throw new Error(String(made.error)); | |
| 23 | const run = createRun(app.db, { repoId: made.value.id, kind: "check" }); | |
| 24 | runId = run.id; | |
| 25 | finishRun(app.db, runId, { state: "ok", summary: "fine" }); | |
| 26 | const minted = await fetch(`${servers.url}/api/v1/tokens`, { | |
| 27 | method: "POST", | |
| 28 | headers: { "content-type": "application/json" }, | |
| 29 | body: JSON.stringify({ adminConfirm: true, username: "alice", password: "correct-horse-battery", name: "cli", scope: "admin" }), | |
| 30 | }); | |
| 31 | bearer = ((await minted.json()) as { token: string }).token; | |
| 32 | }); | |
| 33 | ||
| 34 | afterAll(async () => { | |
| 35 | servers.stop(); | |
| 36 | app.close(); | |
| 37 | await rm(dataDir, { recursive: true, force: true }); | |
| 38 | }); | |
| 39 | ||
| 40 | function names(res: Response): string[] { | |
| 41 | return (res.headers.get("server-timing") ?? "").split(", ").map((p) => p.split(";")[0]!); | |
| 42 | } | |
| 43 | ||
| 44 | test("a finished run's page names session, log, looks and render once each", async () => { | |
| 45 | const res = await fetch(`${servers.url}/alice/notes/runs/${runId}`, { headers: { authorization: `Bearer ${bearer}` } }); | |
| 46 | expect(res.status).toBe(200); | |
| 47 | await res.text(); | |
| 48 | expect(res.headers.get("x-content-type-options")).toBe("nosniff"); | |
| 49 | for (const n of ["session", "log", "looks", "render"]) expect(names(res).filter((x) => x === n).length).toBe(1); | |
| 50 | }); | |
| 51 | ||
| 52 | test("a run whose log is hidden still names looks", async () => { | |
| 53 | const res = await fetch(`${servers.url}/alice/notes/runs/${runId}`); | |
| 54 | expect(res.status).toBe(200); | |
| 55 | expect(names(res)).toContain("looks"); | |
| 56 | }); |
new above
offline
The issue number in this header is #3249; the pull is #3251. Correct it.