Public: anyone can read this; the crew can change it.
Quota and usage admin sentences live in one module, read by the web pages and the terminal #5641
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/5621-quota-and-usage-admin-sentences-live-in → main 2 commits fork
6 files
changed +50
−4
src/actions/admin_limits_words.ts added +10
| @@ -0,0 +1,10 @@ | ||
| 1 | /** | |
| 2 | * The quota and usage sentences an admin reads (#5621): said once here and | |
| 3 | * read by the web pages and the terminal screens alike, so they cannot drift. | |
| 4 | */ | |
| 5 | ||
| 6 | /** A quota change was refused because a value was not a positive whole number. */ | |
| 7 | export const QUOTA_INVALID = "A quota is a positive whole number, or empty for no limit."; | |
| 8 | ||
| 9 | /** Someone who is not a forge admin asked for the usage report. */ | |
| 10 | export const USAGE_ADMIN_ONLY = "Usage is read by a forge admin."; |
src/tui/screens/quotas.ts +2 −1
| @@ -7,6 +7,7 @@ | ||
| 7 | 7 | * action's: an admin who is not an agent; anyone else sees nothing and sets nothing. |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | import { QUOTA_INVALID } from "../../actions/admin_limits_words.ts"; | |
| 10 | 11 | import { changeQuotas, readQuotas } from "../../actions/quotas.ts"; |
| 11 | 12 | import { QUOTA_KEYS, type QuotaChange } from "../../settings/quotas.ts"; |
| 12 | 13 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -36,7 +37,7 @@ export function quotasScreen(f: Session, ctx: Ctx): Screen { | ||
| 36 | 37 | return undefined; |
| 37 | 38 | } |
| 38 | 39 | return made.error === "invalid_quota" |
| 39 | ? "A quota is a positive whole number, or empty for no limit." | |
| 40 | ? QUOTA_INVALID | |
| 40 | 41 | : "You cannot change quotas."; |
| 41 | 42 | }; |
| 42 | 43 |
src/tui/screens/usage.ts +2 −1
| @@ -6,6 +6,7 @@ | ||
| 6 | 6 | * anyone else sees nothing. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { USAGE_ADMIN_ONLY } from "../../actions/admin_limits_words.ts"; | |
| 9 | 10 | import { mayManageFlags } from "../../core/flags.ts"; |
| 10 | 11 | import { ROLES, SURFACES } from "../../core/usage_count.ts"; |
| 11 | 12 | import { routeUsage, WINDOW_DAYS, type RouteUsage } from "../../core/usage_report.ts"; |
| @@ -42,7 +43,7 @@ export function usageScreen(f: Session, ctx: Ctx): Screen { | ||
| 42 | 43 | const [head, list] = split(area, "v", [len(1), fill(1)]); |
| 43 | 44 | const all = rows; |
| 44 | 45 | const text = !allowed |
| 45 | ? "Usage is read by a forge admin." | |
| 46 | ? USAGE_ADMIN_ONLY | |
| 46 | 47 | : `${all.filter((r) => r.total === 0).length} of ${all.length} routes had no request in ${WINDOW_DAYS} days; unused first.`; |
| 47 | 48 | s.text(head!.x, head!.y, truncate(text, head!.w), style(c.mutedFg, c.bg), head!.x + head!.w); |
| 48 | 49 | drawList(s, list!, c, state, usageRows(all)); |
src/web/pages/admin-limits.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * who, when, from what to what. Anyone else gets the not-found page. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { QUOTA_INVALID } from "../../actions/admin_limits_words.ts"; | |
| 8 | 9 | import { changeLimit, listLimits } from "../../actions/limits.ts"; |
| 9 | 10 | import { changeQuotas, readQuotas } from "../../actions/quotas.ts"; |
| 10 | 11 | import { inviteLink, list as listInviteLinks, mint as mintInviteLink, revoke as revokeInviteLink } from "../../actions/invites.ts"; |
| @@ -297,7 +298,7 @@ export async function quotasSet(ctx: Ctx): Promise<Response> { | ||
| 297 | 298 | "/admin/limits", |
| 298 | 299 | changed.ok |
| 299 | 300 | ? { message: "Quotas saved." } |
| 300 | : { tone: "danger", message: "A quota is a positive whole number, or empty for no limit." }, | |
| 301 | : { tone: "danger", message: QUOTA_INVALID }, | |
| 301 | 302 | ); |
| 302 | 303 | } |
| 303 | 304 |
src/web/pages/usage.ts +2 −1
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | * Anyone else is told 403, and an agent is never an admin here. |
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | import { USAGE_ADMIN_ONLY } from "../../actions/admin_limits_words.ts"; | |
| 8 | 9 | import { mayManageFlags } from "../../core/flags.ts"; |
| 9 | 10 | import { ROLES, SURFACES } from "../../core/usage_count.ts"; |
| 10 | 11 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| @@ -33,7 +34,7 @@ export function usagePage(ctx: Ctx, patterns: () => readonly string[]): Response | ||
| 33 | 34 | ${empty({ |
| 34 | 35 | icon: "lock", |
| 35 | 36 | title: "Admins only", |
| 36 | note: "Usage is read by a forge admin.", | |
| 37 | note: USAGE_ADMIN_ONLY, | |
| 37 | 38 | action: btn("Go home", { href: "/", variant: "primary" }), |
| 38 | 39 | })}`, |
| 39 | 40 | }, |
test/admin-limits-words.test.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * The quota and usage admin sentences live in one module (#5621): the web | |
| 3 | * pages and the terminal screens import them, and none types its own copy. | |
| 4 | */ | |
| 5 | ||
| 6 | import { expect, test } from "bun:test"; | |
| 7 | import { readFileSync } from "node:fs"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { QUOTA_INVALID, USAGE_ADMIN_ONLY } from "../src/actions/admin_limits_words.ts"; | |
| 10 | ||
| 11 | const root = join(import.meta.dir, ".."); | |
| 12 | const read = (file: string): string => readFileSync(join(root, file), "utf8"); | |
| 13 | ||
| 14 | const readers: Record<string, { name: string; sentence: string }> = { | |
| 15 | "src/web/pages/admin-limits.ts": { name: "QUOTA_INVALID", sentence: QUOTA_INVALID }, | |
| 16 | "src/tui/screens/quotas.ts": { name: "QUOTA_INVALID", sentence: QUOTA_INVALID }, | |
| 17 | "src/web/pages/usage.ts": { name: "USAGE_ADMIN_ONLY", sentence: USAGE_ADMIN_ONLY }, | |
| 18 | "src/tui/screens/usage.ts": { name: "USAGE_ADMIN_ONLY", sentence: USAGE_ADMIN_ONLY }, | |
| 19 | }; | |
| 20 | ||
| 21 | test("the sentences read as they always have", () => { | |
| 22 | expect(QUOTA_INVALID).toBe("A quota is a positive whole number, or empty for no limit."); | |
| 23 | expect(USAGE_ADMIN_ONLY).toBe("Usage is read by a forge admin."); | |
| 24 | }); | |
| 25 | ||
| 26 | for (const [file, { name, sentence }] of Object.entries(readers)) { | |
| 27 | test(`${file} imports ${name} and types no copy of it`, () => { | |
| 28 | const text = read(file); | |
| 29 | expect(text).not.toContain(sentence); | |
| 30 | expect(text).toContain(`${name} } from "../../actions/admin_limits_words.ts"`); | |
| 31 | }); | |
| 32 | } |
new above
offline