Public: anyone can read this; the crew can change it.
A repository's home names its Server-Timing phases on both paths, the code home and the app home, and /alice/forge leaves the sweep's debt list #5458
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5414-a-repository-s-home-names-its-server-tim → main 1 commit fork 1 thread · 1 unresolved
3 files
changed +96
−2
src/web/pages/repo.ts +4 −1
| @@ -974,6 +974,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 974 | 974 | const refs = await timePhaseAsync(ctx.request, "refs", () => refSetFrom(scope.source)); |
| 975 | 975 | |
| 976 | 976 | if (refs.branches.length === 0) { |
| 977 | const emptyRendering = performance.now(); | |
| 977 | 978 | const body = html`${scopeHeader(ctx, scope, "code")}${archivedLine(ctx, repo)}${noApp} |
| 978 | 979 | <div class="mt"> |
| 979 | 980 | ${empty({ |
| @@ -994,7 +995,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 994 | 995 | }, |
| 995 | 996 | )} |
| 996 | 997 | </div>`; |
| 997 | return page({ | |
| 998 | const emptyResponse = page({ | |
| 998 | 999 | ctx, |
| 999 | 1000 | title: repo.name, |
| 1000 | 1001 | description: repo.description, |
| @@ -1007,6 +1008,8 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> { | ||
| 1007 | 1008 | palette: scope.palette, |
| 1008 | 1009 | body, |
| 1009 | 1010 | }); |
| 1011 | notePhase(ctx.request, "render", performance.now() - emptyRendering); | |
| 1012 | return emptyResponse; | |
| 1010 | 1013 | } |
| 1011 | 1014 | |
| 1012 | 1015 | const wanted = ctx.url.searchParams.get("ref"); |
test/repo-home-paths-timing.test.ts added +92
| @@ -0,0 +1,92 @@ | ||
| 1 | /** A repository's home names its Server-Timing phases on every path: an empty repository, a repository with code, and an app (#5414). */ | |
| 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 { enableApp } from "../src/actions/apps.ts"; | |
| 7 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 8 | import { createApp, type App } from "../src/app.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 11 | import { proveAll } from "./helpers/verified.ts"; | |
| 12 | import { quietLogs } from "./helpers/globals.ts"; | |
| 13 | ||
| 14 | quietLogs(); | |
| 15 | ||
| 16 | let root = ""; | |
| 17 | let app: App; | |
| 18 | let servers: Servers; | |
| 19 | ||
| 20 | beforeAll(async () => { | |
| 21 | root = mkdtempSync(join(tmpdir(), "forge-repo-home-paths-timing-")); | |
| 22 | app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" }); | |
| 23 | const u = await createUser(app.db, { | |
| 24 | origin: "seed", | |
| 25 | trusted: true, | |
| 26 | username: "alice", | |
| 27 | email: "[email protected]", | |
| 28 | password: "a-good-passphrase", | |
| 29 | adminIfFirst: true, | |
| 30 | }); | |
| 31 | if (!u.ok) throw new Error(u.error); | |
| 32 | proveAll(app); | |
| 33 | const user = { id: u.value.id, username: "alice" } as never; | |
| 34 | const empty = await createRepo(app, user, { name: "empty" }); | |
| 35 | if (!empty.ok) throw new Error(String(empty.error)); | |
| 36 | const plain = await createRepo(app, user, { name: "plain" }); | |
| 37 | if (!plain.ok) throw new Error(String(plain.error)); | |
| 38 | const code = await commitToBranch(app, u.value, plain.value, { | |
| 39 | message: "Start", | |
| 40 | files: [{ path: "README.md", content: "p\n" }], | |
| 41 | }); | |
| 42 | if (!code.ok) throw new Error(JSON.stringify(code.error)); | |
| 43 | const made = await createRepo(app, user, { name: "vault" }); | |
| 44 | if (!made.ok) throw new Error(String(made.error)); | |
| 45 | const seeded = await commitToBranch(app, u.value, made.value, { | |
| 46 | message: "Start", | |
| 47 | files: [{ path: "README.md", content: "v\n" }], | |
| 48 | }); | |
| 49 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); | |
| 50 | const enabled = await enableApp(app, u.value, made.value, { slug: "vault" }); | |
| 51 | if (!enabled.ok) throw new Error(String(enabled.error)); | |
| 52 | servers = await serve(app); | |
| 53 | }); | |
| 54 | afterAll(() => { | |
| 55 | servers.stop(); | |
| 56 | app.close(); | |
| 57 | rmSync(root, { recursive: true, force: true }); | |
| 58 | }); | |
| 59 | ||
| 60 | async function phases(path: string): Promise<string[]> { | |
| 61 | const signin = await fetch(`${servers.url}/signin`, { | |
| 62 | method: "POST", | |
| 63 | headers: { origin: servers.url }, | |
| 64 | body: new URLSearchParams({ username: "alice", password: "a-good-passphrase" }), | |
| 65 | redirect: "manual", | |
| 66 | }); | |
| 67 | const cookie = (signin.headers.get("set-cookie") ?? "").split(";")[0]!; | |
| 68 | const res = await fetch(`${servers.url}${path}`, { headers: { cookie } }); | |
| 69 | await res.text(); | |
| 70 | expect(res.status).toBe(200); | |
| 71 | const parts = (res.headers.get("server-timing") ?? "").split(", "); | |
| 72 | for (const p of parts) expect(p).toMatch(/^[a-z]+;dur=\d+(\.\d)?$/); | |
| 73 | return parts.map((p) => p.split(";")[0]!); | |
| 74 | } | |
| 75 | ||
| 76 | test("an empty repository's home names session, appof, refs and render", async () => { | |
| 77 | expect(await phases("/alice/empty")).toEqual( | |
| 78 | expect.arrayContaining(["app", "session", "appof", "refs", "render"]), | |
| 79 | ); | |
| 80 | }); | |
| 81 | ||
| 82 | test("a plain repository's home names session, each read and render", async () => { | |
| 83 | expect(await phases("/alice/plain")).toEqual( | |
| 84 | expect.arrayContaining(["app", "session", "appof", "refs", "tree", "readme", "following", "render"]), | |
| 85 | ); | |
| 86 | }); | |
| 87 | ||
| 88 | test("an app repository's home names session, each read and render", async () => { | |
| 89 | expect(await phases("/alice/vault")).toEqual( | |
| 90 | expect.arrayContaining(["app", "session", "opened", "crew", "pulls", "panels", "render"]), | |
| 91 | ); | |
| 92 | }); |
test/server-timing-sweep.test.ts −1
| @@ -21,7 +21,6 @@ quietLogs(); | ||
| 21 | 21 | /** Pages without named phases yet → the issue that will name them. */ |
| 22 | 22 | const UNNAMED: Array<[path: string, issue: string]> = [ |
| 23 | 23 | ["/-/confirm", "#3390"], |
| 24 | ["/alice/forge", "#3325"], | |
| 25 | 24 | ["/alice/forge/changes", "#3323"], |
| 26 | 25 | ["/alice/forge/map", "#3320"], |
| 27 | 26 | ["/alice/forge/tells", "#3322"], |
new above
offline
Starts the clock before the body template, so
renderhere includes building the body. Check the code path measures the same span.