Public: anyone can read this; the crew can change it.
The growth panel says in one sentence whether it is time to pause the planner #16155
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16135-the-growth-panel-says-in-one-sentence-wh → main 0 commits fork 3 threads · 3 unresolved
docs/features/growth.md +6
| @@ -55,3 +55,9 @@ repository is open says the same (`src/tui/screens/queuegrowth.ts`). Anyone else | ||
| 55 | 55 | Pinned by `test/repo-growth-panel.test.ts`. |
| 56 | 56 | |
| 57 | 57 | Not done: one action per aged item. |
| 58 | ||
| 59 | **The week in one sentence.** The growth panel on a repository's home (admins only) and the terminal's Growth | |
| 60 | screen add one line: issues opened and landed in the last seven UTC days ("landed" means issues closed). Only | |
| 61 | when more was opened than landed and the planner is on does it say it is time to pause the planner, and the | |
| 62 | panel's single link then goes to the switch on the queue page; with the planner already paused it says so and | |
| 63 | gives no advice. Otherwise it gives the counts alone. It never pauses anything by itself. |
src/core/growth_panel.ts +30 −1
| @@ -25,6 +25,32 @@ export interface GrowthPanel { | ||
| 25 | 25 | readonly until: string | null; |
| 26 | 26 | /** "paused: 50 of 20 pulls open" while the open-pull ceiling holds new builds, else null. */ |
| 27 | 27 | readonly pullsHeld: string | null; |
| 28 | /** Issues opened and closed in the last 7 UTC days, and whether opening outran landing. */ | |
| 29 | readonly week: WeekVerdict; | |
| 30 | } | |
| 31 | ||
| 32 | export interface WeekVerdict { | |
| 33 | readonly opened: number; | |
| 34 | readonly landed: number; | |
| 35 | /** True only when more was opened than landed this week. */ | |
| 36 | readonly outgrowing: boolean; | |
| 37 | } | |
| 38 | ||
| 39 | export function weekVerdict(opened: number, landed: number): WeekVerdict { | |
| 40 | return { opened, landed, outgrowing: opened > landed }; | |
| 41 | } | |
| 42 | ||
| 43 | /** | |
| 44 | * One sentence on the week, opened against landed ("landed" is issues closed). Only counts when | |
| 45 | * landings keep up; it advises a pause only when open work outgrew them and the planner is on. | |
| 46 | */ | |
| 47 | export function weekSentence(week: WeekVerdict, paused: boolean): string { | |
| 48 | const { opened, landed } = week; | |
| 49 | const counts = `${opened} ${opened === 1 ? "issue" : "issues"} opened and ${landed} landed this week`; | |
| 50 | if (!week.outgrowing) return `${counts}.`; | |
| 51 | return paused | |
| 52 | ? `${counts}: open work is outgrowing landings; the planner is already paused.` | |
| 53 | : `${counts}: open work is outgrowing landings, so it is time to pause the planner.`; | |
| 28 | 54 | } |
| 29 | 55 | |
| 30 | 56 | type Kept = Map<string, { at: number; panel: GrowthPanel }>; |
| @@ -58,8 +84,11 @@ export function growthPanelFor(db: Database, repo: Repo, user: User | undefined, | ||
| 58 | 84 | const held = pullsCeilingHold(db, repo.id); |
| 59 | 85 | return held === hit.panel.pullsHeld ? hit.panel : { ...hit.panel, pullsHeld: held }; |
| 60 | 86 | } |
| 87 | const g = growth(db, repo, GROWTH_DAYS, now, scope); | |
| 88 | const wk = g.days.slice(-7); | |
| 61 | 89 | const panel: GrowthPanel = { |
| 62 | sentences: growth(db, repo, GROWTH_DAYS, now, scope).sentences, | |
| 90 | sentences: g.sentences, | |
| 91 | week: weekVerdict(wk.reduce((a, d) => a + d.issuesOpened, 0), wk.reduce((a, d) => a + d.issuesClosed, 0)), | |
| 63 | 92 | until: pausedUntil(db, repo.id, now), |
| 64 | 93 | pullsHeld: pullsCeilingHold(db, repo.id), |
| 65 | 94 | }; |
src/tui/screens/queuegrowth.ts +2 −2
| @@ -13,7 +13,7 @@ import { DEFER_TOO_LATE, deferOldest, hasGate, recentDefer, undoDefer } from ".. | ||
| 13 | 13 | import { setCeiling, setPlannerSwitch, setPullsCeiling, SWITCH_REFUSED, switchInput, type SwitchInput } from "../../actions/planner_switch.ts"; |
| 14 | 14 | import { openFlowWords } from "../../core/chapters.ts"; |
| 15 | 15 | import { growth, oldest, WHO } from "../../core/growth.ts"; |
| 16 | import { growthPanelFor } from "../../core/growth_panel.ts"; | |
| 16 | import { growthPanelFor, weekSentence } from "../../core/growth_panel.ts"; | |
| 17 | 17 | import { ceilingHold, CEILING_REASON, openCeiling, PAUSE_STOPS, pauseSentence, pausedUntil } from "../../core/planner_pause.ts"; |
| 18 | 18 | import { canAdmin, getRepoById, type Repo } from "../../core/repos.ts"; |
| 19 | 19 | import { openPullsCeiling, pullsCeilingHold, PULLS_CEILING_REASON, PULLS_HELD_NOTE } from "../../core/pulls_ceiling.ts"; |
| @@ -185,7 +185,7 @@ export function queueScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 185 | 185 | export function growthPanelLines(f: Session, repo: Repo, now = new Date()): string[] { |
| 186 | 186 | const panel = growthPanelFor(f.db, repo, f.user, f.user !== undefined && canAdmin(f.db, repo, f.user), now); |
| 187 | 187 | if (panel === null) return ["An admin of this repository reads its growth here."]; |
| 188 | return [...panel.sentences, pauseSentence(panel.until), ...(panel.pullsHeld === null ? [] : [`${panel.pullsHeld}.`]), "Queue has the days and the planner's switch."]; | |
| 188 | return [...panel.sentences, pauseSentence(panel.until), ...(panel.pullsHeld === null ? [] : [`${panel.pullsHeld}.`]), weekSentence(panel.week, panel.until !== null), "Queue has the days and the planner's switch."]; | |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | export function growthPanelScreen(f: Session, ctx: Ctx, repo: Repo): Screen { |
src/web/pages/growth_panel.ts +4 −2
| @@ -8,7 +8,7 @@ | ||
| 8 | 8 | * `isAdmin` is the one admin check a home render makes, kept per request so the wallet line and the |
| 9 | 9 | * panel share it and a visitor pays for it once. |
| 10 | 10 | */ |
| 11 | import { growthPanelFor } from "../../core/growth_panel.ts"; | |
| 11 | import { growthPanelFor, weekSentence } from "../../core/growth_panel.ts"; | |
| 12 | 12 | import { pauseSentence } from "../../core/planner_pause.ts"; |
| 13 | 13 | import { canAdmin, type Repo } from "../../core/repos.ts"; |
| 14 | 14 | import type { Ctx } from "../../http/context.ts"; |
| @@ -33,10 +33,12 @@ export function isAdmin(ctx: Ctx, repo: Repo): boolean { | ||
| 33 | 33 | export function growthBody(ctx: Ctx, repo: Repo): Html | null { |
| 34 | 34 | const panel = growthPanelFor(ctx.app.db, repo, ctx.auth.user, isAdmin(ctx, repo)); |
| 35 | 35 | if (panel === null) return null; |
| 36 | const advise = panel.week.outgrowing && panel.until === null; | |
| 36 | 37 | return html`<span id="growth-panel" data-growth-panel>${panel.sentences.join(" ")} |
| 37 | 38 | <span data-planner-state="${panel.until === null ? "on" : "paused"}">${pauseSentence(panel.until)}</span> |
| 38 | 39 | ${panel.pullsHeld === null ? null : html`<span data-pulls-paused>${panel.pullsHeld.charAt(0).toUpperCase()}${panel.pullsHeld.slice(1)}.</span>`} |
outdated
Principle 1: this adds a second link to /queue next to the 'Queue' link below it, and the sentence already repeats the planner state shown just above. Also, when the planner is paused the sentence still says to pause it (link is hidden, text is not). Fix: branch the sentence on |
||
| 39 | <a href="${repoBase(repo)}/queue">Queue</a></span>`; | |
| 40 | <span data-week-verdict="${advise ? "pause" : "go"}">${weekSentence(panel.week, panel.until !== null)}</span> | |
| 41 | <a href="${repoBase(repo)}/queue${advise ? "#planner" : ""}"${advise ? " data-pause-link" : ""}>${advise ? "Pause the planner" : "Queue"}</a></span>`; | |
| 40 | 42 | } |
| 41 | 43 | |
| 42 | 44 | /** The panel on its own, folded behind one icon, for a page with no wallet line to carry it. */ |
src/web/pages/queue.ts +1 −1
| @@ -52,7 +52,7 @@ export function growthRows(g: Growth, flow: string | null = null): Html { | ||
| 52 | 52 | |
| 53 | 53 | function switchRow(repo: Repo, until: string | null, owner: boolean): Html { |
| 54 | 54 | const post = `${repoBase(repo)}/queue/planner`; |
| 55 | const state = html`<p data-planner-switch>${pauseSentence(until)} ${until === null ? null : PAUSE_STOPS}</p>`; | |
| 55 | const state = html`<p id="planner" data-planner-switch>${pauseSentence(until)} ${until === null ? null : PAUSE_STOPS}</p>`; | |
| 56 | 56 | if (!owner) return state; |
| 57 | 57 | return until !== null |
| 58 | 58 | ? html`${state}<form method="post" action="${post}"><input type="hidden" name="mode" value="on">${btn("Switch the planner on", { variant: "primary" })}</form>` |
test/growth-sentence.test.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | /** | |
| 2 | * The growth panel's one sentence on the week: pause the planner only when opening outran landing. | |
| 3 | */ | |
| 4 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 5 | import { weekSentence, weekVerdict } from "../src/core/growth_panel.ts"; | |
| 6 | import { getRepo, type Repo } from "../src/core/repos.ts"; | |
outdated
Duplicate bun:test import (line 4), the dynamic import of repos.ts, and |
||
| 7 | import { setPlannerSwitch } from "../src/actions/planner_switch.ts"; | |
| 8 | import type { User } from "../src/core/users.ts"; | |
| 9 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 10 | import { tmpdir } from "node:os"; | |
| 11 | import { join } from "node:path"; | |
| 12 | import { createApp } from "../src/app.ts"; | |
| 13 | import { createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { openIssue } from "../src/actions/issues.ts"; | |
| 15 | import { createUser } from "../src/core/users.ts"; | |
| 16 | import { serve } from "../src/http/server.ts"; | |
| 17 | import { quietLogs } from "./helpers/globals.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | let dir = ""; | |
| 21 | let app: ReturnType<typeof createApp>; | |
| 22 | let servers: Awaited<ReturnType<typeof serve>>; | |
| 23 | let cookie = ""; | |
| 24 | let user: User; | |
| 25 | let repo: Repo; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dir = await mkdtemp(join(tmpdir(), "forge-growth-sentence-")); | |
| 29 | app = createApp({ dataDir: dir, port: 0 }); | |
| 30 | servers = await serve(app); | |
| 31 | const made = await createUser(app.db, { | |
| 32 | origin: "seed", trusted: true, username: "trevato", email: "[email protected]", | |
| 33 | password: "a-good-passphrase", adminIfFirst: true, | |
| 34 | }); | |
| 35 | user = ("value" in made ? made.value : made) as User; | |
| 36 | const res = await fetch(servers.url + "/signin", { | |
| 37 | method: "POST", redirect: "manual", | |
| 38 | headers: { "content-type": "application/x-www-form-urlencoded", origin: servers.url }, | |
| 39 | body: new URLSearchParams({ username: "trevato", password: "a-good-passphrase" }), | |
| 40 | }); | |
| 41 | cookie = (res.headers.get("set-cookie") ?? "").split(";")[0] ?? ""; | |
| 42 | await createRepo(app, user, { name: "garden", visibility: "public" }); | |
| 43 | repo = getRepo(app.db, "trevato", "garden")!; | |
| 44 | }); | |
| 45 | afterAll(async () => { | |
| 46 | servers.stop(); | |
| 47 | app.close(); | |
| 48 | await rm(dir, { recursive: true, force: true }); | |
| 49 | }); | |
| 50 | ||
| 51 | test("it compares opened to landed and says to pause only when open work outgrows landings", () => { | |
| 52 | const more = weekVerdict(12, 5); | |
| 53 | expect(more.outgrowing).toBe(true); | |
| 54 | expect(weekSentence(more, false)).toContain("12 issues opened and 5 landed"); | |
| 55 | expect(weekSentence(more, false)).toContain("time to pause the planner"); | |
| 56 | for (const [o, l] of [[5, 5], [3, 8], [0, 0]] as [number, number][]) { | |
| 57 | const v = weekVerdict(o, l); | |
| 58 | expect(v.outgrowing).toBe(false); | |
| 59 | for (const paused of [false, true]) { | |
| 60 | const t = weekSentence(v, paused); | |
| 61 | expect(t).toBe(`${o} ${o === 1 ? "issue" : "issues"} opened and ${l} landed this week.`); | |
| 62 | expect(t).not.toContain("planner"); | |
| 63 | } | |
| 64 | } | |
| 65 | }); | |
| 66 | ||
| 67 | test("a paused planner is not told to pause", () => { | |
| 68 | const t = weekSentence(weekVerdict(12, 5), true); | |
| 69 | expect(t).toContain("already paused"); | |
| 70 | expect(t).not.toContain("time to pause"); | |
| 71 | }); | |
| 72 | ||
| 73 | const home = async () => (await fetch(servers.url + "/trevato/garden", { headers: { cookie } })).text(); | |
| 74 | ||
| 75 | test("on the home, opened beyond landed says pause and its one link goes to the switch", async () => { | |
| 76 | await openIssue(app, user, repo, { title: "Water the beds" }); | |
| 77 | const page = await home(); | |
| 78 | expect(page).toContain('data-week-verdict="pause"'); | |
| 79 | expect(page).toContain("1 issue opened and 0 landed this week"); | |
| 80 | expect(page).toContain('href="/trevato/garden/queue#planner"'); | |
| 81 | expect(page).not.toContain('href="/trevato/garden/queue"'); | |
| 82 | const queue = await (await fetch(servers.url + "/trevato/garden/queue", { headers: { cookie } })).text(); | |
| 83 | expect(queue).toContain('id="planner"'); | |
| 84 | }); | |
| 85 | ||
| 86 | test("with the planner paused the home gives no advice and no pause link", async () => { | |
| 87 | expect(setPlannerSwitch(app, user, repo, { mode: "owner" }).ok).toBe(true); | |
| 88 | const page = await home(); | |
| 89 | expect(page).toContain('data-planner-state="paused"'); | |
| 90 | expect(page).toContain("the planner is already paused"); | |
| 91 | expect(page).not.toContain("time to pause"); | |
| 92 | expect(page).not.toContain("data-pause-link"); | |
| 93 | expect(page).toContain('href="/trevato/garden/queue"'); | |
| 94 | }); |
test/repo-growth-panel.test.ts +4 −3
| @@ -58,7 +58,7 @@ test("the owner reads the queue's sentences, the planner state and a link; a vis | ||
| 58 | 58 | const owner = await get("/trevato/garden", cookie); |
| 59 | 59 | expect(owner).toContain('id="growth-panel"'); |
| 60 | 60 | expect(owner).toContain('data-planner-state="on"'); |
| 61 | expect(owner).toContain('href="/trevato/garden/queue"'); | |
| 61 | expect(owner).toMatch(/href="\/trevato\/garden\/queue(#planner)?"/); | |
| 62 | 62 | expect(owner).toContain("The planner is on."); |
| 63 | 63 | const panel = text(owner.match(/<span id="growth-panel"[\s\S]*?<\/details>/)![0]); |
| 64 | 64 | const sentence = panel.split("The planner is on.")[0]!.trim(); |
| @@ -80,7 +80,7 @@ test("paused, the panel says so", async () => { | ||
| 80 | 80 | |
| 81 | 81 | // ---- the read, the gate, the cache, the studio app home and the terminal (#15261) ---- |
| 82 | 82 | import { newApp } from "../src/actions/apps.ts"; |
| 83 | import { forgetGrowthPanel, growthPanelFor } from "../src/core/growth_panel.ts"; | |
| 83 | import { forgetGrowthPanel, growthPanelFor, weekSentence } from "../src/core/growth_panel.ts"; | |
| 84 | 84 | import { createSession } from "../src/core/sessions.ts"; |
| 85 | 85 | import { createIssue } from "../src/core/issues.ts"; |
| 86 | 86 | import { growthPanelLines } from "../src/tui/screens/queuegrowth.ts"; |
| @@ -143,7 +143,7 @@ test("the studio app home carries the panel for its admin and for nobody else", | ||
| 143 | 143 | const owner = await get("/trevato/orchard", cookie); |
| 144 | 144 | expect(owner).toContain('id="app-head"'); |
| 145 | 145 | expect(owner).toContain('data-growth-panel'); |
| 146 | expect(owner).toContain('href="/trevato/orchard/queue"'); | |
| 146 | expect(owner).toMatch(/href="\/trevato\/orchard\/queue(#planner)?"/); | |
| 147 | 147 | expect(await get("/trevato/orchard", bob.cookie)).not.toContain("growth-panel"); |
| 148 | 148 | expect(await get("/trevato/orchard", "")).not.toContain("growth-panel"); |
| 149 | 149 | }); |
| @@ -155,5 +155,6 @@ test("the terminal says the same, to an admin only", () => { | ||
| 155 | 155 | const lines = growthPanelLines(f, repo); |
| 156 | 156 | expect(lines[0]).toBe(growthPanelFor(app.db, repo, user, true)!.sentences[0]!); |
| 157 | 157 | expect(lines.join(" ")).toContain("planner"); |
| 158 | expect(lines).toContain(weekSentence(growthPanelFor(app.db, repo, user, true)!.week, false)); | |
| 158 | 159 | expect(growthPanelLines({ ...f, user: undefined }, repo)).toEqual(["An admin of this repository reads its growth here."]); |
| 159 | 160 | }); |
The 'outgrowing' sentence has no paused variant, so a paused planner is told to pause. Pass
pausedinto weekVerdict and say 'the planner is already paused' in that case. The 'so the planner can keep going' text on the other branch also restates the pause sentence; drop it.