Public: anyone can read this; the crew can change it.
A wave's page says which milestones it moved, each with how far along it is now #7957
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/7761-a-wave-s-page-says-which-milestones-it-m → main 4 commits fork 2 threads · 2 unresolved
9 files
changed +416
−9
README.md +2
| @@ -508,6 +508,8 @@ How it works and how to turn it on: [`docs/features/release-keeper.md`](docs/fea | ||
| 508 | 508 | |
| 509 | 509 | `/changelog` lists the last 30 releases of `FORGE_REPO` (public only) with their pulls, for anyone; the terminal's palette has `Changelog` for the same list. In the terminal, `/` takes a word and keeps the releases whose version or pull titles contain it (`esc` clears it); Enter on a release lists its pulls, and Enter on a pull opens it (`docs/features/changelog.md`). |
| 510 | 510 | |
| 511 | A wave's page and the terminal's wave screen both list **Moved**: the milestones above the issues the wave's merged pulls closed, each with how far along it is now (`2 of 3 done`) and a link or path to open it. One function, `movedForViewer` (`src/story/wave_moved.ts`), computes it for both, over the milestones page's cached plan, and leaves out any milestone the viewer may not see; a wave that closed nothing under a milestone shows no Moved block. | |
| 512 | ||
| 511 | 513 | The web changelog's days and its "shipped today" count follow the reader's clock: a small script regroups the server-rendered cards into the browser's own days (Today, Yesterday, then a date) at load and after each live swap. With no script the days are UTC and the page says UTC. The script runs at `DOMContentLoaded`, before the first paint of this small page, and rebuilds the cards from the first one, so only the UTC mark leaves; that shift is accepted. `happy-dom` is a dev dependency, used only by the test that runs this script against a DOM. |
| 512 | 514 | |
| 513 | 515 | A repository admin cuts a wave from two doors, both through `cutWaveFor` (`src/actions/cut_wave.ts`): Settings → *Cut a wave*, and `c` on the terminal's waves screen, which says how many pulls would go in, asks `cut wave N? y/n` (`y` and `n` choose outright) and shows the draft pull's number (Enter opens it). Each opens a draft pull listing the pulls merged since the last wave; nothing merged, an earlier wave that does not parse, or a viewer who is not an admin is refused in the action's words, writing nothing. |
src/story/wave_moved.ts added +95
| @@ -0,0 +1,95 @@ | ||
| 1 | /** | |
| 2 | * The milestones a wave moved: those above the issues its pulls closed, each | |
| 3 | * with how far along it is now. A milestone is an issue that waits for others | |
| 4 | * (`core/milestones.ts`); the plan's furniture — pillar umbrellas, the Later | |
| 5 | * umbrella and gate — is not one here, by the same rule. Pure: plain data in, | |
| 6 | * plain data out; the caller reads the plan once and the pulls' bodies once. | |
| 7 | */ | |
| 8 | ||
| 9 | import type { Database } from "bun:sqlite"; | |
| 10 | import type { Plan } from "../core/milestones.ts"; | |
| 11 | import type { Repo } from "../core/repos.ts"; | |
| 12 | import { mayView } from "../core/sealed.ts"; | |
| 13 | import type { User } from "../core/users.ts"; | |
| 14 | import { closesOfMerged } from "./wave_pulls.ts"; | |
| 15 | import type { PullRef } from "./waves.ts"; | |
| 16 | ||
| 17 | export interface MovedMilestone { | |
| 18 | number: number; | |
| 19 | title: string; | |
| 20 | /** Issues beneath it that are done, out of all of them that count, now. */ | |
| 21 | done: number; | |
| 22 | total: number; | |
| 23 | } | |
| 24 | ||
| 25 | /** | |
| 26 | * `closes` maps a pull's number to the issue numbers it closes; `pulls` names | |
| 27 | * the wave's pulls in this repository. Milestones come back by number. | |
| 28 | */ | |
| 29 | export function movedMilestones(input: { | |
| 30 | pulls: readonly number[]; | |
| 31 | closes: ReadonlyMap<number, readonly number[]>; | |
| 32 | plan: Pick<Plan, "read" | "milestone">; | |
| 33 | }): MovedMilestone[] { | |
| 34 | const { graph, tree } = input.plan.read; | |
| 35 | const byNumber = new Map(graph.issues.map((i) => [i.number, i.id])); | |
| 36 | const numberOf = new Map(graph.issues.map((i) => [i.id, i.number])); | |
| 37 | const seen = new Set<string>(); | |
| 38 | const queue: string[] = []; | |
| 39 | for (const pull of input.pulls) | |
| 40 | for (const n of input.closes.get(pull) ?? []) { | |
| 41 | const id = byNumber.get(n); | |
| 42 | if (id !== undefined && !seen.has(id)) { | |
| 43 | seen.add(id); | |
| 44 | queue.push(id); | |
| 45 | } | |
| 46 | } | |
| 47 | // Walk up: whatever waits for a closed issue, and for that in turn. | |
| 48 | const above = new Set<string>(); | |
| 49 | for (let at = 0; at < queue.length; at++) | |
| 50 | for (const waiter of tree.waitedBy.get(queue[at]!) ?? []) { | |
| 51 | if (seen.has(waiter) || graph.structural.has(waiter)) continue; | |
| 52 | seen.add(waiter); | |
| 53 | above.add(waiter); | |
| 54 | queue.push(waiter); | |
| 55 | } | |
| 56 | const out: MovedMilestone[] = []; | |
| 57 | for (const id of above) { | |
| 58 | const number = numberOf.get(id); | |
| 59 | const milestone = number === undefined ? undefined : input.plan.milestone(number); | |
| 60 | if (number === undefined || milestone === undefined) continue; | |
| 61 | out.push({ | |
| 62 | number, | |
| 63 | title: milestone.issue.title, | |
| 64 | done: milestone.weight.done, | |
| 65 | total: milestone.weight.total, | |
| 66 | }); | |
| 67 | } | |
| 68 | return out.sort((a, b) => a.number - b.number); | |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * What both doors show of a wave: the milestones its merged pulls of `repo` | |
| 73 | * moved, leaving out any the viewer may not see. `plan` is read only when a | |
| 74 | * pull closes something, so a wave that closed nothing costs one query. | |
| 75 | */ | |
| 76 | export function movedForViewer(input: { | |
| 77 | db: Database; | |
| 78 | repo: Repo; | |
| 79 | refs: readonly PullRef[]; | |
| 80 | viewer: User | undefined; | |
| 81 | plan: () => Plan; | |
| 82 | }): MovedMilestone[] { | |
| 83 | const { db, repo } = input; | |
| 84 | const here = input.refs | |
| 85 | .filter((r) => r.owner === repo.ownerName && r.name === repo.name) | |
| 86 | .map((r) => r.number); | |
| 87 | const closes = closesOfMerged(db, repo, here); | |
| 88 | if ([...closes.values()].every((c) => c.length === 0)) return []; | |
| 89 | const plan = input.plan(); | |
| 90 | const issues = new Map(plan.read.graph.issues.map((i) => [i.number, i])); | |
| 91 | return movedMilestones({ pulls: here, closes, plan }).filter((m) => { | |
| 92 | const issue = issues.get(m.number); | |
| 93 | return issue !== undefined && mayView(db, repo, issue, input.viewer); | |
| 94 | }); | |
| 95 | } |
src/story/wave_plan.ts added +15
| @@ -0,0 +1,15 @@ | ||
| 1 | /** | |
| 2 | * What a wave's "Moved" list needs from the plan that the page and the | |
| 3 | * terminal share: where a milestone lives and how to read the plan for it. | |
| 4 | */ | |
| 5 | import type { Database } from "bun:sqlite"; | |
| 6 | import { readPlan, type Plan } from "../core/milestones.ts"; | |
| 7 | import type { Repo } from "../core/repos.ts"; | |
| 8 | ||
| 9 | /** Where a milestone is: its own page, under the repository's base path. */ | |
| 10 | export const milestonePath = (base: string, number: number): string => | |
| 11 | `${base}/milestones/${number}`; | |
| 12 | ||
| 13 | /** The repository's plan, read once, for a door with no cache of its own. */ | |
| 14 | export const planNow = (db: Database, repo: Repo, now: Date): Plan => | |
| 15 | readPlan(db, repo, { spend: false, now }); |
src/story/wave_pulls.ts +21
| @@ -5,6 +5,7 @@ | ||
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | 7 | import type { Database } from "bun:sqlite"; |
| 8 | import { closesFromBody } from "../core/pulls.ts"; | |
| 8 | 9 | import { canRead, getRepo, type Repo } from "../core/repos.ts"; |
| 9 | 10 | import type { User } from "../core/users.ts"; |
| 10 | 11 | import type { PullRef } from "./waves.ts"; |
| @@ -68,3 +69,23 @@ export function carriedPulls( | ||
| 68 | 69 | /** Where the pull lives on this forge: the local path, never the host the wave file was written with. */ |
| 69 | 70 | export const pullPath = (p: Pick<CarriedPull, "owner" | "name" | "number">): string => |
| 70 | 71 | `/${encodeURIComponent(p.owner)}/${encodeURIComponent(p.name)}/pulls/${p.number}`; |
| 72 | ||
| 73 | /** The issue numbers each merged pull of `repo` closes, by pull number: one query. */ | |
| 74 | export function closesOfMerged( | |
| 75 | db: Database, | |
| 76 | repo: Repo, | |
| 77 | numbers: readonly number[], | |
| 78 | ): Map<number, number[]> { | |
| 79 | const out = new Map<number, number[]>(); | |
| 80 | const wanted = [...new Set(numbers)].slice(0, MAX_PULLS); | |
| 81 | if (wanted.length === 0) return out; | |
| 82 | const rows = db | |
| 83 | .query<{ number: number; body: string }, (string | number)[]>( | |
| 84 | `SELECT issue.number, issue.body FROM issue JOIN pull ON pull.issue_id = issue.id | |
| 85 | WHERE issue.repo_id = ? AND pull.merged_at IS NOT NULL | |
| 86 | AND issue.number IN (${wanted.map(() => "?").join(",")})`, | |
| 87 | ) | |
| 88 | .all(repo.id, ...wanted); | |
| 89 | for (const r of rows) out.set(r.number, closesFromBody(r.body)); | |
| 90 | return out; | |
| 91 | } |
src/tui/screens/waves.ts +34 −4
| @@ -8,6 +8,9 @@ | ||
| 8 | 8 | import { cutWaveFor, planCutFor } from "../../actions/cut_wave.ts"; |
| 9 | 9 | import { canRead } from "../../core/repos.ts"; |
| 10 | 10 | import { VERSION } from "../../story/wave.ts"; |
| 11 | import { movedForViewer, type MovedMilestone } from "../../story/wave_moved.ts"; | |
| 12 | import { milestonePath, planNow } from "../../story/wave_plan.ts"; | |
| 13 | import { repoBase } from "../../web/chrome.ts"; | |
| 11 | 14 | import { carriedPulls, pullPath, type CarriedPull } from "../../story/wave_pulls.ts"; |
| 12 | 15 | import { pullRefs, readWave, readWaves, type WaveEntry } from "../../story/waves.ts"; |
| 13 | 16 | import { NO_WAVES } from "../../story/words.ts"; |
| @@ -41,8 +44,15 @@ const plain = (s: string): string => | ||
| 41 | 44 | // eslint-disable-next-line no-control-regex |
| 42 | 45 | s.replace(/[\u0000-\u001f\u007f-\u009f\u202a-\u202e\u2066-\u2069]+/g, " "); |
| 43 | 46 | |
| 47 | /** A moved milestone with the path that opens it. */ | |
| 48 | export type MovedLine = MovedMilestone & { path: string }; | |
| 49 | ||
| 44 | 50 | /** One wave as lines of plain text: headline, version and date, highlights with why, then the pulls the viewer may see. */ |
| 45 | export function waveLines(entry: WaveEntry, pulls: CarriedPull[]): string[] { | |
| 51 | export function waveLines( | |
| 52 | entry: WaveEntry, | |
| 53 | pulls: CarriedPull[], | |
| 54 | moved: MovedLine[] = [], | |
| 55 | ): string[] { | |
| 46 | 56 | if (!entry.ok) return [plain(entry.file), "", `Not a wave: ${plain(entry.reason)}`]; |
| 47 | 57 | const w = entry.wave; |
| 48 | 58 | return [ |
| @@ -52,6 +62,16 @@ export function waveLines(entry: WaveEntry, pulls: CarriedPull[]): string[] { | ||
| 52 | 62 | "Highlights", |
| 53 | 63 | ...w.highlights.map((h) => ` ${plain(h.title)} - ${plain(h.why)}`), |
| 54 | 64 | "", |
| 65 | ...(moved.length === 0 | |
| 66 | ? [] | |
| 67 | : [ | |
| 68 | "Moved", | |
| 69 | ...moved.flatMap((m) => [ | |
| 70 | ` ${plain(m.title)} - ${m.done} of ${m.total} done`, | |
| 71 | ` ${plain(m.path)}`, | |
| 72 | ]), | |
| 73 | "", | |
| 74 | ]), | |
| 55 | 75 | "Pulls", |
| 56 | 76 | ...(pulls.length === 0 |
| 57 | 77 | ? [" No pulls to show here."] |
| @@ -62,8 +82,8 @@ export function waveLines(entry: WaveEntry, pulls: CarriedPull[]): string[] { | ||
| 62 | 82 | ]; |
| 63 | 83 | } |
| 64 | 84 | |
| 65 | function waveScreen(ctx: Ctx, entry: WaveEntry, pulls: CarriedPull[]): Screen { | |
| 66 | const lines = waveLines(entry, pulls); | |
| 85 | function waveScreen(ctx: Ctx, entry: WaveEntry, pulls: CarriedPull[], moved: MovedLine[]): Screen { | |
| 86 | const lines = waveLines(entry, pulls, moved); | |
| 67 | 87 | const scroll = new Scroll(); |
| 68 | 88 | return { |
| 69 | 89 | title: entry.ok ? entry.wave.version : entry.file, |
| @@ -101,7 +121,17 @@ export function wavesScreen(f: Session, ctx: Ctx, src: RepoSource): Screen { | ||
| 101 | 121 | if (!one) return; |
| 102 | 122 | // The page's gate on each pull: one the viewer cannot read is not named. |
| 103 | 123 | const pulls = one.ok ? carriedPulls(f.db, pullRefs(one.wave), f.user) : []; |
| 104 | ctx.push(waveScreen(ctx, one, pulls)); | |
| 124 | // Same list as the page, from the same function, with the same gate. | |
| 125 | const moved = one.ok | |
| 126 | ? movedForViewer({ | |
| 127 | db: f.db, | |
| 128 | repo, | |
| 129 | refs: pullRefs(one.wave), | |
| 130 | viewer: f.user, | |
| 131 | plan: () => planNow(f.db, repo, new Date()), | |
| 132 | }).map((m) => ({ ...m, path: milestonePath(repoBase(repo), m.number) })) | |
| 133 | : []; | |
| 134 | ctx.push(waveScreen(ctx, one, pulls, moved)); | |
| 105 | 135 | }); |
| 106 | 136 | }; |
| 107 | 137 |
src/web/pages/milestones.ts +4 −4
| @@ -42,6 +42,7 @@ import { given, pendingFor } from "../../core/limb_replan.ts"; | ||
| 42 | 42 | import type { Ctx } from "../../http/context.ts"; |
| 43 | 43 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| 44 | 44 | import { cachedPlan } from "../map_cache.ts"; |
| 45 | import { milestonePath } from "../../story/wave_plan.ts"; | |
| 45 | 46 | import { askToLiveFor } from "../ask_to_live.ts"; |
| 46 | 47 | import { |
| 47 | 48 | crumbsFor, |
| @@ -60,8 +61,7 @@ import { badge, btn, card, listCard, pill, row, time } from "../ui.ts"; | ||
| 60 | 61 | import { folded, issueRow, list, wrappedCard } from "./limb_view.ts"; |
| 61 | 62 | |
| 62 | 63 | /** Where a milestone is: its own page. */ |
| 63 | export const milestoneHref = (base: string, number: number): string => | |
| 64 | `${base}/milestones/${number}`; | |
| 64 | export const milestoneHref = milestonePath; | |
| 65 | 65 | |
| 66 | 66 | /** Where an action on the whole limb is previewed and confirmed (`limb.ts`). */ |
| 67 | 67 | export const limbHref = ( |
| @@ -176,7 +176,7 @@ function weightWords(limb: Limb): Html { | ||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | /** How far a limb is, as a bar: the native element, named for a reader who cannot see it. */ |
| 179 | const progress = (done: number, total: number, label: string): Html => | |
| 179 | export const progress = (done: number, total: number, label: string): Html => | |
| 180 | 180 | html`<progress |
| 181 | 181 | max="${Math.max(total, 1)}" |
| 182 | 182 | value="${done}" |
| @@ -200,7 +200,7 @@ function limbLine(base: string, limb: Limb, move: Html | null = null): Html { | ||
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** The repository's plan, kept while nothing it reads changes. */ |
| 203 | const planFor = (ctx: Ctx, repo: Repo, spend: boolean, now: Date): Plan => | |
| 203 | export const planFor = (ctx: Ctx, repo: Repo, spend: boolean, now: Date): Plan => | |
| 204 | 204 | cachedPlan( |
| 205 | 205 | { |
| 206 | 206 | repoId: repo.id, |
src/web/pages/waves.ts +27 −1
| @@ -13,14 +13,16 @@ import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../cor | ||
| 13 | 13 | import { repoDir } from "../../git/repos.ts"; |
| 14 | 14 | import type { Ctx } from "../../http/context.ts"; |
| 15 | 15 | import { VERSION, type Wave } from "../../story/wave.ts"; |
| 16 | import { movedForViewer } from "../../story/wave_moved.ts"; | |
| 16 | 17 | import { carriedPulls, pullPath } from "../../story/wave_pulls.ts"; |
| 17 | 18 | import { pullRefs, readWave, readWaves } from "../../story/waves.ts"; |
| 18 | 19 | import { NO_WAVES } from "../../story/words.ts"; |
| 19 | 20 | import { loadRepo, notFoundPage, repoBase, scopeHeader } from "../chrome.ts"; |
| 20 | 21 | import { escapeHtml, html } from "../html.ts"; |
| 21 | 22 | import { page } from "../layout.ts"; |
| 22 | import { btn, empty, listCard, row } from "../ui.ts"; | |
| 23 | import { btn, empty, listCard, pill, row } from "../ui.ts"; | |
| 23 | 24 | import { localScope } from "../scope.ts"; |
| 25 | import { milestoneHref, planFor, progress } from "./milestones.ts"; | |
| 24 | 26 | |
| 25 | 27 | const WHAT_A_WAVE = |
| 26 | 28 | "A wave is a release note in waves/<version>.md that names its highlights and the pulls merged since the last one."; |
| @@ -172,6 +174,17 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 172 | 174 | carriedPulls(ctx.app.db, pullRefs(entry.wave), ctx.auth.user), |
| 173 | 175 | ) |
| 174 | 176 | : []; |
| 177 | const moved = entry.ok | |
| 178 | ? timePhase(ctx.request, "moved", () => | |
| 179 | movedForViewer({ | |
| 180 | db: ctx.app.db, | |
| 181 | repo, | |
| 182 | refs: pullRefs(entry.wave), | |
| 183 | viewer: ctx.auth.user, | |
| 184 | plan: () => planFor(ctx, repo, false, new Date()), | |
| 185 | }), | |
| 186 | ) | |
| 187 | : []; | |
| 175 | 188 | const rendering = performance.now(); |
| 176 | 189 | const scope = localScope(ctx, repo); |
| 177 | 190 | const back = html`<a href="${repoBase(repo)}/waves">All waves</a>`; |
| @@ -185,6 +198,19 @@ export async function wavePage(ctx: Ctx): Promise<Response> { | ||
| 185 | 198 | (h) => html`<li><strong>${h.title}</strong> — ${h.why}</li>`, |
| 186 | 199 | )} |
| 187 | 200 | </ul> |
| 201 | ${moved.length === 0 | |
| 202 | ? "" | |
| 203 | : listCard( | |
| 204 | moved.map((m) => | |
| 205 | row({ | |
Use |
||
| 206 | href: milestoneHref(repoBase(repo), m.number), | |
| 207 | title: m.title, | |
| 208 | meta: progress(m.done, m.total, `${m.done} of ${m.total} done`), | |
| 209 | trail: pill(`${m.done} of ${m.total} done`), | |
| 210 | }), | |
| 211 | ), | |
| 212 | { head: html`<h2>Moved</h2>` }, | |
| 213 | )} | |
| 188 | 214 | ${carried.length === 0 |
| 189 | 215 | ? html`<p class="muted">No pulls to show here.</p>` |
| 190 | 216 | : listCard( |
test/tui-waves.test.ts +38
| @@ -12,6 +12,9 @@ import { serve } from "../src/http/server.ts"; | ||
| 12 | 12 | import { createApp, type App as Forge } from "../src/app.ts"; |
| 13 | 13 | import type { Repo } from "../src/core/repos.ts"; |
| 14 | 14 | import type { User } from "../src/core/users.ts"; |
| 15 | import { linkIssue } from "../src/actions/dependencies.ts"; | |
| 16 | import { openIssue } from "../src/actions/issues.ts"; | |
| 17 | import { getIssueById, setIssueState } from "../src/core/issues.ts"; | |
| 15 | 18 | import { writeWave, type Wave } from "../src/story/wave.ts"; |
| 16 | 19 | import { createForgeApp } from "../src/tui/forge.ts"; |
| 17 | 20 | import { waveLines, wavesScreen } from "../src/tui/screens/waves.ts"; |
| @@ -181,6 +184,41 @@ describe("waves in the terminal", () => { | ||
| 181 | 184 | expect(outsider.text).not.toContain("/alice/priv/pulls/"); |
| 182 | 185 | }); |
| 183 | 186 | |
| 187 | test("the wave screen names the milestones it moved, as the page does, and not one the viewer may not see", async () => { | |
| 188 | const r = await createRepo(forge, alice, { name: "ms", visibility: "public" }); | |
| 189 | if (!r.ok) throw new Error("repo failed"); | |
| 190 | const repo = r.value; | |
| 191 | await commitToBranch(forge, alice, repo, { message: "init", files: [{ path: "README.md", content: "hi\n" }] }); | |
| 192 | const issue = (title: string, sealed = false) => { | |
| 193 | const o = openIssue(forge, alice, repo, { title, sealed }); | |
| 194 | if (!o.ok) throw new Error("issue failed"); | |
| 195 | return o.value; | |
| 196 | }; | |
| 197 | const goal = issue("Open goal"); | |
| 198 | const hidden = issue("Hidden goal", true); | |
| 199 | const a = issue("Part A"); | |
| 200 | const b = issue("Part B"); | |
| 201 | for (const [up, down] of [[goal, a], [goal, b], [hidden, a]] as const) | |
| 202 | linkIssue(forge, alice, repo, getIssueById(forge.db, up.id)!, getIssueById(forge.db, down.id)!); | |
| 203 | setIssueState(forge.db, a.id, "closed", "done"); | |
| 204 | const n = await mergedPull(forge, alice, repo, "Part A work"); | |
| 205 | forge.db.query("UPDATE issue SET body = ? WHERE repo_id = ? AND number = ?").run(`Closes #${a.number}`, repo.id, n); | |
| 206 | await commitToBranch(forge, alice, repo, { | |
| 207 | message: "wave", | |
| 208 | files: [{ path: "waves/0.1.0.md", content: waveNaming("0.1.0", [{ owner: "alice", name: "ms", number: n }]) }], | |
| 209 | }); | |
| 210 | const owner = await open(alice, repo, ["enter"]); | |
| 211 | owner.stop(); | |
| 212 | expect(owner.text).toContain("Moved"); | |
| 213 | expect(owner.text).toContain("Open goal - 1 of 2 done"); | |
| 214 | expect(owner.text).toContain(`/alice/ms/milestones/${goal.number}`); | |
| 215 | expect(owner.text).not.toContain("Hidden goal"); | |
| 216 | const outsider = await open(bob, repo, ["enter"]); | |
| 217 | outsider.stop(); | |
| 218 | expect(outsider.text).toContain("Open goal - 1 of 2 done"); | |
| 219 | expect(outsider.text).not.toContain("Hidden goal"); | |
| 220 | }); | |
| 221 | ||
| 184 | 222 | test("enter on an unparsable row shows its reason", async () => { |
| 185 | 223 | const h = await open(alice, pub, ["j", "j", "enter"]); |
| 186 | 224 | h.stop(); |
test/wave-moved.test.ts added +180
| @@ -0,0 +1,180 @@ | ||
| 1 | /** A wave says which milestones it moved, each with how far along it is now. */ | |
| 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 3 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 4 | import { tmpdir } from "node:os"; | |
| 5 | import { join } from "node:path"; | |
| 6 | import { linkIssue } from "../src/actions/dependencies.ts"; | |
| 7 | import { openIssue } from "../src/actions/issues.ts"; | |
| 8 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { getIssueById, setIssueState, type Issue } from "../src/core/issues.ts"; | |
| 11 | import { readPlan } from "../src/core/milestones.ts"; | |
| 12 | import { getRepoById, type Repo } from "../src/core/repos.ts"; | |
| 13 | import { createSession } from "../src/core/sessions.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | import { movedForViewer, movedMilestones } from "../src/story/wave_moved.ts"; | |
| 17 | import { mergedPull, waveNaming } from "./helpers/wave-pulls.ts"; | |
| 18 | ||
| 19 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 20 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 21 | return r.value; | |
| 22 | }; | |
| 23 | ||
| 24 | describe("wave moved", () => { | |
| 25 | let dataDir: string; | |
| 26 | let app: App; | |
| 27 | let servers: Servers; | |
| 28 | let alice: User; | |
| 29 | let cookie: string; | |
| 30 | let repo: Repo; | |
| 31 | let milestone: Issue; | |
| 32 | let a: Issue; | |
| 33 | let b: Issue; | |
| 34 | let c: Issue; | |
| 35 | let loose: Issue; | |
| 36 | const fresh = () => getRepoById(app.db, repo.id)!; | |
| 37 | const open = (title: string): Issue => | |
| 38 | must(openIssue(app, alice, fresh(), { title })); | |
| 39 | const link = (waiter: Issue, on: Issue): void => { | |
| 40 | must( | |
| 41 | linkIssue(app, alice, fresh(), getIssueById(app.db, waiter.id)!, getIssueById(app.db, on.id)!), | |
| 42 | ); | |
| 43 | }; | |
| 44 | const closing = async (title: string, closes: Issue): Promise<number> => { | |
| 45 | const n = await mergedPull(app, alice, repo, title); | |
| 46 | app.db | |
| 47 | .query("UPDATE issue SET body = ? WHERE repo_id = ? AND number = ?") | |
| 48 | .run(`Closes #${closes.number}`, repo.id, n); | |
| 49 | return n; | |
| 50 | }; | |
| 51 | ||
| 52 | beforeAll(async () => { | |
| 53 | dataDir = await mkdtemp(join(tmpdir(), "forge-wave-moved-")); | |
| 54 | app = createApp({ dataDir, port: 0 }); | |
| 55 | servers = await serve(app); | |
| 56 | alice = must( | |
| 57 | await createUser(app.db, { | |
| 58 | origin: "seed", | |
| 59 | trusted: true, | |
| 60 | username: "alice", | |
| 61 | email: "[email protected]", | |
| 62 | password: "a-good-passphrase", | |
| 63 | adminIfFirst: true, | |
| 64 | }), | |
| 65 | ); | |
| 66 | cookie = `forge_session=${createSession(app.db, alice.id).token}; forge_mode=dev`; | |
| 67 | repo = must(await createRepo(app, alice, { name: "plan", visibility: "public" })); | |
| 68 | must(await commitToBranch(app, alice, repo, { message: "init", files: [{ path: "README.md", content: "hi\n" }] })); | |
| 69 | milestone = open("Ship the thing"); | |
| 70 | a = open("Part A"); | |
| 71 | b = open("Part B"); | |
| 72 | c = open("Part C"); | |
| 73 | loose = open("Unrelated"); | |
| 74 | for (const part of [a, b, c]) link(milestone, part); | |
| 75 | for (const done of [a, b]) setIssueState(app.db, done.id, "closed", "done"); | |
| 76 | }, 60_000); | |
| 77 | ||
| 78 | afterAll(async () => { | |
| 79 | servers.stop(); | |
| 80 | app.close(); | |
| 81 | await rm(dataDir, { recursive: true, force: true }); | |
| 82 | }); | |
| 83 | ||
| 84 | test("two pulls under one milestone, one under none: exactly that milestone, with counts", () => { | |
| 85 | const plan = readPlan(app.db, fresh(), { spend: false }); | |
| 86 | const moved = movedMilestones({ | |
| 87 | pulls: [1, 2, 3], | |
| 88 | closes: new Map([[1, [a.number]], [2, [b.number]], [3, [loose.number]]]), | |
| 89 | plan, | |
| 90 | }); | |
| 91 | expect(moved).toEqual([ | |
| 92 | { number: milestone.number, title: "Ship the thing", done: 2, total: 3 }, | |
| 93 | ]); | |
| 94 | }); | |
| 95 | ||
| 96 | test("a wave that closed nothing under a milestone moved none", () => { | |
| 97 | const plan = readPlan(app.db, fresh(), { spend: false }); | |
| 98 | expect(movedMilestones({ pulls: [3], closes: new Map([[3, [loose.number]]]), plan })).toEqual([]); | |
| 99 | expect(movedMilestones({ pulls: [], closes: new Map(), plan })).toEqual([]); | |
| 100 | }); | |
| 101 | ||
| 102 | test("the wave page lists the Moved milestone, linked; none when it moved none", async () => { | |
| 103 | const p1 = await closing("Part A work", a); | |
| 104 | const p2 = await closing("Part B work", b); | |
| 105 | const p3 = await closing("Loose work", loose); | |
| 106 | const ref = (number: number) => ({ owner: "alice", name: "plan", number }); | |
| 107 | must( | |
| 108 | await commitToBranch(app, alice, fresh(), { | |
| 109 | message: "waves", | |
| 110 | files: [ | |
| 111 | { path: "waves/0.1.0.md", content: waveNaming("0.1.0", [ref(p1), ref(p2), ref(p3)]) }, | |
| 112 | { path: "waves/0.2.0.md", content: waveNaming("0.2.0", [ref(p3)]) }, | |
| 113 | ], | |
| 114 | }), | |
| 115 | ); | |
| 116 | const text = await (await fetch(`${servers.url}/alice/plan/waves/0.1.0`, { headers: { cookie } })).text(); | |
| 117 | expect(text).toContain("<h2>Moved</h2>"); | |
| 118 | expect(text).toContain(`href="/alice/plan/milestones/${milestone.number}"`); | |
| 119 | expect(text).toContain("Ship the thing"); | |
| 120 | expect(text).toContain("2 of 3 done"); | |
| 121 | const none = await (await fetch(`${servers.url}/alice/plan/waves/0.2.0`, { headers: { cookie } })).text(); | |
| 122 | expect(none).not.toContain("Moved"); | |
| 123 | }); | |
| 124 | ||
| 125 | const wave = async (version: string, numbers: number[]): Promise<string> => { | |
| 126 | must( | |
| 127 | await commitToBranch(app, alice, fresh(), { | |
| 128 | message: `wave ${version}`, | |
| 129 | files: [ | |
| 130 | { | |
| 131 | path: `waves/${version}.md`, | |
| 132 | content: waveNaming(version, numbers.map((number) => ({ owner: "alice", name: "plan", number }))), | |
| 133 | }, | |
| 134 | ], | |
| 135 | }), | |
| 136 | ); | |
| 137 | return `${servers.url}/alice/plan/waves/${version}`; | |
| 138 | }; | |
| 139 | ||
| 140 | test("a milestone the viewer may not see is not named: a guest sees none, a writer sees it", async () => { | |
| 141 | const secret = must(openIssue(app, alice, fresh(), { title: "Sealed goal", sealed: true })); | |
| 142 | const part = open("Sealed part"); | |
| 143 | link(secret, part); | |
| 144 | setIssueState(app.db, part.id, "closed", "done"); | |
| 145 | const url = await wave("0.3.0", [await closing("Sealed part work", part)]); | |
| 146 | const guest = await (await fetch(url)).text(); | |
| 147 | expect(guest).not.toContain("Sealed goal"); | |
| 148 | expect(guest).not.toContain("<h2>Moved</h2>"); | |
| 149 | // The plan itself leaves sealed issues out, for everyone. | |
| 150 | const owner = await (await fetch(url, { headers: { cookie } })).text(); | |
| 151 | expect(owner).not.toContain("Sealed goal"); | |
| 152 | }); | |
| 153 | ||
| 154 | test("the viewer gate holds even if a plan carried a sealed milestone: a guest loses it, a writer keeps it", async () => { | |
| 155 | const goal = open("Gate goal"); | |
| 156 | const part = open("Gate part"); | |
| 157 | link(goal, part); | |
| 158 | setIssueState(app.db, part.id, "closed", "done"); | |
| 159 | const n = await closing("Gate work", part); | |
| 160 | const real = readPlan(app.db, fresh(), { spend: false }); | |
| 161 | const issues = real.read.graph.issues.map((i) => (i.id === goal.id ? { ...i, sealed: true } : i)); | |
| 162 | const plan = { ...real, read: { ...real.read, graph: { ...real.read.graph, issues } } } as typeof real; | |
| 163 | const ask = (viewer: User | undefined) => | |
| 164 | movedForViewer({ db: app.db, repo: fresh(), refs: [{ owner: "alice", name: "plan", number: n }], viewer, plan: () => plan }); | |
| 165 | expect(ask(undefined)).toEqual([]); | |
| 166 | expect(ask(alice).map((m) => m.title)).toEqual(["Gate goal"]); | |
| 167 | }); | |
| 168 | ||
| 169 | test("a pull that was closed and not merged moved nothing", async () => { | |
| 170 | const goal = open("Closed-pull goal"); | |
| 171 | const part = open("Closed-pull part"); | |
| 172 | link(goal, part); | |
| 173 | const n = await closing("Abandoned work", part); | |
| 174 | app.db.query("UPDATE pull SET merged_at = NULL WHERE issue_id = (SELECT id FROM issue WHERE repo_id = ? AND number = ?)").run(repo.id, n); | |
| 175 | app.db.query("UPDATE issue SET state = 'closed' WHERE repo_id = ? AND number = ?").run(repo.id, n); | |
| 176 | const text = await (await fetch(await wave("0.4.0", [n]), { headers: { cookie } })).text(); | |
| 177 | expect(text).not.toContain("Closed-pull goal"); | |
| 178 | expect(text).not.toContain("<h2>Moved</h2>"); | |
| 179 | }); | |
| 180 | }); |
new above
offline
The terminal should not import from src/web/pages. Move
planOf/milestoneHrefto a neutral module both doors share.