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

A wave's page shows its milestone's issues done and open with the date of the last one landed #15860

Merged opened this

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

Merged

torque/forge:torque/15839-a-wave-s-page-shows-its-milestone-s-issu → main 0 commits fork 3 threads · 3 unresolved

  • Merged. torque/15839-a-wave-s-page-shows-its-milestone-s-issu was merged into main as 3d8f440.

Review

Sign in to review this change.
6 files changed +183 −5
docs/design/attention-budget.json +3 −3
@@ -251,15 +251,15 @@
251251 },
252252 "milestone": {
253253 "390": {
254 "words": 87,
254 "words": 90,
255255 "blocks": 20,
256256 "colours": 2
257257 },
258258 "1280": {
259 "words": 87,
259 "words": 90,
260260 "blocks": 20,
261261 "colours": 2
262262 },
263 "note": "Added with #14795: the first view of a milestone, open work first and done folded behind one \"Show done issues (N)\" link."
263 "note": "Added with #14795: the first view of a milestone, open work first and done folded behind one \"Show done issues (N)\" link. Raised for #15839: ` \u00b7 landed <date>` on the muted weight line, 3 words, no block."
264264 }
265265 }
docs/features/milestone-counts.md added +19
@@ -0,0 +1,19 @@
1 ---
2 topic: Your apps
3 row: A milestone says how many issues are done and open, and when the last landed
4 ---
5 # A milestone's issue counts (#15839)
6
7 A milestone's page says, in the muted line beside its progress bar, how many of its issues are
8 open and the day the last done one landed: `1 open · landed 2026-10-22`. The done count is
9 the bar's own (`2 of 3 done`), so it is not said twice. Until something has landed the line names
10 no date. An issue closed as not doing is neither done nor open.
11
12 - Page: `/<owner>/<name>/milestones/<number>`, the line under the title (`#ms-counts`).
13 - API: `GET /api/v1/repos/:owner/:name/milestones/:number` carries
14 `issues: {done, open, lastLanded, words}`; `lastLanded` is `YYYY-MM-DD` or null, `words` reads
15 `2 done, 1 open, last landed 2026-10-22`, `0 done, 2 open, none landed yet`, or `No issues yet.`.
16 - MCP: the `milestones` tool with `issue` answers the same `issues` object (there is no separate
17 `changelog` or `story` tool for a milestone; `releases` is the changelog and does not read it).
18
19 Try it: close one issue under a milestone and open its page.
src/core/milestone_front.ts +27
@@ -52,3 +52,30 @@ export function landedWords(w: Weight, closed: { state: string; closedAt: string
5252 /** The share landed, a whole percentage; a milestone with no issues is 0. */
5353 export const landedPercent = (w: Weight): number =>
5454 w.total <= 0 ? 0 : Math.round((100 * Math.min(w.done, w.total)) / w.total);
55
56 /**
57 * A milestone's issues as the page and the MCP count them: those closed as done, those still open,
58 * and the day the last done one landed (its `closedAt`, `YYYY-MM-DD`; null when none has). An
59 * issue closed as not doing is neither.
60 */
61 export function issueCounts(
62 leaves: readonly { state: string; issue: { closedAt: string | null } }[],
63 ): { done: number; open: number; lastLanded: string | null } {
64 let done = 0;
65 let open = 0;
66 let last: string | null = null;
67 for (const l of leaves) {
68 if (l.state === "done") {
69 done++;
70 const at = l.issue.closedAt;
71 if (at !== null && (last === null || at > last)) last = at;
72 } else if (l.state !== "gone") open++;
73 }
74 return { done, open, lastLanded: last === null ? null : last.slice(0, 10) };
75 }
76
77 /** The count line: `2 done, 1 open, last landed 2026-11-20`; `No issues yet.` when empty. */
78 export function countsWords(c: { done: number; open: number; lastLanded: string | null }): string {
79 if (c.done === 0 && c.open === 0) return "No issues yet.";
80 return `${c.done} done, ${c.open} open${c.lastLanded === null ? ", none landed yet" : `, last landed ${c.lastLanded}`}`;
81 }
src/core/milestones.ts +3 −1
@@ -13,7 +13,7 @@
1313 * from it.
1414 */
1515
16 import { landedWords } from "./milestone_front.ts";
16 import { countsWords, issueCounts, landedWords } from "./milestone_front.ts";
1717 import { paceOf, type Pace } from "./pace.ts";
1818 import type { Database } from "bun:sqlite";
1919 import { writeStamp } from "./write_clock.ts";
@@ -682,6 +682,7 @@ export function milestoneJson(
682682 names: boolean,
683683 ): Record<string, unknown> {
684684 const brief = (issue: Issue) => ({ number: issue.number, title: issue.title });
685 const counts = issueCounts(milestone.leaves);
685686 return {
686687 ...limbJson(milestone),
687688 title: milestone.issue.title,
@@ -713,6 +714,7 @@ export function milestoneJson(
713714 },
714715 }),
715716 limbs: milestone.limbs.map(limbJson),
outdated

issueCounts(milestone.leaves) runs twice. Bind it once.

717 issues: { ...counts, words: countsWords(counts) },
716718 leaves: milestone.leaves.map((leaf) => ({
717719 ...brief(leaf.issue),
718720 state: leaf.state,
src/web/pages/milestones.ts +6 −1
@@ -10,6 +10,7 @@
1010 * Read-only: the page, the API and the MCP tool give the same numbers.
1111 */
1212
13 import { issueCounts } from "../../core/milestone_front.ts";
1314 import {
1415 limbJson,
1516 milestoneJson,
@@ -178,6 +179,10 @@ function weightWords(limb: Limb): Html {
178179 return html`${parts.map((p, n) => html`${n > 0 ? " · " : null}${p}`)}`;
179180 }
180181
182 /** ` · landed 2026-10-22` for the weight line; nothing when no issue has landed. */
183 const landedOn = (day: string | null): string =>
184 day === null ? "" : ` · landed ${day}`;
185
181186 /** How far a limb is, as a bar: the native element, named for a reader who cannot see it. */
182187 export const progress = (done: number, total: number, label: string): Html =>
183188 html`<progress
@@ -489,7 +494,7 @@ function milestoneBody(
489494 <div class="stack stack-tight" id="ms-progress">
490495 <span><b>${w.done}</b> of ${w.total} done</span>
outdated

Principles 1 and 4: this restates the done/open numbers already shown by the progress bar and weight line, and is not muted. Merge it into the weight line or add muted.

491496 ${progress(w.done, w.total, `${w.done} of ${w.total} done`)}
492 <span class="muted small">${weightWords(m)}</span>
497 <span class="muted small" id="ms-counts">${weightWords(m)}${landedOn(issueCounts(m.leaves).lastLanded)}</span>
493498 </div>
494499 <p id="ms-estimate">${m.estimate}</p>
495500 ${paceLine(m.pace)}
test/milestone-counts.test.ts added +125
@@ -0,0 +1,125 @@
1 /**
2 * A milestone's issues counted done and open with the day the last landed, on the page and in the
3 * MCP (#15839).
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 { linkIssue } from "../src/actions/dependencies.ts";
10 import { openIssue, setIssueState } from "../src/actions/issues.ts";
11 import { createRepo } from "../src/actions/repos.ts";
12 import { createApp, type App } from "../src/app.ts";
13 import { getIssueById, type Issue } from "../src/core/issues.ts";
14 import { getRepo, type Repo } from "../src/core/repos.ts";
15 import { createToken } from "../src/core/tokens.ts";
16 import { serve, type Servers } from "../src/http/server.ts";
17 import { createUser, getUserByName } from "../src/core/users.ts";
18 import type { Ctx } from "../src/http/context.ts";
19 import { countsWords, issueCounts } from "../src/core/milestone_front.ts";
20 import { milestoneData, milestonePage } from "../src/web/pages/milestones.ts";
21 import { quietLogs } from "./helpers/globals.ts";
22 import { proveAll } from "./helpers/verified.ts";
23
24 quietLogs();
25
26 // One instant for the whole file; every closing time is before it.
27 const NOW = new Date("2026-10-27T12:00:00.000Z");
28 const at = (daysAgo: number, hours = 1): string =>
29 new Date(NOW.getTime() - daysAgo * 86_400_000 - hours * 3_600_000).toISOString();
30
31 let root = "";
32 let app: App;
33 let servers: Servers;
34 let token = "";
35 let repo: Repo;
36
37 beforeAll(async () => {
38 root = mkdtempSync(join(tmpdir(), "forge-counts-"));
39 app = createApp({ dataDir: root, port: 0, forgeRepo: "alice/forge" });
40 const u = await createUser(app.db, {
41 origin: "seed",
42 trusted: true,
43 username: "alice",
44 email: "[email protected]",
45 password: "a-good-passphrase",
46 adminIfFirst: true,
47 });
48 if (!u.ok) throw new Error(u.error);
49 proveAll(app);
50 servers = await serve(app);
51 token = createToken(app.db, u.value.id, "ro", "ro").token;
52 const made = await createRepo(app, getUserByName(app.db, "alice")!, { name: "forge" });
53 if (!made.ok) throw new Error(made.error);
54 repo = getRepo(app.db, "alice", "forge")!;
55 });
56 afterAll(() => {
57 servers.stop();
58 app.close();
59 rmSync(root, { recursive: true, force: true });
60 });
61
62 const alice = () => getUserByName(app.db, "alice")!;
63 const make = (title: string): Issue => {
64 const o = openIssue(app, alice(), repo, { title });
65 if (!o.ok) throw new Error(String(o.error));
66 return o.value;
67 };
68
69 /**
70 * A milestone of `open` open leaves and one closed leaf for each entry of
71 * `closedAt`, a closing time (a number is that many days before NOW).
72 */
73 function milestone(name: string, open: number, closedAt: (number | string)[], gate?: Issue): Issue {
74 const top = make(name);
75 for (const [i, ago] of [...closedAt, ...Array(open).fill(null)].entries()) {
76 const leaf = make(`${name} ${i}`);
77 const linked = linkIssue(app, alice(), repo, top, leaf);
78 if (!linked.ok) throw new Error(String(linked.error));
79 if (ago === null) continue;
80 expect(setIssueState(app, alice(), repo, getIssueById(app.db, leaf.id)!, "closed").ok).toBe(true);
81 app.db
82 .query("UPDATE issue SET closed_at = ?1 WHERE id = ?2")
83 .run(typeof ago === "number" ? at(ago) : ago, leaf.id);
84 }
85 if (gate !== undefined && !linkIssue(app, alice(), repo, top, gate).ok) throw new Error("gate");
86 return top;
87 }
88
89 const ctxFor = (number: number): Ctx =>
90 ({
91 app,
92 request: new Request(`http://x/alice/forge/milestones/${number}`),
93 url: new URL(`http://x/alice/forge/milestones/${number}`),
94 params: { owner: "alice", name: "forge", number: String(number) },
95 auth: { user: alice(), scope: undefined, via: "session" },
96 theme: undefined,
97 }) as Ctx;
98
99 const html = async (top: Issue) => (await (await milestonePage(ctxFor(top.number), NOW)).text());
100
101 const mcp = async (issue: number) => {
102 const res = await fetch(`${servers.url}/mcp`, {
103 method: "POST",
104 headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` },
105 body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "milestones", arguments: { app: "alice/forge", issue } } }),
106 });
107 return JSON.parse(((await res.json()) as any).result.content[0].text);
108 };
109
110 test("two done and one open: the weight line, the page's data and the milestones MCP tool agree on the counts and the later landing day", async () => {
111 const top = milestone("Wave", 1, ["2026-10-20T09:00:00.000Z", "2026-10-22T09:00:00.000Z"]);
outdated

Dead code: void empty; void other; plus the unused make calls above it. Remove them and test the page's empty wording through a real empty milestone.

112 const page = await html(top);
113 expect(page).toMatch(/id="ms-counts"[^>]*>1 open[\s\S]*?· landed 2026-10-22<\/span>/);
114 const want = { done: 2, open: 1, lastLanded: "2026-10-22", words: "2 done, 1 open, last landed 2026-10-22" };
115 const data = (await milestoneData(ctxFor(top.number), repo, top.number, NOW))!;
116 expect(data["issues"]).toEqual(want);
117 expect((await mcp(top.number)).issues).toEqual(want);
118 });
119
120 test("nothing landed: the page names no date and the words say none landed; an empty list says no issues", async () => {
121 const waiting = milestone("Waiting", 2, []);
122 expect(await html(waiting)).not.toContain("· landed");
123 expect((await mcp(waiting.number)).issues.words).toBe("0 done, 2 open, none landed yet");
124 expect(countsWords(issueCounts([]))).toBe("No issues yet.");
125 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs