Public: anyone can read this; the crew can change it.
Waves: what landed between two releases, gathered and told as one note worth reading #1098
scout/forge:scout/1082-waves-what-landed-between-two-releases-g → main 2 commits fork
15 files
changed +879
−1
docs/MCP.md +1
| @@ -51,6 +51,7 @@ for a tunnel and a forge that sleeps. | ||
| 51 | 51 | | `front_page` | `{ pinned?, hidden?, weights?, dryRun? }`: the front page as a stranger sees it, ranked, with numbers; a site admin sets what is pinned (first public one featured), hidden, and what counts (weights of forks, ships, use, fresh, 0 to 10) | yes | |
| 52 | 52 | | `map` | an app's plan: ready now, waiting on what, the critical path, where the crew is, parked twice and why (`app`) | | |
| 53 | 53 | | `milestones` | `{ app, issue? }`: how far each thing asked for is (and, with `issue`, whether you watch it: `watching`), from the dependency tree: the plan's limbs with their weights, or one milestone opened (who is building, what is blocked and on what, what merged in 7 days, an estimate) | | |
| 54 | | `waves` | `{ app, limit? }`: what landed between releases, as notes (version, date, headline, milestones moved, highlights with why, every change), newest first, from `waves/<version>.md` | | | |
| 54 | 55 | | `limb` | `{ app, issue, action, reason?, pillar?, operation?, dryRun? }`: defer, resume or close a whole limb as not doing, or undo an operation; plans unless `dryRun` is false, and applying takes an admin token | yes | |
| 55 | 56 | | `watch` | `{ app, issue, watch? }`: watch a milestone, or stop with `watch: false`: one item in your feed that follows it, and one push to your phone when it lands | yes | |
| 56 | 57 | | `usage` | `{ repo, days? }`: what the crew's runs spent — tokens, cost, wall time — by subscription, agent, issue, and each account's 5-hour and weekly standing; a writer's | | |
docs/STORY.md added +51
| @@ -0,0 +1,51 @@ | ||
| 1 | # Story: waves | |
| 2 | ||
| 3 | A **wave** is the note for what landed between two releases, told once and | |
| 4 | kept in git. `waves/<version>.md` on the default branch *is* the wave; the | |
| 5 | pages render the file as it is, so an owner's edit is the truth. | |
| 6 | ||
| 7 | ## The shape of a note | |
| 8 | ||
| 9 | ||
| 10 | --- | |
| 11 | version: 0.7.53 | |
| 12 | date: 2026-10-12 | |
| 13 | headline: One line, concrete. | |
| 14 | milestones: 12, 14 | |
| 15 | --- | |
| 16 | ||
| 17 | ## Highlights | |
| 18 | ||
| 19 | - **Title** (#31): why a person would care. | |
| 20 | ||
| 21 | ## Changes | |
| 22 | ||
| 23 | - #31 Title | |
| 24 | ||
| 25 | ||
| 26 | Front matter: `version` (the file's name, letters, digits, `.`, `-`, `_`), | |
| 27 | `date` (`YYYY-MM-DD`), `headline`, and the numbers of the milestones moved. | |
| 28 | Three to five highlights, each with its pull and its why. Then every change, | |
| 29 | oldest last, one line each. `src/story/wave.ts` reads and writes exactly this. | |
| 30 | ||
| 31 | ## Where it lives | |
| 32 | ||
| 33 | - `/:owner/:name/waves`, `/waves/:version`, and `/waves.xml` (RSS) — for whoever | |
| 34 | may read the repository (`canRead`); anyone else gets 404, as everywhere. | |
| 35 | Each change links to its pull and its conversation; a milestone links to | |
| 36 | `/milestones/:n`. | |
| 37 | - **Cut a wave** (Settings → Waves, admins) writes the note from every merged | |
| 38 | pull no wave lists yet and opens it as a pull on `wave/<version>`. Landing | |
| 39 | the pull publishes the wave. A wave's own pull is never news in the next one. | |
| 40 | - The forge's home links to the latest wave of `trevato/forge`; the MCP tool | |
| 41 | `waves { app, limit }` returns the same notes. | |
| 42 | ||
| 43 | ## The writing standard | |
| 44 | ||
| 45 | A note says only what a pull says. `composeNote` is given merged pulls (title, | |
| 46 | body) and the decision ledger's outcome for each; there is nothing else for it | |
| 47 | to draw on, and when a pull gives no reason the note says so rather than | |
| 48 | inventing one. The voice is the forge's: concrete, no filler, a number only | |
| 49 | where it changes what the reader does. Ask of every line: *would a person be | |
| 50 | happy to hear this?* — what changed for them, in their words, then the | |
| 51 | change's name. The owner edits the file on the pull before landing it. |
scripts/gate.ts +1
| @@ -170,6 +170,7 @@ export const GATE: readonly string[] = [ | ||
| 170 | 170 | "test/map.test.ts", |
| 171 | 171 | "test/pillars.test.ts", |
| 172 | 172 | "test/milestones.test.ts", |
| 173 | "test/waves.test.ts", | |
| 173 | 174 | "test/mcp.test.ts", |
| 174 | 175 | "test/name-marks.test.ts", |
| 175 | 176 | "test/new-forge.test.ts", |
src/actions/waves.ts added +50
| @@ -0,0 +1,50 @@ | ||
| 1 | /** | |
| 2 | * Cut a wave: write the note for everything merged since the last one and | |
| 3 | * open it as a pull — `waves/<version>.md`, reviewed and landed like any | |
| 4 | * change. The owner may edit the file on its branch before it lands. | |
| 5 | */ | |
| 6 | ||
| 7 | import type { App } from "../app.ts"; | |
| 8 | import { canAdmin, type Repo } from "../core/repos.ts"; | |
| 9 | import type { Pull } from "../core/pulls.ts"; | |
| 10 | import type { User } from "../core/users.ts"; | |
| 11 | import { composeNote, isVersion, renderWave, wavePath } from "../story/wave.ts"; | |
| 12 | import { readWave, untold } from "../story/waves.ts"; | |
| 13 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 14 | import { editFiles } from "./contents.ts"; | |
| 15 | ||
| 16 | export type CutWaveError = | |
| 17 | | "not_found" | |
| 18 | | "bad_version" | |
| 19 | | "exists" | |
| 20 | | "nothing_merged" | |
| 21 | | "failed"; | |
| 22 | ||
| 23 | export async function cutWave( | |
| 24 | app: App, | |
| 25 | actor: User | undefined, | |
| 26 | repo: Repo, | |
| 27 | version: string, | |
| 28 | ): Promise<Result<Pull, CutWaveError>> { | |
| 29 | if (!actor || !canAdmin(app.db, repo, actor)) return err("not_found"); | |
| 30 | if (!isVersion(version)) return err("bad_version"); | |
| 31 | if ((await readWave(app.reposRoot, repo, version)) !== undefined) | |
| 32 | return err("exists"); | |
| 33 | const pulls = await untold(app.db, app.reposRoot, repo); | |
| 34 | if (pulls.length === 0) return err("nothing_merged"); | |
| 35 | const note = composeNote({ | |
| 36 | version, | |
| 37 | date: new Date().toISOString().slice(0, 10), | |
| 38 | pulls, | |
| 39 | }); | |
| 40 | const done = await editFiles(app, actor, repo, { | |
| 41 | newBranch: `wave/${version}`, | |
| 42 | message: `Wave ${version}`, | |
| 43 | files: [{ path: wavePath(version), content: renderWave(note) }], | |
| 44 | openPull: { | |
| 45 | title: `Wave ${version}: ${note.headline}`.slice(0, 200), | |
| 46 | body: `The note for wave ${version}, written from ${pulls.length} merged pull${pulls.length === 1 ? "" : "s"}. Edit \`${wavePath(version)}\` on this branch before landing if a line should read differently.`, | |
| 47 | }, | |
| 48 | }); | |
| 49 | return done.ok && done.value.pull !== undefined ? ok(done.value.pull) : err("failed"); | |
| 50 | } |
src/http/mcp.ts +34
| @@ -17,6 +17,7 @@ | ||
| 17 | 17 | * no page. `ro` tokens read; `rw` tokens act. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | import { listWaves } from "../story/waves.ts"; | |
| 20 | 21 | import { mayView, mayViewId, sealedScope } from "../core/sealed.ts"; |
| 21 | 22 | import { changeCapacity, listCapacity } from "../actions/capacity.ts"; |
| 22 | 23 | import { relationOf, takeUpdates } from "../actions/forks.ts"; |
| @@ -1194,6 +1195,39 @@ const TOOLS: readonly Tool[] = [ | ||
| 1194 | 1195 | : good(data); |
| 1195 | 1196 | }, |
| 1196 | 1197 | }, |
| 1198 | { | |
| 1199 | name: "waves", | |
| 1200 | description: | |
| 1201 | "What landed between releases, told as notes: each wave's version, date, headline, the milestones it moved, highlights with why, and every change as a pull number. Newest first, read from `waves/<version>.md` on the default branch.", | |
| 1202 | inputSchema: { | |
| 1203 | type: "object", | |
| 1204 | properties: { | |
| 1205 | app: APP_ARG, | |
| 1206 | limit: { | |
| 1207 | type: "integer", | |
| 1208 | minimum: 1, | |
| 1209 | maximum: 50, | |
| 1210 | description: "How many waves, newest first. Default 10.", | |
| 1211 | }, | |
| 1212 | }, | |
| 1213 | required: ["app"], | |
| 1214 | }, | |
| 1215 | writes: false, | |
| 1216 | async run(ctx, user, args) { | |
| 1217 | const repo = planRepo(ctx, user, args); | |
| 1218 | if (isAnswer(repo)) return repo; | |
| 1219 | const asked = args["limit"]; | |
| 1220 | const limit = | |
| 1221 | typeof asked === "number" && Number.isInteger(asked) | |
| 1222 | ? Math.min(Math.max(asked, 1), 50) | |
| 1223 | : 10; | |
| 1224 | const waves = await listWaves(ctx.app.reposRoot, repo); | |
| 1225 | return good({ | |
| 1226 | repo: { owner: repo.ownerName, name: repo.name }, | |
| 1227 | waves: waves.slice(0, limit), | |
| 1228 | }); | |
| 1229 | }, | |
| 1230 | }, | |
| 1197 | 1231 | { |
| 1198 | 1232 | name: "watch", |
| 1199 | 1233 | description: |
src/http/server.ts +8
| @@ -158,6 +158,7 @@ import { | ||
| 158 | 158 | milestonesPage, |
| 159 | 159 | milestoneWatch, |
| 160 | 160 | } from "../web/pages/milestones.ts"; |
| 161 | import { wavePage, wavesFeed, wavesPage } from "../web/pages/waves.ts"; | |
| 161 | 162 | import { |
| 162 | 163 | limbPreviewPage, |
| 163 | 164 | limbReceiptPage, |
| @@ -284,6 +285,8 @@ import { | ||
| 284 | 285 | repoDelete, |
| 285 | 286 | settingsPage, |
| 286 | 287 | settingsUpdate, |
| 288 | waveCut, | |
| 289 | wavesSettingsPage, | |
| 287 | 290 | webhookCreate, |
| 288 | 291 | webhookDelete, |
| 289 | 292 | } from "../web/pages/settings.ts"; |
| @@ -1036,6 +1039,11 @@ export function buildRouter(): Router<Handler> { | ||
| 1036 | 1039 | |
| 1037 | 1040 | // Settings (owner-gated inside the handlers). |
| 1038 | 1041 | router.add("GET", "/:owner/:name/settings", settingsPage); |
| 1042 | router.add("GET", "/:owner/:name/waves", wavesPage); | |
| 1043 | router.add("GET", "/:owner/:name/waves.xml", wavesFeed); | |
| 1044 | router.add("GET", "/:owner/:name/waves/:version", wavePage); | |
| 1045 | router.add("GET", "/:owner/:name/settings/waves", wavesSettingsPage); | |
| 1046 | router.add("POST", "/:owner/:name/settings/waves", waveCut); | |
| 1039 | 1047 | router.add("POST", "/:owner/:name/settings", settingsUpdate); |
| 1040 | 1048 | router.add("GET", "/:owner/:name/settings/app", appSettingsPage); |
| 1041 | 1049 | router.add("POST", "/:owner/:name/settings/app", appSettingsUpdate); |
src/story/ledger.ts added +14
| @@ -0,0 +1,14 @@ | ||
| 1 | /** What the decision ledger recorded about each pull: its outcome, once known. */ | |
| 2 | ||
| 3 | import type { Database } from "bun:sqlite"; | |
| 4 | import { listDecisions } from "../core/decisions.ts"; | |
| 5 | ||
| 6 | /** Issue id → the newest known outcome, from one read of the ledger. */ | |
| 7 | export function outcomesByIssue(db: Database, repoId: string): Map<string, string> { | |
| 8 | const out = new Map<string, string>(); | |
| 9 | for (const d of listDecisions(db, repoId, { limit: 500 })) { | |
| 10 | if (d.issueId !== null && d.outcome !== null && !out.has(d.issueId)) | |
| 11 | out.set(d.issueId, d.outcome); | |
| 12 | } | |
| 13 | return out; | |
| 14 | } |
src/story/wave.ts added +201
| @@ -0,0 +1,201 @@ | ||
| 1 | /** | |
| 2 | * A wave's note: the one shape `waves/<version>.md` has, read and written. | |
| 3 | * | |
| 4 | * --- | |
| 5 | * version: 0.7.53 | |
| 6 | * date: 2026-10-12 | |
| 7 | * headline: One line, concrete. | |
| 8 | * milestones: 12, 14 | |
| 9 | * --- | |
| 10 | * | |
| 11 | * ## Highlights | |
| 12 | * | |
| 13 | * - **Title** (#31): why a person would care. | |
| 14 | * | |
| 15 | * ## Changes | |
| 16 | * | |
| 17 | * - #31 Title | |
| 18 | * | |
| 19 | * Plain data in, plain data out: no database, no git. A note says only what | |
| 20 | * a pull says — `composeNote` takes pulls and the ledger's outcomes and | |
| 21 | * nothing else, so there is nothing else for it to say (docs/STORY.md). | |
| 22 | */ | |
| 23 | ||
| 24 | import { err, ok, type Result } from "../kernel/result.ts"; | |
| 25 | ||
| 26 | export interface Highlight { | |
| 27 | readonly title: string; | |
| 28 | readonly pull: number; | |
| 29 | readonly why: string; | |
| 30 | } | |
| 31 | ||
| 32 | export interface Change { | |
| 33 | readonly pull: number; | |
| 34 | readonly title: string; | |
| 35 | } | |
| 36 | ||
| 37 | export interface Wave { | |
| 38 | readonly version: string; | |
| 39 | readonly date: string; | |
| 40 | readonly headline: string; | |
| 41 | /** Issue numbers of the milestones this wave moved. */ | |
| 42 | readonly milestones: readonly number[]; | |
| 43 | readonly highlights: readonly Highlight[]; | |
| 44 | readonly changes: readonly Change[]; | |
| 45 | } | |
| 46 | ||
| 47 | /** A version is a file name: no slash, no dot-dot, nothing git reads as a flag. */ | |
| 48 | export const VERSION = /^[0-9A-Za-z][0-9A-Za-z._-]{0,39}$/; | |
| 49 | const DATE = /^\d{4}-\d{2}-\d{2}$/; | |
| 50 | ||
| 51 | export const isVersion = (v: string): boolean => | |
| 52 | VERSION.test(v) && !v.includes("..") && !v.endsWith("."); | |
| 53 | ||
| 54 | export const wavePath = (version: string): string => `waves/${version}.md`; | |
| 55 | ||
| 56 | /** One line of plain words: whitespace collapsed, markup that would break the shape removed. */ | |
| 57 | export function oneLine(text: string, max = 200): string { | |
| 58 | const flat = text | |
| 59 | .replace(/\*\*/g, "") | |
| 60 | .replace(/[\r\n\t\0]+/g, " ") | |
| 61 | .replace(/ {2,}/g, " ") | |
| 62 | .trim(); | |
| 63 | return flat.length > max ? `${flat.slice(0, max - 1).trimEnd()}…` : flat; | |
| 64 | } | |
| 65 | ||
| 66 | export function renderWave(w: Wave): string { | |
| 67 | const lines = [ | |
| 68 | "---", | |
| 69 | `version: ${w.version}`, | |
| 70 | `date: ${w.date}`, | |
| 71 | `headline: ${oneLine(w.headline)}`, | |
| 72 | `milestones: ${w.milestones.join(", ")}`, | |
| 73 | "---", | |
| 74 | "", | |
| 75 | "## Highlights", | |
| 76 | "", | |
| 77 | ...w.highlights.map( | |
| 78 | (h) => `- **${oneLine(h.title)}** (#${h.pull}): ${oneLine(h.why, 400)}`, | |
| 79 | ), | |
| 80 | "", | |
| 81 | "## Changes", | |
| 82 | "", | |
| 83 | ...w.changes.map((c) => `- #${c.pull} ${oneLine(c.title)}`), | |
| 84 | "", | |
| 85 | ]; | |
| 86 | return lines.join("\n"); | |
| 87 | } | |
| 88 | ||
| 89 | export type WaveError = | |
| 90 | | "no_front_matter" | |
| 91 | | "bad_version" | |
| 92 | | "bad_date" | |
| 93 | | "no_headline" | |
| 94 | | "bad_milestones"; | |
| 95 | ||
| 96 | export function parseWave(text: string): Result<Wave, WaveError> { | |
| 97 | const m = /^---\n([\s\S]*?)\n---\n([\s\S]*)$/.exec(text.replace(/\r\n/g, "\n")); | |
| 98 | if (!m) return err("no_front_matter"); | |
| 99 | const front = new Map<string, string>(); | |
| 100 | for (const line of m[1]!.split("\n")) { | |
| 101 | const colon = line.indexOf(":"); | |
| 102 | if (colon > 0) front.set(line.slice(0, colon).trim(), line.slice(colon + 1).trim()); | |
| 103 | } | |
| 104 | const version = front.get("version") ?? ""; | |
| 105 | if (!isVersion(version)) return err("bad_version"); | |
| 106 | const date = front.get("date") ?? ""; | |
| 107 | if (!DATE.test(date)) return err("bad_date"); | |
| 108 | const headline = front.get("headline") ?? ""; | |
| 109 | if (headline === "") return err("no_headline"); | |
| 110 | const raw = (front.get("milestones") ?? "").split(",").map((s) => s.trim()); | |
| 111 | const milestones: number[] = []; | |
| 112 | for (const s of raw) { | |
| 113 | if (s === "") continue; | |
| 114 | if (!/^\d{1,9}$/.test(s)) return err("bad_milestones"); | |
| 115 | milestones.push(Number(s)); | |
| 116 | } | |
| 117 | const highlights: Highlight[] = []; | |
| 118 | const changes: Change[] = []; | |
| 119 | let section = ""; | |
| 120 | for (const line of m[2]!.split("\n")) { | |
| 121 | if (line.startsWith("## ")) section = line.slice(3).trim().toLowerCase(); | |
| 122 | else if (section === "highlights") { | |
| 123 | const h = /^- \*\*(.+)\*\* \(#(\d{1,9})\): (.+)$/.exec(line); | |
| 124 | if (h) highlights.push({ title: h[1]!, pull: Number(h[2]), why: h[3]! }); | |
| 125 | } else if (section === "changes") { | |
| 126 | const c = /^- #(\d{1,9}) (.+)$/.exec(line); | |
| 127 | if (c) changes.push({ pull: Number(c[1]), title: c[2]! }); | |
| 128 | } | |
| 129 | } | |
| 130 | return ok({ version, date, headline, milestones, highlights, changes }); | |
| 131 | } | |
| 132 | ||
| 133 | // ---- writing the note ---- | |
| 134 | ||
| 135 | export interface NotePull { | |
| 136 | readonly number: number; | |
| 137 | readonly title: string; | |
| 138 | readonly body: string; | |
| 139 | /** What the decision ledger recorded for this pull, when it did. */ | |
| 140 | readonly outcome?: string | undefined; | |
| 141 | /** The milestones (issue numbers) this pull closes. */ | |
| 142 | readonly milestones?: readonly number[] | undefined; | |
| 143 | } | |
| 144 | ||
| 145 | const NO_REASON = "The pull gives no reason."; | |
| 146 | ||
| 147 | /** The first sentence-sized line of a body that is not a reference or a heading. */ | |
| 148 | function whyOf(body: string): string { | |
| 149 | for (const raw of body.split("\n")) { | |
| 150 | const line = raw.trim(); | |
| 151 | if (line === "" || /^(#|>|```|[-*] \[)/.test(line)) continue; | |
| 152 | if (/^(closes|fixes|resolves)\b/i.test(line)) continue; | |
| 153 | return oneLine(line, 300); | |
| 154 | } | |
| 155 | return NO_REASON; | |
| 156 | } | |
| 157 | ||
| 158 | /** | |
| 159 | * The note for pulls merged since the last wave, oldest first. Three to five | |
| 160 | * highlights (all of them when there are fewer): the pulls that gave a | |
| 161 | * reason, then the rest, newest first. Every word comes from a pull's title | |
| 162 | * or body, or from the ledger's recorded outcome for it. | |
| 163 | */ | |
| 164 | export function composeNote(input: { | |
| 165 | version: string; | |
| 166 | date: string; | |
| 167 | pulls: readonly NotePull[]; | |
| 168 | }): Wave { | |
| 169 | const { pulls } = input; | |
| 170 | const reasons = new Map(pulls.map((p) => [p.number, whyOf(p.body)])); | |
| 171 | const ranked = [...pulls].reverse(); | |
| 172 | const picked = [ | |
| 173 | ...ranked.filter((p) => reasons.get(p.number) !== NO_REASON), | |
| 174 | ...ranked.filter((p) => reasons.get(p.number) === NO_REASON), | |
| 175 | ].slice(0, 5); | |
| 176 | const highlights = picked.map((p) => ({ | |
| 177 | title: oneLine(p.title), | |
| 178 | pull: p.number, | |
| 179 | why: | |
| 180 | reasons.get(p.number)! + | |
| 181 | (p.outcome === undefined ? "" : ` The ledger recorded: ${oneLine(p.outcome, 60)}.`), | |
| 182 | })); | |
| 183 | const first = ranked[0]; | |
| 184 | const headline = | |
| 185 | first === undefined | |
| 186 | ? "Nothing merged since the last wave" | |
| 187 | : pulls.length === 1 | |
| 188 | ? oneLine(first.title) | |
| 189 | : `${oneLine(first.title, 120)}, and ${pulls.length - 1} more`; | |
| 190 | const milestones = [...new Set(pulls.flatMap((p) => p.milestones ?? []))].sort( | |
| 191 | (a, b) => a - b, | |
| 192 | ); | |
| 193 | return { | |
| 194 | version: input.version, | |
| 195 | date: input.date, | |
| 196 | headline, | |
| 197 | milestones, | |
| 198 | highlights, | |
| 199 | changes: ranked.map((p) => ({ pull: p.number, title: oneLine(p.title) })), | |
| 200 | }; | |
| 201 | } |
src/story/waves.ts added +84
| @@ -0,0 +1,84 @@ | ||
| 1 | /** | |
| 2 | * A repository's waves, read from its default branch (git is truth; the | |
| 3 | * page renders the files), and the pulls no wave has told yet. | |
| 4 | */ | |
| 5 | ||
| 6 | import type { Database } from "bun:sqlite"; | |
| 7 | import { outcomesByIssue } from "./ledger.ts"; | |
| 8 | import { composeNote, isVersion, parseWave, wavePath, type NotePull, type Wave } from "./wave.ts"; | |
| 9 | import { closesFromBody, mergedPullsForRepos } from "../core/pulls.ts"; | |
| 10 | import { readPlan } from "../core/milestones.ts"; | |
| 11 | import type { Repo } from "../core/repos.ts"; | |
| 12 | import { isSafeRef } from "../git/guard.ts"; | |
| 13 | import { listTree, readerFor } from "../git/read.ts"; | |
| 14 | import { repoDir } from "../git/repos.ts"; | |
| 15 | ||
| 16 | const MAX_WAVES = 100; | |
| 17 | ||
| 18 | /** Compare dotted versions numerically where they are numbers; newest first. */ | |
| 19 | const newestFirst = (a: Wave, b: Wave): number => | |
| 20 | b.date.localeCompare(a.date) || | |
| 21 | b.version.localeCompare(a.version, undefined, { numeric: true }); | |
| 22 | ||
| 23 | export async function readWave( | |
| 24 | reposRoot: string, | |
| 25 | repo: Repo, | |
| 26 | version: string, | |
| 27 | ): Promise<Wave | undefined> { | |
| 28 | if (!isVersion(version) || !isSafeRef(repo.defaultBranch)) return undefined; | |
| 29 | const dir = repoDir(reposRoot, repo.ownerName, repo.name); | |
| 30 | const object = await readerFor(dir).object( | |
| 31 | `refs/heads/${repo.defaultBranch}:${wavePath(version)}`, | |
| 32 | ); | |
| 33 | if (!object.ok || object.value.type !== "blob") return undefined; | |
| 34 | const parsed = parseWave(new TextDecoder().decode(object.value.body)); | |
| 35 | // The file's own name is the version: a note cannot claim another's. | |
| 36 | return parsed.ok && parsed.value.version === version ? parsed.value : undefined; | |
| 37 | } | |
| 38 | ||
| 39 | /** Every wave the default branch holds, newest first. */ | |
| 40 | export async function listWaves(reposRoot: string, repo: Repo): Promise<Wave[]> { | |
| 41 | if (!isSafeRef(repo.defaultBranch)) return []; | |
| 42 | const dir = repoDir(reposRoot, repo.ownerName, repo.name); | |
| 43 | const tree = await listTree(dir, `refs/heads/${repo.defaultBranch}`, "waves"); | |
| 44 | if (!tree.ok) return []; | |
| 45 | const names = tree.value | |
| 46 | .filter((e) => e.type === "blob" && e.name.endsWith(".md")) | |
| 47 | .map((e) => e.name.slice(0, -3)) | |
| 48 | .filter(isVersion) | |
| 49 | .slice(0, MAX_WAVES); | |
| 50 | const waves = await Promise.all(names.map((v) => readWave(reposRoot, repo, v))); | |
| 51 | return waves.filter((w): w is Wave => w !== undefined).sort(newestFirst); | |
| 52 | } | |
| 53 | ||
| 54 | /** | |
| 55 | * The merged pulls no wave lists yet (a wave's own pull, from `wave/<version>`, | |
| 56 | * is the note, not news), oldest first, with the ledger's | |
| 57 | * outcome for each and the milestones each closes. | |
| 58 | */ | |
| 59 | export async function untold( | |
| 60 | db: Database, | |
| 61 | reposRoot: string, | |
| 62 | repo: Repo, | |
| 63 | ): Promise<NotePull[]> { | |
| 64 | const told = new Set( | |
| 65 | (await listWaves(reposRoot, repo)).flatMap((w) => w.changes.map((c) => c.pull)), | |
| 66 | ); | |
| 67 | const plan = readPlan(db, repo, { spend: false }); | |
| 68 | const outcomes = outcomesByIssue(db, repo.id); | |
| 69 | return mergedPullsForRepos(db, [repo.id], 100) | |
| 70 | .filter((p) => p.repoId === repo.id && !told.has(p.number) && !p.headBranch.startsWith("wave/")) | |
| 71 | .reverse() | |
| 72 | .map((p) => ({ | |
| 73 | number: p.number, | |
| 74 | title: p.title, | |
| 75 | body: p.body, | |
| 76 | outcome: outcomes.get(p.id), | |
| 77 | milestones: closesFromBody(p.body).filter((n) => plan.milestone(n) !== undefined), | |
| 78 | })); | |
| 79 | } | |
| 80 | ||
| 81 | export { composeNote }; | |
| 82 | ||
| 83 | /** The forge's own repository, whose latest wave the home links to. */ | |
| 84 | export const FORGE_REPO = { owner: "trevato", name: "forge" } as const; |
src/web/pages/settings.ts +58
| @@ -100,6 +100,7 @@ import { | ||
| 100 | 100 | time, |
| 101 | 101 | timeAgo, |
| 102 | 102 | } from "../ui.ts"; |
| 103 | import { cutWave } from "../../actions/waves.ts"; | |
| 103 | 104 | import { secretsSection } from "./secrets.ts"; |
| 104 | 105 | import { saveGrants } from "./subscriptions.ts"; |
| 105 | 106 | |
| @@ -108,6 +109,7 @@ type Section = | ||
| 108 | 109 | | "app" |
| 109 | 110 | | "prompts" |
| 110 | 111 | | "labels" |
| 112 | | "waves" | |
| 111 | 113 | | "hooks" |
| 112 | 114 | | "danger"; |
| 113 | 115 | |
| @@ -145,6 +147,12 @@ function sections(base: string, active: Section) { | ||
| 145 | 147 | icon: "tag" as const, |
| 146 | 148 | current: active === "labels", |
| 147 | 149 | }, |
| 150 | { | |
| 151 | label: "Waves", | |
| 152 | href: `${base}/settings/waves`, | |
| 153 | icon: "rocket" as const, | |
| 154 | current: active === "waves", | |
| 155 | }, | |
| 148 | 156 | { |
| 149 | 157 | label: "Webhooks", |
| 150 | 158 | href: `${base}/settings/hooks`, |
| @@ -1782,3 +1790,53 @@ export async function autonomySettingsUpdate(ctx: Ctx): Promise<Response> { | ||
| 1782 | 1790 | }), |
| 1783 | 1791 | }); |
| 1784 | 1792 | } |
| 1793 | ||
| 1794 | // ---- waves ---- | |
| 1795 | ||
| 1796 | const WAVE_ERRORS: Record<string, string> = { | |
| 1797 | bad_version: | |
| 1798 | "A version is letters, digits, dots, dashes and underscores, up to 40.", | |
| 1799 | exists: "A wave by that version already exists.", | |
| 1800 | nothing_merged: "Nothing has merged since the last wave.", | |
| 1801 | failed: "The note could not be written.", | |
| 1802 | }; | |
| 1803 | ||
| 1804 | export async function wavesSettingsPage(ctx: Ctx): Promise<Response> { | |
| 1805 | const repo = loadAdminRepo(ctx); | |
| 1806 | if (!repo) return repoNotFound(ctx); | |
| 1807 | const body = card( | |
| 1808 | html`<p> | |
| 1809 | A wave is the note for everything merged since the last one. Cutting | |
| 1810 | one writes <code>waves/<version>.md</code> and opens it as a pull | |
| 1811 | for you to read, edit and land. | |
| 1812 | </p> | |
| 1813 | <form method="post" action="${repoBase(repo)}/settings/waves" class="stack"> | |
| 1814 | <label class="field" | |
| 1815 | ><span>Version</span> | |
| 1816 | <input class="input" name="version" required maxlength="40" /> | |
| 1817 | </label> | |
| 1818 | <div class="form-actions">${btn("Cut a wave", { variant: "primary" })}</div> | |
| 1819 | </form> | |
| 1820 | <p class="small muted mt"> | |
| 1821 | <a href="${repoBase(repo)}/waves">The waves so far</a> | |
| 1822 | </p>`, | |
| 1823 | { head: html`${icon("rocket")}<h2>Cut a wave</h2>` }, | |
| 1824 | ); | |
| 1825 | return settingsPageResponse(ctx, repo, "waves", "Waves", body); | |
| 1826 | } | |
| 1827 | ||
| 1828 | // POST /:owner/:name/settings/waves | |
| 1829 | export async function waveCut(ctx: Ctx): Promise<Response> { | |
| 1830 | const gate = await adminForm(ctx); | |
| 1831 | if (gate instanceof Response) return gate; | |
| 1832 | const { repo, form } = gate; | |
| 1833 | const cut = await cutWave(ctx.app, ctx.auth.user, repo, field(form, "version").trim()); | |
| 1834 | if (!cut.ok && cut.error === "not_found") return repoNotFound(ctx); | |
| 1835 | return flashTo( | |
| 1836 | ctx, | |
| 1837 | cut.ok ? `${repoBase(repo)}/pulls/${cut.value.number}` : `${repoBase(repo)}/settings/waves`, | |
| 1838 | cut.ok | |
| 1839 | ? { message: "The note is a pull. Read it, edit it, land it." } | |
| 1840 | : { tone: "danger", message: WAVE_ERRORS[cut.error] ?? "No wave was cut." }, | |
| 1841 | ); | |
| 1842 | } |
src/web/pages/waves.ts added +138
| @@ -0,0 +1,138 @@ | ||
| 1 | /** | |
| 2 | * Waves (#1082): what landed between two releases, told as one note. | |
| 3 | * `/:owner/:name/waves` lists them newest first, `/waves/:version` opens one, | |
| 4 | * `/waves.xml` is the same list as RSS. Every page renders the file | |
| 5 | * `waves/<version>.md` as it is on the default branch (`story/waves.ts`); | |
| 6 | * nothing here is stored, so git stays the truth. | |
| 7 | */ | |
| 8 | ||
| 9 | import { canRead, getRepo, type Repo } from "../../core/repos.ts"; | |
| 10 | import type { Ctx } from "../../http/context.ts"; | |
| 11 | import { notFound } from "../../http/respond.ts"; | |
| 12 | import { isVersion, type Wave } from "../../story/wave.ts"; | |
| 13 | import { listWaves, readWave } from "../../story/waves.ts"; | |
| 14 | import { crumbsFor, loadRepo, notFoundPage, repoBase, repoHeader, repoPalette } from "../chrome.ts"; | |
| 15 | import { xml } from "../feeds.ts"; | |
| 16 | import { html, type Html } from "../html.ts"; | |
| 17 | import { page } from "../layout.ts"; | |
| 18 | import { card, empty } from "../ui.ts"; | |
| 19 | ||
| 20 | export const waveHref = (repo: Repo, version: string): string => | |
| 21 | `${repoBase(repo)}/waves/${encodeURIComponent(version)}`; | |
| 22 | ||
| 23 | function milestoneLinks(repo: Repo, w: Wave): Html | null { | |
| 24 | if (w.milestones.length === 0) return null; | |
| 25 | return html`<p class="small muted"> | |
| 26 | Milestones moved: | |
| 27 | ${w.milestones.map( | |
| 28 | (n) => html`<a href="${repoBase(repo)}/milestones/${n}">#${n}</a> `, | |
| 29 | )} | |
| 30 | </p>`; | |
| 31 | } | |
| 32 | ||
| 33 | function noteBody(repo: Repo, w: Wave): Html { | |
| 34 | const base = repoBase(repo); | |
| 35 | return html`<p class="muted small">${w.date}</p> | |
| 36 | ${milestoneLinks(repo, w)} | |
| 37 | <h2>Highlights</h2> | |
| 38 | <ul class="stack"> | |
| 39 | ${w.highlights.map( | |
| 40 | (h) => html`<li> | |
| 41 | <strong>${h.title}</strong> | |
| 42 | <a href="${base}/pulls/${h.pull}">#${h.pull}</a> | |
| 43 | <p class="muted">${h.why}</p> | |
| 44 | </li>`, | |
| 45 | )} | |
| 46 | </ul> | |
| 47 | <h2>Every change</h2> | |
| 48 | <ul class="list"> | |
| 49 | ${w.changes.map( | |
| 50 | (c) => html`<li> | |
| 51 | <a href="${base}/pulls/${c.pull}">#${c.pull} ${c.title}</a> | |
| 52 | <a class="small muted" href="${base}/pulls/${c.pull}#conversation">conversation</a> | |
| 53 | </li>`, | |
| 54 | )} | |
| 55 | </ul>`; | |
| 56 | } | |
| 57 | ||
| 58 | // GET /:owner/:name/waves | |
| 59 | export async function wavesPage(ctx: Ctx): Promise<Response> { | |
| 60 | const repo = loadRepo(ctx); | |
| 61 | if (!repo) return notFoundPage(ctx); | |
| 62 | const waves = await listWaves(ctx.app.reposRoot, repo); | |
| 63 | const body = | |
| 64 | waves.length === 0 | |
| 65 | ? empty({ icon: "tag", title: "No waves yet", note: "A wave is the note for what landed between two releases." }) | |
| 66 | : html`<ul class="stack"> | |
| 67 | ${waves.map((w) => | |
| 68 | card( | |
| 69 | html`<h2><a href="${waveHref(repo, w.version)}">${w.version}</a></h2> | |
| 70 | <p>${w.headline}</p> | |
| 71 | <p class="small muted">${w.date}</p>`, | |
| 72 | ), | |
| 73 | )} | |
| 74 | </ul>`; | |
| 75 | return page({ | |
| 76 | ctx, | |
| 77 | title: `Waves · ${repo.name}`, | |
| 78 | crumbs: crumbsFor(repo), | |
| 79 | palette: repoPalette(ctx, repo), | |
| 80 | body: html`${repoHeader(ctx, repo, "code", { compact: true })} | |
| 81 | <h1>Waves</h1> | |
| 82 | <p class="small"><a href="${repoBase(repo)}/waves.xml">RSS</a></p> | |
| 83 | ${body}`, | |
| 84 | }); | |
| 85 | } | |
| 86 | ||
| 87 | // GET /:owner/:name/waves/:version | |
| 88 | export async function wavePage(ctx: Ctx): Promise<Response> { | |
| 89 | const repo = loadRepo(ctx); | |
| 90 | const version = ctx.params.version ?? ""; | |
| 91 | if (!repo || !isVersion(version)) return notFoundPage(ctx); | |
| 92 | const wave = await readWave(ctx.app.reposRoot, repo, version); | |
| 93 | if (!wave) return notFoundPage(ctx); | |
| 94 | return page({ | |
| 95 | ctx, | |
| 96 | title: `${wave.version} · Waves · ${repo.name}`, | |
| 97 | crumbs: [...crumbsFor(repo), { label: "Waves", href: `${repoBase(repo)}/waves` }], | |
| 98 | palette: repoPalette(ctx, repo), | |
| 99 | body: html`${repoHeader(ctx, repo, "code", { compact: true, ownTitle: true })} | |
| 100 | <h1>${wave.version}: ${wave.headline}</h1> | |
| 101 | ${noteBody(repo, wave)}`, | |
| 102 | }); | |
| 103 | } | |
| 104 | ||
| 105 | // GET /:owner/:name/waves.xml — RSS for whoever may read the repository. | |
| 106 | export async function wavesFeed(ctx: Ctx): Promise<Response> { | |
| 107 | const repo = getRepo(ctx.app.db, ctx.params["owner"]!, ctx.params["name"]!); | |
| 108 | if (!repo || !canRead(ctx.app.db, repo, ctx.auth.user)) return notFound(); | |
| 109 | const waves = await listWaves(ctx.app.reposRoot, repo); | |
| 110 | const base = `${ctx.url.origin}${repoBase(repo)}`; | |
| 111 | const items = waves.map((w) => { | |
| 112 | const link = `${base}/waves/${encodeURIComponent(w.version)}`; | |
| 113 | const text = [w.headline, ...w.highlights.map((h) => `${h.title}: ${h.why}`)].join("\n"); | |
| 114 | return ` <item> | |
| 115 | <title>${xml(`${w.version}: ${w.headline}`)}</title> | |
| 116 | <link>${xml(link)}</link> | |
| 117 | <guid isPermaLink="true">${xml(link)}</guid> | |
| 118 | <pubDate>${new Date(`${w.date}T00:00:00Z`).toUTCString()}</pubDate> | |
| 119 | <description>${xml(text)}</description> | |
| 120 | </item>`; | |
| 121 | }); | |
| 122 | const body = `<?xml version="1.0" encoding="utf-8"?> | |
| 123 | <rss version="2.0"> | |
| 124 | <channel> | |
| 125 | <title>${xml(`${repo.ownerName}/${repo.name} waves`)}</title> | |
| 126 | <link>${xml(`${base}/waves`)}</link> | |
| 127 | <description>${xml(`What landed in ${repo.ownerName}/${repo.name}, one note per release.`)}</description> | |
| 128 | ${items.join("\n")} | |
| 129 | </channel> | |
| 130 | </rss> | |
| 131 | `; | |
| 132 | return new Response(body, { | |
| 133 | headers: { | |
| 134 | "content-type": "application/rss+xml; charset=utf-8", | |
| 135 | "cache-control": repo.visibility === "public" ? "public, max-age=300" : "private, no-store", | |
| 136 | }, | |
| 137 | }); | |
| 138 | } |
src/web/studio/home.ts +18 −1
| @@ -6,6 +6,8 @@ | ||
| 6 | 6 | * best of what is public (`actions/front.ts`). |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { FORGE_REPO, listWaves } from "../../story/waves.ts"; | |
| 10 | import { waveHref } from "../pages/waves.ts"; | |
| 9 | 11 | import { |
| 10 | 12 | frontPage, |
| 11 | 13 | frontPicksJson, |
| @@ -157,6 +159,20 @@ export function liveOnYouFragment(ctx: Ctx): Response { | ||
| 157 | 159 | * your repositories are one step away on your own page. On a phone they are |
| 158 | 160 | * a tab away. The app rows and the cost line live on `/apps`. |
| 159 | 161 | */ |
| 162 | /** The forge's latest wave: its headline, linking to the note. */ | |
| 163 | async function latestWaveNote(ctx: Ctx): Promise<Html | null> { | |
| 164 | const repo = getRepo(ctx.app.db, FORGE_REPO.owner, FORGE_REPO.name); | |
| 165 | if (!repo || !canRead(ctx.app.db, repo, ctx.auth.user)) return null; | |
| 166 | const latest = (await listWaves(ctx.app.reposRoot, repo))[0]; | |
| 167 | return latest === undefined | |
| 168 | ? null | |
| 169 | : html`<p class="small" id="latest-wave"> | |
| 170 | Latest wave: | |
| 171 | <a href="${waveHref(repo, latest.version)}">${latest.version}</a> | |
| 172 | ${latest.headline} | |
| 173 | </p>`; | |
| 174 | } | |
| 175 | ||
| 160 | 176 | export async function studioHome( |
| 161 | 177 | ctx: Ctx, |
| 162 | 178 | user: User, |
| @@ -176,8 +192,9 @@ export async function studioHome( | ||
| 176 | 192 | // On a spawned forge its owner's first steps come first, and carry the |
| 177 | 193 | // everyday account themselves (#600); anywhere else, #803's card asks. |
| 178 | 194 | const firstSteps = await nextStepsCard(ctx, user); |
| 195 | const latest = await latestWaveNote(ctx); | |
| 179 | 196 | const body = html`<h1 class="sr-only">Home</h1> |
| 180 | ${firstSteps ?? everydayCard(ctx, user)} ${address} | |
| 197 | ${firstSteps ?? everydayCard(ctx, user)} ${address} ${latest} | |
| 181 | 198 | ${homeTabs("feed")} |
| 182 | 199 | <div class="dash"> |
| 183 | 200 | <div class="dash-main stack"> |
test/mcp.test.ts +1
| @@ -184,6 +184,7 @@ describe("the forge over MCP", () => { | ||
| 184 | 184 | "front_page", |
| 185 | 185 | "map", |
| 186 | 186 | "milestones", |
| 187 | "waves", | |
| 187 | 188 | "watch", |
| 188 | 189 | "limb", |
| 189 | 190 | "returns", |
test/sealed-release.test.ts +1
| @@ -66,6 +66,7 @@ async function reportAndFix( | ||
| 66 | 66 | await openPull(app, alice, repo, { |
| 67 | 67 | title: `Fix ${slug}`, |
| 68 | 68 | body: `Closes #${report.number}`, |
| 69 | confirmPublic: true, | |
| 69 | 70 | baseBranch: "main", |
| 70 | 71 | headBranch: `fix/${slug}`, |
| 71 | 72 | }), |
test/waves.test.ts added +219
| @@ -0,0 +1,219 @@ | ||
| 1 | /** | |
| 2 | * Waves (#1082): the note's shape, the writer that says only what pulls say, | |
| 3 | * and the pages, feed and Cut a wave over a real repository. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { cutWave } from "../src/actions/waves.ts"; | |
| 11 | import { mergePull, openPull } from "../src/actions/pulls.ts"; | |
| 12 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 13 | import { recordDecision } from "../src/core/decisions.ts"; | |
| 14 | import type { Repo } from "../src/core/repos.ts"; | |
| 15 | import { createUser, type User } from "../src/core/users.ts"; | |
| 16 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 17 | import { composeNote, parseWave, renderWave } from "../src/story/wave.ts"; | |
| 18 | ||
| 19 | describe("the note", () => { | |
| 20 | const pulls = [ | |
| 21 | { number: 3, title: "Faster search", body: "Search answers in 20 ms now.\n\nCloses #9" }, | |
| 22 | { number: 4, title: "Dark theme", body: "" }, | |
| 23 | ]; | |
| 24 | ||
| 25 | test("names both pulls and nothing else", () => { | |
| 26 | const wave = composeNote({ | |
| 27 | version: "1.0.0", | |
| 28 | date: "2026-10-12", | |
| 29 | pulls: pulls.map((p) => ({ ...p, outcome: p.number === 3 ? "shipped" : undefined })), | |
| 30 | }); | |
| 31 | const text = renderWave(wave); | |
| 32 | expect(wave.changes.map((c) => c.pull).sort()).toEqual([3, 4]); | |
| 33 | expect(wave.highlights.map((h) => h.pull).sort()).toEqual([3, 4]); | |
| 34 | expect(text).toContain("Search answers in 20 ms now."); | |
| 35 | expect(text).toContain("The ledger recorded: shipped."); | |
| 36 | expect(wave.headline).toBe("Dark theme, and 1 more"); | |
| 37 | // Every pull number the note mentions is one it was given. | |
| 38 | for (const m of text.matchAll(/#(\d+)/g)) expect([3, 4]).toContain(Number(m[1])); | |
| 39 | // No reason is not made up. | |
| 40 | expect(wave.highlights.find((h) => h.pull === 4)!.why).toBe("The pull gives no reason."); | |
| 41 | }); | |
| 42 | ||
| 43 | test("reads back what it wrote, and refuses a file that is not the shape", () => { | |
| 44 | const wave = composeNote({ version: "1.0.0", date: "2026-10-12", pulls: [{ ...pulls[0]!, milestones: [9] }] }); | |
| 45 | expect(parseWave(renderWave(wave))).toEqual({ ok: true, value: wave }); | |
| 46 | expect(wave.milestones).toEqual([9]); | |
| 47 | expect(parseWave("no front matter").ok).toBe(false); | |
| 48 | expect(parseWave(renderWave(wave).replace("version: 1.0.0", "version: ../x")).ok).toBe(false); | |
| 49 | expect(parseWave(renderWave(wave).replace("2026-10-12", "yesterday")).ok).toBe(false); | |
| 50 | }); | |
| 51 | ||
| 52 | test("a title cannot break out of its line", () => { | |
| 53 | const wave = composeNote({ | |
| 54 | version: "1.0.0", | |
| 55 | date: "2026-10-12", | |
| 56 | pulls: [{ number: 1, title: "x\n---\nversion: evil", body: "" }], | |
| 57 | }); | |
| 58 | expect(parseWave(renderWave(wave))).toEqual({ ok: true, value: wave }); | |
| 59 | expect(wave.headline).not.toContain("\n"); | |
| 60 | }); | |
| 61 | }); | |
| 62 | ||
| 63 | describe("waves over a repository", () => { | |
| 64 | let dataDir: string; | |
| 65 | let app: App; | |
| 66 | let servers: Servers; | |
| 67 | let alice: User; | |
| 68 | let repo: Repo; | |
| 69 | let secret: Repo; | |
| 70 | ||
| 71 | const get = (path: string, headers: Record<string, string> = {}) => | |
| 72 | fetch(`${servers.url}${path}`, { headers }); | |
| 73 | ||
| 74 | const ship = async (r: Repo, branch: string, title: string, body: string) => { | |
| 75 | const wrote = await commitToBranch(app, alice, r, { | |
| 76 | branch, | |
| 77 | base: "main", | |
| 78 | message: title, | |
| 79 | files: [{ path: `${branch}.txt`, content: branch }], | |
| 80 | }); | |
| 81 | if (!wrote.ok) throw new Error(JSON.stringify(wrote.error)); | |
| 82 | const opened = await openPull(app, alice, r, { title, body, baseBranch: "main", headBranch: branch }); | |
| 83 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 84 | const merged = await mergePull(app, alice, r, opened.value, "squash"); | |
| 85 | if (!merged.ok) throw new Error(JSON.stringify(merged.error)); | |
| 86 | return opened.value; | |
| 87 | }; | |
| 88 | ||
| 89 | const madeRepo = async (name: string, visibility: "public" | "private") => { | |
| 90 | const made = await createRepo(app, alice, { name, visibility }); | |
| 91 | if (!made.ok) throw new Error(String(made.error)); | |
| 92 | await commitToBranch(app, alice, made.value, { | |
| 93 | branch: "main", | |
| 94 | message: "base", | |
| 95 | files: [{ path: "README.md", content: "hi\n" }], | |
| 96 | }); | |
| 97 | return made.value; | |
| 98 | }; | |
| 99 | ||
| 100 | beforeAll(async () => { | |
| 101 | dataDir = await mkdtemp(join(tmpdir(), "forge-waves-")); | |
| 102 | app = createApp({ dataDir, port: 0 }); | |
| 103 | servers = await serve(app); | |
| 104 | const a = await createUser(app.db, { | |
| 105 | trusted: true, | |
| 106 | username: "alice", | |
| 107 | email: "[email protected]", | |
| 108 | password: "a-good-passphrase", | |
| 109 | adminIfFirst: true, | |
| 110 | }); | |
| 111 | if (!a.ok) throw new Error(a.error); | |
| 112 | alice = a.value; | |
| 113 | repo = await madeRepo("site", "public"); | |
| 114 | secret = await madeRepo("vault", "private"); | |
| 115 | }, 30_000); | |
| 116 | ||
| 117 | afterAll(async () => { | |
| 118 | servers.stop(); | |
| 119 | app.close(); | |
| 120 | await rm(dataDir, { recursive: true, force: true }); | |
| 121 | }); | |
| 122 | ||
| 123 | test("no waves yet: the page says so and the feed is empty but valid", async () => { | |
| 124 | const page = await get("/alice/site/waves"); | |
| 125 | expect(page.status).toBe(200); | |
| 126 | expect(await page.text()).toContain("No waves yet"); | |
| 127 | const feed = await get("/alice/site/waves.xml"); | |
| 128 | expect(feed.headers.get("content-type")).toContain("application/rss+xml"); | |
| 129 | }); | |
| 130 | ||
| 131 | test("Cut a wave opens the note as a pull from the merged pulls and the ledger; landing it publishes it", async () => { | |
| 132 | const a = await ship(repo, "feature/a", "Faster pages", "Pages paint before the script loads."); | |
| 133 | const b = await ship(repo, "feature/b", "Quieter <b>errors</b>", ""); | |
| 134 | recordDecision(app.db, { | |
| 135 | kind: "land", | |
| 136 | repoId: repo.id, | |
| 137 | issueId: a.id, | |
| 138 | state: {}, | |
| 139 | answer: "land", | |
| 140 | p: 1, | |
| 141 | by: "rule", | |
| 142 | ms: 1, | |
| 143 | }); | |
| 144 | const cut = await cutWave(app, alice, repo, "1.0.0"); | |
| 145 | if (!cut.ok) throw new Error(cut.error); | |
| 146 | expect(cut.value.title).toContain("Wave 1.0.0"); | |
| 147 | ||
| 148 | // Not on the page until it lands: git is truth. | |
| 149 | expect(await (await get("/alice/site/waves")).text()).toContain("No waves yet"); | |
| 150 | ||
| 151 | const merged = await mergePull(app, alice, repo, cut.value, "squash"); | |
| 152 | if (!merged.ok) throw new Error(JSON.stringify(merged.error)); | |
| 153 | ||
| 154 | const list = await (await get("/alice/site/waves")).text(); | |
| 155 | expect(list).toContain("1.0.0"); | |
| 156 | const note = await (await get("/alice/site/waves/1.0.0")).text(); | |
| 157 | expect(note).toContain(`/alice/site/pulls/${a.number}"`); | |
| 158 | expect(note).toContain(`/alice/site/pulls/${b.number}#conversation`); | |
| 159 | expect(note).toContain("Pages paint before the script loads."); | |
| 160 | // Escaped on the way out. | |
| 161 | expect(note).toContain("Quieter <b>errors</b>"); | |
| 162 | expect(note).not.toContain("<b>errors</b>"); | |
| 163 | ||
| 164 | // The next cut has nothing to say, and an existing version is not rewritten. | |
| 165 | expect(await cutWave(app, alice, repo, "1.0.1")).toEqual({ ok: false, error: "nothing_merged" }); | |
| 166 | expect(await cutWave(app, alice, repo, "1.0.0")).toEqual({ ok: false, error: "exists" }); | |
| 167 | expect(await cutWave(app, alice, repo, "../x")).toEqual({ ok: false, error: "bad_version" }); | |
| 168 | }, 30_000); | |
| 169 | ||
| 170 | test("a milestone named in the note links to it; the feed carries the wave", async () => { | |
| 171 | const w = composeNote({ | |
| 172 | version: "2.0.0", | |
| 173 | date: "2026-10-13", | |
| 174 | pulls: [{ number: 1, title: "Plan", body: "", milestones: [7] }], | |
| 175 | }); | |
| 176 | await commitToBranch(app, alice, repo, { | |
| 177 | branch: "main", | |
| 178 | message: "wave 2", | |
| 179 | files: [{ path: "waves/2.0.0.md", content: renderWave(w) }], | |
| 180 | }); | |
| 181 | const note = await (await get("/alice/site/waves/2.0.0")).text(); | |
| 182 | expect(note).toContain('href="/alice/site/milestones/7"'); | |
| 183 | const feed = await (await get("/alice/site/waves.xml")).text(); | |
| 184 | expect(feed).toContain("<rss version=\"2.0\">"); | |
| 185 | expect(feed).toContain("/alice/site/waves/2.0.0"); | |
| 186 | expect(feed.indexOf("2.0.0")).toBeLessThan(feed.indexOf("1.0.0")); | |
| 187 | }); | |
| 188 | ||
| 189 | test("a bad version in the address is a 404, not a git read", async () => { | |
| 190 | expect((await get("/alice/site/waves/..%2Fetc")).status).toBe(404); | |
| 191 | expect((await get("/alice/site/waves/9.9.9")).status).toBe(404); | |
| 192 | }); | |
| 193 | ||
| 194 | test("a private repository's waves and feed are for its readers only", async () => { | |
| 195 | await commitToBranch(app, alice, secret, { | |
| 196 | branch: "main", | |
| 197 | message: "wave", | |
| 198 | files: [ | |
| 199 | { | |
| 200 | path: "waves/1.0.0.md", | |
| 201 | content: renderWave(composeNote({ version: "1.0.0", date: "2026-10-12", pulls: [{ number: 1, title: "Hidden", body: "" }] })), | |
| 202 | }, | |
| 203 | ], | |
| 204 | }); | |
| 205 | for (const path of ["/alice/vault/waves", "/alice/vault/waves/1.0.0", "/alice/vault/waves.xml"]) | |
| 206 | expect((await get(path)).status).toBe(404); | |
| 207 | }); | |
| 208 | ||
| 209 | test("only an admin cuts a wave", async () => { | |
| 210 | const bob = await createUser(app.db, { | |
| 211 | trusted: true, | |
| 212 | username: "bob", | |
| 213 | email: "[email protected]", | |
| 214 | password: "a-good-passphrase", | |
| 215 | }); | |
| 216 | if (!bob.ok) throw new Error(bob.error); | |
| 217 | expect(await cutWave(app, bob.value, repo, "3.0.0")).toEqual({ ok: false, error: "not_found" }); | |
| 218 | }); | |
| 219 | }); |
new above
offline