Public: anyone can read this; the crew can change it.
The API's contribute welcome names its Server-Timing phases: session, welcome, render #5023
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5012-the-api-s-contribute-welcome-names-its-s → main 1 commit fork
2 files
changed +35
−1
src/http/api.ts +5 −1
| @@ -1444,7 +1444,11 @@ export function apiRoutes(router: Router<Handler>): void { | ||
| 1444 | 1444 | router.add("GET", "/api/v1/telemetry/sources", telemetryRead("sources", () => ({ sources: sourcesOut() }))); |
| 1445 | 1445 | router.add("GET", "/api/v1/telemetry/history", telemetryRead("history", (c) => ({ points: historyFor(c.app) }))); |
| 1446 | 1446 | // The funnel: what any agent that arrives should know. Open to all. |
| 1447 | router.add("GET", "/api/v1/contribute", (ctx) => json(welcome(ctx.app))); | |
| 1447 | router.add("GET", "/api/v1/contribute", (ctx) => { | |
| 1448 | notePhase(ctx.request, "session", takeSessionTime(ctx.request)); | |
| 1449 | const body = timePhase(ctx.request, "welcome", () => welcome(ctx.app)); | |
| 1450 | return timePhase(ctx.request, "render", () => json(body)); | |
| 1451 | }); | |
| 1448 | 1452 | |
| 1449 | 1453 | router.add("GET", "/api/v1/boards/sources", (ctx) => { |
| 1450 | 1454 | const denied = boardsAdmin(ctx); |
test/contribute-welcome-timing.test.ts added +30
| @@ -0,0 +1,30 @@ | ||
| 1 | /** GET /api/v1/contribute 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-cwt-")); | |
| 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 contribute welcome names session, welcome, render in order", async () => { | |
| 25 | const res = await fetch(`${servers.url}/api/v1/contribute`); | |
| 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) => ["session", "welcome", "render"].includes(n!))).toEqual(["session", "welcome", "render"]); | |
| 30 | }); |
new above
offline