Public: anyone can read this; the crew can change it.
/llms.txt names its Server-Timing phases: repos, render #5390
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/5376-llms-txt-names-its-server-timing-phases → main 3 commits fork
2 files
changed +57
−3
src/web/standards.ts +3 −3
| @@ -257,8 +257,8 @@ export function iconPng(ctx: Ctx): Response { | ||
| 257 | 257 | */ |
| 258 | 258 | export function llmsTxt(ctx: Ctx): Response { |
| 259 | 259 | const o = ctx.url.origin; |
| 260 | const repos = llmsRepos(ctx.app.db); | |
| 261 | return text( | |
| 260 | const repos = timePhase(ctx.request, "repos", () => llmsRepos(ctx.app.db)); | |
| 261 | return timePhase(ctx.request, "render", () => text( | |
| 262 | 262 | [ |
| 263 | 263 | `# forge at ${ctx.url.host}`, |
| 264 | 264 | "", |
| @@ -302,7 +302,7 @@ export function llmsTxt(ctx: Ctx): Response { | ||
| 302 | 302 | "", |
| 303 | 303 | ].join("\n"), |
| 304 | 304 | "text/markdown; charset=utf-8", |
| 305 | ); | |
| 305 | )); | |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | export interface PageLink { |
test/llms-txt-timing.test.ts added +54
| @@ -0,0 +1,54 @@ | ||
| 1 | /** `/llms.txt` names repos and render in Server-Timing (#5376). */ | |
| 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 { createApp, type App } from "../src/app.ts"; | |
| 7 | import { createRepo } from "../src/actions/repos.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-llms-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 | for (const [name, visibility] of [["openyard", "public"], ["secretyard", "private"]] as const) { | |
| 33 | const r = await createRepo(app, u.value, { name, visibility }); | |
| 34 | if (!r.ok) throw new Error(String(r.error)); | |
| 35 | } | |
| 36 | servers = await serve(app); | |
| 37 | }); | |
| 38 | afterAll(() => { | |
| 39 | servers.stop(); | |
| 40 | app.close(); | |
| 41 | rmSync(root, { recursive: true, force: true }); | |
| 42 | }); | |
| 43 | ||
| 44 | test("GET /llms.txt names its phases and lists only public repositories", async () => { | |
| 45 | const res = await fetch(`${servers.url}/llms.txt`); | |
| 46 | const body = await res.text(); | |
| 47 | expect(res.status).toBe(200); | |
| 48 | expect(res.headers.get("content-type")).toBe("text/markdown; charset=utf-8"); | |
| 49 | const timing = res.headers.get("server-timing") ?? ""; | |
| 50 | expect(timing).toContain("repos;"); | |
| 51 | expect(timing).toContain("render;"); | |
| 52 | expect(body).toContain("alice/openyard"); | |
| 53 | expect(body).not.toContain("secretyard"); | |
| 54 | }); |
new above
offline