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

A repository's tell page's Server-Timing names its phases: session, each read, render #3538

Merged opened this

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

Merged

scout/forge:scout/3508-a-repository-s-tell-page-s-server-timing → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/3508-a-repository-s-tell-page-s-server-timing was merged into main as ee74add.

Review

Sign in to review this change.
2 files changed +76 −10
src/web/studio/tell_here.ts +18 −10
@@ -11,15 +11,20 @@ import { parseFrom } from "../../actions/tell.ts";
1111 import { mayDirectCrew } from "../../crew/direct.ts";
1212 import type { Ctx } from "../../http/context.ts";
1313 import { crumbsFor, loadRepo, notFoundPage, pageHead, repoBase, signInFirst } from "../chrome.ts";
14 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
1415 import { html } from "../html.ts";
1516 import { fragment, page } from "../layout.ts";
1617 import { composer } from "../pages/thread.ts";
1718
1819 export function tellHerePage(ctx: Ctx): Response {
19 const repo = loadRepo(ctx);
20 notePhase(ctx.request, "session", takeSessionTime(ctx.request));
21 const repo = timePhase(ctx.request, "repo", () => loadRepo(ctx));
2022 if (!repo) return notFoundPage(ctx);
2123 if (!ctx.auth.user) return signInFirst(ctx);
22 if (!mayDirectCrew(ctx.app.db, repo, ctx.auth.user)) return notFoundPage(ctx);
24 const user = ctx.auth.user;
25 const may = timePhase(ctx.request, "access", () => mayDirectCrew(ctx.app.db, repo, user));
26 if (!may) return notFoundPage(ctx);
27 const rendering = performance.now();
2328 const from = parseFrom(ctx.url.searchParams.get("from") ?? undefined) ?? null;
2429 // The page of the app the toolbar was pressed on, and its pull: both
2530 // checked here and again when the tell is sent.
@@ -44,12 +49,15 @@ export function tellHerePage(ctx: Ctx): Response {
4449 ...(where?.pull === undefined ? {} : { pull: where.pull }),
4550 },
4651 });
47 if (ctx.url.searchParams.get("in") === "place")
48 return fragment(box, { request: ctx.request });
49 return page({
50 ctx,
51 title: `Tell the crew · ${repo.name}`,
52 crumbs: crumbsFor(repo),
53 body: html`${pageHead("Tell the crew")}${box}`,
54 });
52 const response =
53 ctx.url.searchParams.get("in") === "place"
54 ? fragment(box, { request: ctx.request })
55 : page({
56 ctx,
57 title: `Tell the crew · ${repo.name}`,
58 crumbs: crumbsFor(repo),
59 body: html`${pageHead("Tell the crew")}${box}`,
60 });
61 notePhase(ctx.request, "render", performance.now() - rendering);
62 return response;
5563 }
test/tell-here-timing.test.ts added +58
@@ -0,0 +1,58 @@
1 /** `/:owner/:name/tell` names session, repo, access and render in Server-Timing (#3508). */

Header cites #3508; this pull is #3538. Correct the reference.

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 { createRepo } from "../src/actions/repos.ts";
7 import { createApp, type App } from "../src/app.ts";
8 import { createUser } from "../src/core/users.ts";
9 import { serve, type Servers } from "../src/http/server.ts";
10 import { proveAll } from "./helpers/verified.ts";
11 import { quietLogs } from "./helpers/globals.ts";
12
13 quietLogs();
14
15 let root = "";
16 let app: App;
17 let servers: Servers;
18
19 beforeAll(async () => {
20 root = mkdtempSync(join(tmpdir(), "forge-tell-here-timing-"));
21 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
22 const u = await createUser(app.db, {
23 origin: "seed",
24 trusted: true,
25 username: "alice",
26 email: "[email protected]",
27 password: "a-good-passphrase",
28 adminIfFirst: true,
29 });
30 if (!u.ok) throw new Error(u.error);
31 proveAll(app);
32 const made = await createRepo(app, { id: u.value.id, username: "alice" } as never, { name: "forge" });
33 if (!made.ok) throw new Error(made.error);
34 servers = await serve(app);
35 });
36 afterAll(() => {
37 servers.stop();
38 app.close();
39 rmSync(root, { recursive: true, force: true });
40 });
41
42 test("GET /:owner/:name/tell names its phases", async () => {
43 const signin = await fetch(`${servers.url}/signin`, {
44 method: "POST",
45 headers: { origin: servers.url },
46 body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }),
47 redirect: "manual",
48 });
49 const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!;
50 for (const query of ["", "?in=place"]) {
51 const res = await fetch(`${servers.url}/alice/forge/tell${query}`, { headers: { cookie } });
52 await res.text();
53 expect(res.status).toBe(200);
54 const parts = (res.headers.get("server-timing") ?? "").split(", ");
55 for (const name of ["app", "session", "repo", "access", "render"])
56 expect(parts.find((p) => p.startsWith(`${name};`))).toMatch(/^[a-z]+;dur=\d+\.\d$/);
57 }
58 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs