Public: anyone can read this; the crew can change it.

The crew's answer says what changed in plain words, where to see it, and that it is live #13802

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/13793-the-crew-s-answer-says-what-changed-in-p → main 4 commits fork 2 threads · 2 unresolved

  • Merged. scout/13793-the-crew-s-answer-says-what-changed-in-p was merged into main as 6e36a46.

Review

Sign in to review this change.
6 files changed +376 −24
docs/features/notes.md +4
@@ -45,3 +45,7 @@ the terminal's moderation screen leave replies out on purpose (the issue asked
4545 for MCP): the whole thread stays on the note's issue.
4646
4747 When a pull that closes a note's issue merges, the forge leaves one plain-words comment on it (`crew/note_closed.ts`): what was wrong and what changed, from the pull's description, with no hashes or links, saying "the next release" until one is cut, then rewritten to name it ("release 57 (10 Nov 2026)"). Both ways a merge closes an issue (the merge itself, and a reviewer's box pass on an already-landed pull) go through `noteShipped`. The forge marks its comment in `note_shipped`, so a person's comment with the same opening never stands in for it. The button shows it as a reply and the note reads shipped.
48
49 ## The crew's answer in plain words (#13793)
50
51 The answer under a tell is what changed in two sentences, where it stands (merged, waiting for review, closed without landing, or still being worked on) and one link: "Open the … page" on the live app, or the change itself while it waits. File names, tests, commit ids and pull numbers stay in the pull (`src/actions/plain_answer.ts`). The terminal's answers screen reads the same words and link; `o` opens it.
src/actions/plain_answer.ts added +124
@@ -0,0 +1,124 @@
1 /**
2 * The answer a person reads under their tell (#13793): two or three plain
3 * sentences, what changed, and where it stands. The run's own summary is
4 * written for the pull (file names, tests, commit ids); this keeps the
5 * sentences a person can use and leaves the rest to the pull. Plain data
6 * in, plain data out; the caller escapes.
7 */
8
9 /** The longest answer, in characters. */
10 const MAX = 320;
11 /** The most sentences kept. */
12 const SENTENCES = 2;
13
14 const FILE = /(?:[\w.-]+\/[\w./-]*[\w-]\.\w+|\b[\w-]+\.(?:ts|tsx|js|css|md|json|html|sql|toml|yml|yaml)\b|\bsrc\/|\btest\/)/;
15 /** Code-like talk only: tool commands, test results, hashes and numbers; ordinary words stay. */
16 const TALK =
17 /\b(?:bun (?:test|x|run|install)|git \w+|tsc|type[- ]?check|(?:tests?|lint|checks?) (?:pass|passes|passed|fail|fails|failed)|PR #?\d+|pull #\d+)\b|\b[0-9a-f]{7,40}\b|#\d+/i;
18 /**
19 * A route a person can open: `/countdown`, `/notes/new`; never a file, never part of a longer word.
20 */
21 const ROUTE = /(?<![\w./:-])\/[a-z][a-z0-9-]*(?:\/[a-z0-9-]+)*(?![\w./-])/;
22
23 /** The first route the text names, or undefined. */
24 export function routeIn(raw: string): string | undefined {
25 const spans = [...raw.matchAll(/`([^`\n]+)`/g)].map((m) => m[1]!);
26 for (const s of [...spans, raw]) {
27 const m = ROUTE.exec(s);
28 if (m && !FILE.test(m[0])) return m[0];
29 }
30 return undefined;
31 }
32
33 const unmark = (s: string): string =>
34 s
35 .replace(/```[\s\S]*?```/g, " ")
36 .replace(/\[([^\]]*)\]\([^)]*\)/g, "$1")
37 .replace(/`([^`]*)`/g, "$1")
38 .replace(/[*_~`]+/g, "")
39 .replace(/^\s{0,3}#{1,6}\s+/gm, "");
40
41 /**
42 * What changed, in plain words: the prose sentences of `raw` that mention no
43 * file, test or commit, the first two, cut at a word. Empty when none is left.
44 */
45 export function plainChange(raw: string): string {
46 const prose = raw
47 .split("\n")
48 .filter((line) => !/^\s*(?:[-*+]|\d+[.)])\s/.test(line))
49 .join(" ");
50 const sentences = (unmark(prose).replace(/\s+/g, " ").trim().match(/[^.!?]+(?:[.!?]+(?=\s|$)|$)/g) ?? [])
51 .map((s) => s.trim())
52 .filter((s) => s !== "" && !FILE.test(s) && !TALK.test(s));
53 let out = "";
54 for (const s of sentences.slice(0, SENTENCES)) {
55 if (`${out} ${s}`.trim().length > MAX) break;
56 out = `${out} ${s}`.trim();
57 }
58 if (out === "" && sentences[0] !== undefined) {
59 const cut = sentences[0].slice(0, MAX);
60 out = `${cut.slice(0, Math.max(cut.lastIndexOf(" "), 1)).trimEnd()}…`;
61 }
62 return out;
63 }
64
65 /** Where a change stands now. */
66 export type Standing = "merged" | "waiting" | "closed" | "working" | "none";
67
68 const STATE_WORDS: Record<Standing, string> = {
69 merged: "It is merged and will show on the app shortly.",
70 closed: "That change was closed without landing.",
71 waiting: "It is waiting for review.",
72 working: "The crew is still working on it.",
73 none: "",
74 };
75
76 /**
77 * The whole answer: what changed (or the first of `fallbacks`, the pull's title then its body, when
78 * the summary says only file talk), then its state.
79 */
80 export function plainAnswer(raw: string, standing: Standing, ...fallbacks: readonly string[]): string {
81 const change =
82 plainChange(raw) ||
83 fallbacks.map(plainChange).find((c) => c !== "") ||
84 (standing === "none" ? "" : "The crew made your change.");
85 const said = /[.!?…]$/.test(change) || change === "" ? change : `${change}.`;
86 return [said, STATE_WORDS[standing]].filter((s) => s !== "").join(" ");
87 }
88
89 /**
90 * The words for a route: `/countdown` is "the countdown page", `/notes/new` "the notes new page".
91 */
92 export function pageWords(route: string): string {
93 return `the ${route.slice(1).replace(/[/-]+/g, " ")} page`;
94 }

Add the pure link decision here (merged/route/live -> {href, words}) so the page and the terminal share it and every branch is unit tested.

95
96 /** Where a person sees the change: a link and its words. */
97 export interface SeenLink {
98 readonly href: string;
99 readonly words: string;
100 }
101
102 /**
103 * The one link under an answer: merged, the live app at the changed page
104 * ("Open the countdown page", else "Open the app"); waiting, the pull ("See the change"); otherwise
105 * none. No live address, no merged link: never a guessed one.
106 */
107 export function seenLink(o: {
108 readonly standing: Standing;
109 readonly route: string | undefined;
110 readonly live: string | undefined;
111 readonly pull: number | undefined;
112 readonly base: string;
113 }): SeenLink | undefined {
114 if (o.standing === "merged")
115 return o.live
116 ? {
117 href: `${o.live.replace(/\/+$/, "")}${o.route ?? ""}`,
118 words: o.route ? `Open ${pageWords(o.route)}` : "Open the app",
119 }
120 : undefined;
121 if (o.standing === "waiting" && o.pull !== undefined)
122 return { href: `${o.base}/pulls/${o.pull}`, words: "See the change" };
123 return undefined;
124 }
src/tui/screens/answers.ts +22 −8
@@ -2,12 +2,13 @@
22 * Your tells on an app, and what the crew said back — the page's own rows
33 * (`answersFor`), behind the page's own gate (`canSeeAnswers`): the owner of
44 * an app sees their tells; anyone else gets an empty screen, never a name.
5 * `enter` opens the tell on the web, `r` reads again, and `t` tells the crew
6 * more (#7416): one line through the same `tell()` and `tellAnswer` words the
7 * palette's tell uses, told from the row's page when the cursor is on one.
5 * `enter` opens the tell on the web, `o` opens the answer's link (the
6 * changed page on the live app, or the change while it waits), `r` reads again, and `t` tells the
7 * crew more (#7416): one line through the same `tell()` and `tellAnswer` words the palette's tell
8 * uses, told from the row's page when the cursor is on one.
89 */
910
10 import { answersFor, canSeeAnswers } from "../../web/studio/answers.ts";
11 import { answersFor, canSeeAnswers, liveUrl } from "../../web/studio/answers.ts";
1112 import { CREW_WORKING } from "../../actions/ask_state_words.ts";
1213 import { tell } from "../../actions/tell.ts";
1314 import { SAY_SOMETHING_WORDS } from "../../actions/tell_words.ts";
@@ -19,7 +20,7 @@ import { fill, len, split } from "../ui/layout.ts";
1920 import { emptyState } from "../ui/widgets.ts";
2021 import { style } from "../term/style.ts";
2122 import { truncate } from "../term/width.ts";
22 import { ListState, drawList, hitList, metaOf, openOnWeb, promptScreen, relTime, type ListRow } from "./common.ts";
23 import { ListState, drawList, hitList, metaOf, openLink, openOnWeb, promptScreen, relTime, type ListRow } from "./common.ts";
2324 import { tellAnswer } from "../../actions/tell_answer.ts";
2425
2526 /** One line of plain text: a tell or an answer may carry escapes the terminal must not obey. */
@@ -29,21 +30,24 @@ const plain = (text: string): string =>
2930
3031 export interface AnswerLine extends ListRow {
3132 readonly path: string;
33 /** The answer's link, as the page shows it: a forge path or the live app's address. */
34 readonly link: { readonly href: string; readonly words: string } | undefined;
3235 }
3336
3437 /** The rows for `repo`; none unless the viewer may see the answers. */
3538 export function answerLines(f: Session, repo: Repo): AnswerLine[] {
3639 if (!canSeeAnswers(f.db, repo, f.user)) return [];
37 return answersFor(f.db, repo, f.user).map(({ issue, said, working }) => ({
40 return answersFor(f.db, repo, f.user, liveUrl(f.app, repo)).map(({ issue, said, working, link }) => ({
3841 title: plain(issue.title),
3942 secondary:
4043 said === undefined
4144 ? working
4245 ? CREW_WORKING
4346 : "Waiting for the crew."
44 : `${plain(said.who)}: ${plain(said.text)}`,
47 : `${plain(said.who)}: ${plain(said.text)}${link ? ` ${link.words} (o): ${plain(link.href)}` : ""}`,
4548 meta: metaOf(said === undefined ? (working ? "working" : "waiting") : "answered", relTime(said?.at ?? issue.createdAt)),
4649 path: `/${repo.ownerName}/${repo.name}/issues/${issue.number}`,
50 link,
4751 }));
4852 }
4953
@@ -58,6 +62,12 @@ export function answersScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
5862 const line = lines[index];
5963 if (line !== undefined) openOnWeb(f, ctx, line.path, "That tell");
6064 };
65 const follow = (index: number): void => {
66 const link = lines[index]?.link;
67 if (link === undefined) return ctx.toast("This answer has no link yet.", "attn");
68 if (link.href.startsWith("/")) openOnWeb(f, ctx, link.href, link.words);
69 else openLink(ctx, link.href);
70 };
6171 const more = (): void => {
6272 if (!canSeeAnswers(f.db, repo, f.user)) return;
6373 // The row's page goes in as the tell's `from`, as a toolbar tell's does.
@@ -81,7 +91,7 @@ export function answersScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
8191 };
8292 const screen: Screen = {
8393 title: "Your tells",
84 keys: [binding(["j", "k"], "move"), binding(["enter"], "open"), binding(["t"], "tell"), binding(["r"], "refresh")],
94 keys: [binding(["j", "k"], "move"), binding(["enter"], "open"), binding(["o"], "link"), binding(["t"], "tell"), binding(["r"], "refresh")],
8595 load: async () => read(),
8696 render(area, s) {
8797 const c = ctx.theme.c;
@@ -109,6 +119,10 @@ export function answersScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
109119 open(state.index);
110120 return true;
111121 }
122 if (e.key === "o") {
123 follow(state.index);
124 return true;
125 }
112126 if (e.key === "t") {
113127 more();
114128 return true;
src/web/studio/answers.ts +54 −16
@@ -12,11 +12,16 @@ import type { Database } from "bun:sqlite";
1212 import { CREW_WORKING } from "../../actions/ask_state_words.ts";
1313 import { getAppByRepo } from "../../core/apps.ts";
1414 import { listComments, listIssues, type Issue } from "../../core/issues.ts";
15 import { getPull, mergedPullClosing, openPullsClosing, type Pull } from "../../core/pulls.ts";
16 import { plainAnswer, routeIn, seenLink, type SeenLink, type Standing } from "../../actions/plain_answer.ts";
17 import { appsRuntime } from "../../apps/runtime.ts";
18 import { shownProduction } from "../../core/forge_repo.ts";
1519 import { canSeeOwnerFacts, type Repo } from "../../core/repos.ts";
1620 import { listRuns } from "../../core/runs.ts";
1721 import { notePhase, takeSessionTime, timePhase } from "../../core/route_timing.ts";
1822 import { getUsersByIds, type User } from "../../core/users.ts";
1923 import type { Ctx } from "../../http/context.ts";
24 import type { App } from "../../app.ts";
2025 import { loadRepo, repoBase } from "../chrome.ts";
2126 import { html, type Html } from "../html.ts";
2227 import { fragment, missingFragment } from "../layout.ts";
@@ -35,15 +40,32 @@ export interface Answer {
3540 /** Who answered and what they said; undefined while nobody has. */
3641 readonly said: { readonly who: string; readonly text: string; readonly at: string } | undefined;
3742 readonly working: boolean;
43 /** Where the change stands, the page it changed (a route), and the pull that holds it. */
44 readonly standing: Standing;
45 readonly route: string | undefined;
46 readonly pull: Pull | undefined;
47 /** Where the person sees it (`seenLink`); both doors show it. */
48 readonly link: SeenLink | undefined;
3849 }
3950
40 /** The viewer's own tells on `repo`, newest first, each with the crew's answer. */
41 export function answersFor(db: Database, repo: Repo, user: User): readonly Answer[] {
51 /** The app's live address, once per request; undefined with no app or no production. */
52 export function liveUrl(app: App, repo: Repo): string | undefined {
53 const record = getAppByRepo(app.db, repo.id);
54 return record ? shownProduction(app, repo, appsRuntime(app)?.urlFor(record, "production")).url : undefined;
55 }
56
57 /**
58 * The viewer's own tells on `repo`, newest first, each with the crew's answer; `live` is the app's
59 * address (`liveUrl`), read once by the caller.
60 */
61 export function answersFor(db: Database, repo: Repo, user: User, live?: string): readonly Answer[] {
62 const base = repoBase(repo);
4263 const issues = listIssues(db, repo.id, {
4364 state: "all",
4465 author: user.username,
4566 limit: SHOWN,
4667 }).filter((i) => i.id !== repo.directionIssueId);
68 const waiting = openPullsClosing(db, repo.id);
4769 return issues.map((issue) => {
4870 const comments = listComments(db, issue.id, { kind: "comment" });
4971 const speakers = getUsersByIds(db, [...new Set(comments.map((c) => c.authorId))]);
@@ -58,16 +80,32 @@ export function answersFor(db: Database, repo: Repo, user: User): readonly Answe
5880 const actors = finished?.actorId
5981 ? getUsersByIds(db, [finished.actorId]).get(finished.actorId)
6082 : undefined;
61 const said = crewComment
62 ? { who: crewComment.authorName, text: crewComment.body, at: crewComment.createdAt }
63 : finished
64 ? {
65 who: actors?.username ?? "crew",
66 text: finished.summary,
67 at: finished.finishedAt ?? finished.createdAt,
68 }
69 : undefined;
70 return { issue, said, working };
83 const raw = crewComment ? crewComment.body : (finished?.summary ?? "");
84 const named = /(?:opened|updated) pull #(\d+)/.exec(finished?.summary ?? "");
85 const found = named ? getPull(db, repo.id, Number(named[1])) : undefined;
86 // A merged pull for the tell wins over an open one the summary named.
87 const pull =
88 (found?.mergedAt != null ? found : undefined) ??
89 mergedPullClosing(db, repo.id, issue.number) ??
90 found ??
91 waiting.get(issue.number);
92 const standing: Standing =
93 pull?.mergedAt != null
94 ? "merged"
95 : pull?.state === "open"
96 ? "waiting"
97 : pull !== undefined
98 ? "closed"
99 : working
100 ? "working"
101 : "none";
102 const route = routeIn(raw) ?? (pull ? routeIn(pull.body) : undefined);
103 const text = plainAnswer(raw, standing, ...(pull ? [pull.title, pull.body] : []));
104 const who = crewComment ? crewComment.authorName : (actors?.username ?? "crew");
105 const at = crewComment ? crewComment.createdAt : (finished?.finishedAt ?? finished?.createdAt ?? "");
106 const said = raw === "" && pull === undefined ? undefined : { who, text, at };
107 const link = seenLink({ standing, route, live, pull: pull?.number, base });
108 return { issue, said, working, standing, route, pull, link };
71109 });
72110 }
73111
@@ -81,10 +119,10 @@ export function answersRegion(
81119 ctx: Ctx,
82120 repo: Repo,
83121 user: User,
84 answers: readonly Answer[] = answersFor(ctx.app.db, repo, user),
122 answers: readonly Answer[] = answersFor(ctx.app.db, repo, user, liveUrl(ctx.app, repo)),
85123 ): Html {
86124 const base = repoBase(repo);
87 const rows = answers.map(({ issue, said, working }) => {
125 const rows = answers.map(({ issue, said, working, link: seen }) => {
88126 const text =
89127 said === undefined
90128 ? null
@@ -95,7 +133,7 @@ export function answersRegion(
95133 <a href="${tellHref(base, issue.number)}" class="answer-tell">${issue.title}</a>
96134 ${said === undefined
97135 ? html`<p class="muted small answer-wait">${working ? CREW_WORKING : "Waiting for the crew."}</p>`
98 : html`<p class="answer-said"><b>${said.who}</b> ${time(said.at)}<br />${text}</p>`}
136 : html`<p class="answer-said"><b>${said.who}</b> ${time(said.at)}<br />${text}${seen ? html` <a href="${seen.href}">${seen.words}</a>` : null}</p>`}
99137 </li>`;
100138 });
101139 return html`<div
@@ -120,7 +158,7 @@ export function appAnswersFragment(ctx: Ctx): Response {
120158 const user = ctx.auth.user;
121159 if (!repo || !timePhase(ctx.request, "access", () => canSeeAnswers(ctx.app.db, repo, user)))
122160 return missingFragment(ctx.request);
123 const answers = timePhase(ctx.request, "answers", () => answersFor(ctx.app.db, repo, user!));
161 const answers = timePhase(ctx.request, "answers", () => answersFor(ctx.app.db, repo, user!, liveUrl(ctx.app, repo)));
124162 const rendering = performance.now();
125163 const region = answersRegion(ctx, repo, user!, answers);
126164 notePhase(ctx.request, "render", performance.now() - rendering);
test/app-answers.test.ts +99
@@ -13,7 +13,11 @@ import { TOO_LONG_WORDS } from "../src/actions/tell.ts";
1313 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1414 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
1515 import { createApp, type App } from "../src/app.ts";
16 import { mergePull, openPull } from "../src/actions/pulls.ts";
1617 import { addComment, listIssues } from "../src/core/issues.ts";
18 import { getPull } from "../src/core/pulls.ts";
19 import { getRepoById } from "../src/core/repos.ts";
20 import { answersFor } from "../src/web/studio/answers.ts";
1721 import type { Repo } from "../src/core/repos.ts";
1822 import { claimRun, createRun, finishRun } from "../src/core/runs.ts";
1923 import { createUser, getUserByName } from "../src/core/users.ts";
@@ -156,6 +160,101 @@ describe("the crew's answer under the tell box", () => {
156160 expect(listIssues(app.db, repo.id, { state: "all", limit: 50 }).length).toBe(before);
157161 });
158162
163 test("the answer says what changed, where it stands, and links the page or the change", async () => {
164 const owner = getUserByName(app.db, "alice")!;
165 const scout = getUserByName(app.db, "scout")!;
166 const fresh = () => getRepoById(app.db, repo.id)!;
167 const told = async (text: string) => {
168 await tell(alice, text);
169 return listIssues(app.db, repo.id, { limit: 1 })[0]!;
170 };
171 const propose = async (branch: string, closes: number, title: string, body: string) => {
172 const pushed = await commitToBranch(app, owner, fresh(), {
173 branch,
174 message: branch,
175 files: [{ path: `${branch}.txt`, content: "x\n" }],
176 });
177 if (!pushed.ok) throw new Error(JSON.stringify(pushed.error));
178 const opened = await openPull(app, owner, fresh(), {
179 title,
180 body: `${body}\n\nCloses #${closes}`,
181 baseBranch: "main",
182 headBranch: branch,
183 });
184 if (!opened.ok) throw new Error(String(opened.error));
185 return getPull(app.db, repo.id, opened.value.number)!;
186 };
187 const finish = (issueId: string, summary: string) => {
188 const run = createRun(app.db, { repoId: repo.id, kind: "agent", issueId, actorId: scout.id, reason: "assigned" });
189 claimRun(app.db, run.id);
190 finishRun(app.db, run.id, { state: "ok", summary });
191 };
192 const answerOf = (number: number) => answersFor(app.db, fresh(), owner).find((a) => a.issue.number === number)!;
193
194 // Merged: the pull is found by what closes the tell; the words say merged, not live.
195 const a = await told("Add a countdown page");
196 const merged = await propose("countdown", a.number, "Countdown page", "A `/countdown` page that counts the days to New Year.");
197 finish(a.id, "Wrote src/countdown.ts and tests; all tests pass.");
198 expect((await mergePull(app, owner, fresh(), merged, "squash")).ok).toBe(true);
199 const got = answerOf(a.number);
200 expect(got.standing).toBe("merged");
201 expect(got.route).toBe("/countdown");
202 expect(got.said!.text).toBe("Countdown page. It is merged and will show on the app shortly.");
203 expect(got.said!.text).not.toMatch(/src\/|tests|pull #|live now/);
204
205 // Open, named by the run's summary: waiting, and the link goes to the pull.
206 const b = await told("Make the gate page friendlier");
207 const open = await propose("friendly", b.number, "Friendlier gate page", "Visitors now pass through a gate page that greets them.");
208 finish(b.id, `opened pull #${open.number} (b6b1564)`);
209 const waiting = answerOf(b.number);
210 expect(waiting.standing).toBe("waiting");
211 expect(waiting.pull!.number).toBe(open.number);
212 // An ordinary word like "gate" stays; the bare summary falls back to the pull's title.
213 expect(waiting.said!.text).toBe("Friendlier gate page. It is waiting for review.");
214 const page = await (await get(alice, "/alice/notes/app/answers")).text();
215 expect(page).toContain(`href="/alice/notes/pulls/${open.number}">See the change</a>`);
216
217 // Closed without landing is said, not silent.
218 const c = await told("Try a purple header");
219 const shut = await propose("purple", c.number, "Purple header", "The header is purple.");
220 app.db.run("UPDATE issue SET state = 'closed' WHERE id = ?1", [shut.id]);
221 finish(c.id, `opened pull #${shut.number} (abc1234)`);
222 expect(answerOf(c.number).standing).toBe("closed");
223 expect(answerOf(c.number).said!.text).toContain("closed without landing");
224
225 // A merged pull for the tell wins over a stale open one the summary names.
226 const e = await told("Add a clock page");
227 const stale = await propose("clock-a", e.number, "Clock page, first try", "A clock.");
228 const landed = await propose("clock-b", e.number, "Clock page", "A `/clock` page.");
229 expect((await mergePull(app, owner, fresh(), landed, "squash")).ok).toBe(true);
230 finish(e.id, `opened pull #${stale.number} (abc1234)`);
231 const preferred = answerOf(e.number);
232 expect(preferred.pull!.number).toBe(landed.number);
233 expect(preferred.standing).toBe("merged");
234
235 // Neither: nothing invented.
236 const d = await told("Say hello");
237 const none = answerOf(d.number);
238 expect(none.standing).toBe("none");
239 expect(none.said).toBeUndefined();
240
241 // The terminal reads the same words.
242 const user = getUserByName(app.db, "alice")!;
243 const { answerLines } = await import("../src/tui/screens/answers.ts");
244 const { session } = createForgeApp(
245 app,
246 { sshUsername: "alice", remoteAddress: "127.0.0.1", user },
247 { terminal: headlessTerminal(120, 30), exitHooks: false },
248 );
249 const rows = answerLines(session, fresh());
250 // The terminal carries the same link the page shows.
251 expect(rows.find((r) => r.link?.words === "See the change")?.link?.href).toBe(`/alice/notes/pulls/${open.number}`);
252 expect(rows.some((r) => (r.secondary ?? "").includes("See the change (o)"))).toBe(true);
253 const lines = rows.map((l) => l.secondary ?? "");
254 expect(lines.some((l) => l.includes("It is waiting for review."))).toBe(true);
255 expect(lines.some((l) => l.includes("It is merged and will show on the app shortly."))).toBe(true);
256 });
257
159258 test("the terminal shows the same answers to the owner, and nothing to a stranger", async () => {
160259 const screen = async (who: string): Promise<{ text: string; count: number }> => {
161260 const user = getUserByName(app.db, who)!;
test/plain-answer.test.ts added +73
@@ -0,0 +1,73 @@
1 import { describe, expect, test } from "bun:test";

No test covers the merged 'Open the … page' / 'Open the app' links; they would survive being broken.

2 import { pageWords, plainAnswer, plainChange, routeIn, seenLink } from "../src/actions/plain_answer.ts";
3
4 const RAW =
5 "I added a `/countdown` page that counts down the days to New Year. It's public, like the home page, and the server renders it. The focused tests pass; the type check couldn't run.\n- **`src/countdown.ts`:** works out the next New Year\n- **Page and route:** `countdownPage` is in `src/page.ts`";
6
7 describe("the answer a person reads", () => {
8 test("keeps what changed and drops files, tests and markers", () => {
9 const text = plainAnswer(RAW, "merged");
10 expect(text).toBe(
11 "I added a /countdown page that counts down the days to New Year. It's public, like the home page, and the server renders it. It is merged and will show on the app shortly.",
12 );
13 expect(text).not.toMatch(/`|src\/|\.ts|pull #|\*\*/);
14 });
15 test("finds the page that changed", () => {
16 expect(routeIn(RAW)).toBe("/countdown");
17 expect(routeIn("edited src/page.ts and notes/new.md")).toBeUndefined();
18 });
19 test("a bare pull marker falls back to the pull's words and says it waits", () => {
20 const text = plainAnswer("opened pull #4 (b6b1564)", "waiting", "Heading says Riley's guestbook. The Sign button is green.");
21 expect(text).toBe("Heading says Riley's guestbook. The Sign button is green. It is waiting for review.");
22 expect(text).not.toMatch(/pull #|b6b1564/);
23 });
24 test("nothing usable still answers in words", () => {
25 expect(plainAnswer("opened pull #4 (b6b1564)", "merged")).toBe("The crew made your change. It is merged and will show on the app shortly.");
26 expect(plainChange("")).toBe("");
27 });
28 test("ordinary words stay; code talk goes", () => {
29 expect(plainChange("Visitors now pass through a gate page. The tests pass. I ran bun test.")).toBe(
30 "Visitors now pass through a gate page.",
31 );
32 });
33 test("the pull's title comes before its body, and a page is named in words", () => {
34 expect(plainAnswer("opened pull #4 (b6b1564)", "waiting", "Bigger header", "Makes it large.")).toBe(
35 "Bigger header. It is waiting for review.",
36 );
37 expect(pageWords("/countdown")).toBe("the countdown page");
38 expect(pageWords("/notes/new")).toBe("the notes new page");
39 });
40 test("a pull closed without landing says so", () => {
41 expect(plainAnswer("", "closed", "Purple header")).toBe("Purple header. That change was closed without landing.");
42 });
43 });
44
45 describe("the link under an answer", () => {
46 const base = "/alice/notes";
47 const live = "https://notes.example/";
48 test("merged with a page: the live app at that page", () => {
49 expect(seenLink({ standing: "merged", route: "/countdown", live, pull: 4, base })).toEqual({
50 href: "https://notes.example/countdown",
51 words: "Open the countdown page",
52 });
53 });
54 test("merged without a page: the app", () => {
55 expect(seenLink({ standing: "merged", route: undefined, live, pull: 4, base })).toEqual({
56 href: "https://notes.example",
57 words: "Open the app",
58 });
59 });
60 test("merged with no live address: no link, never a guessed one", () => {
61 expect(seenLink({ standing: "merged", route: "/countdown", live: undefined, pull: 4, base })).toBeUndefined();
62 });
63 test("waiting: the change itself", () => {
64 expect(seenLink({ standing: "waiting", route: "/countdown", live, pull: 7, base })).toEqual({
65 href: "/alice/notes/pulls/7",
66 words: "See the change",
67 });
68 });
69 test("closed, working or none: no link", () => {
70 for (const standing of ["closed", "working", "none"] as const)
71 expect(seenLink({ standing, route: "/countdown", live, pull: 7, base })).toBeUndefined();
72 });
73 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs