Public: anyone can read this; the crew can change it.
An issue whose body opens "Follow-up to #N" waits for #N on the map while #N is open #12308
mason/forge:mason/12301-an-issue-whose-body-opens-follow-up-to-n → main 6 commits fork 4 threads · 4 unresolved
12 files
changed +418
−15
docs/MCP.md +7
| @@ -495,6 +495,13 @@ numbers of issues already open. A loop, an unknown key, an unknown number, an | ||
| 495 | 495 | over-long title or body, or more than 12 items refuses the whole plan, naming |
| 496 | 496 | the item, and nothing is opened. Issues belong to the token's owner and emit |
| 497 | 497 | the same events as opening and linking one by one. It needs an `rw` token. |
| 498 | An item whose body opens "Follow-up to #N" or "Split from #N" also waits for | |
| 499 | #N while #N is an open issue here; the answer lists those links as `inferred` | |
| 500 | (`{ key, number, blockedBy }`). A closed or unknown #N, or a link that would | |
| 501 | loop, adds nothing and refuses nothing, and neither does a sealed #N (#12301). Opening one issue does the | |
| 502 | same at every door, a mirror's included: the API's create answer carries | |
| 503 | `inferredBlocker`, and the issue page, the terminal and a tell's answer say | |
| 504 | "it waits for #N". | |
| 498 | 505 | |
| 499 | 506 | Where the app has pillars (docs/PLANNING.md), every item also says what it |
| 500 | 507 | is for, or the whole plan is refused (`no_pillar`), naming the item and the |
docs/features/follow-up-blocks.md added +23
| @@ -0,0 +1,23 @@ | ||
| 1 | # A follow-up waits for what it follows | |
| 2 | ||
| 3 | An issue whose body opens "Follow-up to #N" or "Split from #N" waits for #N on | |
| 4 | the map, as if someone had linked it, while #N is an open issue of the same | |
| 5 | repository (#12301). Only the opening words count; a mention further down is | |
| 6 | not a plan. | |
| 7 | ||
| 8 | Nothing is linked, and nothing is refused, when #N is closed, unknown, a pull, | |
| 9 | in another repository, sealed, or when the link would make a loop. A sealed #N | |
| 10 | is skipped for everyone, writers too: an answer of "it waits for #N" would tell | |
| 11 | anyone who may open an issue that a sealed #N exists and is open. | |
| 12 | ||
| 13 | Every door says what it linked: | |
| 14 | ||
| 15 | - API: `POST …/issues` answers with `inferredBlocker: N`; `POST …/plan` lists | |
| 16 | the links as `inferred` (`{ key, number, blockedBy }`). | |
| 17 | - Page: the new issue's flash says "it waits for #N". | |
| 18 | - Terminal: the new-issue toast says the same. | |
| 19 | - A tell's answer says the same. | |
| 20 | - A mirror does the same: its numbers are its origin's, so #N names the same issue. | |
| 21 | ||
| 22 | The rule lives in `inferFollowUpBlocker` (`src/core/dependencies.ts`); it is | |
| 23 | tested in `test/follow-up-blocks.test.ts`. |
src/actions/issues.ts +27 −6
| @@ -27,7 +27,7 @@ import { crewRole, isCrew } from "../core/agents.ts"; | ||
| 27 | 27 | import { pausedUntil } from "../core/planner_pause.ts"; |
| 28 | 28 | import { keepWithinChapter } from "./chapters.ts"; |
| 29 | 29 | import { inheritChapter } from "../core/chapters.ts"; |
| 30 | import { moveBlockersToChildren } from "../core/dependencies.ts"; | |
| 30 | import { inferFollowUpBlocker, moveBlockersToChildren } from "../core/dependencies.ts"; | |
| 31 | 31 | import { |
| 32 | 32 | addComment as insertComment, |
| 33 | 33 | createIssue, |
| @@ -74,7 +74,7 @@ import { err, ok, type Result } from "../kernel/result.ts"; | ||
| 74 | 74 | import { clearFirst } from "../core/first.ts"; |
| 75 | 75 | import { clearRank } from "../core/rank.ts"; |
| 76 | 76 | import { followLabel } from "./gate.ts"; |
| 77 | import { inheritPillar } from "./pillars.ts"; | |
| 77 | import { followLink, inheritPillar } from "./pillars.ts"; | |
| 78 | 78 | import { |
| 79 | 79 | requireParticipant, |
| 80 | 80 | requireWriter, |
| @@ -96,7 +96,7 @@ export function openIssue( | ||
| 96 | 96 | repo: Repo, |
| 97 | 97 | input: { title: string; body?: string; sealed?: boolean }, |
| 98 | 98 | ): Result< |
| 99 | Issue, | |
| 99 | Opened, | |
| 100 | 100 | "not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long" | MirrorError |
| 101 | 101 | > { |
| 102 | 102 | const user = requireParticipant(app, actor, repo); |
| @@ -129,9 +129,30 @@ export function openIssue( | ||
| 129 | 129 | actorId: user.value.id, |
| 130 | 130 | payload: { number: created.value.number }, |
| 131 | 131 | }); |
| 132 | return created; | |
| 132 | return ok(waitForFollowedUp(app, user.value, repo, created.value)); | |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | /** | |
| 136 | * "Follow-up to #N" opens waiting for #N while #N is open (#12301), on a | |
| 137 | * repository of our own and on a mirror alike: the map is this forge's, | |
| 138 | * and a mirror's numbers are its origin's, so #N names the same issue. | |
| 139 | */ | |
| 140 | function waitForFollowedUp(app: App, user: User, repo: Repo, issue: Issue): Opened { | |
| 141 | const blocker = inferFollowUpBlocker(app.db, issue, user.id); | |
| 142 | if (blocker === undefined) return issue; | |
| 143 | app.bus.append({ | |
| 144 | kind: "issue.blocked", | |
| 145 | repoId: repo.id, | |
| 146 | actorId: user.id, | |
| 147 | payload: { number: issue.number, blockedBy: blocker.number }, | |
| 148 | }); | |
| 149 | followLink(app, user, repo, issue, blocker); | |
| 150 | return { ...issue, inferredBlocker: blocker.number }; | |
| 151 | } | |
| 152 | ||
| 153 | /** A new issue, and the open issue its "Follow-up to #N" made it wait for. */ | |
| 154 | export type Opened = Issue & { readonly inferredBlocker?: number }; | |
| 155 | ||
| 135 | 156 | export type EditError = |
| 136 | 157 | | AccessError |
| 137 | 158 | | MirrorError |
| @@ -816,7 +837,7 @@ export async function openIssueThrough( | ||
| 816 | 837 | }, |
| 817 | 838 | ): Promise< |
| 818 | 839 | Result< |
| 819 | Issue, | |
| 840 | Opened, | |
| 820 | 841 | ThroughError<"not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long"> |
| 821 | 842 | > |
| 822 | 843 | > { |
| @@ -851,7 +872,7 @@ export async function openIssueThrough( | ||
| 851 | 872 | actorId: user.value.id, |
| 852 | 873 | payload: { number: created.value.number, via: "origin" }, |
| 853 | 874 | }); |
| 854 | return ok(getIssueById(app.db, imported.issueId)!); | |
| 875 | return ok(waitForFollowedUp(app, user.value, repo, getIssueById(app.db, imported.issueId)!)); | |
| 855 | 876 | } |
| 856 | 877 | |
| 857 | 878 | export async function addCommentThrough( |
src/actions/opened_words.ts added +17
| @@ -0,0 +1,17 @@ | ||
| 1 | /** | |
| 2 | * What opening an issue says (#12301): one place, so the issue page's flash, | |
| 3 | * the terminal's new-issue toast and a tell's answer all name the open issue | |
| 4 | * a "Follow-up to #N" made it wait for. | |
| 5 | */ | |
| 6 | ||
| 7 | /** "It waits for #N." when the opening inferred a blocker; "" otherwise. */ | |
| 8 | export function waitsWords(inferredBlocker: number | undefined): string { | |
| 9 | return inferredBlocker === undefined ? "" : `It waits for #${inferredBlocker}.`; | |
| 10 | } | |
| 11 | ||
| 12 | /** "Issue #12 opened." or "Issue #12 opened; it waits for #7." */ | |
| 13 | export function openedWords(opened: { number: number; inferredBlocker?: number }): string { | |
| 14 | return opened.inferredBlocker === undefined | |
| 15 | ? `Issue #${opened.number} opened.` | |
| 16 | : `Issue #${opened.number} opened; it waits for #${opened.inferredBlocker}.`; | |
| 17 | } |
src/actions/plan.ts +17 −1
| @@ -15,7 +15,7 @@ import { sealedScope } from "../core/sealed.ts"; | ||
| 15 | 15 | import type { App } from "../app.ts"; |
| 16 | 16 | import { crewRole, isCrew } from "../core/agents.ts"; |
| 17 | 17 | import { mapHeldFor, type HoldName } from "../crew/held.ts"; |
| 18 | import { addDependency, repoGraph, readyNow } from "../core/dependencies.ts"; | |
| 18 | import { addDependency, followUpNumber, inferFollowUpBlocker, repoGraph, readyNow } from "../core/dependencies.ts"; | |
| 19 | 19 | import { findPillar, pillarsOf, type Pillar } from "../core/pillars.ts"; |
| 20 | 20 | import { |
| 21 | 21 | createIssue, |
| @@ -171,6 +171,8 @@ export interface Planned { | ||
| 171 | 171 | readonly held: { key: string; number: number; by: HoldName; detail: string }[]; |
| 172 | 172 | /** The Later gate's number, when the plan put something behind it. */ |
| 173 | 173 | readonly gate?: number; |
| 174 | /** Opened issues whose body opens "Follow-up to #N", now waiting for that open #N (#12301). */ | |
| 175 | readonly inferred?: { key: string; number: number; blockedBy: number }[]; | |
| 174 | 176 | } |
| 175 | 177 | |
| 176 | 178 | /** "P0 Trust, P1 Feed or P2 Explorer". */ |
| @@ -361,6 +363,8 @@ export function openPlan( | ||
| 361 | 363 | const opened: { key: string; number: number }[] = []; |
| 362 | 364 | /** The links an item's purpose adds: [the issue that waits, what it waits for]. */ |
| 363 | 365 | const purpose: [Issue, Issue][] = []; |
| 366 | /** The links a body's "Follow-up to #N" adds (#12301). */ | |
| 367 | const inferred: { key: string; number: number; blockedBy: number }[] = []; | |
| 364 | 368 | const failed = transact(app.db, (): PlanError | undefined => { |
| 365 | 369 | app.db.exec("SAVEPOINT plan"); |
| 366 | 370 | const made = new Map<string, Issue>(); |
| @@ -424,6 +428,17 @@ export function openPlan( | ||
| 424 | 428 | purpose.push([waits, blocker]); |
| 425 | 429 | } |
| 426 | 430 | } |
| 431 | // "Follow-up to #N" waits for #N while it is open, unless the item already said so (#12301). | |
| 432 | for (const item of items) { | |
| 433 | const issue = made.get(item.key)!; | |
| 434 | const before = followUpNumber(issue.body); | |
| 435 | if (before === undefined || item.blockedBy.some((w) => (typeof w === "string" ? made.get(w)!.number : w) === before)) continue; | |
| 436 | const blocker = inferFollowUpBlocker(app.db, issue, actor.id); | |
| 437 | if (blocker !== undefined) { | |
| 438 | inferred.push({ key: item.key, number: issue.number, blockedBy: blocker.number }); | |
| 439 | purpose.push([issue, blocker]); | |
| 440 | } | |
| 441 | } | |
| 427 | 442 | app.db.exec("RELEASE plan"); |
| 428 | 443 | for (const item of items) |
| 429 | 444 | opened.push({ key: item.key, number: made.get(item.key)!.number }); |
| @@ -477,5 +492,6 @@ export function openPlan( | ||
| 477 | 492 | held, |
| 478 | 493 | later: deferred, |
| 479 | 494 | ...(deferred.length > 0 && gate ? { gate: gate.number } : {}), |
| 495 | ...(inferred.length > 0 ? { inferred } : {}), | |
| 480 | 496 | }); |
| 481 | 497 | } |
src/actions/tell.ts +20 −3
| @@ -16,7 +16,8 @@ import { mayDirectCrew } from "../crew/direct.ts"; | ||
| 16 | 16 | import { routeIssue, type Routed } from "../crew/route.ts"; |
| 17 | 17 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 18 | 18 | import { requireParticipant } from "./access.ts"; |
| 19 | import { assignIssue, openIssue, type MirrorError } from "./issues.ts"; | |
| 19 | import { assignIssue, openIssue, type MirrorError, type Opened } from "./issues.ts"; | |
| 20 | import { waitsWords } from "./opened_words.ts"; | |
| 20 | 21 | import { parseFrom } from "./tell_from.ts"; |
| 21 | 22 | import { requireVerified } from "./verify.ts"; |
| 22 | 23 | import { VERIFY_FIRST } from "./verify_words.ts"; |
| @@ -33,6 +34,8 @@ export interface Told { | ||
| 33 | 34 | readonly assignedNumbers: readonly number[]; |
| 34 | 35 | /** The group the variants share; null for an ordinary tell. */ |
| 35 | 36 | readonly variantGroup: string | null; |
| 37 | /** The open issue the first one waits for, from its "Follow-up to #N" (#12301). */ | |
| 38 | readonly inferredBlocker?: number; | |
| 36 | 39 | } |
| 37 | 40 | |
| 38 | 41 | /** The longest title a tell keeps whole; a longer first line is cut and the body keeps it all. */ |
| @@ -115,7 +118,7 @@ export async function tell( | ||
| 115 | 118 | for (const r of listRuns(app.db, repo.id, { kind: "agent", limit: 50 })) |
| 116 | 119 | if ((r.state === "running" || r.state === "queued") && r.actorId !== null) |
| 117 | 120 | inFlight.set(r.actorId, (inFlight.get(r.actorId) ?? 0) + 1); |
| 118 | const issues: Issue[] = []; | |
| 121 | const issues: Opened[] = []; | |
| 119 | 122 | let routed: Routed | undefined; |
| 120 | 123 | let assigned = false; |
| 121 | 124 | const assignedNumbers: number[] = []; |
| @@ -153,7 +156,16 @@ export async function tell( | ||
| 153 | 156 | return ok(told()); |
| 154 | 157 | |
| 155 | 158 | function told(): Told { |
| 156 | return { issue: issues[0]!, routed, assigned, issues, assignedNumbers, variantGroup }; | |
| 159 | const inferredBlocker = issues[0]!.inferredBlocker; | |
| 160 | return { | |
| 161 | issue: issues[0]!, | |
| 162 | routed, | |
| 163 | assigned, | |
| 164 | issues, | |
| 165 | assignedNumbers, | |
| 166 | variantGroup, | |
| 167 | ...(inferredBlocker === undefined ? {} : { inferredBlocker }), | |
| 168 | }; | |
| 157 | 169 | } |
| 158 | 170 | } |
| 159 | 171 | |
| @@ -165,6 +177,11 @@ export const TOO_LONG_WORDS = "That is too long to tell in one go."; | ||
| 165 | 177 | |
| 166 | 178 | /** What happened, in the sentence both doors say. */ |
| 167 | 179 | export function toldWords(told: Told): string { |
| 180 | const waits = waitsWords(told.inferredBlocker); | |
| 181 | return waits === "" ? routedWords(told) : `${routedWords(told)} ${waits}`; | |
| 182 | } | |
| 183 | ||
| 184 | function routedWords(told: Told): string { | |
| 168 | 185 | if (told.routed === undefined) |
| 169 | 186 | return `Opened as issue #${told.issue.number}. Nobody is on the crew to take it yet — add someone under Settings → Crew.`; |
| 170 | 187 | const r = told.routed; |
src/core/dependencies.ts +32 −1
| @@ -10,7 +10,7 @@ | ||
| 10 | 10 | |
| 11 | 11 | import type { Database } from "bun:sqlite"; |
| 12 | 12 | import { err, ok, type Result } from "../kernel/result.ts"; |
| 13 | import { getIssuesByIds, getIssuesOfRepo, type CloseReason, type Issue } from "./issues.ts"; | |
| 13 | import { getIssue, getIssuesByIds, getIssuesOfRepo, type CloseReason, type Issue } from "./issues.ts"; | |
| 14 | 14 | import { pillarsOf, structuralIds, type Pillars } from "./pillars.ts"; |
| 15 | 15 | import { getRepoById, isGo, type Repo } from "./repos.ts"; |
| 16 | 16 | import { unadoptedAmong } from "../crew/direct.ts"; |
| @@ -56,6 +56,37 @@ export function addDependency( | ||
| 56 | 56 | return ok(undefined); |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | /** | |
| 60 | * The issue number a body names when it opens "Follow-up to #N" or | |
| 61 | * "Split from #N" (#12301): what was written as groundwork-first, said in | |
| 62 | * words. Only the opening counts; a mention further down is not a plan. | |
| 63 | */ | |
| 64 | export function followUpNumber(body: string): number | undefined { | |
| 65 | const m = /^\s*(?:follow-up to|split from)\s+#(\d{1,9})\b/i.exec(body); | |
| 66 | return m === null ? undefined : Number(m[1]); | |
| 67 | } | |
| 68 | ||
| 69 | /** | |
| 70 | * A new issue whose body opens "Follow-up to #N" waits for #N, while #N is | |
| 71 | * an open issue of the same repository (#12301). A closed #N, an unknown | |
| 72 | * number, a pull, or a link that would make a cycle adds nothing, and the | |
| 73 | * issue stands as it is. A sealed #N adds nothing either, whoever writes | |
| 74 | * it: anyone who may open an issue may write "Follow-up to #N", and an | |
| 75 | * answer of "it waits for #N" would tell them a sealed #N exists and is | |
| 76 | * open (`core/sealed.ts`). Answers the blocker it linked, if any. | |
| 77 | */ | |
| 78 | export function inferFollowUpBlocker( | |
| 79 | db: Database, | |
| 80 | issue: Issue, | |
| 81 | actorId: string | undefined, | |
| 82 | ): Issue | undefined { | |
| 83 | const n = followUpNumber(issue.body); | |
| 84 | if (n === undefined) return undefined; | |
| 85 | const blocker = getIssue(db, issue.repoId, n); | |
| 86 | if (blocker === undefined || blocker.state !== "open" || blocker.sealed) return undefined; | |
| 87 | return addDependency(db, issue, blocker, actorId).ok ? blocker : undefined; | |
| 88 | } | |
| 89 | ||
| 59 | 90 | export function removeDependency( |
| 60 | 91 | db: Database, |
| 61 | 92 | issueId: string, |
src/http/mcp/tools/plan.ts +4 −2
| @@ -66,17 +66,19 @@ export const tool: Tool = { | ||
| 66 | 66 | } |
| 67 | 67 | const planned = openPlan(ctx.app, user, repo, items.value); |
| 68 | 68 | if (!planned.ok) return bad(planned.error.error, planned.error.message); |
| 69 | const { opened, ready, held, later, gate } = planned.value; | |
| 69 | const { opened, ready, held, later, gate, inferred } = planned.value; | |
| 70 | 70 | const waits = |
| 71 | 71 | gate === undefined |
| 72 | 72 | ? "" |
| 73 | 73 | : ` ${later.map((n) => `#${n}`).join(", ")} wait${later.length === 1 ? "s" : ""} behind the Later gate #${gate}.`; |
| 74 | const follows = (inferred ?? []).map((i) => ` #${i.number} waits for #${i.blockedBy}, its "Follow-up to".`).join(""); | |
| 74 | 75 | return good({ |
| 75 | says: `Opened ${opened.length} issue${opened.length === 1 ? "" : "s"}: ${opened.map((o) => `${o.key} is #${o.number}`).join(", ")}.${waits}`, | |
| 76 | says: `Opened ${opened.length} issue${opened.length === 1 ? "" : "s"}: ${opened.map((o) => `${o.key} is #${o.number}`).join(", ")}.${waits}${follows}`, | |
| 76 | 77 | opened, |
| 77 | 78 | ready, |
| 78 | 79 | held, |
| 79 | 80 | later, |
| 81 | ...(inferred === undefined ? {} : { inferred }), | |
| 80 | 82 | }); |
| 81 | 83 | }, |
| 82 | 84 | }; |
src/tui/screens/issues.ts +2 −1
| @@ -10,6 +10,7 @@ | ||
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | 12 | import { openIssueThrough } from "../../actions/issues.ts"; |
| 13 | import { openedWords } from "../../actions/opened_words.ts"; | |
| 13 | 14 | import type { IssueKind, Label } from "../../core/issues.ts"; |
| 14 | 15 | import { getIssuesByNumbers, numberKey } from "../../core/issues.ts"; |
| 15 | 16 | import { LATER, pillarsOf, servedBy, type Pillar } from "../../core/pillars.ts"; |
| @@ -473,7 +474,7 @@ export function newIssueScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 473 | 474 | ctx.toast(error, "danger"); |
| 474 | 475 | return; |
| 475 | 476 | } |
| 476 | ctx.toast(`opened #${created.value.number}`, "success"); | |
| 477 | ctx.toast(openedWords(created.value), "success"); | |
| 477 | 478 | ctx.replace(issueScreen(f, ctx, local(f, repo), created.value.number)); |
| 478 | 479 | }); |
| 479 | 480 | }; |
src/web/pages/issues.ts +2 −1
| @@ -15,6 +15,7 @@ import type { Issue } from "../../core/issues.ts"; | ||
| 15 | 15 | import { canRead, getRepo, listReposWritableTo, type Repo } from "../../core/repos.ts"; |
| 16 | 16 | import { privateRepoForSealed } from "../../actions/repos.ts"; |
| 17 | 17 | import { sealedWords, sealRefusedWords } from "../../actions/seal_issue_words.ts"; |
| 18 | import { openedWords } from "../../actions/opened_words.ts"; | |
| 18 | 19 | import { BODY_TOO_LONG, TITLE_TOO_LONG } from "../../actions/thread_limits_words.ts"; |
| 19 | 20 | import { COMMENT_EMPTY, COMMENT_NOT_POSTED } from "../../actions/comment_words.ts"; |
| 20 | 21 | import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts"; |
| @@ -269,7 +270,7 @@ export async function newIssueSubmit(ctx: Ctx): Promise<Response> { | ||
| 269 | 270 | return composePage(ctx, repo, typed, message); |
| 270 | 271 | } |
| 271 | 272 | return flashTo(ctx, `${repoBase(repo)}/issues/${created.value.number}`, { |
| 272 | message: `Issue #${created.value.number} opened.`, | |
| 273 | message: openedWords(created.value), | |
| 273 | 274 | }); |
| 274 | 275 | } |
| 275 | 276 |
test/follow-up-blocks.test.ts added +253
| @@ -0,0 +1,253 @@ | ||
| 1 | /** | |
| 2 | * An issue whose body opens "Follow-up to #N" or "Split from #N" waits for | |
| 3 | * #N on the map while #N is open (#12301): through the action every door | |
| 4 | * calls, and every door says it — the API's create answer, the plan route's | |
| 5 | * answer, the issue page's flash, a tell's answer and the terminal's toast. | |
| 6 | */ | |
| 7 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; | |
| 8 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 9 | import { tmpdir } from "node:os"; | |
| 10 | import { join } from "node:path"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { openIssue, setIssueSealed, setIssueState } from "../src/actions/issues.ts"; | |
| 13 | import { createRepo } from "../src/actions/repos.ts"; | |
| 14 | import { dependenciesOf, followUpNumber } from "../src/core/dependencies.ts"; | |
| 15 | import { getIssue, type Issue } from "../src/core/issues.ts"; | |
| 16 | import type { Repo } from "../src/core/repos.ts"; | |
| 17 | import { createToken } from "../src/core/tokens.ts"; | |
| 18 | import { createUser, type User } from "../src/core/users.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import { tell, toldWords } from "../src/actions/tell.ts"; | |
| 21 | import { createSession } from "../src/core/sessions.ts"; | |
| 22 | import { createForgeApp } from "../src/tui/forge.ts"; | |
| 23 | import { newIssueScreen } from "../src/tui/screens/issues.ts"; | |
| 24 | import { headlessTerminal } from "../src/tui/term/terminal.ts"; | |
| 25 | import { proveAll } from "./helpers/verified.ts"; | |
| 26 | import { quietLogs } from "./helpers/globals.ts"; | |
| 27 | import { settleApp } from "./helpers/tui.ts"; | |
| 28 | ||
| 29 | quietLogs(); | |
| 30 | ||
| 31 | describe("follow-up blocks", () => { | |
| 32 | let dataDir: string; | |
| 33 | let app: App; | |
| 34 | let servers: Servers; | |
| 35 | let alice: User; | |
| 36 | let token: string; | |
| 37 | let repo: Repo; | |
| 38 | let other: Repo; | |
| 39 | ||
| 40 | const open = (title: string, body = "", into: Repo = repo) => { | |
| 41 | const made = openIssue(app, alice, into, { title, body }); | |
| 42 | if (!made.ok) throw new Error(String(made.error)); | |
| 43 | return made.value; | |
| 44 | }; | |
| 45 | const blockersOf = (issue: Issue) => | |
| 46 | dependenciesOf(app.db, issue.id).blockedBy.map((b) => b.number); | |
| 47 | const post = (path: string, data: unknown) => | |
| 48 | fetch(`${servers.url}/api/v1/repos/alice/${path}`, { | |
| 49 | method: "POST", | |
| 50 | headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, | |
| 51 | body: JSON.stringify(data), | |
| 52 | }); | |
| 53 | ||
| 54 | beforeAll(async () => { | |
| 55 | dataDir = await mkdtemp(join(tmpdir(), "forge-follow-up-")); | |
| 56 | app = createApp({ dataDir, port: 0 }); | |
| 57 | servers = await serve(app); | |
| 58 | const a = await createUser(app.db, { | |
| 59 | origin: "seed", | |
| 60 | trusted: true, | |
| 61 | username: "alice", | |
| 62 | email: "[email protected]", | |
| 63 | password: "a-good-passphrase", | |
| 64 | adminIfFirst: true, | |
| 65 | }); | |
| 66 | if (!a.ok) throw new Error(a.error); | |
| 67 | alice = a.value; | |
| 68 | token = createToken(app.db, alice.id, "test", "rw").token; | |
| 69 | const made = await createRepo(app, alice, { name: "engine", visibility: "private" }); | |
| 70 | if (!made.ok) throw new Error(String(made.error)); | |
| 71 | repo = made.value; | |
| 72 | const second = await createRepo(app, alice, { name: "other", visibility: "private" }); | |
| 73 | if (!second.ok) throw new Error(String(second.error)); | |
| 74 | other = second.value; | |
| 75 | proveAll(app); | |
| 76 | }); | |
| 77 | ||
| 78 | afterAll(async () => { | |
| 79 | servers.stop(); | |
| 80 | app.close(); | |
| 81 | await rm(dataDir, { recursive: true, force: true }); | |
| 82 | }); | |
| 83 | ||
| 84 | test("only the opening words count", () => { | |
| 85 | expect(followUpNumber("Follow-up to #12, which landed the groundwork.")).toBe(12); | |
| 86 | expect(followUpNumber(" split from #7\n\nmore")).toBe(7); | |
| 87 | expect(followUpNumber("This is a follow-up to #12.")).toBeUndefined(); | |
| 88 | expect(followUpNumber("Follow-up to issue 12")).toBeUndefined(); | |
| 89 | }); | |
| 90 | ||
| 91 | test("an open #N in the same repository becomes the blocker", () => { | |
| 92 | const ground = open("Groundwork"); | |
| 93 | const next = open("Build on it", `Follow-up to #${ground.number}\n\nThe rest.`); | |
| 94 | expect(next.inferredBlocker).toBe(ground.number); | |
| 95 | expect(blockersOf(next)).toEqual([ground.number]); | |
| 96 | const split = open("A piece", `Split from #${ground.number}.`); | |
| 97 | expect(blockersOf(split)).toEqual([ground.number]); | |
| 98 | }); | |
| 99 | ||
| 100 | test("a closed #N, an unknown number or another repository adds nothing", () => { | |
| 101 | const done = open("Done already"); | |
| 102 | const closed = setIssueState(app, alice, repo, done, "closed"); | |
| 103 | if (!closed.ok) throw new Error(String(closed.error)); | |
| 104 | const afterClosed = open("After a closed one", `Follow-up to #${done.number}`); | |
| 105 | expect(afterClosed.inferredBlocker).toBeUndefined(); | |
| 106 | expect(blockersOf(afterClosed)).toEqual([]); | |
| 107 | ||
| 108 | const unknown = open("After nothing", "Follow-up to #9999"); | |
| 109 | expect(unknown.inferredBlocker).toBeUndefined(); | |
| 110 | expect(blockersOf(unknown)).toEqual([]); | |
| 111 | ||
| 112 | // #1 is open in `engine`; from `other` it names other's own #1, which does not exist. | |
| 113 | const elsewhere = open("Elsewhere", "Follow-up to #1", other); | |
| 114 | expect(elsewhere.inferredBlocker).toBeUndefined(); | |
| 115 | expect(blockersOf(elsewhere)).toEqual([]); | |
| 116 | }); | |
| 117 | ||
| 118 | test("a sealed #N adds nothing, so a non-writer learns nothing of it", async () => { | |
| 119 | const pub = await createRepo(app, alice, { name: "public-engine", visibility: "public" }); | |
| 120 | if (!pub.ok) throw new Error(String(pub.error)); | |
| 121 | const b = await createUser(app.db, { | |
| 122 | origin: "seed", | |
| 123 | trusted: true, | |
| 124 | username: "bob", | |
| 125 | email: "[email protected]", | |
| 126 | password: "a-good-passphrase", | |
| 127 | }); | |
| 128 | if (!b.ok) throw new Error(b.error); | |
| 129 | const report = open("A hole", "", pub.value); | |
| 130 | const sealed = setIssueSealed(app, alice, pub.value, report, true); | |
| 131 | if (!sealed.ok) throw new Error(String(sealed.error)); | |
| 132 | const guess = openIssue(app, b.value, pub.value, { | |
| 133 | title: "Guessing", | |
| 134 | body: `Follow-up to #${report.number}`, | |
| 135 | }); | |
| 136 | if (!guess.ok) throw new Error(String(guess.error)); | |
| 137 | expect(guess.value.inferredBlocker).toBeUndefined(); | |
| 138 | expect(blockersOf(guess.value)).toEqual([]); | |
| 139 | // A writer's follow-up skips it too: the edge would show on the map to readers. | |
| 140 | const mine = open("Mine", `Follow-up to #${report.number}`, pub.value); | |
| 141 | expect(mine.inferredBlocker).toBeUndefined(); | |
| 142 | expect(blockersOf(mine)).toEqual([]); | |
| 143 | }); | |
| 144 | ||
| 145 | test("a blocker that would make a cycle is not added, and the plan still opens", async () => { | |
| 146 | // A new issue has nothing waiting on it, so a loop needs the plan route: | |
| 147 | // `first` waits for `second`, whose body names `first`'s coming number. | |
| 148 | const probe = open("Probe"); | |
| 149 | const res = await post("engine/plan", { | |
| 150 | issues: [ | |
| 151 | { key: "first", title: "First", blockedBy: ["second"] }, | |
| 152 | { key: "second", title: "Second", body: `Follow-up to #${probe.number + 1}` }, | |
| 153 | ], | |
| 154 | }); | |
| 155 | expect(res.status).toBe(201); | |
| 156 | const planned = (await res.json()) as { | |
| 157 | opened: { key: string; number: number }[]; | |
| 158 | inferred?: unknown; | |
| 159 | }; | |
| 160 | const [first, second] = planned.opened; | |
| 161 | expect(first!.number).toBe(probe.number + 1); | |
| 162 | expect(planned.inferred).toBeUndefined(); | |
| 163 | expect(blockersOf(getIssue(app.db, repo.id, first!.number)!)).toEqual([second!.number]); | |
| 164 | expect(blockersOf(getIssue(app.db, repo.id, second!.number)!)).toEqual([]); | |
| 165 | }); | |
| 166 | ||
| 167 | test("the API's create answer names the inferred blocker", async () => { | |
| 168 | const ground = open("API groundwork"); | |
| 169 | const res = await post("engine/issues", { | |
| 170 | title: "API follow-up", | |
| 171 | body: `Follow-up to #${ground.number}`, | |
| 172 | }); | |
| 173 | expect(res.status).toBe(201); | |
| 174 | const made = (await res.json()) as { number: number; inferredBlocker?: number }; | |
| 175 | expect(made.inferredBlocker).toBe(ground.number); | |
| 176 | ||
| 177 | const plain = await post("engine/issues", { title: "Unrelated" }); | |
| 178 | expect(((await plain.json()) as { inferredBlocker?: number }).inferredBlocker).toBeUndefined(); | |
| 179 | }); | |
| 180 | ||
| 181 | test("the plan route links and reports a follow-up, and skips a closed one", async () => { | |
| 182 | const ground = open("Plan groundwork"); | |
| 183 | const gone = open("Plan gone"); | |
| 184 | setIssueState(app, alice, repo, gone, "closed"); | |
| 185 | const res = await post("engine/plan", { | |
| 186 | issues: [ | |
| 187 | { key: "next", title: "Next step", body: `Follow-up to #${ground.number}` }, | |
| 188 | { key: "late", title: "Late step", body: `Split from #${gone.number}` }, | |
| 189 | ], | |
| 190 | }); | |
| 191 | expect(res.status).toBe(201); | |
| 192 | const planned = (await res.json()) as { | |
| 193 | opened: { key: string; number: number }[]; | |
| 194 | inferred?: { key: string; number: number; blockedBy: number }[]; | |
| 195 | }; | |
| 196 | const next = planned.opened.find((o) => o.key === "next")!; | |
| 197 | expect(planned.inferred).toEqual([{ key: "next", number: next.number, blockedBy: ground.number }]); | |
| 198 | }); | |
| 199 | ||
| 200 | test("the issue page's flash says what the new issue waits for", async () => { | |
| 201 | const ground = open("Page groundwork"); | |
| 202 | const cookie = `forge_session=${createSession(app.db, alice.id).token}`; | |
| 203 | const made = await fetch(`${servers.url}/alice/engine/issues/new`, { | |
| 204 | method: "POST", | |
| 205 | headers: { cookie }, | |
| 206 | body: new URLSearchParams({ title: "Page follow-up", body: `Follow-up to #${ground.number}` }), | |
| 207 | redirect: "manual", | |
| 208 | }); | |
| 209 | expect(made.status).toBe(303); | |
| 210 | const flash = made.headers.getSetCookie().map((c) => c.split(";")[0]!).join("; "); | |
| 211 | const shown = await ( | |
| 212 | await fetch(`${servers.url}${made.headers.get("location")}`, { | |
| 213 | headers: { cookie: `${cookie}; ${flash}` }, | |
| 214 | }) | |
| 215 | ).text(); | |
| 216 | expect(shown).toContain(`opened; it waits for #${ground.number}.`); | |
| 217 | }); | |
| 218 | ||
| 219 | test("a tell's answer says what the new issue waits for", async () => { | |
| 220 | const ground = open("Tell groundwork"); | |
| 221 | const told = await tell(app, alice, repo, `Build the next part\n\nFollow-up to #${ground.number}`); | |
| 222 | if (!told.ok) throw new Error(told.error); | |
| 223 | // The body is what follows the title, so the opening words are the body's. | |
| 224 | expect(told.value.inferredBlocker).toBe(ground.number); | |
| 225 | expect(toldWords(told.value)).toEndWith(`It waits for #${ground.number}.`); | |
| 226 | ||
| 227 | const plain = await tell(app, alice, repo, "Something else entirely"); | |
| 228 | if (!plain.ok) throw new Error(plain.error); | |
| 229 | expect(toldWords(plain.value)).not.toContain("waits for"); | |
| 230 | }); | |
| 231 | ||
| 232 | test("the terminal's new-issue toast says what the new issue waits for", async () => { | |
| 233 | const ground = open("Terminal groundwork"); | |
| 234 | const { app: tui, session } = createForgeApp( | |
| 235 | app, | |
| 236 | { sshUsername: "t", remoteAddress: "127.0.0.1", user: alice }, | |
| 237 | { terminal: headlessTerminal(140, 40), exitHooks: false }, | |
| 238 | ); | |
| 239 | tui.start(); | |
| 240 | await settleApp(tui); | |
| 241 | tui.push(newIssueScreen(session, tui.ctx, repo)); | |
| 242 | await settleApp(tui); | |
| 243 | const key = (k: string, ctrl = false) => | |
| 244 | tui.dispatch({ type: "key", key: k, ctrl, alt: false, shift: false }); | |
| 245 | tui.dispatch({ type: "paste", text: "Terminal follow-up" }); | |
| 246 | key("tab"); | |
| 247 | tui.dispatch({ type: "paste", text: `Follow-up to #${ground.number}` }); | |
| 248 | key("d", true); | |
| 249 | await settleApp(tui); | |
| 250 | expect(tui.screen.toText()).toContain(`opened; it waits for #${ground.number}.`); | |
| 251 | tui.stop?.(); | |
| 252 | }); | |
| 253 | }); |
test/origin-issues.test.ts +14
| @@ -6,6 +6,7 @@ import { addCommentThrough, openIssueThrough } from "../src/actions/issues.ts"; | ||
| 6 | 6 | import { createApp, type App } from "../src/app.ts"; |
| 7 | 7 | import { getOriginById } from "../src/core/origins.ts"; |
| 8 | 8 | import { getRepo } from "../src/core/repos.ts"; |
| 9 | import { dependenciesOf } from "../src/core/dependencies.ts"; | |
| 9 | 10 | import { createToken } from "../src/core/tokens.ts"; |
| 10 | 11 | import { getUserByName } from "../src/core/users.ts"; |
| 11 | 12 | import { serve, type Servers } from "../src/http/server.ts"; |
| @@ -106,6 +107,19 @@ describe("issues on a repository brought from another forge", () => { | ||
| 106 | 107 | for (const dir of dirs) await rm(dir, { recursive: true, force: true, maxRetries: 5 }); |
| 107 | 108 | }, 120_000); |
| 108 | 109 | |
| 110 | test("a follow-up opened here waits for the open issue it names, as on a repository of our own (#12301)", async () => { | |
| 111 | const alice = getUserByName(mine.db, "alice")!; | |
| 112 | const ground = await openIssueThrough(mine, alice, mirror(), { title: "Groundwork", body: "" }); | |
| 113 | if (!ground.ok) throw new Error(ground.error); | |
| 114 | const next = await openIssueThrough(mine, alice, mirror(), { | |
| 115 | title: "On top", | |
| 116 | body: `Follow-up to #${ground.value.number}`, | |
| 117 | }); | |
| 118 | if (!next.ok) throw new Error(next.error); | |
| 119 | expect(next.value.inferredBlocker).toBe(ground.value.number); | |
| 120 | expect(dependenciesOf(mine.db, next.value.id).blockedBy.map((b) => b.number)).toEqual([ground.value.number]); | |
| 121 | }); | |
| 122 | ||
| 109 | 123 | test("an issue and a comment opened here are written to the origin as the connected account", async () => { |
| 110 | 124 | const alice = getUserByName(mine.db, "alice")!; |
| 111 | 125 | const opened = await openIssueThrough(mine, alice, mirror(), { title: "It breaks", body: "on start" }); |
new above
offline
High: a sealed open issue is accepted as a blocker here. Refuse when
blocker.sealed, or the "it waits for #N" answer tells a non-writer that sealed #N exists and is open. Add a test.