Public: anyone can read this; the crew can change it.
A release entry on /changelog says which routes got faster or slower than the day before it #16081
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16067-a-release-entry-on-changelog-says-which → main 0 commits fork 3 threads · 3 unresolved
8 files
changed +277
−9
docs/features/performance-watcher.md +7 −1
| @@ -10,7 +10,9 @@ row: Performance watcher | ||
| 10 | 10 | |
| 11 | 11 | The last 24 hours read in the terminal's System screen (admin who is a person; the five slowest p95 first, with n, p50, p95 and the budget) and as the admin-only `route_hour` boards source (route, hour, n, p50, p95; `slowestRoutes` is one indexed query). |
| 12 | 12 | |
| 13 | Not yet: a synthetic probe for routes with no traffic (a client-written label would let anyone hide requests; it needs an admin-only door first), browser timings, release before/after. | |
| 13 | `/changelog` shows admins, under a heading, a plain row per release of the last seven days saying which routes got faster or slower after it (`release_delta.ts` compares the p95 of the 24 hours either side; `release_speed.ts` reads the rows). The terminal's changelog screen (`src/tui/screens/changelog.ts`) puts the same line in the release's own row, for an admin who is a person. | |
| 14 | ||
| 15 | Not yet: a synthetic probe for routes with no traffic (a client-written label would let anyone hide requests; it needs an admin-only door first), browser timings. | |
| 14 | 16 | |
| 15 | 17 | ## Sampling the main thread: `FORGE_PROFILE=1` (#12455) |
| 16 | 18 | |
| @@ -23,3 +25,7 @@ process with `FORGE_PROFILE=1` — meant for the stage rig, not production. Once | ||
| 23 | 25 | a sample has run the profiler stays attached until the process restarts, and |
| 24 | 26 | its traces are drained and discarded every two seconds by the `profiler-drain` |
| 25 | 27 | job; a window being sampled keeps its traces until it ends. |
| 28 | ||
| 29 | ## Release before/after (#16067) | |
| 30 | ||
| 31 | `release_delta.ts` compares each route's p95 in `route_hour` over the 24 hours before a release with the 24 hours after it (the release's own hour is left out; a day's p95 is the request-weighted mean of its hours', an estimate). A route that moved 20% or more with 20+ requests on both sides is named, at most three faster and three slower. `/changelog` shows one line per release of the last seven days ("Faster: /x (120 → 80 ms). Slower: /y (40 → 70 ms).") to admins only; a release with nothing moved, or older than the 168 hours kept, shows nothing. |
src/perf/release_delta.ts added +69
| @@ -0,0 +1,69 @@ | ||
| 1 | /** | |
| 2 | * What a release did to speed (#16067): per route, the p95 of the 24 hours before the release | |
| 3 | * against the 24 hours after it, from `route_hour` rows. The release's own hour is left out (it | |
| 4 | * holds both). A day's p95 is the request-weighted mean of its hours' p95: an estimate, since | |
| 5 | * hourly rows cannot be merged exactly. Pure: rows in, one line out. | |
| 6 | */ | |
| 7 | ||
| 8 | import type { RouteHour } from "./history.ts"; | |
| 9 | ||
| 10 | const HOUR_MS = 3_600_000; | |
| 11 | /** Hours each side. */ | |
| 12 | export const SIDE_HOURS = 24; | |
| 13 | /** A route moved when p95 changed by this share or more. */ | |
| 14 | export const MOVED = 0.2; | |
| 15 | /** Requests needed on each side. */ | |
| 16 | export const MIN_REQUESTS = 20; | |
| 17 | /** Routes named per direction. */ | |
| 18 | export const NAMED = 3; | |
| 19 | ||
| 20 | interface Side { | |
| 21 | n: number; | |
| 22 | weighted: number; | |
| 23 | } | |
| 24 | ||
| 25 | /** One route's change: `shift` is signed, positive when slower. */ | |
| 26 | export interface Moved { | |
| 27 | readonly route: string; | |
| 28 | readonly before: number; | |
| 29 | readonly after: number; | |
| 30 | readonly shift: number; | |
| 31 | } | |
| 32 | ||
| 33 | /** The routes that moved, from the rows of the day around `releaseAt` (ms). */ | |
| 34 | export function routesMoved(rows: readonly RouteHour[], releaseAt: number): Moved[] { | |
| 35 | const h = Math.floor(releaseAt / HOUR_MS); | |
| 36 | const before = new Map<string, Side>(); | |
| 37 | const after = new Map<string, Side>(); | |
| 38 | for (const r of rows) { | |
| 39 | const into = r.hour >= h - SIDE_HOURS && r.hour < h ? before : r.hour > h && r.hour <= h + SIDE_HOURS ? after : undefined; | |
| 40 | if (into === undefined || r.n <= 0) continue; | |
| 41 | const side = into.get(r.route) ?? { n: 0, weighted: 0 }; | |
| 42 | side.n += r.n; | |
| 43 | side.weighted += r.n * r.p95; | |
| 44 | into.set(r.route, side); | |
| 45 | } | |
| 46 | const out: Moved[] = []; | |
| 47 | for (const [route, b] of before) { | |
| 48 | const a = after.get(route); | |
| 49 | if (a === undefined || a.n < MIN_REQUESTS || b.n < MIN_REQUESTS) continue; | |
| 50 | const was = b.weighted / b.n; | |
| 51 | const now = a.weighted / a.n; | |
| 52 | if (was <= 0) continue; | |
| 53 | const shift = (now - was) / was; | |
| 54 | if (Math.abs(shift) >= MOVED) out.push({ route, before: Math.round(was), after: Math.round(now), shift }); | |
| 55 | } | |
| 56 | return out; | |
| 57 | } | |
| 58 | ||
| 59 | /** | |
| 60 | * "Faster: /x (120 → 80 ms). Slower: /y (40 → 70 ms)." at most three each; "" when nothing moved. | |
| 61 | */ | |
| 62 | export function releaseDelta(rows: readonly RouteHour[], releaseAt: number): string { | |
| 63 | const moved = routesMoved(rows, releaseAt); | |
| 64 | const say = (label: string, list: Moved[]) => | |
| 65 | list.length === 0 ? null : `${label}: ${list.slice(0, NAMED).map((m) => `${m.route} (${m.before} → ${m.after} ms)`).join(", ")}.`; | |
| 66 | const faster = moved.filter((m) => m.shift < 0).sort((x, y) => x.shift - y.shift || x.route.localeCompare(y.route)); | |
| 67 | const slower = moved.filter((m) => m.shift > 0).sort((x, y) => y.shift - x.shift || x.route.localeCompare(y.route)); | |
| 68 | return [say("Faster", faster), say("Slower", slower)].filter((s) => s !== null).join(" "); | |
| 69 | } |
src/perf/release_speed.ts added +24
| @@ -0,0 +1,24 @@ | ||
| 1 | /** | |
| 2 | * What each release of the last seven days did to route speed (#16067), one line per release, read | |
| 3 | * from the stored `route_hour` rows. The page (`/changelog`) and the terminal's changelog screen | |
| 4 | * both read it, and both show it to admins only: route timings are not public. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { Database } from "bun:sqlite"; | |
| 8 | import { routeHours } from "./history.ts"; | |
| 9 | import { releaseDelta } from "./release_delta.ts"; | |
| 10 | import type { ReleaseEntry } from "../release/changelog.ts"; | |
| 11 | ||
| 12 | const DAY_MS = 86_400_000; | |
| 13 | ||
| 14 | /** A release with nothing to say, or older than the 168 hours kept, has no line. */ | |
| 15 | export function speedLines(db: Database, entries: readonly ReleaseEntry[], now = Date.now()): { version: string; line: string }[] { | |
| 16 | const rows = routeHours(db, 168, now); | |
| 17 | if (rows.length === 0) return []; | |
| 18 | return entries.flatMap((e) => { | |
| 19 | const at = Date.parse(e.date); | |
| 20 | if (!Number.isFinite(at) || now - at > 7 * DAY_MS || at > now) return []; | |
| 21 | const line = releaseDelta(rows, at); | |
| 22 | return line === "" ? [] : [{ version: e.version, line }]; | |
| 23 | }); | |
| 24 | } |
src/tui/screens/changelog.ts +10 −4
| @@ -17,6 +17,7 @@ import { monthLabel } from "../../release/month.ts"; | ||
| 17 | 17 | import { rangeOf, rangeWords } from "../../release/range.ts"; |
| 18 | 18 | import { commitLog } from "../../git/read.ts"; |
| 19 | 19 | import { repoDir } from "../../git/repos.ts"; |
| 20 | import { speedLines } from "../../perf/release_speed.ts"; | |
| 20 | 21 | import { forgeChangelog, type ReleaseEntry } from "../../release/changelog.ts"; |
| 21 | 22 | import { readLandings, type Landing } from "../../release/landings.ts"; |
| 22 | 23 | import { nearMilestones, nearWords, type Near } from "../../web/pages/milestones_near.ts"; |
| @@ -50,7 +51,8 @@ export function releaseRange(e: ReleaseEntry): string { | ||
| 50 | 51 | return r === undefined ? "" : rangeWords(r); |
| 51 | 52 | } |
| 52 | 53 | |
| 53 | export function changelogRows(entries: readonly ReleaseEntry[]): ListRow[] { | |
| 54 | /** `speed`: each release's route speed line (admins only), in its entry's row. */ | |
| 55 | export function changelogRows(entries: readonly ReleaseEntry[], speed: ReadonlyMap<string, string> = new Map()): ListRow[] { | |
| 54 | 56 | return entries.map((e) => ({ |
| 55 | 57 | title: e.version, |
| 56 | 58 | meta: metaOf( |
| @@ -58,6 +60,7 @@ export function changelogRows(entries: readonly ReleaseEntry[]): ListRow[] { | ||
| 58 | 60 | `${e.pulls.length} ${e.pulls.length === 1 ? "pull" : "pulls"}`, |
| 59 | 61 | releaseRange(e), |
| 60 | 62 | e.pulls.map((p) => `#${p.number} ${plainTitle(p.title)}`.trim()).join("; "), |
| 63 | speed.get(e.version) ?? "", | |
| 61 | 64 | ), |
| 62 | 65 | })); |
| 63 | 66 | } |
| @@ -95,7 +98,7 @@ export function chapterLines(groups: readonly Group[], keep: (l: Landing) => boo | ||
| 95 | 98 | } |
| 96 | 99 | |
| 97 | 100 | /** The releases as lines, for a repository with no chapter to tell them in. */ |
| 98 | export function changelogLines(entries: readonly ReleaseEntry[]): Line[] { | |
| 101 | export function changelogLines(entries: readonly ReleaseEntry[], speed: ReadonlyMap<string, string> = new Map()): Line[] { | |
| 99 | 102 | const out: Line[] = []; |
| 100 | 103 | let month = ""; |
| 101 | 104 | for (const e of entries) { |
| @@ -106,7 +109,7 @@ export function changelogLines(entries: readonly ReleaseEntry[]): Line[] { | ||
| 106 | 109 | const n = entries.filter((x) => x.date.slice(0, 7) === month).length; |
| 107 | 110 | out.push({ row: { title: monthLabel(month), meta: `${n} ${n === 1 ? "release" : "releases"}` } }); |
| 108 | 111 | } |
| 109 | out.push({ row: changelogRows([e])[0]!, entry: e }); | |
| 112 | out.push({ row: changelogRows([e], speed)[0]!, entry: e }); | |
| 110 | 113 | } |
| 111 | 114 | return out; |
| 112 | 115 | } |
| @@ -222,9 +225,10 @@ export function changelogScreen(f: Session, ctx: Ctx): Screen { | ||
| 222 | 225 | let repoRef: Repo | undefined; |
| 223 | 226 | let credits = new Map<number, string>(); |
| 224 | 227 | let near: string[] = []; |
| 228 | let speed = new Map<string, string>(); | |
| 225 | 229 | let groups: Group[] = []; |
| 226 | 230 | const lines = (): Line[] => |
| 227 | groups.length > 0 ? chapterLines(groups, (l) => filter.matches(`${plainTitle(l.title)}\n#${l.number}`), filter.query !== "") : changelogLines(shown()); | |
| 231 | groups.length > 0 ? chapterLines(groups, (l) => filter.matches(`${plainTitle(l.title)}\n#${l.number}`), filter.query !== "") : changelogLines(shown(), speed); | |
| 228 | 232 | // In releases the cursor starts on the first release, not on the month line above it. |
| 229 | 233 | const home = (): void => { |
| 230 | 234 | state.clamp(lines().length); |
| @@ -269,6 +273,8 @@ export function changelogScreen(f: Session, ctx: Ctx): Screen { | ||
| 269 | 273 | const live = (landings?.live ?? []).filter((l) => l.repo.toLowerCase() === name.toLowerCase()); |
| 270 | 274 | groups = groupByChapter(live, withStanding(f.app, await withWaves(f.app, entries), f.user)); |
| 271 | 275 | } |
| 276 | // Route timings are not public: admins who are people read each release's speed line. | |
| 277 | speed = f.user?.isAdmin === true && f.user.kind !== "agent" ? new Map(speedLines(f.app.db, entries).map((x) => [x.version, x.line])) : new Map(); | |
| 272 | 278 | near = nearLines(nearMilestones(f.app, f.app.config.forgeRepo, f.user)?.near ?? []); |
| 273 | 279 | if (groups.length > 0) near = [weekOfGroups(groups, new Date()).sentence, ...near]; |
| 274 | 280 | home(); |
src/web/pages/changelog.ts +14 −2
| @@ -28,6 +28,7 @@ import { doneWords } from "../../story/wave_moved.ts"; | ||
| 28 | 28 | import { weekOfGroups } from "../../story/week.ts"; |
| 29 | 29 | import { withStanding } from "./wave_standing.ts"; |
| 30 | 30 | import { nearMilestones, nearWords, type Near } from "./milestones_near.ts"; |
| 31 | import { speedLines } from "../../perf/release_speed.ts"; | |
| 31 | 32 | import { liveRegionsJs } from "../client.ts"; |
| 32 | 33 | import { pageHead, repoBase } from "../chrome.ts"; |
| 33 | 34 | import { changelogTag, holds } from "../feeds.ts"; |
| @@ -78,6 +79,16 @@ function shippedWords(l: Landing): Html | null { | ||
| 78 | 79 | return html` · in ${s.version} ${s.from === undefined ? html`<span class="sha" title="${s.to}">${words}</span>` : html`<a class="sha" data-range href="/${l.repo}${comparePath({ from: s.from, to: s.to })}">${words}</a>`}`; |
| 79 | 80 | } |
| 80 | 81 | |
| 82 | /** | |
| 83 | * The speed lines under their own sentence, as plain rows: absent when there are none. They sit | |
| 84 | * above the shipped list, whose rows name the release each change went out in. | |
| 85 | */ | |
| 86 | function speedBlock(speed: readonly { version: string; line: string }[]): Html | null { | |
| 87 | return speed.length === 0 | |
| 88 | ? null | |
| 89 | : html`<section aria-labelledby="route-speed"><h2 id="route-speed" class="small muted">Route speed after each release of the last seven days, p95 of the day before against the day after</h2>${speed.map((s) => html`<p class="small"><span class="sha">${s.version}</span> ${s.line}</p>`)}</section>`; | |
| 90 | } | |
| 91 | ||
| 81 | 92 | /** Releases on a page: the rest are read on demand with `?before=`. */ |
| 82 | 93 | export const PAGE = 30; |
| 83 | 94 | |
| @@ -391,9 +402,10 @@ export async function changelogPage(ctx: Ctx): Promise<Response> { | ||
| 391 | 402 | // The tag comes from what the page would say, before any of it is rendered: |
| 392 | 403 | // a match answers 304 without building the page. |
| 393 | 404 | const toLive = newestLive(ctx.app.db); |
| 405 | const speed = ctx.auth.user?.isAdmin === true ? speedLines(ctx.app.db, releases?.entries ?? []) : []; | |
| 394 | 406 | const target = askedAnchor(ctx.url.searchParams.get("release")); |
| 395 | 407 | const flashed = readFlash(ctx.request) !== undefined; |
| 396 | const tag = flashed ? undefined : changelogTag(read.version, everything, [choice, bet, read.commit, read.live.map((l) => `${l.repo}#${l.number}`), readable, toLive ?? null, everything.map((l) => timeAgo(l.at)), new Date().toISOString().slice(0, 10), releases?.entries[0]?.oid ?? null, releases?.entries.length ?? 0, ctx.auth.user?.id ?? null, ctx.auth.user?.isAdmin === true, ctx.theme ?? null, near, stamp, tips, read.more ?? null, ctx.url.searchParams.get("before") === null ? 0 : 1, target ?? null]); | |
| 408 | const tag = flashed ? undefined : changelogTag(read.version, everything, [choice, bet, read.commit, read.live.map((l) => `${l.repo}#${l.number}`), readable, toLive ?? null, everything.map((l) => timeAgo(l.at)), new Date().toISOString().slice(0, 10), releases?.entries[0]?.oid ?? null, releases?.entries.length ?? 0, ctx.auth.user?.id ?? null, ctx.auth.user?.isAdmin === true, ctx.theme ?? null, near, stamp, tips, read.more ?? null, ctx.url.searchParams.get("before") === null ? 0 : 1, target ?? null, speed]); | |
| 397 | 409 | const keep = tag === undefined ? undefined : cacheHeaders(ctx, tag); |
| 398 | 410 | if (keep !== undefined && keep.matched) return keep.response; |
| 399 | 411 | const chapters = withStanding(ctx.app, await withWaves(ctx.app, chapterEntries(ctx.app.db, read.live, ctx.auth.user)), ctx.auth.user); |
| @@ -410,7 +422,7 @@ export async function changelogPage(ctx: Ctx): Promise<Response> { | ||
| 410 | 422 | { label: "Every bet", href: "/changelog", current: bet === "" }, |
| 411 | 423 | ...bets.map((b) => ({ label: b, href: `/changelog?bet=${encodeURIComponent(b)}`, current: bet === b })), |
| 412 | 424 | ]); |
| 413 | const body = html`${pageHead("Changelog", { sub: "What went live, as it happens." })}${nearBlock(planned === undefined ? "" : repoBase(planned.repo), near)}${filters}${betFilters}${read.own !== undefined && readable ? html`<p class="small"><a href="/${read.own}/waves" data-waves-link>Read it by wave</a></p>` : null} | |
| 425 | const body = html`${pageHead("Changelog", { sub: "What went live, as it happens." })}${nearBlock(planned === undefined ? "" : repoBase(planned.repo), near)}${filters}${betFilters}${speedBlock(speed)}${read.own !== undefined && readable ? html`<p class="small"><a href="/${read.own}/waves" data-waves-link>Read it by wave</a></p>` : null} | |
| 414 | 426 | <div id="shipped" data-live="${LIVE}" aria-live="polite">${shippedRegion(read, choice, new Date(), "UTC", toLive, readable, chapters, bet, target)}</div>`; |
| 415 | 427 | const response = page({ ctx, title: "Changelog", description: "What shipped on this forge, newest first: each change that landed and when.", body, feed: { href: "/changelog.atom", title: "Changelog" }, json: { href: `/api/v1/changelog${choice === read.own ? "" : `?repo=${encodeURIComponent(choice)}`}`, title: "Changelog (JSON)" }, scriptJs: `${liveRegionsJs}\n${localDaysJs}` }); |
| 416 | 428 | notePhase(ctx.request, "render", performance.now() - rendering); |
test/changelog-speed.test.ts added +72
| @@ -0,0 +1,72 @@ | ||
| 1 | /** | |
| 2 | * /changelog's route speed list is admin-only (route timings are not public) and part of the ETag. | |
| 3 | */ | |
| 4 | import { afterAll, beforeAll, expect, setSystemTime, test } from "bun:test"; | |
| 5 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 6 | import { tmpdir } from "node:os"; | |
| 7 | import { join } from "node:path"; | |
| 8 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { createToken } from "../src/core/tokens.ts"; | |
| 11 | import { createUser, type User } from "../src/core/users.ts"; | |
| 12 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 13 | import { quietLogs } from "./helpers/globals.ts"; | |
| 14 | ||
| 15 | quietLogs(); | |
| 16 | ||
| 17 | const H = 3_600_000; | |
| 18 | let dir: string; | |
| 19 | let app: App; | |
| 20 | let servers: Servers; | |
| 21 | let adminToken: string; | |
| 22 | let memberToken: string; | |
| 23 | let releaseHour: number; | |
| 24 | ||
| 25 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 26 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 27 | return r.value; | |
| 28 | }; | |
| 29 | const read = (token?: string) => fetch(`${servers.url}/changelog`, token === undefined ? {} : { headers: { authorization: `Bearer ${token}` } }); | |
| 30 | const put = (route: string, hour: number, p95: number) => app.db.query("INSERT OR REPLACE INTO route_hour (route, hour, n, p50, p95) VALUES (?,?,?,?,?)").run(route, hour, 30, p95 / 2, p95); | |
| 31 | ||
| 32 | beforeAll(async () => { | |
| 33 | dir = await mkdtemp(join(tmpdir(), "forge-changelog-speed-")); | |
| 34 | app = createApp({ dataDir: dir, port: 0 }); | |
| 35 | servers = await serve(app); | |
| 36 | const alice: User = must(await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true })); | |
| 37 | const bob: User = must(await createUser(app.db, { origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase" })); | |
| 38 | const repo = must(await createRepo(app, alice, { name: "forge", visibility: "public" })); | |
| 39 | must(await commitToBranch(app, alice, repo, { message: "Release 0.2.0: Faster thing (#2)", files: [{ path: "f.txt", content: "1\n" }] })); | |
| 40 | app.config.forgeRepo = "alice/forge"; | |
| 41 | releaseHour = Math.floor(Date.now() / H); | |
| 42 | // Three hours later the release is in the past, with a day of rows on each side of it. | |
| 43 | setSystemTime(new Date(Date.now() + 3 * H)); | |
| 44 | put("/slow", releaseHour - 5, 100); | |
| 45 | put("/slow", releaseHour + 1, 200); | |
| 46 | adminToken = createToken(app.db, alice.id, "rw", "rw").token; | |
| 47 | memberToken = createToken(app.db, bob.id, "rw", "rw").token; | |
| 48 | }, 60_000); | |
| 49 | ||
| 50 | afterAll(async () => { | |
| 51 | setSystemTime(); | |
| 52 | servers.stop(); | |
| 53 | app.close(); | |
| 54 | await rm(dir, { recursive: true, force: true }); | |
| 55 | }); | |
| 56 | ||
| 57 | test("an admin reads the route speed under its heading; a guest and a non-admin do not", async () => { | |
| 58 | const admin = await (await read(adminToken)).text(); | |
| 59 | expect(admin).toContain("Route speed after each release"); | |
| 60 | expect(admin).toContain("Slower: /slow (100 → 200 ms)."); | |
| 61 | for (const body of [await (await read()).text(), await (await read(memberToken)).text()]) { | |
| 62 | expect(body).not.toContain("Route speed after each release"); | |
| 63 | expect(body).not.toContain("/slow"); | |
| 64 | } | |
| 65 | }); | |
| 66 | ||
| 67 | test("the ETag changes with the lines", async () => { | |
| 68 | const before = (await read(adminToken)).headers.get("etag"); | |
| 69 | put("/slow", releaseHour + 1, 400); | |
| 70 | const after = (await read(adminToken)).headers.get("etag"); | |
| 71 | expect(after).not.toBe(before); | |
| 72 | }); |
test/release-route-delta.test.ts added +46
| @@ -0,0 +1,46 @@ | ||
| 1 | import { expect, test } from "bun:test"; | |
| 2 | import { releaseDelta } from "../src/perf/release_delta.ts"; | |
| 3 | import type { RouteHour } from "../src/perf/history.ts"; | |
| 4 | ||
| 5 | const H = 3_600_000; | |
| 6 | const at = 1000 * H + 5 * 60_000; | |
| 7 | const row = (route: string, hour: number, n: number, p95: number): RouteHour => ({ route, hour, n, p50: p95 / 2, p95 }); | |
| 8 | const pair = (route: string, was: number, now: number, n = 20): RouteHour[] => [row(route, 990, n, was), row(route, 1010, n, now)]; | |
| 9 | ||
| 10 | test("names a route that moved 20% with 20 requests each side", () => { | |
| 11 | expect(releaseDelta([...pair("/a", 120, 80), ...pair("/b", 40, 70)], at)).toBe("Faster: /a (120 → 80 ms). Slower: /b (40 → 70 ms)."); | |
| 12 | }); | |
| 13 | ||
| 14 | test("thresholds: 19% and 19 requests say nothing, 20% exactly counts", () => { | |
| 15 | expect(releaseDelta(pair("/a", 100, 119), at)).toBe(""); | |
| 16 | expect(releaseDelta(pair("/a", 100, 81), at)).toBe(""); | |
| 17 | expect(releaseDelta(pair("/a", 100, 120, 19), at)).toBe(""); | |
| 18 | expect(releaseDelta([row("/a", 990, 19, 100), row("/a", 1010, 20, 200)], at)).toBe(""); | |
| 19 | expect(releaseDelta(pair("/a", 100, 120), at)).toBe("Slower: /a (100 → 120 ms)."); | |
| 20 | }); | |
| 21 | ||
| 22 | test("at most three each, biggest move first", () => { | |
| 23 | const rows = ["/a", "/b", "/c", "/d"].flatMap((r, i) => pair(r, 100, 100 + 30 * (i + 1))); | |
| 24 | expect(releaseDelta(rows, at)).toBe("Slower: /d (100 → 220 ms), /c (100 → 190 ms), /b (100 → 160 ms)."); | |
| 25 | }); | |
| 26 | ||
| 27 | test("nothing moved, no rows, one side missing, or outside the 24 hours: empty", () => { | |
| 28 | expect(releaseDelta([], at)).toBe(""); | |
| 29 | expect(releaseDelta(pair("/a", 100, 100), at)).toBe(""); | |
| 30 | expect(releaseDelta([row("/a", 990, 50, 100)], at)).toBe(""); | |
| 31 | expect(releaseDelta([row("/a", 970, 50, 100), row("/a", 1030, 50, 300)], at)).toBe(""); | |
| 32 | expect(releaseDelta([row("/a", 1000, 50, 100), row("/a", 1000, 50, 300)], at)).toBe(""); | |
| 33 | }); | |
| 34 | ||
| 35 | test("the page's speed lines: only releases of the last seven days, none without rows", async () => { | |
| 36 | const { Database } = await import("bun:sqlite"); | |
| 37 | const { speedLines } = await import("../src/perf/release_speed.ts"); | |
| 38 | const db = new Database(":memory:"); | |
| 39 | db.run("CREATE TABLE route_hour (route TEXT, hour INTEGER, n INTEGER, p50 INTEGER, p95 INTEGER, PRIMARY KEY (route, hour))"); | |
| 40 | const now = 1100 * H; | |
| 41 | const put = (r: RouteHour) => db.query("INSERT INTO route_hour VALUES (?,?,?,?,?)").run(r.route, r.hour, r.n, r.p50, r.p95); | |
| 42 | expect(speedLines(db, [{ version: "1.0.0", date: new Date(1050 * H).toISOString(), pulls: [], oid: "x" }], now)).toEqual([]); | |
| 43 | for (const r of [row("/a", 1040, 30, 100), row("/a", 1060, 30, 200)]) put(r); | |
| 44 | const e = (version: string, hour: number) => ({ version, date: new Date(hour * H + 60_000).toISOString(), pulls: [], oid: version }); | |
| 45 | expect(speedLines(db, [e("1.0.1", 1050), e("1.0.0", 900)], now)).toEqual([{ version: "1.0.1", line: "Slower: /a (100 → 200 ms)." }]); | |
| 46 | }); |
test/tui-changelog.test.ts +35 −2
| @@ -2,14 +2,14 @@ | ||
| 2 | 2 | * The changelog in the terminal: the palette offers it to a guest, and the screen lists the page's |
| 3 | 3 | * releases. |
| 4 | 4 | */ |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 5 | import { afterAll, beforeAll, expect, setSystemTime, test } from "bun:test"; | |
| 6 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 7 | import { tmpdir } from "node:os"; |
| 8 | 8 | import { join } from "node:path"; |
| 9 | 9 | import { openPull } from "../src/actions/pulls.ts"; |
| 10 | 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import { createUser } from "../src/core/users.ts"; | |
| 12 | import { createUser, getUserByName } from "../src/core/users.ts"; | |
| 13 | 13 | import { createForgeApp, forgeCommands, Session } from "../src/tui/forge.ts"; |
| 14 | 14 | import type { Ctx } from "../src/tui/app/app.ts"; |
| 15 | 15 | import { groupByChapter } from "../src/release/chapter_groups.ts"; |
| @@ -197,3 +197,36 @@ test("the terminal's wave tells its milestone under the sentence; a wave with no | ||
| 197 | 197 | expect(titles()).toEqual(["Chapter v1", " Shipped it."]); |
| 198 | 198 | expect(titles({ title: "Empty", done: 0, total: 0 })).toEqual(["Chapter v1", " Shipped it."]); |
| 199 | 199 | }); |
| 200 | ||
| 201 | test("a release's route speed line sits in its row for an admin who is a person, and for no one else", async () => { | |
| 202 | const H = 3_600_000; | |
| 203 | const hour = Math.floor(Date.now() / H); | |
| 204 | for (const [h, p95] of [[hour - 5, 100], [hour + 1, 200]] as const) app.db.query("INSERT OR REPLACE INTO route_hour (route, hour, n, p50, p95) VALUES (?,?,?,?,?)").run("/slow", h, 30, p95 / 2, p95); | |
| 205 | setSystemTime(new Date(Date.now() + 3 * H)); | |
| 206 | try { | |
| 207 | const alice = getUserByName(app.db, "alice")!; | |
| 208 | const seen = async (user: typeof alice | undefined): Promise<string> => { | |
| 209 | const terminal = headlessTerminal(160, 30); | |
| 210 | const { app: tui, session } = createForgeApp(app, guest, { terminal, exitHooks: false }); | |
| 211 | (session as { user: typeof user }).user = user; | |
| 212 | tui.start(); | |
| 213 | tui.ctx.push(changelogScreen(session, tui.ctx)); | |
| 214 | await settleApp(tui); | |
| 215 | const text = tui.screen.toText(); | |
| 216 | tui.stop?.(); | |
| 217 | return text; | |
| 218 | }; | |
| 219 | expect(await seen(alice)).toContain("Slower: /slow (100 → 200 ms)."); | |
| 220 | expect(await seen(undefined)).not.toContain("/slow"); | |
| 221 | expect(await seen({ ...alice, isAdmin: false })).not.toContain("/slow"); | |
| 222 | expect(await seen({ ...alice, kind: "agent" } as typeof alice)).not.toContain("/slow"); | |
| 223 | } finally { | |
| 224 | setSystemTime(); | |
| 225 | } | |
| 226 | }); | |
| 227 | ||
| 228 | test("changelogRows puts a release's speed line in its row", () => { | |
| 229 | const e = { version: "1.0.0", date: "2026-11-01T00:00:00.000Z", pulls: [], oid: "x" }; | |
| 230 | expect(changelogRows([e], new Map([["1.0.0", "Faster: /a (2 → 1 ms)."]]))[0]!.meta).toContain("Faster: /a (2 → 1 ms)."); | |
| 231 | expect(changelogRows([e])[0]!.meta).not.toContain("Faster"); | |
| 232 | }); |
new above
offline
Both doors: no src/tui/ screen reads this. Add the per-release speed line to the terminal (System screen or changelog screen), admin-only like the page, and name its entry in AGENTS.md's way.