Public: anyone can read this; the crew can change it.
Chapter close reads as a short ceremony: what shipped, what slipped, the next chapter's first three #15603
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15593-chapter-close-reads-as-a-short-ceremony → main 0 commits fork 3 threads · 3 unresolved
9 files
changed +200
−14
docs/features/chapter-close.md added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | --- | |
| 2 | topic: Tell the crew | |
| 3 | row: Chapter close summary | |
| 4 | --- | |
| 5 | # Chapter close summary (#15593) | |
| 6 | ||
| 7 | A closed chapter reads as a short ceremony: what landed, what was carried forward, and the next chapter's first three issues after the carried ones, so no issue is named twice. | |
| 8 | ||
| 9 | - Page: open a closed chapter, e.g. `/trevato/forge/chapters/v1`. The notes already say what landed and what moved, so below them one line names the next chapter's first three past what was carried, with Open vN for the owner when it is a draft. | |
| 10 | - Terminal: open the same chapter in the chapters screen (`src/tui/screens/chapters.ts`); the summary shows above the Next line. | |
| 11 | - Data: `src/core/chapter_notes.ts` builds it; the page, terminal and MCP chapter tool all read that one function. |
src/actions/chapters.ts +26 −2
| @@ -6,7 +6,7 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | import type { App } from "../app.ts"; |
| 9 | import { chapterNotes, daysBetween } from "../core/chapter_notes.ts"; | |
| 9 | import { chapterNotes, daysBetween, FIRST_OF_NEXT, type CloseSummary, type Line } from "../core/chapter_notes.ts"; | |
| 10 | 10 | import { |
| 11 | 11 | draftChapter, |
| 12 | 12 | getChapter, |
| @@ -27,6 +27,7 @@ import { | ||
| 27 | 27 | type Item, |
| 28 | 28 | type ChapterError, |
| 29 | 29 | recordV1, |
| 30 | shows, | |
| 30 | 31 | V1_NAME, |
| 31 | 32 | } from "../core/chapters.ts"; |
| 32 | 33 | import { addDependency } from "../core/dependencies.ts"; |
| @@ -331,7 +332,7 @@ export async function close( | ||
| 331 | 332 | await runGit(["update-ref", "-d", ref, tip], { cwd: dir }); |
| 332 | 333 | return err(getChapter(app.db, repo.id, name)?.state === "closed" ? "closed" : "git"); |
| 333 | 334 | } |
| 334 | app.bus.append({ kind: "chapter.closed", repoId: repo.id, actorId: by.id, payload: { name, tag: chapter.name, shipped: landed.length, moved: left.length, ...(next === undefined ? {} : { into: next.name }) } }); | |
| 335 | app.bus.append({ kind: "chapter.closed", repoId: repo.id, actorId: by.id, payload: { name, tag: chapter.name, shipped: landed.length, moved: left.length, carried: left.map((i) => i.number), ...(next === undefined ? {} : { into: next.name }) } }); | |
| 335 | 336 | const closedChapter = getChapter(app.db, repo.id, name)!; |
| 336 | 337 | // The wave is the chapter's entry in the changelog; a failure to write it never undoes the close. |
| 337 | 338 | await writeChapterWave(app, by, repo, closedChapter); |
| @@ -392,3 +393,26 @@ export const CHAPTER_WORDS: Readonly<Record<ChapterActError, string>> = { | ||
| 392 | 393 | unproven: "v1.0.0 closes only when the proof passes on production, every probe.", |
| 393 | 394 | another_open: "Another chapter has been opened since, so this close cannot be taken back.", |
| 394 | 395 | }; |
| 396 | ||
| 397 | /** | |
| 398 | * The close as a short ceremony: what landed, what was carried forward (as the close recorded it, | |
| 399 | * so it never changes) and the next chapter's first three items now, past what was carried, so no | |
| 400 | * issue is named twice. Only what `view` may see. | |
| 401 | */ | |
| 402 | export function closeSummary(app: App, repo: Repo, chapter: Chapter, view: ItemView): CloseSummary { | |
| 403 | const line = (i: { number: number; title: string }): Line => ({ number: i.number, title: i.title }); | |
| 404 | const shipped = itemsOf(app.db, chapter, view).filter((i) => i.status === "done").map(line); | |
| 405 | // The close event of this chapter by name, never a window of recent events. | |
| 406 | const found = app.db | |
| 407 | .query<{ payload: string }, [string, string]>("SELECT payload FROM event WHERE repo_id = ?1 AND kind = 'chapter.closed' AND json_extract(payload, '$.name') = ?2 ORDER BY id DESC LIMIT 1") | |
| 408 | .get(repo.id, chapter.name); | |
| 409 | const row = found === null ? undefined : (JSON.parse(found.payload) as { carried?: unknown }); | |
| 410 | const numbers = Array.isArray(row?.carried) ? row.carried.filter((n): n is number => Number.isInteger(n)) : []; | |
| 411 | const carried = numbers.flatMap((n) => { | |
| 412 | const issue = getIssue(app.db, repo.id, n); | |
| 413 | return issue === undefined || !shows(view, { sealed: issue.sealed, authorId: issue.authorId }) ? [] : [line(issue)]; | |
| 414 | }); | |
| 415 | const next = nextChapterOf(app.db, repo.id); | |
| 416 | const first = next === undefined ? [] : itemsOf(app.db, next, view).filter((i) => i.status !== "done" && !numbers.includes(i.number)).slice(0, FIRST_OF_NEXT).map(line); | |
| 417 | return { name: chapter.name, shipped, carried, next: next?.name ?? null, first }; | |
| 418 | } |
src/core/chapter_notes.ts +45
| @@ -52,3 +52,48 @@ export function chapterNotes( | ||
| 52 | 52 | lines.push(`## Moved to ${next}`, ...moved.map((m) => `- ${m.title.trim()} (#${m.number})`), ""); |
| 53 | 53 | return `${lines.join("\n").trimEnd()}\n`; |
| 54 | 54 | } |
| 55 | ||
| 56 | /** One issue as the close summary lists it. */ | |
| 57 | export interface Line { | |
| 58 | readonly number: number; | |
| 59 | readonly title: string; | |
| 60 | } | |
| 61 | ||
| 62 | /** What a close says: what landed, what was carried forward, and the next chapter's first items. */ | |
| 63 | export interface CloseSummary { | |
| 64 | readonly name: string; | |
| 65 | readonly shipped: readonly Line[]; | |
| 66 | readonly carried: readonly Line[]; | |
| 67 | /** The next chapter's name, or null when none is drafted. */ | |
| 68 | readonly next: string | null; | |
| 69 | /** Its first items not already carried, at most `FIRST_OF_NEXT`. */ | |
| 70 | readonly first: readonly Line[]; | |
| 71 | } | |
| 72 | ||
| 73 | export const FIRST_OF_NEXT = 3; | |
| 74 | ||
| 75 | const list = (ls: readonly Line[]): string => ls.map((l) => `#${l.number} ${l.title.trim()}`).join(", "); | |
| 76 | ||
| 77 | /** | |
| 78 | * How the next chapter is introduced: "starts with" its first items, or "then takes up" the ones | |
| 79 | * after what was carried, so a carried issue is named once. Ends in a full stop when it has none. | |
| 80 | */ | |
| 81 | export function nextLead(s: CloseSummary): string { | |
| 82 | if (s.next === null) return ""; | |
| 83 | if (s.first.length === 0) return s.carried.length === 0 ? `${s.next} has no items yet.` : `${s.next} has nothing else yet.`; | |
| 84 | return s.carried.length === 0 ? `${s.next} starts with` : `${s.next} then takes up`; | |
| 85 | } | |
| 86 | ||
| 87 | /** The summary as one short paragraph set: the same words on the page and through the MCP. */ | |
| 88 | export function summaryWords(s: CloseSummary): string { | |
| 89 | const out = [ | |
| 90 | s.shipped.length === 0 | |
| 91 | ? `${s.name} closed with nothing landed.` | |
| 92 | : `${s.name} closed: ${s.shipped.length} ${s.shipped.length === 1 ? "item" : "items"} landed: ${list(s.shipped)}.`, | |
| 93 | s.carried.length === 0 ? "Nothing was carried forward." : `Carried forward: ${list(s.carried)}.`, | |
| 94 | ]; | |
| 95 | if (s.next === null) out.push("No next chapter is drafted."); | |
| 96 | else if (s.first.length === 0) out.push(nextLead(s)); | |
| 97 | else out.push(`${nextLead(s)} ${list(s.first)}.`); | |
| 98 | return out.join(" "); | |
| 99 | } |
src/core/chapters.ts +1 −1
| @@ -236,7 +236,7 @@ interface Sealing { | ||
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** Whether `view` may hold a row with this sealing. */ |
| 239 | const shows = (view: ItemView, row: Sealing): boolean => | |
| 239 | export const shows = (view: ItemView, row: Sealing): boolean => | |
| 240 | 240 | !row.sealed || view.sealed === true || (view.sealedBy !== undefined && view.sealedBy === row.authorId); |
| 241 | 241 | |
| 242 | 242 | interface ItemRow extends Sealing { |
src/http/mcp/tools/repo.ts +6 −3
| @@ -4,8 +4,9 @@ import { audienceFor } from "../../../core/audience.ts"; | ||
| 4 | 4 | import { repoFor } from "../../../core/repo_fields.ts"; |
| 5 | 5 | import { upstreamFacts } from "../../../actions/upstream_follow.ts"; |
| 6 | 6 | import { creditFacts } from "../../../actions/credit_facts.ts"; |
| 7 | import { type ChapterActError, close, fill, open, preview, refusalWords, type Refused } from "../../../actions/chapters.ts"; | |
| 8 | import { costSentence, flowOf, flowSentence, getChapter, itemsOf, spentOf, listChapters, progressOf, progressSentence } from "../../../core/chapters.ts"; | |
| 7 | import { type ChapterActError, close, closeSummary, fill, open, preview, refusalWords, type Refused } from "../../../actions/chapters.ts"; | |
| 8 | import { summaryWords } from "../../../core/chapter_notes.ts"; | |
| 9 | import { costSentence, EVERY_ITEM, flowOf, flowSentence, getChapter, itemsOf, spentOf, listChapters, progressOf, progressSentence } from "../../../core/chapters.ts"; | |
| 9 | 10 | import { err } from "../../../kernel/result.ts"; |
| 10 | 11 | import { sealedScope } from "../../../core/sealed.ts"; |
| 11 | 12 | import { good, str, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; |
| @@ -44,7 +45,9 @@ export const tool: Tool = { | ||
| 44 | 45 | : verb === "open" ? open(ctx.app, user, repo, name) |
| 45 | 46 | : n === undefined ? err<ChapterActError>("not_found") |
| 46 | 47 | : fill(ctx.app, user, repo, name, n, verb === "add"); |
| 47 | return done.ok ? good({ done: true, chapter: name, action: verb, ...(n === undefined ? {} : { number: n }) }) : refused(done); | |
| 48 | if (!done.ok) return refused(done); | |
| 49 | const says = verb === "close" ? { says: summaryWords(closeSummary(ctx.app, repo, getChapter(ctx.app.db, repo.id, name)!, EVERY_ITEM)) } : {}; | |
| 50 | return good({ done: true, chapter: name, action: verb, ...(n === undefined ? {} : { number: n }), ...says }); | |
| 48 | 51 | } |
| 49 | 52 | if (args["view"] === undefined && args["chapter"] !== undefined) return bad("invalid", "`chapter` needs `view: chapters`"); |
| 50 | 53 | if (args["view"] !== undefined) { |
src/tui/screens/chapters.ts +6 −2
| @@ -9,7 +9,8 @@ | ||
| 9 | 9 | * sees it, and this screen follows a change made there. |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | import { CHAPTER_WORDS, close, draft, fill, open, patch, reopen, refusalWords, undoableClose } from "../../actions/chapters.ts"; | |
| 12 | import { summaryWords } from "../../core/chapter_notes.ts"; | |
| 13 | import { CHAPTER_WORDS, close, closeSummary, draft, fill, open, patch, reopen, refusalWords, undoableClose } from "../../actions/chapters.ts"; | |
| 13 | 14 | import { barCount, barNext, barOf, costSentence, getChapter, nextChapterOf, nextWords, itemsOf, listChapters, progressOf, progressSentence, type Chapter, type Item } from "../../core/chapters.ts"; |
| 14 | 15 | import { canAdmin, type Repo } from "../../core/repos.ts"; |
| 15 | 16 | import { sealedScope } from "../../core/sealed.ts"; |
| @@ -65,8 +66,11 @@ export function chapterScreen(f: Session, ctx: Ctx, repo: Repo, name: string): S | ||
| 65 | 66 | // The page's Next line, read when the screen loads and when a chapter event arrives, not per |
| 66 | 67 | // frame. |
| 67 | 68 | let nextLine = ""; |
| 69 | let summary = ""; | |
| 68 | 70 | const refresh = (): void => { |
| 69 | 71 | const c = getChapter(f.app.db, repo.id, name); |
| 72 | // The page's ceremony: what landed, what was carried, the next chapter's first three. | |
| 73 | summary = c?.state === "closed" ? summaryWords(closeSummary(f.app, repo, c, sealedScope(f.app.db, repo, f.user))) : ""; | |
| 70 | 74 | nextLine = c?.state === "closed" ? nextWords(nextChapterOf(f.app.db, repo.id)) : ""; |
| 71 | 75 | }; |
| 72 | 76 | const screen: Screen = { |
| @@ -84,7 +88,7 @@ export function chapterScreen(f: Session, ctx: Ctx, repo: Repo, name: string): S | ||
| 84 | 88 | const chapter = getChapter(f.app.db, repo.id, name); |
| 85 | 89 | const all = items(); |
| 86 | 90 | // A closed chapter ends with the page's Next line, wrapped, never cut. |
| 87 | const next = nextLine === "" ? [] : wrap(nextLine, Math.max(area.w, 1)); | |
| 91 | const next = [...(summary === "" ? [] : wrap(summary, Math.max(area.w, 1))), ...(nextLine === "" ? [] : wrap(nextLine, Math.max(area.w, 1)))]; | |
| 88 | 92 | const [head, nextArea, list] = split(area, "v", [len(1), len(next.length), fillSpace(1)]); |
| 89 | 93 | next.forEach((line, i) => s.text(nextArea!.x, nextArea!.y + i, line, style(c.mutedFg, c.bg), nextArea!.x + nextArea!.w)); |
| 90 | 94 | const p = chapter === undefined ? undefined : progressOf(chapter, all, new Date()); |
src/web/pages/chapters.ts +19 −4
| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | * change is a same-origin POST by a person who administers the repository. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | import { CHAPTER_WORDS, close, draft, fill, open, patch, reopen, refusalWords } from "../../actions/chapters.ts"; | |
| 10 | import { costSentence, flowOf, flowSentence, nextParts, getChapter, itemsOf, nextChapterOf, listChapters, progressOf, progressSentence, type Chapter, type Item } from "../../core/chapters.ts"; | |
| 9 | import { CHAPTER_WORDS, close, closeSummary, draft, fill, open, patch, reopen, refusalWords } from "../../actions/chapters.ts"; | |
| 10 | import { nextLead } from "../../core/chapter_notes.ts"; | |
| 11 | import { costSentence, flowOf, flowSentence, nextParts, openChapterOf, getChapter, itemsOf, nextChapterOf, listChapters, progressOf, progressSentence, type Chapter, type Item } from "../../core/chapters.ts"; | |
| 11 | 12 | import { canAdmin, type Repo } from "../../core/repos.ts"; |
| 12 | 13 | import { sealedScope } from "../../core/sealed.ts"; |
| 13 | 14 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -83,7 +84,20 @@ function nextLine(repo: Repo, later: Chapter | undefined): Html { | ||
| 83 | 84 | return p.chapter === null ? html`${p.lead}` : html`${p.lead}<a href="${hrefOf(repo, p.chapter)}">${p.name}</a>${p.tail}`; |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | function finished(repo: Repo, c: Chapter, items: readonly Item[], may: boolean, later: Chapter | undefined): Html { | |
| 87 | /** | |
| 88 | * The ceremony, after the notes that already say what landed and what moved: the next chapter's | |
| 89 | * first three past those, and one button to open it. One line; nothing the notes say again. | |
| 90 | */ | |
| 91 | function ceremony(ctx: Ctx, repo: Repo, c: Chapter, may: boolean, later: Chapter | undefined): Html { | |
| 92 | const s = closeSummary(ctx.app, repo, c, sealedScope(ctx.app.db, repo, ctx.auth.user)); | |
| 93 | if (s.next === null || later === undefined) return html``; | |
| 94 | const canOpen = may && later.state === "draft" && openChapterOf(ctx.app.db, repo.id) === undefined; | |
| 95 | const links = s.first.map((l, k) => html`${k === 0 ? "" : ", "}<a href="${repoBase(repo)}/issues/${l.number}">#${l.number} ${l.title}</a>`); | |
| 96 | return html`<p data-ceremony>${nextLead(s)}${s.first.length === 0 ? null : html` ${links}.`}</p> | |
| 97 | ${canOpen ? html`<form method="post" action="${hrefOf(repo, later)}/open">${btn(`Open ${later.name}`, { variant: "primary" })}</form>` : null}`; | |
outdated
Principle 1: this sentence says again what the three sections below it list, and the Notes block lists a third time. Drop the sentence from the page (keep it for MCP/TUI if needed). |
||
| 98 | } | |
| 99 | ||
| 100 | function finished(ctx: Ctx, repo: Repo, c: Chapter, items: readonly Item[], may: boolean, later: Chapter | undefined): Html { | |
| 87 | 101 | const done = items.filter((i) => i.status === "done"); |
| 88 | 102 | const days = c.openedAt === null || c.closedAt === null ? 0 : Math.max(1, Math.round((Date.parse(c.closedAt) - Date.parse(c.openedAt)) / 86_400_000)); |
| 89 | 103 | return html`<p data-finished><strong>${c.name} is finished.</strong> ${c.means}</p> |
| @@ -95,6 +109,7 @@ function finished(repo: Repo, c: Chapter, items: readonly Item[], may: boolean, | ||
| 95 | 109 | </dl> |
| 96 | 110 | <h2>Notes</h2> |
| 97 | 111 | <pre data-notes>${c.notes}</pre> |
| 112 | ${ceremony(ctx, repo, c, may, later)} | |
| 98 | 113 | ${may |
| 99 | 114 | ? html`<form method="post" action="${hrefOf(repo, c)}/patch">${btn(`Open a patch chapter for ${c.name}`, { variant: "primary" })}</form>` |
| 100 | 115 | : null} |
| @@ -114,7 +129,7 @@ export function chapterPage(ctx: Ctx): Response { | ||
| 114 | 129 | const rendering = performance.now(); |
| 115 | 130 | const here = hrefOf(repo, c); |
| 116 | 131 | let main: Html; |
| 117 | if (c.state === "closed") main = finished(repo, c, items, may, nextChapterOf(ctx.app.db, repo.id)); | |
| 132 | if (c.state === "closed") main = finished(ctx, repo, c, items, may, nextChapterOf(ctx.app.db, repo.id)); | |
| 118 | 133 | else { |
| 119 | 134 | const building = items.filter((i) => i.status === "building"); |
| 120 | 135 | const left = items.filter((i) => i.status === "left"); |
test/mcp-chapters-act.test.ts +79 −2
| @@ -5,10 +5,11 @@ import { mkdtemp, rm } from "node:fs/promises"; | ||
| 5 | 5 | import { tmpdir } from "node:os"; |
| 6 | 6 | import { join } from "node:path"; |
| 7 | 7 | import { createRepo } from "../src/actions/repos.ts"; |
| 8 | import { CHAPTER_WORDS, close, draft, fill, open } from "../src/actions/chapters.ts"; | |
| 8 | import { summaryWords } from "../src/core/chapter_notes.ts"; | |
| 9 | import { CHAPTER_WORDS, close, closeSummary, draft, fill, open } from "../src/actions/chapters.ts"; | |
| 9 | 10 | import { createApp, type App } from "../src/app.ts"; |
| 10 | 11 | import { createIssue } from "../src/core/issues.ts"; |
| 11 | import { getChapter, itemsOf, listChapters, EVERY_ITEM } from "../src/core/chapters.ts"; | |
| 12 | import { getChapter, itemsOf, listChapters, EVERY_ITEM, PUBLIC_ITEMS } from "../src/core/chapters.ts"; | |
| 12 | 13 | import { getRepo } from "../src/core/repos.ts"; |
| 13 | 14 | import { createToken } from "../src/core/tokens.ts"; |
| 14 | 15 | import { createUser, getUserByName } from "../src/core/users.ts"; |
| @@ -125,6 +126,7 @@ test("an unconfirmed close names the tag and what moves, and changes nothing; co | ||
| 125 | 126 | |
| 126 | 127 | const done = await call(alice, { repo: "alice/pub", action: "close", chapter: "v1", confirm: true }); |
| 127 | 128 | expect(done.value.done).toBe(true); |
| 129 | expect(done.value.says).toContain("Carried forward"); | |
| 128 | 130 | const c = getChapter(app.db, repo().id, "v1")!; |
| 129 | 131 | expect(c.state).toBe("closed"); |
| 130 | 132 | const next = getChapter(app.db, repo().id, "v2")!; |
| @@ -211,3 +213,78 @@ test("closing through the MCP leaves what the page's close leaves", async () => | ||
| 211 | 213 | expect(await shape("mcp")).toEqual(page); |
| 212 | 214 | expect(page.tagAtTip).toBe(true); |
| 213 | 215 | }); |
| 216 | ||
| 217 | test("the close says what landed, what was carried and the next chapter's first three, in the page's words", async () => { | |
Add: a sealed carried issue hidden from a guest/other viewer; a close event without |
||
| 218 | const alice_ = getUserByName(app.db, "alice")!; | |
| 219 | const page = await (await fetch(`${servers.url}/alice/pub/chapters/v1`)).text(); | |
| 220 | // The notes list what moved; the ceremony names only what comes after it. | |
| 221 | for (const num of nums) expect(page.match(new RegExp(`#${num}\\b`, "g"))?.length).toBe(1); | |
| 222 | expect(page).not.toContain("Carried forward"); | |
| 223 | const notes = getChapter(app.db, repo().id, "v1")!.notes; | |
| 224 | expect(draft(app, alice_, repo(), { name: "v9" }).ok).toBe(true); | |
| 225 | for (let k = 0; k < 4; k++) { | |
| 226 | const extra = createIssue(app.db, { repoId: repo().id, authorId: alice_.id, title: `late ${k}`, body: "" }); | |
| 227 | if (!extra.ok) throw new Error("issue"); | |
| 228 | expect(fill(app, alice_, repo(), "v9", extra.value.number, true).ok).toBe(true); | |
| 229 | } | |
| 230 | const s = closeSummary(app, repo(), getChapter(app.db, repo().id, "v1")!, EVERY_ITEM); | |
| 231 | expect(s.carried.map((l) => l.number)).toEqual([...nums]); | |
| 232 | expect(s.next).not.toBeNull(); | |
| 233 | expect(s.first.length).toBeLessThanOrEqual(3); | |
| 234 | for (const l of s.first) expect(nums).not.toContain(l.number); | |
| 235 | expect(summaryWords(s)).toContain("Carried forward"); | |
| 236 | // A closed chapter's record does not move when the next one changes. | |
| 237 | expect(getChapter(app.db, repo().id, "v1")!.notes).toBe(notes); | |
| 238 | }); | |
| 239 | ||
| 240 | test("carried is read by chapter, however many closes came after; a close without it carries nothing", () => { | |
| 241 | const alice_ = getUserByName(app.db, "alice")!; | |
| 242 | const v1 = () => getChapter(app.db, repo().id, "v1")!; | |
| 243 | for (let k = 0; k < 60; k++) app.bus.append({ kind: "chapter.closed", repoId: repo().id, actorId: alice_.id, payload: { name: `later${k}`, carried: [] } }); | |
| 244 | expect(closeSummary(app, repo(), v1(), EVERY_ITEM).carried.map((l) => l.number)).toEqual([...nums]); | |
| 245 | const saved = app.db.query<{ id: number; payload: string }, []>("SELECT id, payload FROM event WHERE kind = 'chapter.closed' AND json_extract(payload, '$.name') = 'v1'").all(); | |
| 246 | app.db.query("UPDATE event SET payload = json_remove(payload, '$.carried') WHERE kind = 'chapter.closed' AND json_extract(payload, '$.name') = 'v1'").run(); | |
| 247 | const old = closeSummary(app, repo(), v1(), EVERY_ITEM); | |
| 248 | expect(old.carried).toEqual([]); | |
| 249 | expect(summaryWords(old)).toContain("Nothing was carried forward."); | |
| 250 | for (const e of saved) app.db.query("UPDATE event SET payload = ?2 WHERE id = ?1").run(e.id, e.payload); | |
| 251 | }); | |
| 252 | ||
| 253 | test("the record of what was carried does not move when the next chapter changes", () => { | |
| 254 | const alice_ = getUserByName(app.db, "alice")!; | |
| 255 | const v1 = getChapter(app.db, repo().id, "v1")!; | |
| 256 | const before = closeSummary(app, repo(), v1, EVERY_ITEM).carried; | |
| 257 | expect(before.length).toBe(nums.length); | |
| 258 | for (const num of nums) fill(app, alice_, repo(), "v2", num, false); | |
| 259 | const extra = createIssue(app.db, { repoId: repo().id, authorId: alice_.id, title: "another", body: "" }); | |
| 260 | if (!extra.ok) throw new Error("issue"); | |
| 261 | expect(fill(app, alice_, repo(), "v2", extra.value.number, true).ok).toBe(true); | |
| 262 | expect(closeSummary(app, repo(), v1, EVERY_ITEM).carried).toEqual(before); | |
| 263 | }); | |
| 264 | ||
| 265 | test("a sealed carried issue is listed for who may see it and not for anyone else", () => { | |
| 266 | const v1 = getChapter(app.db, repo().id, "v1")!; | |
| 267 | const alice_ = getUserByName(app.db, "alice")!; | |
| 268 | app.db.query("UPDATE issue SET sealed = 1 WHERE repo_id = ?1 AND number = ?2").run(repo().id, nums[0]!); | |
| 269 | try { | |
| 270 | expect(closeSummary(app, repo(), v1, EVERY_ITEM).carried.map((l) => l.number)).toContain(nums[0]!); | |
| 271 | expect(closeSummary(app, repo(), v1, PUBLIC_ITEMS).carried.map((l) => l.number)).not.toContain(nums[0]!); | |
| 272 | expect(closeSummary(app, repo(), v1, { sealedBy: alice_.id }).carried.map((l) => l.number)).toContain(nums[0]!); | |
| 273 | } finally { | |
| 274 | app.db.query("UPDATE issue SET sealed = 0 WHERE repo_id = ?1 AND number = ?2").run(repo().id, nums[0]!); | |
| 275 | } | |
| 276 | }); | |
| 277 | ||
| 278 | test("the page offers Open for the draft next chapter to its owner only, and names each carried issue once", async () => { | |
| 279 | // v2 may have been opened by an earlier test; the button is for a draft with nothing else open. | |
| 280 | app.db.query("UPDATE chapter SET state = 'draft' WHERE repo_id = ?1 AND name = 'v2'").run(repo().id); | |
| 281 | const get = async (token?: string) => (await fetch(`${servers.url}/alice/pub/chapters/v1`, { headers: token === undefined ? {} : { authorization: `Bearer ${token}` } })).text(); | |
| 282 | expect(await get(alice)).toContain("Open v2"); | |
| 283 | expect(await get()).not.toContain("Open v2"); | |
| 284 | expect(await get(bob)).not.toContain("Open v2"); | |
| 285 | const page = await get(alice); | |
| 286 | expect(page).toContain("data-ceremony"); | |
| 287 | expect(page).not.toContain("<h2>Landed</h2>"); | |
| 288 | expect(page).not.toContain("<h2>Carried forward</h2>"); | |
| 289 | for (const num of nums) expect(page.match(new RegExp(`#${num}\\b`, "g"))?.length).toBe(1); | |
| 290 | }); |
test/tui-chapter-lines.test.ts +7
| @@ -120,3 +120,10 @@ test("/next with a long open chapter name wraps the ranked-for line at 40 column | ||
| 120 | 120 | expect(squash(narrow)).toContain(line); |
| 121 | 121 | expect(plain(await page("/alice/longshop/next"))).toContain(line); |
| 122 | 122 | }); |
| 123 | ||
| 124 | test("a closed chapter prints the ceremony's sentence in the terminal", async () => { | |
| 125 | const out = squash(await text((f, ctx) => chapterScreen(f, ctx, repo, "v1.0.0"))); | |
| 126 | expect(out).toContain("v1.0.0 closed with nothing landed."); | |
| 127 | expect(out).toContain("Nothing was carried forward."); | |
| 128 | expect(out).toContain("has no items yet."); | |
| 129 | }); |
new above
offline
LIMIT 50 drops older closes, so carried goes empty with no error. Select the event for this chapter name (json_extract on payload, or index by chapter), no window.