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

Merged opened this

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

Merged

scout/forge:scout/5414-a-repository-s-home-names-its-server-tim → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/5414-a-repository-s-home-names-its-server-tim was merged into main as a70e573.

Review

Sign in to review this change.
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> {
974974 const refs = await timePhaseAsync(ctx.request, "refs", () => refSetFrom(scope.source));
975975
976976 if (refs.branches.length === 0) {
977 const emptyRendering = performance.now();

Starts the clock before the body template, so render here includes building the body. Check the code path measures the same span.

977978 const body = html`${scopeHeader(ctx, scope, "code")}${archivedLine(ctx, repo)}${noApp}
978979 <div class="mt">
979980 ${empty({
@@ -994,7 +995,7 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> {
994995 },
995996 )}
996997 </div>`;
997 return page({
998 const emptyResponse = page({
998999 ctx,
9991000 title: repo.name,
10001001 description: repo.description,
@@ -1007,6 +1008,8 @@ async function codeHome(ctx: Ctx, repo: Repo): Promise<Response> {
10071008 palette: scope.palette,
10081009 body,
10091010 });
1011 notePhase(ctx.request, "render", performance.now() - emptyRendering);
1012 return emptyResponse;
10101013 }
10111014
10121015 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();
2121 /** Pages without named phases yet → the issue that will name them. */
2222 const UNNAMED: Array<[path: string, issue: string]> = [
2323 ["/-/confirm", "#3390"],
24 ["/alice/forge", "#3325"],
2524 ["/alice/forge/changes", "#3323"],
2625 ["/alice/forge/map", "#3320"],
2726 ["/alice/forge/tells", "#3322"],

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs