Public: anyone can read this; the crew can change it.
The forge-wide map read names its Server-Timing phases: session, graph, render #5020
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5008-the-forge-wide-map-read-names-its-server → main 1 commit fork
2 files
changed +37
−3
src/http/api.ts +7 −3
| @@ -3638,9 +3638,13 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 3638 | 3638 | }); |
| 3639 | 3639 | }); |
| 3640 | 3640 | // Every repository the caller can see, one entry each: the global map. |
| 3641 | router.add("GET", "/api/v1/map", (ctx) => | |
| 3642 | json(globalMapJson(ctx.app, ctx.auth.user)), | |
| 3643 | ); | |
| 3641 | router.add("GET", "/api/v1/map", (ctx) => { | |
| 3642 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 3643 | const graph = timePhase(ctx.request, "graph", () => | |
| 3644 | globalMapJson(ctx.app, ctx.auth.user), | |
| 3645 | ); | |
| 3646 | return timePhase(ctx.request, "render", () => json(graph)); | |
| 3647 | }); | |
| 3644 | 3648 | |
| 3645 | 3649 | // The decision ledger: what the crew's decider answered and what came of |
| 3646 | 3650 | // it, newest first, with the week summed up per kind. |
test/map-timing.test.ts added +30
| @@ -0,0 +1,30 @@ | ||
| 1 | /** GET /api/v1/map names its phases in Server-Timing. */ | |
| 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 { serve, type Servers } from "../src/http/server.ts"; | |
| 8 | ||
| 9 | let dataDir = ""; | |
| 10 | let app: App, servers: Servers; | |
| 11 | ||
| 12 | beforeAll(async () => { | |
| 13 | dataDir = await mkdtemp(join(tmpdir(), "forge-maptime-")); | |
| 14 | app = createApp({ dataDir, port: 0 }); | |
| 15 | servers = await serve(app); | |
| 16 | }); | |
| 17 | ||
| 18 | afterAll(async () => { | |
| 19 | servers.stop(); | |
| 20 | app.close(); | |
| 21 | await rm(dataDir, { recursive: true, force: true }); | |
| 22 | }); | |
| 23 | ||
| 24 | test("the forge-wide map names session, graph, render in order", async () => { | |
| 25 | const res = await fetch(`${servers.url}/api/v1/map`); | |
| 26 | await res.arrayBuffer(); | |
| 27 | expect(res.status).toBe(200); | |
| 28 | const names = (res.headers.get("server-timing") ?? "").split(", ").map((p) => p.split(";")[0]); | |
| 29 | expect(names.filter((n) => n !== "app")).toEqual(["session", "graph", "render"]); | |
| 30 | }); |
new above
offline