Public: anyone can read this; the crew can change it.
A wave's page says how many of its issues landed, as 'n of m', with a bar #14872
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14860-a-wave-s-page-says-how-many-of-its-issue → main 1 commit fork
1 file
changed +83
−0
test/wave-progress.test.ts added +83
| @@ -0,0 +1,83 @@ | ||
| 1 | /** | |
| 2 | * A wave's page reads as progress toward its end: "n of m changes landed." and one bar sized by | |
| 3 | * the ratio. Already built (#13425); this proves 0, partial and full on the page, and that a pull | |
| 4 | * closed without merging (parked) is never counted as landed. | |
| 5 | */ | |
| 6 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 7 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 8 | import { tmpdir } from "node:os"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { commitToBranch, createRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { createSession } from "../src/core/sessions.ts"; | |
| 13 | import { createUser } from "../src/core/users.ts"; | |
| 14 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 15 | import { WAVE_NO_CHANGES } from "../src/story/words.ts"; | |
| 16 | import { quietLogs } from "./helpers/globals.ts"; | |
| 17 | import { mergedPull, waveNaming } from "./helpers/wave-pulls.ts"; | |
| 18 | ||
| 19 | quietLogs(); | |
| 20 | ||
| 21 | let dataDir = ""; | |
| 22 | let app: App; | |
| 23 | let servers: Servers; | |
| 24 | let cookie = ""; | |
| 25 | ||
| 26 | beforeAll(async () => { | |
| 27 | dataDir = await mkdtemp(join(tmpdir(), "forge-wave-progress-")); | |
| 28 | app = createApp({ dataDir, port: 0 }); | |
| 29 | servers = await serve(app); | |
| 30 | const u = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true }); | |
| 31 | if (!u.ok) throw new Error(String(u.error)); | |
| 32 | cookie = `forge_session=${createSession(app.db, u.value.id).token}; forge_mode=dev`; | |
| 33 | const made = await createRepo(app, u.value, { name: "plan", visibility: "public" }); | |
| 34 | if (!made.ok) throw new Error(String(made.error)); | |
| 35 | const repo = made.value; | |
| 36 | const init = await commitToBranch(app, u.value, repo, { message: "init", files: [{ path: "README.md", content: "hi\n" }] }); | |
| 37 | if (!init.ok) throw new Error(JSON.stringify(init.error)); | |
| 38 | const a = await mergedPull(app, u.value, repo, "Alpha"); | |
| 39 | const b = await mergedPull(app, u.value, repo, "Beta"); | |
| 40 | const c = await mergedPull(app, u.value, repo, "Gamma"); | |
| 41 | // Gamma is parked: closed, never merged. | |
| 42 | app.db | |
| 43 | .query("UPDATE pull SET merged_at = NULL WHERE issue_id = (SELECT id FROM issue WHERE repo_id = ? AND number = ?)") | |
| 44 | .run(repo.id, c); | |
| 45 | app.db.query("UPDATE issue SET state = 'closed' WHERE repo_id = ? AND number = ?").run(repo.id, c); | |
| 46 | const ref = (number: number) => ({ owner: "alice", name: "plan", number }); | |
| 47 | const w = await commitToBranch(app, u.value, repo, { | |
| 48 | message: "waves", | |
| 49 | files: [ | |
| 50 | { path: "waves/0.1.0.md", content: waveNaming("0.1.0", []) }, | |
| 51 | { path: "waves/0.2.0.md", content: waveNaming("0.2.0", [ref(a), ref(c)]) }, | |
| 52 | { path: "waves/0.3.0.md", content: waveNaming("0.3.0", [ref(a), ref(b)]) }, | |
| 53 | ], | |
| 54 | }); | |
| 55 | if (!w.ok) throw new Error(JSON.stringify(w.error)); | |
| 56 | }, 60_000); | |
| 57 | ||
| 58 | afterAll(async () => { | |
| 59 | servers?.stop(); | |
| 60 | app?.close(); | |
| 61 | await rm(dataDir, { recursive: true, force: true }); | |
| 62 | }); | |
| 63 | ||
| 64 | const get = async (v: string) => (await fetch(`${servers.url}/alice/plan/waves/${v}`, { headers: { cookie } })).text(); | |
| 65 | ||
| 66 | test("zero issues: says so, no bar, no division", async () => { | |
| 67 | const text = await get("0.1.0"); | |
| 68 | expect(text).toContain(`<span data-wave-landed>${WAVE_NO_CHANGES}</span>`); | |
| 69 | expect(text).not.toContain("<progress"); | |
| 70 | expect(text).not.toContain("NaN"); | |
| 71 | }); | |
| 72 | ||
| 73 | test("partial: a parked (closed, unmerged) pull is not counted as landed", async () => { | |
| 74 | const text = await get("0.2.0"); | |
| 75 | expect(text).toContain("<span data-wave-landed>1 of 2 changes landed.</span>"); | |
| 76 | expect(text).toMatch(/<progress\s+max="2"\s+value="1"/); | |
| 77 | }); | |
| 78 | ||
| 79 | test("full: n of n, bar full", async () => { | |
| 80 | const text = await get("0.3.0"); | |
| 81 | expect(text).toContain("<span data-wave-landed>2 of 2 changes landed.</span>"); | |
| 82 | expect(text).toMatch(/<progress\s+max="2"\s+value="2"/); | |
| 83 | }); |
new above
offline