Public: anyone can read this; the crew can change it.

The data volume's free space is a calm line on the maintenance page that turns amber under 15 percent #16018

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15999-the-data-volume-s-free-space-is-a-calm-l → main 0 commits fork 3 threads · 3 unresolved

  • Merged. scout/15999-the-data-volume-s-free-space-is-a-calm-l was merged into main as cb4449d.

Review

Sign in to review this change.
8 files changed +191 −21
docs/design/areas/disk-line.md added +3
@@ -0,0 +1,3 @@
1 # Disk line
2
3 `.disk-line` is the one line on /maintenance giving the data volume's free space (src/maintenance/disk_line.ts). Plain muted text above 15% free; under it `data-tone="attn"` turns it amber, with the one sentence on what to do. No banner elsewhere.
docs/design/size-budget.json +18 −18
@@ -1,31 +1,31 @@
11 {
22 "/": {
33 "js": 22016,
4 "css": 47616
4 "css": 48384
55 },
66 "/explore": {
77 "js": 21760,
8 "css": 47616
8 "css": 48384
99 },
1010 "/map": {
1111 "js": 28672,
12 "css": 49152
12 "css": 50176
1313 },
1414 "/:owner/:name": {
1515 "js": 38400,
16 "css": 47616
16 "css": 48384
1717 },
1818 "/changelog": {
1919 "js": 26880,
20 "css": 47616
20 "css": 48384
2121 },
2222 "/:owner/:name/next": {
2323 "js": 23296,
24 "css": 47872
24 "css": 48896
2525 },
2626 "/:owner/:name/space": {
2727 "js": 30208,
28 "css": 48640
28 "css": 49664
2929 },
3030 "/:owner/:name/space.json": {
3131 "js": 0,
@@ -33,46 +33,46 @@
3333 },
3434 "/maintenance": {
3535 "js": 21760,
36 "css": 47616
36 "css": 48384
3737 },
3838 "/pricing": {
3939 "js": 21760,
40 "css": 47616
40 "css": 48384
4141 },
4242 "/forges/new": {
4343 "js": 21760,
44 "css": 47616
44 "css": 48384
4545 },
4646 "/claim": {
4747 "js": 24320,
48 "css": 47616
48 "css": 48384
4949 },
5050 "/templates": {
5151 "js": 21760,
52 "css": 47616
52 "css": 48384
5353 },
5454 "/system": {
5555 "js": 23808,
56 "css": 48128
56 "css": 48384
5757 },
5858 "/feed": {
5959 "js": 36352,
60 "css": 48128
60 "css": 48384
6161 },
6262 "/board": {
6363 "js": 26880,
64 "css": 48128
64 "css": 48384
6565 },
6666 "/fleet": {
6767 "js": 21760,
68 "css": 48128
68 "css": 48384
6969 },
7070 "/talk": {
7171 "js": 27392,
72 "css": 49920
72 "css": 50432
7373 },
7474 "/:owner/:name/pulls/:number": {
7575 "js": 32000,
76 "css": 48128
76 "css": 48384
7777 }
7878 }
docs/features/maintenance.md +2
@@ -29,6 +29,8 @@ count, only when there are some; /system keeps them as a section under its own h
2929 on, "End maintenance now" sits under the status line. The forge's looks picture it as the owner (the slot was
3030 /repos'). Tests: `test/maintenance-calm.test.ts`, `test/maintain-stale-web.test.ts`.
3131
32 **Disk line (#15999).** Under the heading `/maintenance` and the terminal's Maintenance screen say "Disk: N percent free" for the data volume (`diskLine()` in `src/maintenance/disk_line.ts`, one function for both; N is the share rounded down, and the same figure is compared). Under 15 percent the page turns the line amber with an alert icon and adds what to do: remove old backups, previews and merged branches, or grow the volume; the terminal says the same sentence and lists it under "Needs you" (`l`), and plain under "For information". Nothing is filed and nothing alarms; a volume that reports no size shows no line. To read it, open `/maintenance` as an admin. Tests: `test/maintenance-disk-line.test.ts`.
33
3234 **Duties.** `/maintenance`, the terminal's Maintenance screen and the `duties` of MCP `maintenance {action: "status"}`
3335 list each nightly job and the radar in one line (`src/maintenance/duties.ts`, one function for all three doors):
3436 when it last ran (UTC), what it found: each issue or pull it filed is a link on the page (plain `owner/name#N` in the terminal), a finding that names none ends "nothing filed", and a reference to a repository you cannot read reads "something you cannot read", never its name, and "overdue". A duty is
src/maintenance/disk_line.ts added +35
@@ -0,0 +1,35 @@
1 /**
2 * The data volume's free space as one line for the maintenance page: plain
3 * above the line, amber under it with the one thing to do. Reads the figure
4 * the forge already has (`DiskReading`); it files and alarms nothing.
5 */
6
7 import type { DiskReading } from "../kernel/disk_reading.ts";
8
9 /** Free space under this share of the volume turns the line amber. */
10 export const DISK_LINE_UNDER = 0.15;
11
12 export interface DiskLine {
13 readonly text: string;
14 readonly low: boolean;
15 /** The sentence on what to do; empty when not low. */
16 readonly todo: string;
17 }
18
19 /** Null when the volume reports no size (nothing true to say). */
20 export function diskLine(d: DiskReading): DiskLine | null {
21 if (!(d.totalBytes > 0) || !(d.freeBytes >= 0)) return null;
22 // One figure, floored, for the words and the comparison: 14.6% prints 14 and is low.
23 const percent = Math.floor((d.freeBytes * 100) / d.totalBytes);
outdated

Math.round shows 15 for 14.6% while low is true. Use the same figure for both (Math.floor, or compare the rounded share).

24 const low = percent < DISK_LINE_UNDER * 100;
25 return {
26 text: `Disk: ${String(percent)} percent free`,
27 low,
28 todo: low ? "Free space by removing old backups, previews and merged branches, or grow the volume." : "",
29 };
30 }
31
32 /** The line as one plain sentence, for the terminal: the same words the page sets in markup. */
33 export function diskSentence(line: DiskLine): string {
34 return line.low ? `${line.text}. ${line.todo}` : line.text;
35 }
src/tui/screens/maintenance.ts +9 −3
@@ -7,6 +7,8 @@
77 * refused by the service. Enter, Esc or q closes it.
88 */
99
10 import { diskLine, diskSentence } from "../../maintenance/disk_line.ts";
11 import { readDisk } from "../../kernel/disk_reading.ts";
1012 import { filedText } from "../../maintenance/filed.ts";
1113 import { findingLines } from "../../maintenance/findings.ts";
1214 import { LEVEL_WORDS, nextLevel, returnLevel, stateLevel, type Level } from "../../maintenance/level.ts";
@@ -65,15 +67,19 @@ export function maintenanceLines(f: Session, standby?: Standby, level?: Level):
6567 const hiddenText = hidden.length === 0 ? [] : ["", ...hidden];
6668 // A paused duty waits on a person to resume it, as on the page.
6769 const paused = dutyStates(f.app.db).filter((d) => d.paused).flatMap((d) => wrap(d.says, INNER));
68 if (level === undefined) return [...stalled, ...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText];
70 // The data volume's free space, as on the page (#15999): amber there, so it waits on a person
71 // here.
72 const disk = diskLine((f.app.config.disk ?? readDisk)(f.app.config.dataDir));
73 const diskText = disk === null ? [] : [...wrap(diskSentence(disk), INNER), ""];
74 if (level === undefined) return [...diskText, ...stalled, ...lead, "", ...facts, ...checks, "", ...dutyText(loud), ...paused, ...quietText, ...findings, ...hiddenText];
6975 // The same split as the page, by the same rule (maintenance/level.ts): what waits on a person,
7076 // and what is only to read.
7177 const needs = stateLevel(s.phase) === "needs-you" || returnLevel(last?.healthy) === "needs-you";
7278 const overdue = loud.filter((d) => d.overdue);
7379 const out =
7480 level === "needs-you"
75 ? [...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused]
76 : [...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText];
81 ? [...(disk?.low === true ? diskText : []), ...stalled, ...(needs ? [...lead, "", ...facts, ...checks, ""] : []), ...dutyText(overdue), ...paused]
82 : [...(disk?.low === false ? diskText : []), ...(needs ? [] : [...lead, "", ...facts, ...checks, ""]), ...dutyText(loud.filter((d) => !d.overdue)), ...quietText, ...findings, ...hiddenText];
7783 return out.length === 0 ? [level === "needs-you" ? "Nothing here needs you." : "Nothing here to read."] : out;
7884 }
7985
src/web/pages/maintenance.ts +8
@@ -32,6 +32,8 @@ import { liveLabel } from "../../maintenance/quiet_live.ts";
3232 import { writePauseFold } from "./maintenance_pause.ts";
3333 import { budgetRows } from "./maintenance_budgets.ts";
3434 import { statusRow } from "./security.ts";
35 import { diskLine } from "../../maintenance/disk_line.ts";
36 import { readDisk } from "../../kernel/disk_reading.ts";
3537
3638 function admin(ctx: Ctx): Response | undefined {
3739 if (!ctx.auth.user) return signInFirst(ctx);
@@ -215,7 +217,13 @@ async function maintenanceAnswer(ctx: Ctx): Promise<Response> {
215217 : null;
216218 // Maintenance being on waits on a person: its sentence and button stay off the calm view.
217219 const calm = asked === "fyi";
220 const disk = diskLine((ctx.app.config.disk ?? readDisk)(ctx.app.config.dataDir));
221 const diskRow = disk === null ? null
222 : disk.low

The page and the terminal should share one renderer of diskLine(). The terminal screen src/tui/screens/maintenance.ts has no disk line, which breaks the both-doors rule.

223 ? html`<p id="maintenance-disk" class="disk-line mb" data-tone="attn">${icon("alert")} <strong>${disk.text}.</strong> ${disk.todo}</p>`
224 : html`<p id="maintenance-disk" class="muted mb">${disk.text}</p>`;
218225 const body = html`<div class="page-head"><h1>Maintenance</h1></div>
226 ${diskRow}
219227 ${calm ? null : statusLine}
220228 ${calm ? null : stalledCard(stalledStep(stalePending), ctx.auth.user!.kind !== "agent")}
221229 ${idle || calm ? null : html`<p id="maintenance-says" class="muted">${s.says}</p>
src/web/style/components.ts +3
@@ -457,6 +457,9 @@ a.sha:hover { color: var(--accent); }
457457 .card[data-tone="danger"] { border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
458458 .card[data-tone="merged"] { border-color: color-mix(in srgb, var(--merged) 40%, var(--border)); }
459459 .card[data-tone="attn"] { border-color: color-mix(in srgb, var(--attn) 40%, var(--border)); }
460 /* --attn is under 4.5:1 on the light themes' --bg; mixed toward --fg the words pass AA in all six (the icon keeps the amber). */
461 .disk-line[data-tone="attn"] { color: color-mix(in srgb, var(--attn) 30%, var(--fg)); }
462 .disk-line[data-tone="attn"] svg { color: var(--attn); }
460463
461464 /* ---- look: a picture the forge took, in a hairline frame ----
462465 A strip sets a phone beside a desktop: the phone keeps a phone's
test/maintenance-disk-line.test.ts added +113
@@ -0,0 +1,113 @@
1 /**
2 * The maintenance page's disk line (#15999): plain at 40%, plain at exactly 15%, amber at 9%; no
3 * other page has it.
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtemp, rm } from "node:fs/promises";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createApp, type App } from "../src/app.ts";
10 import { createUser, type User } from "../src/core/users.ts";
11 import { serve, type Servers } from "../src/http/server.ts";
12 import { diskLine } from "../src/maintenance/disk_line.ts";
13 import { contrast } from "../src/design/contrast.ts";
14 import { THEMES } from "../src/design/themes.ts";
15 import { createForgeApp } from "../src/tui/forge.ts";
16 import { headlessTerminal } from "../src/tui/term/terminal.ts";
17 import { maintenanceLines } from "../src/tui/screens/maintenance.ts";
18 import { quietLogs } from "./helpers/globals.ts";
19
20 quietLogs();
21 let admin: User, dir = "", app: App, servers: Servers, cookie = "";
22 let pct = 40;
23 beforeAll(async () => {
24 dir = await mkdtemp(join(tmpdir(), "forge-diskline-"));
25 app = createApp({ dataDir: dir, port: 0, disk: () => ({ freeBytes: pct * 1e9, totalBytes: 100e9 }) });
26 servers = await serve(app);
27 const made = await createUser(app.db, { username: "boss", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, isAdmin: true });
28 if (!made.ok) throw new Error("user");
29 admin = made.value;
30 const res = await fetch(`${servers.url}/signin`, {
31 method: "POST", redirect: "manual",
32 headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url },
33 body: new URLSearchParams({ username: "boss", password: "a-good-passphrase" }),
34 });
35 cookie = (res.headers.get("set-cookie") ?? "").split(";")[0] ?? "";
36 });
37 afterAll(async () => {
38 servers.stop();
39 app.close();
40 await rm(dir, { recursive: true, force: true });
41 });
42 const get = async (path = "/maintenance"): Promise<string> => (await fetch(`${servers.url}${path}`, { headers: { cookie } })).text();
43
44 test("40% free is plain text", async () => {
45 pct = 40;
46 const html = await get();
outdated

This only checks that one exact class string is absent. Assert not.toContain(data-tone="attn") and that the todo sentence is absent.

47 expect(html).toContain("Disk: 40 percent free");
48 expect(html).toMatch(/<p id="maintenance-disk" class="muted mb">/);
49 expect(html).not.toContain('data-tone="attn"');
50 });
51
52 test("exactly 15% free is still plain", async () => {
53 pct = 15;
54 const html = await get();
55 expect(html).toContain("Disk: 15 percent free");
56 expect(html).not.toContain('data-tone="attn"');
57 expect(html).not.toContain("disk-line");
58 expect(html).not.toContain("Free space by removing");
59 expect(html).toMatch(/<p id="maintenance-disk" class="muted mb">/);
60 });
61
62 test("14.6% free prints 14 and is amber: the figure shown is the one compared", async () => {
63 const l = diskLine({ freeBytes: 14.6e9, totalBytes: 100e9 });
64 expect(l?.text).toBe("Disk: 14 percent free");
65 expect(l?.low).toBe(true);
66 pct = 14.6;
67 const html = await get();
68 expect(html).toContain("Disk: 14 percent free.");
69 expect(html).toMatch(/id="maintenance-disk"[^>]*data-tone="attn"/);
70 expect(diskLine({ freeBytes: 15e9, totalBytes: 100e9 })?.low).toBe(false);
71 });
72
73 test("the terminal screen has the same line and sentence", () => {
74 const { session: f } = createForgeApp(app, { sshUsername: admin.username, remoteAddress: "127.0.0.1", fingerprint: "SHA256:t", user: admin }, { terminal: headlessTerminal(120, 40), exitHooks: false });
75 pct = 40;
76 expect(maintenanceLines(f).join("\n")).toContain("Disk: 40 percent free");
77 expect(maintenanceLines(f).join("\n")).not.toContain("Free space by removing");
78 pct = 9;
79 const all = maintenanceLines(f).join("\n");
80 expect(all).toContain("Disk: 9 percent free.");
81 expect(all).toContain("Free space by removing old backups");
82 expect(maintenanceLines(f, undefined, "needs-you").join("\n")).toContain("Disk: 9 percent free");
83 expect(maintenanceLines(f, undefined, "fyi").join("\n")).not.toContain("Disk:");
84 pct = 40;
85 expect(maintenanceLines(f, undefined, "fyi").join("\n")).toContain("Disk: 40 percent free");
86 expect(maintenanceLines(f, undefined, "needs-you").join("\n")).not.toContain("Disk:");
87 });
88
89 test("the amber text passes AA on --bg in every theme", () => {
90 const mix = (a: string, b: string): string =>
91 "#" + [1, 3, 5].map((i) => Math.round(parseInt(a.slice(i, i + 2), 16) * 0.3 + parseInt(b.slice(i, i + 2), 16) * 0.7).toString(16).padStart(2, "0")).join("");
92 for (const [name, t] of Object.entries(THEMES)) {
93 const k = t.tokens as Record<string, string>;
94 expect(contrast(mix(k["attn"]!, k["fg"]!), k["bg"]!), name).toBeGreaterThanOrEqual(4.5);
95 }
96 });
97
98 test("9% free is amber and says what to do", async () => {
99 pct = 9;
100 const html = await get();
101 expect(html).toMatch(/id="maintenance-disk"[^>]*data-tone="attn"/);
102 expect(html).toContain("Disk: 9 percent free.");
103 expect(html).toContain("Free space by removing old backups");
104 });
105
106 test("no other page carries the line", async () => {
107 pct = 9;
108 expect(await get("/")).not.toContain("maintenance-disk");
109 });
110
111 test("a volume with no size says nothing", () => {
112 expect(diskLine({ freeBytes: 0, totalBytes: 0 })).toBeNull();
113 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs