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

A milestone page leads with its open work, and done issues fold behind a count #14817

Merged opened this in answer to

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

Merged

scout/forge:scout/14795-a-milestone-page-leads-with-its-open-wor → main 5 commits fork

  • Merged. scout/14795-a-milestone-page-leads-with-its-open-wor was merged into main as 6f36491.

Review

Sign in to review this change.
6 files changed +217 −13
docs/design/attention-budget.json +13
@@ -248,5 +248,18 @@
248248 "blocks": 89,
249249 "colours": 4
250250 }
251 },
252 "milestone": {
253 "390": {
254 "words": 87,
255 "blocks": 20,
256 "colours": 2
257 },
258 "1280": {
259 "words": 87,
260 "blocks": 20,
261 "colours": 2
262 },
263 "note": "Added with #14795: the first view of a milestone, open work first and done folded behind one \"Show done issues (N)\" link."
251264 }
252265 }
docs/features/front-milestones.md +8
@@ -12,3 +12,11 @@ The few biggest open milestones sit on a signed-in person's door (`/front`) and
1212 - The wave that moved a milestone: its page says "Last moved in wave X", and its JSON has `lastWave` and `movedThisWeek`. The newest 8 wave files are read from git once per repository's latest event (`src/story/wave_last.ts`), then kept for a minute.
1313 - Terminal: the palette entry **Milestones** (`src/tui/screens/frontms.ts`) lists the same rows, gated by the same `frontApps`, for a signed-in person; `enter` opens one on the web.
1414 - Tests: `test/milestone-front-door.test.ts`, `test/tui-front-milestones.test.ts`.
15
16 ## A milestone's own page: open work first (#14795)
17
18 A milestone's page (`/:owner/:name/milestones/:n`) lists its limbs and its building, blocked and open issues. Done issues fold behind one link, **Show done issues (N)**; the count line above ("X of Y done") owns the number. The link opens `?done=1`, the first 50 done issues, and `?done=N` is page N: a line says "page a of b" with **Hide done**, **Previous** and **Next** as plain links. A page past the end answers the last one; anything but a whole number from 1 is the first view. Only the rows of the page asked for are built, so a milestone with 1,500 done issues renders its first view as cheaply as its open work.
19
20 - Read: `doneFold` and `donePageOf` in `src/web/pages/milestones.ts`.
21 - Terminal: the **Milestones** screen (`src/tui/screens/limbs.ts`) lists each limb with its `done/total done` count and no per-issue rows, so there is no done list to fold; `enter` on a limb opens its sub-limbs.
22 - Tests: `test/milestone-done-fold.test.ts`, `test/milestones.test.ts`.
src/web/pages/milestones.ts +46 −9
@@ -408,12 +408,56 @@ function paceLine(pace: Pace): Html | null {
408408 </div>`;
409409 }
410410
411 /** Done issues shown per page when they are asked for. */
412 export const DONE_PAGE = 50;
413
414 /**
415 * Which page of done issues `?done=` asks for: a whole number from 1, or
416 * nothing (the first view, done folded behind its count).
417 */
418 export function donePageOf(raw: string | null): number | undefined {
419 if (raw === null || !/^[1-9]\d{0,5}$/.test(raw)) return undefined;
420 return Number(raw);
421 }
422
423 /**
424 * Done issues fold behind one link (#14795): the first view leads with what
425 * is open, and the count line above owns the number. Rows are built for the
426 * page asked for only, so a long-done milestone costs its open work.
427 */
428 export function doneFold<T>(
429 base: string,
430 number: number,
431 done: T[],
432 rowOf: (item: T) => Html,
433 donePage: number | undefined,
434 ): Html | null {
435 if (done.length === 0) return null;
436 const href = milestoneHref(base, number);
437 if (donePage === undefined)
438 return html`<p class="small mt" id="ms-done">
439 <a href="${href}?done=1#ms-done">Show done issues (${done.length})</a>
440 </p>`;
441 const pages = Math.ceil(done.length / DONE_PAGE);
442 const at = Math.min(donePage, pages);
443 const shown = done.slice((at - 1) * DONE_PAGE, at * DONE_PAGE).map(rowOf);
444 const step = (to: number, word: string, rel: string): Html =>
445 html` · <a href="${href}?done=${to}#ms-done" rel="${rel}">${word}</a>`;
446 return html`<div class="mt" id="ms-done">
447 <p class="small muted">
448 ${pages > 1 ? `page ${at} of ${pages} · ` : ""}<a href="${href}">Hide done</a>${at > 1 ? step(at - 1, "Previous", "prev") : null}${at < pages ? step(at + 1, "Next", "next") : null}
449 </p>
450 ${list(shown, true)}
451 </div>`;
452 }
453
411454 function milestoneBody(
412455 repo: Repo,
413456 m: Milestone,
414457 names: boolean,
415458 actions: Html | null,
416459 move?: Mover,
460 donePage?: number,
417461 ): Html {
418462 const base = repoBase(repo);
419463 const w = m.weight;
@@ -567,14 +611,7 @@ function milestoneBody(
567611 "open",
568612 8,
569613 )}
570 ${when(
571 closed.length > 0,
572 () =>
573 html`<details>
574 <summary class="small muted">${closed.length} closed</summary>
575 ${list(closed.map((leaf) => leafRow(leaf, false)), true)}
576 </details>`,
577 )}
614 ${doneFold(base, m.issue.number, closed, (leaf) => leafRow(leaf, false), donePage)}
578615 </section>`,
579616 )}`;
580617 }
@@ -640,7 +677,7 @@ export async function milestonePage(
640677 crumbs: crumbsFor(repo),
641678 palette: repoPalette(ctx, repo),
642679 body: html`${repoHeader(ctx, repo, "map")}<div data-milestone>
643 ${milestoneBody(repo, milestone, owner, actions, move)}
680 ${milestoneBody(repo, milestone, owner, actions, move, donePageOf(ctx.url.searchParams.get("done")))}
644681 ${wave === undefined ? null : html`<ul class="list setting-list" id="ms-wave">${row({ nav: true, href: wave.href, title: `Last moved in wave ${wave.version}`, meta: html`${wave.headline}`, trail: html`${wave.date}` })}</ul>`}
645682 ${replanChanged(ctx, repo, milestone)}</div>
646683 ${liveMount({ repo: repoBase(repo) })}`,
test/attention.test.ts +15 −1
@@ -10,7 +10,8 @@ import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
1010 import { tmpdir } from "node:os";
1111 import { join } from "node:path";
1212 import { enableApp } from "../src/actions/apps.ts";
13 import { openIssue } from "../src/actions/issues.ts";
13 import { linkIssue } from "../src/actions/dependencies.ts";
14 import { openIssue, setIssueState } from "../src/actions/issues.ts";
1415 import { openPull } from "../src/actions/pulls.ts";
1516 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1617 import { createApp, type App } from "../src/app.ts";
@@ -105,6 +106,19 @@ beforeAll(async () => {
105106 const text = await res.text();
106107 pages[name] = name === "system" ? fixedCaps(text) : name === "boards" ? fixedWait(text) : text;
107108 }
109 // A milestone (#14795), made after the pages above so their counts stay put:
110 // one open step and one done, which folds behind its count.
111 const steps = ["Seal the vault", "Count the keys"].map((title) => {
112 const made = openIssue(app, u.value, repo, { title, body: "" });
113 if (!made.ok) throw new Error(String(made.error));
114 const linked = linkIssue(app, u.value, repo, issue.value, made.value);
115 if (!linked.ok) throw new Error(String(linked.error));
116 return made.value;
117 });
118 if (!setIssueState(app, u.value, repo, steps[1]!, "closed").ok) throw new Error("close");
119 const res = await fetch(`${servers.url}${r}/milestones/${issue.value.number}`, { headers: { cookie } });
120 if (res.status !== 200) throw new Error(`milestone answered ${res.status}`);
121 pages.milestone = await res.text();
108122 });
109123 afterAll(() => {
110124 servers.stop();
test/milestone-done-fold.test.ts added +124
@@ -0,0 +1,124 @@
1 /**
2 * A milestone page leads with its open work; done issues fold behind
3 * "N done" and load on request, a page at a time (#14795).
4 */
5 import { afterAll, beforeAll, expect, test } from "bun:test";
6 import { mkdtempSync, rmSync } from "node:fs";
7 import { tmpdir } from "node:os";
8 import { join } from "node:path";
9 import { createRepo } from "../src/actions/repos.ts";
10 import { createApp, type App } from "../src/app.ts";
11 import { getRepo } from "../src/core/repos.ts";
12 import { createUser } from "../src/core/users.ts";
13 import { serve, type Servers } from "../src/http/server.ts";
14 import { html } from "../src/web/html.ts";
15 import { DONE_PAGE, doneFold, donePageOf } from "../src/web/pages/milestones.ts";
16 import { quietLogs } from "./helpers/globals.ts";
17 import { signInCookie } from "./helpers/studio-signin.ts";
18 import { proveAll } from "./helpers/verified.ts";
19
20 quietLogs();
21
22 const CLOSED = 1500;
23 const OPEN = 6;
24
25 let root = "";
26 let app: App;
27 let servers: Servers;
28 let cookie = "";
29
30 beforeAll(async () => {
31 root = mkdtempSync(join(tmpdir(), "forge-milestone-done-"));
32 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
33 const u = await createUser(app.db, {
34 origin: "seed", trusted: true, username: "alice", email: "[email protected]",
35 password: "a-good-passphrase", adminIfFirst: true,
36 });
37 if (!u.ok) throw new Error(u.error);
38 proveAll(app);
39 const made = await createRepo(app, u.value, { name: "forge" });
40 if (!made.ok) throw new Error(made.error);
41 const repoId = getRepo(app.db, "alice", "forge")!.id;
42 const issue = app.db.prepare(
43 `INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, created_at, updated_at, closed_at)
44 VALUES (?1, ?2, ?3, 'issue', ?4, '', ?5, ?6, ?7, ?7, ?8)`,
45 );
46 const edge = app.db.prepare("INSERT INTO issue_dependency (issue_id, blocked_by_id) VALUES (?1, ?2)");
47 const at = new Date(Date.now() - 3_600_000).toISOString();
48 app.db.transaction(() => {
49 let n = 0;
50 issue.run("u", repoId, ++n, "P0 Trust: ask", u.value.id, "open", at, null);
51 for (let k = 0; k < CLOSED + OPEN; k++) {
52 const closed = k < CLOSED;
53 issue.run(`c-${k}`, repoId, ++n, closed ? `Done step ${k}` : `Open step ${k}`, u.value.id, closed ? "closed" : "open", at, closed ? at : null);
54 edge.run("u", `c-${k}`);
55 }
56 app.db.run("UPDATE repo SET issue_seq = ?1 WHERE id = ?2", [n, repoId]);
57 })();
58 servers = await serve(app);
59 cookie = await signInCookie(servers.url, "alice");
60 });
61 afterAll(() => {
62 servers.stop();
63 app.close();
64 rmSync(root, { recursive: true, force: true });
65 });
66
67 /** The milestone page with `query`, read as the signed-in owner. */
68 const milestone = (query = ""): Promise<string> =>
69 fetch(`${servers.url}/alice/forge/milestones/1${query}`, { headers: { cookie } }).then((res) => {
70 if (res.status !== 200) throw new Error(`status ${res.status}`);
71 return res.text();
72 });
73 const doneRows = (page: string) => (page.match(/>Done step \d+</g) ?? []).length;
74
75 test("the first view lists only the open work, a count of done, and stays under 100 KB", async () => {
76 const page = await milestone();
77 expect(new TextEncoder().encode(page).length).toBeLessThan(100_000);
78 expect(doneRows(page)).toBe(0);
79 for (let k = CLOSED; k < CLOSED + OPEN; k++) expect(page).toContain(`>Open step ${k}<`);
80 expect(page).toContain(`href="/alice/forge/milestones/1?done=1#ms-done">Show done issues (${CLOSED})</a>`);
81 // The count line stays as it is.
82 expect(page).toMatch(new RegExp(`<b>${CLOSED}</b> of ${CLOSED + OPEN} done`));
83 });
84
85 test("done loads on request, a page at a time, with links either way", async () => {
86 const pages = Math.ceil(CLOSED / DONE_PAGE);
87 const first = await milestone("?done=1");
88 expect(doneRows(first)).toBe(DONE_PAGE);
89 expect(first).toContain(`page 1 of ${pages}`);
90 expect(first).toContain('href="/alice/forge/milestones/1?done=2#ms-done"');
91 expect(first).not.toContain("?done=0");
92 // The count line owns the number; the open fold says only where it is.
93 expect(first).not.toContain(`${CLOSED} done ·`);
94 expect(first).not.toContain('class="pager"');
95 const second = await milestone("?done=2");
96 expect(doneRows(second)).toBe(DONE_PAGE);
97 expect(second).toContain('href="/alice/forge/milestones/1?done=1#ms-done"');
98 // Pages do not overlap.
99 const names = (p: string) => new Set(p.match(/>Done step \d+</g));
100 for (const n of names(second)) expect(names(first).has(n)).toBe(false);
101 // Past the end answers the last page, not an empty one.
102 const past = await milestone("?done=999");
103 expect(past).toContain(`page ${pages} of ${pages}`);
104 expect(doneRows(past)).toBe(CLOSED - (pages - 1) * DONE_PAGE);
105 expect(past).not.toContain(`?done=${pages + 1}`);
106 });
107
108 test("?done= takes a whole page number from 1, and anything else is the first view", async () => {
109 expect(donePageOf(null)).toBeUndefined();
110 for (const bad of ["", "0", "-1", "1.5", "abc", "01", "1e3", "9999999"]) expect(donePageOf(bad)).toBeUndefined();
111 expect(donePageOf("1")).toBe(1);
112 expect(donePageOf("30")).toBe(30);
113 expect(doneRows(await milestone("?done=%3Cscript%3E"))).toBe(0);
114 });
115
116 test("only the rows of the page asked for are built", () => {
117 const done = Array.from({ length: CLOSED }, (_, k) => k);
118 let built = 0;
119 const rowOf = (k: number) => (built++, html`<li>${k}</li>`);
120 doneFold("/alice/forge", 1, done, rowOf, undefined);
121 expect(built).toBe(0);
122 doneFold("/alice/forge", 1, done, rowOf, 3);
123 expect(built).toBe(DONE_PAGE);
124 });
test/milestones.test.ts +11 −3
@@ -369,7 +369,6 @@ describe("milestones", () => {
369369 expect(one).toContain("<h1>Ship the sandbox</h1>");
370370 expect(one).toMatch(/<b>1<\/b> of 3 done/);
371371 expect(one).toContain('aria-label="1 of 3 done"');
372 expect(one).toMatch(/class="badge"[^>]*>\s*done/);
373372 expect(one).toContain(
374373 "About 14 days at this week&#39;s pace: 1 closed in 7 days, 2 open.",
375374 );
@@ -393,8 +392,17 @@ describe("milestones", () => {
393392 one.indexOf('id="ms-leaves"'),
394393 one.indexOf("</section>", one.indexOf('id="ms-leaves"')),
395394 );
396 expect(issues).toContain("1 closed");
397 expect(issues).toContain("Sandbox the shell");
395 // Done folds behind its count (#14795): a link, no rows, until asked.
396 expect(issues).toContain(`href="/alice/engine/milestones/${ship.number}?done=1#ms-done"`);
397 expect(issues).toMatch(/>Show done issues \(1\)</);
398 expect(issues).not.toContain("Sandbox the shell");
399 const done = await (
400 await get("alice", `/alice/engine/milestones/${ship.number}?done=1`)
401 ).text();
402 const doneRows = done.slice(done.indexOf('id="ms-done"'), done.indexOf("</section>", done.indexOf('id="ms-done"')));
403 expect(doneRows).toContain("Sandbox the shell");
404 expect(doneRows).toMatch(/class="badge"[^>]*>\s*done/);
405 expect(doneRows).toContain(`href="/alice/engine/milestones/${ship.number}"`);
398406 expect(issues).not.toContain("Sandbox the network");
399407 expect(issues).not.toContain("Sandbox the disk");
400408 expect(issues).not.toContain("None open.");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs