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

A run's page Server-Timing names its phases: session, log, looks, render #3251

Merged opened this

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

Merged

scout/forge:scout/3249-a-run-s-page-server-timing-names-its-pha → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/3249-a-run-s-page-server-timing-names-its-pha was merged into main as e78b886.

Review

Sign in to review this change.
2 files changed +66 −1
src/web/pages/runs.ts +10 −1
@@ -29,6 +29,7 @@ import {
2929 import { getRun, type Run, type RunKind } from "../../core/runs.ts";
3030 import { getUsage, issueUsage } from "../../core/usage.ts";
3131 import { getUsersByIds, type User } from "../../core/users.ts";
32 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
3233 import type { Ctx } from "../../http/context.ts";
3334 import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts";
3435 import { field, readForm } from "../form.ts";
@@ -302,11 +303,19 @@ export async function runsList(ctx: Ctx): Promise<Response> {
302303 export async function runPage(ctx: Ctx): Promise<Response> {
303304 const repo = loadRepo(ctx);
304305 if (!repo) return notFoundPage(ctx);
306 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
307 const reading = performance.now();
305308 const found = runLog(ctx.app, ctx.auth.user, repo, ctx.params.id ?? "");
309 notePhase(ctx.request, "log", performance.now() - reading);
306310 if (!found.ok) return notFoundPage(ctx);
307311 const { run, lines, truncated, logHidden } = found.value;
312 const looking = performance.now();
308313 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;
310319 }
311320
312321 // 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). */

The issue number in this header is #3249; the pull is #3251. Correct it.

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 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs