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

The release story names the biggest wave of the week in one sentence on /changelog's head #16017

Merged opened this

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

Merged

scout/forge:scout/15995-the-release-story-names-the-biggest-wave → main 0 commits fork 4 threads · 4 unresolved

  • Merged. scout/15995-the-release-story-names-the-biggest-wave was merged into main as 073491c.

Review

Sign in to review this change.
7 files changed +173 −1
docs/features/changelog.md +4
@@ -109,3 +109,7 @@ A forge that has cut no release says so once. `/changelog` opens with "Nothing h
109109 ## A wave opens in four steps (#15752)
110110
111111 On `/changelog` a wave's row opens the wave's own page (`/<repo>/waves/<version>`): its headline, its changes, and each change's pull, whose page holds the conversation. A chapter with no wave still opens its chapter page. The terminal is not changed by this. Tested by following the links in `test/changelog-depth.test.ts`.
112
113 ## The week's biggest wave (#15995)
114
115 `/changelog` opens, under its top line, with one sentence: "The biggest wave this week is <name>: N pulls landed.", the name linking to the wave's page (or its chapter's, when it wrote no wave). It counts the live pulls of the last seven days per chapter, over the landings loaded on the page only: older pulls on later pages ("Older") are not counted; a tie goes to the chapter listed first, so it relies on the list's order (newest first); a quiet week says "Nothing landed this week." and pulls in no chapter say "N pulls landed this week, none in a wave." The sentence is built from counts and names (`weekStory` in `src/story/week.ts`), never from model text. The terminal's Changelog screen (`src/tui/screens/changelog.ts`, `chapterLines`) shows the same sentence first. The page sets it at reading size, not muted (`design-lint` clean). Tested in `test/story-week.test.ts` and `test/changelog-week.test.ts`.
outdated

"a tie goes to the newer chapter" does not match the code, where a tie goes to the first listed. Also state that only the loaded page is counted.

src/story/week.ts added +78
@@ -0,0 +1,78 @@
1 /**
2 * The week's biggest wave in one sentence, for the head of /changelog: the wave (chapter) with the
3 * most pulls landed in the last seven days. Pure: plain data in, plain data out; the sentence is
4 * built from counts and names, never from model text.
5 */
6
7 import type { Group } from "../release/chapter_groups.ts";
8
9 export const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
10
11 export interface WaveLandings {
12 /** The wave's name (its chapter). */
13 readonly name: string;
14 /** Where its page is. */
15 readonly href: string;
16 /** When each of its landed pulls merged (ISO). */
17 readonly at: readonly string[];
18 }
19
20 export interface WeekStory {
21 /** Plain text of the sentence: `lead` + the wave's name + `tail`. The one builder. */
22 readonly sentence: string;
23 /** The words before the wave's name (the whole sentence when no wave is named). */
24 readonly lead: string;
25 /** The words after the wave's name; empty when no wave is named. */
26 readonly tail: string;
27 /** The wave named, and how many pulls it landed this week; absent when none landed. */
28 readonly wave?: { readonly name: string; readonly href: string; readonly pulls: number };
29 /** Pulls landed in the week outside the named wave. */
30 readonly landed: number;
31 }
32
33 const pullWords = (n: number): string => `${n} ${n === 1 ? "pull" : "pulls"}`;
34
35 /** Whether `at` (ISO) falls in the seven days up to `now`. The one window, for every count. */
36 export function inWeek(at: string, now: Date): boolean {
37 const t = Date.parse(at);
38 return t > now.getTime() - WEEK_MS && t <= now.getTime();
39 }
40
41 /**
42 * Count each wave's pulls with `at` in the seven days up to `now`; the largest is named. A tie goes
43 * to the earlier wave in the list (the page lists the newest first). A week where nothing landed
44 * says so.
45 */
46 export function weekStory(waves: readonly WaveLandings[], now: Date, extra = 0): WeekStory {
47 let best: { name: string; href: string; pulls: number } | undefined;
48 let landed = Math.max(0, Math.floor(extra));
49 for (const w of waves) {
50 const pulls = w.at.filter((a) => inWeek(a, now)).length;
51 landed += pulls;
52 if (pulls > 0 && (best === undefined || pulls > best.pulls)) best = { name: w.name, href: w.href, pulls };
53 }
54 if (landed === 0) return { sentence: "Nothing landed this week.", lead: "Nothing landed this week.", tail: "", landed: 0 };
55 if (best === undefined) {
56 const lead = `${pullWords(landed)} landed this week, none in a wave.`;
57 return { sentence: lead, lead, tail: "", landed };
58 }
59 const lead = "The biggest wave this week is ";
60 const tail = `: ${pullWords(best.pulls)} landed.`;
61 return { sentence: `${lead}${best.name}${tail}`, lead, tail, wave: best, landed };
62 }
63
64 /** A chapter grouping of the changelog (`release/chapter_groups.ts`) as the week's story. */
65 export function weekOfGroups(groups: readonly Group[], now: Date): WeekStory {
66 const waves: WaveLandings[] = [];
67 let extra = 0;
68 for (const g of groups) {
outdated

The seven-day window is written out again here. Reuse weekStory's inWeek.

69 if (g.kind === "chapter")
70 waves.push({
71 name: g.chapter.name,
72 href: g.wave === undefined ? `/${g.repo}/chapters/${encodeURIComponent(g.chapter.name)}` : `/${g.repo}/waves/${encodeURIComponent(g.wave.version)}`,
73 at: g.landings.map((l) => l.at),
74 });
75 else extra += g.landings.filter((l) => inWeek(l.at, now)).length;
76 }
77 return weekStory(waves, now, extra);
78 }
src/tui/screens/changelog.ts +2
@@ -7,6 +7,7 @@
77 * Esc returns to the same row.
88 */
99
10 import { weekOfGroups } from "../../story/week.ts";
1011 import { chapterOfPulls, listChapters } from "../../core/chapters.ts";
1112 import { sealedScope } from "../../core/sealed.ts";
1213 import { withWaves } from "../../release/chapter_waves.ts";
@@ -269,6 +270,7 @@ export function changelogScreen(f: Session, ctx: Ctx): Screen {
269270 groups = groupByChapter(live, withStanding(f.app, await withWaves(f.app, entries), f.user));
270271 }
271272 near = nearLines(nearMilestones(f.app, f.app.config.forgeRepo, f.user)?.near ?? []);
273 if (groups.length > 0) near = [weekOfGroups(groups, new Date()).sentence, ...near];
272274 home();
273275 loaded = true;
274276 ctx.invalidate();
src/web/pages/changelog.ts +10 −1
@@ -25,6 +25,7 @@ import { comparePath, rangeOf, rangeWords } from "../../release/range.ts";
2525 import { gather, plainTitle, type Gathered } from "../../story/gather.ts";
2626 import { milestoneHref, progress } from "./milestones.ts";
2727 import { doneWords } from "../../story/wave_moved.ts";
28 import { weekOfGroups } from "../../story/week.ts";
2829 import { withStanding } from "./wave_standing.ts";
2930 import { nearMilestones, nearWords, type Near } from "./milestones_near.ts";
3031 import { liveRegionsJs } from "../client.ts";
@@ -302,6 +303,13 @@ export function shippedRegion(
302303 return made;
303304 }
304305
306 /** The week's one sentence, at the page's reading size and colour; the wave's name is its link. */
307 function weekLine(groups: readonly Group[], now: Date): Html {
308 const story = weekOfGroups(groups, now);
309 const w = story.wave;

Principles 1 and 8: the sentence is built here by hand a second time, and small mutes it. Use story.sentence with the name linked, from one builder.

310 return html`<p id="week-story" data-week-story>${story.lead}${w === undefined ? null : html`<a href="${w.href}">${w.name}</a>${story.tail}`}</p>`;
311 }
312
305313 /** The region: the top line, what is on its way, and what went live by day. */
306314 function renderRegion(
307315 read: Landings,
@@ -356,7 +364,8 @@ function renderRegion(
356364 : !grouped
357365 ? html`${byDay(live, read.own, choice === "all", zone, todayIs, target)}`
358366 : html`${groups.map((g) => (g.kind === "chapter" ? chapterSection(g, read.own, choice === "all") : betweenSection(g, read.own, choice === "all")))}`;
359 return html`${top}${way}${gone}${older(read.more, read.live[read.live.length - 1]?.at, choice, read.own, bet)}`;
367 const week = live.length === 0 ? null : weekLine(grouped ? groups : [{ kind: "between", landings: live }], now);
368 return html`${top}${week}${way}${gone}${older(read.more, read.live[read.live.length - 1]?.at, choice, read.own, bet)}`;
360369 }
361370
362371 // GET /changelog?repo=all|owner/name
test/changelog-week.test.ts added +40
@@ -0,0 +1,40 @@
1 /**
2 * The week's sentence on /changelog's head: linked, escaped, quiet when nothing landed (#15995).
3 */
4 import { expect, test } from "bun:test";
5 import type { Chapter } from "../src/core/chapters.ts";
6 import type { Landing, Landings } from "../src/release/landings.ts";
7 import type { ChapterEntry } from "../src/release/chapter_groups.ts";
8 import { shippedRegion } from "../src/web/pages/changelog.ts";
9
10 const NOW = new Date("2026-11-12T12:00:00Z");
11 const at = (daysAgo: number) => new Date(NOW.getTime() - daysAgo * 864e5).toISOString();
12 const land = (number: number, when: string): Landing => ({ repo: "a/b", number, title: `Pull ${number}`, at: when, live: true });
13 const chapter = (name: string): Chapter => ({
14 id: name, repoId: "r", name, means: "m", state: "open", position: 1, patchOf: null,
15 createdAt: at(30), openedAt: at(30), closedAt: null, tagOid: null, notes: "", costUsd: 1,
16 });
17 const entry = (name: string, pulls: number[]): ChapterEntry => ({ repo: "a/b", chapter: chapter(name), canSee: true, pulls });
18 const read = (live: Landing[]): Landings => ({ version: "1.0.0", commit: null, own: "a/b", live, onItsWay: [] });
19
20 test("the head names the biggest wave, linked, as a plain sentence", () => {
21 const html = String(shippedRegion(read([land(1, at(1)), land(2, at(2)), land(3, at(3))]), "a/b", NOW, "UTC", undefined, true, [entry("v1", [1, 2]), entry("v2", [3])]));
22 expect(html).toContain('<p id="week-story" data-week-story>The biggest wave this week is <a href="/a/b/chapters/v1">v1</a>: 2 pulls landed.</p>');
23 expect(html).not.toContain('class="small" id="week-story"');
24 });
25
26 test("a wave name with HTML in it is escaped in the sentence and its link", () => {
27 const html = String(shippedRegion(read([land(1, at(1))]), "a/b", NOW, "UTC", undefined, true, [entry("<b>x</b>", [1])]));
28 expect(html).toContain("&lt;b&gt;x&lt;/b&gt;");
29 expect(html).not.toContain("<b>x</b>");
30 });
31
32 test("a quiet week says so", () => {
33 const html = String(shippedRegion(read([land(1, at(20))]), "a/b", NOW, "UTC", undefined, true, [entry("v1", [1])]));
34 expect(html).toContain(">Nothing landed this week.</p>");
35 });
36
37 test("pulls outside any wave are counted once, without a link", () => {
38 const html = String(shippedRegion(read([land(1, at(1)), land(2, at(2))]), "a/b", NOW));
39 expect(html).toContain(">2 pulls landed this week, none in a wave.</p>");
40 });
test/story-week.test.ts added +35
@@ -0,0 +1,35 @@
1 import { describe, expect, test } from "bun:test";

Only the pure function is tested. Add page tests (link, escaping, quiet week) and a TUI test; the pull says they exist, but they are not in the diff.

2 import { inWeek, weekOfGroups, weekStory } from "../src/story/week.ts";
3
4 const now = new Date("2026-11-23T12:00:00Z");
5 const day = (n: number) => new Date(now.getTime() - n * 864e5).toISOString();
6
7 describe("week story", () => {
8 test("an empty week says nothing landed", () => {
9 expect(weekStory([], now).sentence).toBe("Nothing landed this week.");
10 expect(weekStory([{ name: "v1", href: "/a", at: [day(9)] }], now).wave).toBeUndefined();
11 });
12 test("a single wave is named with its count and link", () => {
13 const s = weekStory([{ name: "v1.2.0", href: "/o/r/waves/1.2.0", at: [day(1), day(2), day(30)] }], now);
14 expect(s.wave).toEqual({ name: "v1.2.0", href: "/o/r/waves/1.2.0", pulls: 2 });
15 expect(s.sentence).toBe("The biggest wave this week is v1.2.0: 2 pulls landed.");
16 });
17 test("a tie goes to the first listed; the biggest wins", () => {
18 const a = { name: "new", href: "/n", at: [day(1), day(2)] };
19 const b = { name: "old", href: "/o", at: [day(3), day(4)] };
20 expect(weekStory([a, b], now).wave?.name).toBe("new");
21 expect(weekStory([a, { ...b, at: [...b.at, day(5)] }], now).wave?.name).toBe("old");
22 });
23 test("pulls in no wave are said, never invented a wave", () => {
24 expect(weekStory([], now, 3).sentence).toBe("3 pulls landed this week, none in a wave.");
25 });
26 test("one builder: the sentence is lead + name + tail; one window for every count", () => {
27 const s = weekStory([{ name: "v9", href: "/x", at: [day(1)] }], now);
28 expect(s.lead + "v9" + s.tail).toBe(s.sentence);
29 expect(inWeek(day(6.9), now)).toBe(true);
30 expect(inWeek(day(7.1), now)).toBe(false);
31 expect(inWeek(new Date(now.getTime() + 1000).toISOString(), now)).toBe(false);
32 const between = { kind: "between", landings: [{ repo: "a/b", number: 1, title: "t", at: day(1), live: true }] } as const;
33 expect(weekOfGroups([between], now).landed).toBe(1);
34 });
35 });
test/tui-changelog-chapters.test.ts +4
@@ -67,6 +67,10 @@ test("Enter on a pull line under a chapter opens that pull; the filter and its e
6767 const { terminal, tui } = await open();
6868 const text = tui.screen.toText();
6969 expect(text).toContain("Chapter v1");
70 // The week's sentence is the first line under the title (the fixture's pulls are older than a
71 // week).
72 expect(text.indexOf("Nothing landed this week.")).toBeGreaterThan(-1);
73 expect(text.indexOf("Nothing landed this week.")).toBeLessThan(text.indexOf("Chapter v1"));
7074 expect(text).toContain("#2 Landed pull 2");
7175 expect(text).toContain("Between chapters");
7276 // Down past the heading to the pull line, then Enter.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs