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

Closed opened this
Closed without merging

mason/forge:mason/12301-an-issue-whose-body-opens-follow-up-to-n → main 6 commits fork 4 threads · 4 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
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
495495 over-long title or body, or more than 12 items refuses the whole plan, naming
496496 the item, and nothing is opened. Issues belong to the token's owner and emit
497497 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".
498505
499506 Where the app has pillars (docs/PLANNING.md), every item also says what it
500507 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";
2727 import { pausedUntil } from "../core/planner_pause.ts";
2828 import { keepWithinChapter } from "./chapters.ts";
2929 import { inheritChapter } from "../core/chapters.ts";
30 import { moveBlockersToChildren } from "../core/dependencies.ts";
30 import { inferFollowUpBlocker, moveBlockersToChildren } from "../core/dependencies.ts";
3131 import {
3232 addComment as insertComment,
3333 createIssue,
@@ -74,7 +74,7 @@ import { err, ok, type Result } from "../kernel/result.ts";
7474 import { clearFirst } from "../core/first.ts";
7575 import { clearRank } from "../core/rank.ts";
7676 import { followLabel } from "./gate.ts";
77 import { inheritPillar } from "./pillars.ts";
77 import { followLink, inheritPillar } from "./pillars.ts";
7878 import {
7979 requireParticipant,
8080 requireWriter,
@@ -96,7 +96,7 @@ export function openIssue(
9696 repo: Repo,
9797 input: { title: string; body?: string; sealed?: boolean },
9898 ): Result<
99 Issue,
99 Opened,
100100 "not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long" | MirrorError
101101 > {
102102 const user = requireParticipant(app, actor, repo);
@@ -129,9 +129,30 @@ export function openIssue(
129129 actorId: user.value.id,
130130 payload: { number: created.value.number },
131131 });
132 return created;
132 return ok(waitForFollowedUp(app, user.value, repo, created.value));
133133 }
134134
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
135156 export type EditError =
136157 | AccessError
137158 | MirrorError
@@ -816,7 +837,7 @@ export async function openIssueThrough(
816837 },
817838 ): Promise<
818839 Result<
819 Issue,
840 Opened,
820841 ThroughError<"not_found" | "unauthorized" | "planner_paused" | TitleError | "body_too_long">
821842 >
822843 > {
@@ -851,7 +872,7 @@ export async function openIssueThrough(
851872 actorId: user.value.id,
852873 payload: { number: created.value.number, via: "origin" },
853874 });
854 return ok(getIssueById(app.db, imported.issueId)!);
875 return ok(waitForFollowedUp(app, user.value, repo, getIssueById(app.db, imported.issueId)!));
855876 }
856877
857878 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";
1515 import type { App } from "../app.ts";
1616 import { crewRole, isCrew } from "../core/agents.ts";
1717 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";
1919 import { findPillar, pillarsOf, type Pillar } from "../core/pillars.ts";
2020 import {
2121 createIssue,
@@ -171,6 +171,8 @@ export interface Planned {
171171 readonly held: { key: string; number: number; by: HoldName; detail: string }[];
172172 /** The Later gate's number, when the plan put something behind it. */
173173 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 }[];
174176 }
175177
176178 /** "P0 Trust, P1 Feed or P2 Explorer". */
@@ -361,6 +363,8 @@ export function openPlan(
361363 const opened: { key: string; number: number }[] = [];
362364 /** The links an item's purpose adds: [the issue that waits, what it waits for]. */
363365 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 }[] = [];
364368 const failed = transact(app.db, (): PlanError | undefined => {
365369 app.db.exec("SAVEPOINT plan");
366370 const made = new Map<string, Issue>();
@@ -424,6 +428,17 @@ export function openPlan(
424428 purpose.push([waits, blocker]);
425429 }
426430 }
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 }
427442 app.db.exec("RELEASE plan");
428443 for (const item of items)
429444 opened.push({ key: item.key, number: made.get(item.key)!.number });
@@ -477,5 +492,6 @@ export function openPlan(
477492 held,
478493 later: deferred,
479494 ...(deferred.length > 0 && gate ? { gate: gate.number } : {}),
495 ...(inferred.length > 0 ? { inferred } : {}),
480496 });
481497 }
src/actions/tell.ts +20 −3
@@ -16,7 +16,8 @@ import { mayDirectCrew } from "../crew/direct.ts";
1616 import { routeIssue, type Routed } from "../crew/route.ts";
1717 import { err, ok, type Result } from "../kernel/result.ts";
1818 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";
2021 import { parseFrom } from "./tell_from.ts";
2122 import { requireVerified } from "./verify.ts";
2223 import { VERIFY_FIRST } from "./verify_words.ts";
@@ -33,6 +34,8 @@ export interface Told {
3334 readonly assignedNumbers: readonly number[];
3435 /** The group the variants share; null for an ordinary tell. */
3536 readonly variantGroup: string | null;
37 /** The open issue the first one waits for, from its "Follow-up to #N" (#12301). */
38 readonly inferredBlocker?: number;
3639 }
3740
3841 /** 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(
115118 for (const r of listRuns(app.db, repo.id, { kind: "agent", limit: 50 }))
116119 if ((r.state === "running" || r.state === "queued") && r.actorId !== null)
117120 inFlight.set(r.actorId, (inFlight.get(r.actorId) ?? 0) + 1);
118 const issues: Issue[] = [];
121 const issues: Opened[] = [];
119122 let routed: Routed | undefined;
120123 let assigned = false;
121124 const assignedNumbers: number[] = [];
@@ -153,7 +156,16 @@ export async function tell(
153156 return ok(told());
154157
155158 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 };
157169 }
158170 }
159171
@@ -165,6 +177,11 @@ export const TOO_LONG_WORDS = "That is too long to tell in one go.";
165177
166178 /** What happened, in the sentence both doors say. */
167179 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 {
168185 if (told.routed === undefined)
169186 return `Opened as issue #${told.issue.number}. Nobody is on the crew to take it yet — add someone under Settings → Crew.`;
170187 const r = told.routed;
src/core/dependencies.ts +32 −1
@@ -10,7 +10,7 @@
1010
1111 import type { Database } from "bun:sqlite";
1212 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";
1414 import { pillarsOf, structuralIds, type Pillars } from "./pillars.ts";
1515 import { getRepoById, isGo, type Repo } from "./repos.ts";
1616 import { unadoptedAmong } from "../crew/direct.ts";
@@ -56,6 +56,37 @@ export function addDependency(
5656 return ok(undefined);
5757 }
5858
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;
outdated

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.

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
5990 export function removeDependency(
6091 db: Database,
6192 issueId: string,
src/http/mcp/tools/plan.ts +4 −2
@@ -66,17 +66,19 @@ export const tool: Tool = {
6666 }
6767 const planned = openPlan(ctx.app, user, repo, items.value);
6868 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;
7070 const waits =
7171 gate === undefined
7272 ? ""
7373 : ` ${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("");
7475 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}`,
7677 opened,
7778 ready,
7879 held,
7980 later,
81 ...(inferred === undefined ? {} : { inferred }),
8082 });
8183 },
8284 };
src/tui/screens/issues.ts +2 −1
@@ -10,6 +10,7 @@
1010 */
1111
1212 import { openIssueThrough } from "../../actions/issues.ts";
13 import { openedWords } from "../../actions/opened_words.ts";
1314 import type { IssueKind, Label } from "../../core/issues.ts";
1415 import { getIssuesByNumbers, numberKey } from "../../core/issues.ts";
1516 import { LATER, pillarsOf, servedBy, type Pillar } from "../../core/pillars.ts";
@@ -473,7 +474,7 @@ export function newIssueScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
473474 ctx.toast(error, "danger");
474475 return;
475476 }
476 ctx.toast(`opened #${created.value.number}`, "success");
477 ctx.toast(openedWords(created.value), "success");
477478 ctx.replace(issueScreen(f, ctx, local(f, repo), created.value.number));
478479 });
479480 };
src/web/pages/issues.ts +2 −1
@@ -15,6 +15,7 @@ import type { Issue } from "../../core/issues.ts";
1515 import { canRead, getRepo, listReposWritableTo, type Repo } from "../../core/repos.ts";
1616 import { privateRepoForSealed } from "../../actions/repos.ts";
1717 import { sealedWords, sealRefusedWords } from "../../actions/seal_issue_words.ts";
18 import { openedWords } from "../../actions/opened_words.ts";
1819 import { BODY_TOO_LONG, TITLE_TOO_LONG } from "../../actions/thread_limits_words.ts";
1920 import { COMMENT_EMPTY, COMMENT_NOT_POSTED } from "../../actions/comment_words.ts";
2021 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
@@ -269,7 +270,7 @@ export async function newIssueSubmit(ctx: Ctx): Promise<Response> {
269270 return composePage(ctx, repo, typed, message);
270271 }
271272 return flashTo(ctx, `${repoBase(repo)}/issues/${created.value.number}`, {
outdated

The page says it waits for #N. The terminal's new-issue toast and toldWords in src/actions/tell.ts do not, so the two doors differ. Say it in both and test it.

272 message: `Issue #${created.value.number} opened.`,
273 message: openedWords(created.value),
273274 });
274275 }
275276
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;
outdated

No test covers the page flash, the tell answer or the terminal wording. Add one for each door that says the blocker.

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";
66 import { createApp, type App } from "../src/app.ts";
77 import { getOriginById } from "../src/core/origins.ts";
88 import { getRepo } from "../src/core/repos.ts";
9 import { dependenciesOf } from "../src/core/dependencies.ts";
910 import { createToken } from "../src/core/tokens.ts";
1011 import { getUserByName } from "../src/core/users.ts";
1112 import { serve, type Servers } from "../src/http/server.ts";
@@ -106,6 +107,19 @@ describe("issues on a repository brought from another forge", () => {
106107 for (const dir of dirs) await rm(dir, { recursive: true, force: true, maxRetries: 5 });
107108 }, 120_000);
108109
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
109123 test("an issue and a comment opened here are written to the origin as the connected account", async () => {
110124 const alice = getUserByName(mine.db, "alice")!;
111125 const opened = await openIssueThrough(mine, alice, mirror(), { title: "It breaks", body: "on start" });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs