Public: anyone can read this; the crew can change it.
The story's wave plan and the feed's shipped and step rows are pinned by tests that fail without them #15932
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15930-the-story-s-wave-plan-and-the-feed-s-shi → main 0 commits fork
2 files
changed +170
−0
test/feed-shipped-step.test.ts added +94
| @@ -0,0 +1,94 @@ | ||
| 1 | import { afterAll, expect, test } from "bun:test"; | |
| 2 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp } from "../src/app.ts"; | |
| 6 | import { createRepo } from "../src/core/repos.ts"; | |
| 7 | import { createUser } from "../src/core/users.ts"; | |
| 8 | import { shipped } from "../src/feed/shipped.ts"; | |
| 9 | import { stepsOf } from "../src/feed/step.ts"; | |
| 10 | import { id } from "../src/kernel/id.ts"; | |
| 11 | import { escapeHtml } from "../src/web/html.ts"; | |
| 12 | ||
| 13 | const roots: string[] = []; | |
| 14 | afterAll(() => roots.forEach((r) => rmSync(r, { recursive: true, force: true }))); | |
| 15 | ||
| 16 | async function seed() { | |
| 17 | const root = mkdtempSync(join(tmpdir(), "forge-shipstep-")); | |
| 18 | roots.push(root); | |
| 19 | const app = createApp({ dataDir: root, port: 0 }); | |
| 20 | const u = await createUser(app.db, { username: "alice", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true }); | |
| 21 | if (!u.ok) throw new Error(u.error); | |
| 22 | const r = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "r", visibility: "public", description: "r" }); | |
| 23 | if (!r.ok) throw new Error(r.error); | |
| 24 | let n = 0; | |
| 25 | /** A pull row: merged at `mergedAt`, open when null, closed unmerged when `closed`. */ | |
| 26 | const pull = (title: string, mergedAt: string | null, closed = false) => { | |
| 27 | const rowId = id(); | |
| 28 | n++; | |
| 29 | const state = mergedAt !== null || closed ? "closed" : "open"; | |
| 30 | app.db | |
| 31 | .query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, close_reason, created_at, closed_at) VALUES (?1,?2,?3,'pull',?4,'',?5,?6,NULL,'2026-11-10T00:00:00.000Z',?7)`) | |
| 32 | .run(rowId, r.value.id, n, title, u.value.id, state, state === "closed" ? "2026-11-11T00:00:00.000Z" : null); | |
| 33 | app.db | |
| 34 | .query(`INSERT INTO pull (issue_id, base_branch, head_branch, base_oid, head_oid, head_repo_id, merged_at) VALUES (?1,'main',?2,'','',?3,?4)`) | |
| 35 | .run(rowId, `b/${n}`, r.value.id, mergedAt); | |
| 36 | return { id: rowId, number: n }; | |
| 37 | }; | |
| 38 | return { app, repo: r.value, pull }; | |
| 39 | } | |
| 40 | ||
| 41 | test("shipped lists merged pulls newest first, with the repository they are on", async () => { | |
| 42 | const { app, repo, pull } = await seed(); | |
| 43 | pull("old", "2026-11-12T00:00:00.000Z"); | |
| 44 | pull("new", "2026-11-14T00:00:00.000Z"); | |
| 45 | pull("open one", null); | |
| 46 | pull("closed unmerged", null, true); | |
| 47 | const own = shipped(app.db, { repoId: repo.id }, 10); | |
| 48 | expect(own.map((s) => s.issue.title)).toEqual(["new", "old"]); | |
| 49 | expect(own.map((s) => s.at)).toEqual(["2026-11-14T00:00:00.000Z", "2026-11-12T00:00:00.000Z"]); | |
| 50 | expect(own.every((s) => s.app === "alice/r")).toBe(true); | |
| 51 | expect(shipped(app.db, "public", 10).map((s) => s.issue.title)).toEqual(["new", "old"]); | |
| 52 | expect(shipped(app.db, { repoId: repo.id }, 1).map((s) => s.issue.title)).toEqual(["new"]); | |
| 53 | }); | |
| 54 | ||
| 55 | test("shipped leaves out sealed pulls, private and archived repositories in the public scope", async () => { | |
| 56 | const { app, repo, pull } = await seed(); | |
| 57 | const sealed = pull("sealed", "2026-11-14T00:00:00.000Z"); | |
| 58 | pull("kept", "2026-11-13T00:00:00.000Z"); | |
| 59 | app.db.query("UPDATE issue SET sealed = 1 WHERE id = ?1").run(sealed.id); | |
| 60 | expect(shipped(app.db, { repoId: repo.id }, 10).map((s) => s.issue.title)).toEqual(["kept"]); | |
| 61 | app.db.query("UPDATE repo SET visibility = 'private' WHERE id = ?1").run(repo.id); | |
| 62 | expect(shipped(app.db, "public", 10)).toEqual([]); | |
| 63 | app.db.query("UPDATE repo SET visibility = 'public', archived_at = '2026-11-15T00:00:00.000Z' WHERE id = ?1").run(repo.id); | |
| 64 | expect(shipped(app.db, "public", 10)).toEqual([]); | |
| 65 | }); | |
| 66 | ||
| 67 | test("a title with markup comes back as stored and is escaped on the way out", async () => { | |
| 68 | const { app, repo, pull } = await seed(); | |
| 69 | pull(`<script>alert("x")</script> & more`, "2026-11-14T00:00:00.000Z"); | |
| 70 | const [item] = shipped(app.db, { repoId: repo.id }, 10); | |
| 71 | expect(item!.issue.title).toBe(`<script>alert("x")</script> & more`); | |
| 72 | const out = escapeHtml(item!.issue.title); | |
| 73 | expect(out).not.toContain("<script>"); | |
| 74 | expect(out).toContain("<script>"); | |
| 75 | expect(out).toContain("& more"); | |
| 76 | }); | |
| 77 | ||
| 78 | test("stepsOf gives a pull post its step and skips every other post", async () => { | |
| 79 | const { app, pull } = await seed(); | |
| 80 | const merged = pull("merged", "2026-11-14T00:00:00.000Z"); | |
| 81 | const open = pull("open", null); | |
| 82 | const closed = pull("closed", null, true); | |
| 83 | const steps = stepsOf(app.db, [ | |
| 84 | { id: "p-merged", kind: "pull", link: `/alice/r/pulls/${merged.number}` }, | |
| 85 | { id: "p-open", kind: "pull", link: `/alice/r/pulls/${open.number}` }, | |
| 86 | { id: "p-closed", kind: "pull", link: `/alice/r/pulls/${closed.number}` }, | |
| 87 | { id: "p-issue", kind: "issue", link: `/alice/r/pulls/${open.number}` }, | |
| 88 | { id: "p-nowhere", kind: "pull", link: `/alice/nope/pulls/1` }, | |
| 89 | { id: "p-odd", kind: "pull", link: `/alice/r/pulls/abc` }, | |
| 90 | ]); | |
| 91 | expect([...steps.keys()].sort()).toEqual(["p-merged", "p-open"]); | |
| 92 | expect(steps.get("p-merged")).toMatchObject({ step: "land", done: true }); | |
| 93 | expect(steps.get("p-open")).toMatchObject({ step: "review", done: false }); | |
| 94 | }); |
test/story-wave-plan.test.ts added +76
| @@ -0,0 +1,76 @@ | ||
| 1 | import { afterAll, expect, test } from "bun:test"; | |
| 2 | import { mkdtempSync, rmSync } from "node:fs"; | |
| 3 | import { tmpdir } from "node:os"; | |
| 4 | import { join } from "node:path"; | |
| 5 | import { createApp } from "../src/app.ts"; | |
| 6 | import { addDependency } from "../src/core/dependencies.ts"; | |
| 7 | import { getIssue } from "../src/core/issues.ts"; | |
| 8 | import { createRepo } from "../src/core/repos.ts"; | |
| 9 | import { createUser } from "../src/core/users.ts"; | |
| 10 | import { id } from "../src/kernel/id.ts"; | |
| 11 | import { milestonePath, planNow } from "../src/story/wave_plan.ts"; | |
| 12 | ||
| 13 | const NOW = new Date("2026-11-20T12:00:00.000Z"); | |
| 14 | const roots: string[] = []; | |
| 15 | afterAll(() => roots.forEach((r) => rmSync(r, { recursive: true, force: true }))); | |
| 16 | ||
| 17 | async function seed() { | |
| 18 | const root = mkdtempSync(join(tmpdir(), "forge-wave-")); | |
| 19 | roots.push(root); | |
| 20 | const app = createApp({ dataDir: root, port: 0 }); | |
| 21 | const u = await createUser(app.db, { username: "alice", email: "[email protected]", password: "a-good-passphrase", origin: "seed", trusted: true, adminIfFirst: true }); | |
| 22 | if (!u.ok) throw new Error(u.error); | |
| 23 | const r = await createRepo(app.db, app.reposRoot, { ownerId: u.value.id, name: "r", visibility: "public", description: "r" }); | |
| 24 | if (!r.ok) throw new Error(r.error); | |
| 25 | let n = 0; | |
| 26 | const issue = (state: "open" | "closed") => { | |
| 27 | n++; | |
| 28 | app.db | |
| 29 | .query(`INSERT INTO issue (id, repo_id, number, kind, title, body, author_id, state, close_reason, created_at, closed_at) VALUES (?1,?2,?3,'issue',?4,'',?5,?6,?7,?8,?9)`) | |
| 30 | .run(id(), r.value.id, n, `issue ${n}`, u.value.id, state, state === "closed" ? "done" : null, "2026-11-10T00:00:00.000Z", state === "closed" ? "2026-11-15T00:00:00.000Z" : null); | |
| 31 | return getIssue(app.db, r.value.id, n)!; | |
| 32 | }; | |
| 33 | return { app, repo: r.value, issue }; | |
| 34 | } | |
| 35 | ||
| 36 | test("milestonePath puts a milestone under the base path", () => { | |
| 37 | expect(milestonePath("/alice/r", 7)).toBe("/alice/r/milestones/7"); | |
| 38 | expect(milestonePath("", 12)).toBe("/milestones/12"); | |
| 39 | }); | |
| 40 | ||
| 41 | test("planNow on an empty repository has no limbs and no milestones", async () => { | |
| 42 | const { app, repo } = await seed(); | |
| 43 | const plan = planNow(app.db, repo, NOW); | |
| 44 | expect(plan.limbs).toHaveLength(0); | |
| 45 | expect(plan.milestone(1)).toBeUndefined(); | |
| 46 | }); | |
| 47 | ||
| 48 | test("planNow on one milestone opens it with its open leaf, and reads no spend", async () => { | |
| 49 | const { app, repo, issue } = await seed(); | |
| 50 | const parent = issue("open"); | |
| 51 | const child = issue("open"); | |
| 52 | expect(addDependency(app.db, parent, child, undefined).ok).toBe(true); | |
| 53 | const plan = planNow(app.db, repo, NOW); | |
| 54 | const m = plan.milestone(parent.number); | |
| 55 | expect(m).toBeDefined(); | |
| 56 | expect(m!.issue.number).toBe(parent.number); | |
| 57 | expect(m!.leaves.map((l) => l.issue.number)).toEqual([child.number]); | |
| 58 | expect(m!.leaves[0]!.state).toBe("ready"); | |
| 59 | expect(m!.spend).toBeUndefined(); | |
| 60 | expect(plan.milestone(child.number)).toBeUndefined(); | |
| 61 | }); | |
| 62 | ||
| 63 | test("planNow on a finished milestone shows nothing left to do beneath it", async () => { | |
| 64 | const { app, repo, issue } = await seed(); | |
| 65 | const parent = issue("closed"); | |
| 66 | const child = issue("closed"); | |
| 67 | expect(addDependency(app.db, parent, child, undefined).ok).toBe(true); | |
| 68 | const plan = planNow(app.db, repo, NOW); | |
| 69 | const m = plan.milestone(parent.number); | |
| 70 | expect(m).toBeDefined(); | |
| 71 | expect(m!.leaves.filter((l) => l.state === "ready")).toHaveLength(0); | |
| 72 | expect(m!.building).toHaveLength(0); | |
| 73 | expect(m!.blocked).toHaveLength(0); | |
| 74 | expect(plan.limbs).toHaveLength(0); | |
| 75 | expect(plan.limb(parent.number)!.own.filter((i) => i.state === "open")).toHaveLength(0); | |
| 76 | }); |
new above
offline