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

A fork's page says in one sentence how far it is from its upstream and what following would do #14477

Merged opened this

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

Merged

mason/forge:mason/14462-a-fork-s-page-says-in-one-sentence-how-f → main 8 commits fork 7 threads · 7 unresolved

  • Merged. mason/14462-a-fork-s-page-says-in-one-sentence-how-f was merged into main as b5e17d0.

Review

Sign in to review this change.
12 files changed +183 −29
docs/FOLLOWING.md +6
@@ -203,6 +203,12 @@ page, `POST /api/v1/repos/:owner/:name/following/take` (409, naming the
203203 converge issue), and the MCP `take_updates` tool, so the same press does the
204204 same thing at every door.
205205
206 ## The one sentence
207
208 A fork's page, MCP `forks` and `GET /api/v1/repos/:owner/:name/forks` say how far it is from its parent
209 and what its follow mode will do in one sentence (`driftWords`, `words` in the answers): "3 changes behind
210 a/b; following will apply 3 changes.", "Up to date with a/b; …". It reads the cached drift, never a new walk.
211
206212 ## Ranked forks
207213
208214 `/:owner/:name/forks` and the terminal's forks screen (`f` in a repository)
docs/features/fork-standing.md added +16
@@ -0,0 +1,16 @@
1 ---
2 topic: Your apps
3 row: How far a fork is from its upstream, in one sentence
4 ---
5 # How far a fork is from its upstream, in one sentence
6
7 A fork's page says under its head how far it is from its parent and what its
8 follow mode will do about it, for example "3 changes behind a/b; following will
9 apply 3 changes." or "Up to date with a/b; following has nothing to apply."
10
11 - `driftWords` (`src/actions/follow_words.ts`) builds the sentence from the
12 ahead and behind counts and the mode; `followWords` (`src/actions/follow.ts`)
13 reads the cached drift, never a new git walk.
14 - The page's standing line, the terminal's forks screen (`f` in a repository)
15 and the `words` field of MCP `forks` and `GET /api/v1/repos/:owner/:name/forks`
16 all say that one string. A parent the reader cannot read is not named.
src/actions/follow.ts +24 −2
@@ -14,13 +14,13 @@ import type { User } from "../core/users.ts";
1414 import { err, ok, type Result } from "../kernel/result.ts";
1515 import { chainOfRepo, forgeLinkOf, FOLLOW_MODES, isFollowMode, setChainMode, severChain } from "../spawn/chain.ts";
1616 import { FAMILY_WORDS } from "./family_words.ts";
17 import { FOLLOWS_NOTHING, followModeWords, followStandingLine } from "./follow_words.ts";
17 import { FOLLOWS_NOTHING, agoWords, driftWords, followModeWords, followStandingLine } from "./follow_words.ts";
1818 import { FORK_FOLLOW_MODES, forkFollowMode, lastTookAt, isForkFollowMode, setForkFollowMode, type ForkFollowMode } from "../core/fork_follow.ts";
1919 import { requireUser } from "./access.ts";
2020 import { getFollow, setFollowTaking } from "../core/upstream_follow.ts";
2121 import { isChecking, severUpstream } from "./upstream_follow.ts";
2222 import { takeFromParent, type Taken } from "../spawn/take.ts";
23 import { takeUpdates, type ForkSync, type TakeUpdatesError } from "./forks.ts";
23 import { driftOfForks, takeUpdates, type ForkSync, type TakeUpdatesError } from "./forks.ts";
2424 import { convergeFollowed } from "./upstream_sync.ts";
2525
2626 /**
@@ -148,6 +148,28 @@ export async function followStanding(app: App, repo: Repo, viewer: User | undefi
148148 );
149149 }
150150
151 /**
152 * The one sentence on how far a fork is from its parent and what following will do (#14462); the
153 * drift is the cached reading (`driftOfForks`), never a new walk. Undefined for a repository that
154 * is no fork.
155 */
156 export async function followWords(app: App, repo: Repo, viewer: User | undefined): Promise<string | undefined> {
157 if (repo.forkParentId === null) return undefined;
158 const parent = forkParentFor(app.db, repo, viewer);
159 const drift =
160 parent === undefined || repo.archivedAt !== null
161 ? { ahead: null, behind: null }
162 : (await driftOfForks(app, parent, [repo]))[0]!.drift;
163 const sentence = driftWords(
164 await followModeOf(app, repo),
165 parent === undefined ? undefined : `${parent.ownerName}/${parent.name}`,
166 drift.ahead,
167 drift.behind,
168 );
169 const took = lastTookAt(app.db, repo.id);
170 return took === null ? sentence : `${sentence} Last took ${agoWords(took)}.`;
171 }
172
151173 export type FollowModeError = SeverError | "invalid_mode" | "severed" | "updating";
152174
153175 /** The one answer every door gives a refused mode change, with the status an HTTP door sends. */
src/actions/follow_words.ts +38
@@ -130,6 +130,44 @@ export function followStandingLine(
130130 return tookAt === null ? line : `${line} · last took ${agoWords(tookAt, now)}`;
131131 }
132132
133 const changes = (n: number): string => `${n} change${n === 1 ? "" : "s"}`;
134
135 /**
136 * How far a fork is from its upstream and what its follow mode will do about it, in one plain
137 * sentence (#14462): the fork's page and the forks answers (MCP and API) say this one string.
138 * `ahead` and `behind` are the cached drift; null (git could not say) leaves the distance unsaid.
139 */
140 export function driftWords(
141 mode: ForkFollowMode,
142 upstream: string | undefined,
143 ahead: number | null,
144 behind: number | null,
145 ): string {
146 const name = upstream ?? "its upstream";
147 const none = mode === "dont-follow" ? "not following, so nothing will be applied" : "following has nothing to apply";
148 if (ahead === null || behind === null) {
149 const will =
150 mode === "take-updates"
151 ? "following will take what it can"
152 : mode === "tell-me"
153 ? "following will wait for you to take it"
154 : none;
155 return `Not known how far this is from ${name}; ${will}.`;
156 }
157 if (ahead === 0 && behind === 0) return `Up to date with ${name}; ${none}.`;
158 const apart =
159 behind > 0 && ahead > 0
outdated

Duplicate of the dont-follow return at line 156; fold into one check before the behind === 0 split.

160 ? `${changes(behind)} behind and ${ahead} ahead of ${name}`
161 : behind > 0
162 ? `${changes(behind)} behind ${name}`
163 : `${changes(ahead)} ahead of ${name}`;
outdated

Principle 8: 'a conflict goes to the crew' and 'offered up' are jargon; say plainly what happens (e.g. 'a conflict is sent for review'). Also long: the sentence reaches ~110 characters.

164 if (mode === "dont-follow" || behind === 0) return `${apart}; ${none}.`;
165 if (mode === "tell-me") return `${apart}; following will apply nothing until you take ${behind === 1 ? "it" : `the ${behind}`}.`;
166 return ahead === 0
167 ? `${apart}; following will apply ${changes(behind)}.`
168 : `${apart}; following will merge ${changes(behind)}, or open an issue on a conflict.`;
169 }
170
133171 /**
134172 * How a fork follows its upstream in one word, for a tree node; a severed fork says so rather than
135173 * saying nothing.
src/http/api/upstream.ts +3
@@ -16,6 +16,7 @@ import {
1616 setFollowUpstream,
1717 } from "../../actions/upstream_follow.ts";
1818 import { ENABLED_WORDS } from "../../core/arg_words.ts";
19 import { followWords } from "../../actions/follow.ts";
1920 import { driftOfForks, MAX_RANKED_FORKS, type RankedFork } from "../../actions/forks.ts";
2021 import { canAdmin, forkParentFor, visibleForks } from "../../core/repos.ts";
2122 import { notePhase, takeSessionTime, timePhase, timePhaseAsync } from "../../core/route_timing.ts";
@@ -123,9 +124,11 @@ export function upstreamRoutes(router: Router<Handler>): void {
123124 const parent = forkParentFor(ctx.app.db, repo, ctx.auth.user);
124125 // The tag is of the exact bytes sent: a fork made, pushed or hidden, or a parent that moved, changes
125126 // the body; limit and cursor choose the page. A 404 or bad page returned above carries none.
127 const words = (await followWords(ctx.app, repo, ctx.auth.user)) ?? null;
126128 return timePhase(ctx.request, "render", () => {
127129 const text = JSON.stringify({
128130 parent: parent === undefined ? null : `${parent.ownerName}/${parent.name}`,
131 words,
129132 items: drifts.map(({ fork, drift, pushedAt }) => ({
130133 ...fork,
131134 ahead: drift.ahead,
src/http/mcp/tools/forks.ts +3 −1
@@ -1,12 +1,13 @@
11 import { driftOfForks, MAX_RANKED_FORKS, type RankedFork } from "../../../actions/forks.ts";
22 import { forkParentFor, visibleForks, type Repo } from "../../../core/repos.ts";
3 import { followWords } from "../../../actions/follow.ts";
34 import { forkChain } from "../../../actions/fork_chain.ts";
45 import { pageRows } from "../page.ts";
56 import { good, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
67
78 export const tool: Tool = {
89 name: "forks",
9 doc: "`{ repo, kind: chain }`: `{ chain: [{ role, repo, follows, page }], severed, truncated }`, its grandparent, parent, itself and children in the fork tree page's words, a severed link stops it, unreadable forks are left out; else `{ repo, limit?, cursor? }`: `{ parent, forks: [{ repo, ahead, behind, updatedAt }], next_cursor }`, the forks the caller may see in the order `/:owner/:name/forks` lists them, each with its commits ahead of and behind this one (`null` when git cannot say); `limit` 1-200 (default 50), `cursor` the last `next_cursor` (null on the last page); drift is read for the page only; draws the `ui://forge/forks` card",
10 doc: "`{ repo, kind: chain }`: `{ chain: [{ role, repo, follows, page }], severed, truncated }`, its grandparent, parent, itself and children in the fork tree page's words, a severed link stops it, unreadable forks are left out; else `{ repo, limit?, cursor? }`: `{ parent, words, forks: [{ repo, ahead, behind, updatedAt }], next_cursor }`, the forks the caller may see in the order `/:owner/:name/forks` lists them, each with its commits ahead of and behind this one (`null` when git cannot say); `limit` 1-200 (default 50), `cursor` the last `next_cursor` (null on the last page); `words` is the one sentence on how far this fork is from its parent and what following will do (`null` when it is no fork); drift is read for the page only; draws the `ui://forge/forks` card",
1011 description: "A repo's forks you may see, paged by limit and cursor (next_cursor), each with commits ahead and behind.",
1112 inputSchema: {
1213 type: "object",
@@ -39,6 +40,7 @@ export const tool: Tool = {
3940 }));
4041 return good({
4142 parent: parent === undefined ? null : `${parent.ownerName}/${parent.name}`,
43 words: (await followWords(ctx.app, repo, user)) ?? null,
4244 forks: rows,
4345 next_cursor,
4446 });
src/tui/screens/forks.ts +10 −9
@@ -21,8 +21,8 @@ import {
2121 type ForkRanking,
2222 type ForkRelation,
2323 } from "../../actions/forks.ts";
24 import { FOLLOW_CHOICES, FOLLOW_PHRASE, FOLLOW_WORD, FOLLOWS_NOTHING, followChoiceLine, proposeRefusalWords } from "../../actions/follow_words.ts";
25 import { FOLLOW_MODE_REFUSALS, convergeWords, followModeOf, followStanding, setFollowMode, takeOrTell, takeWords } from "../../actions/follow.ts";
24 import { FOLLOW_CHOICES, FOLLOW_PHRASE, FOLLOWS_NOTHING, followChoiceLine, proposeRefusalWords } from "../../actions/follow_words.ts";
25 import { FOLLOW_MODE_REFUSALS, convergeWords, followModeOf, followStanding, followWords, setFollowMode, takeOrTell, takeWords } from "../../actions/follow.ts";
2626 import { incomingOf, type Incoming } from "../../actions/follow_incoming.ts";
2727 import { convergeFollowed, followedAs, followedOf } from "../../actions/upstream_sync.ts";
2828 import { forkOffers } from "../../core/fork_offers.ts";
@@ -36,7 +36,7 @@ import { canAdmin, canRead, canWrite, forkTree, getRepoById, listForks, type For
3636 import type { Ctx, Screen } from "../app/app.ts";
3737 import { binding } from "../app/keys.ts";
3838 import { style } from "../term/style.ts";
39 import { truncate } from "../term/width.ts";
39 import { truncate, wrap } from "../term/width.ts";
4040 import { fill, len, split } from "../ui/layout.ts";
4141 import { emptyState } from "../ui/widgets.ts";
4242 import type { Session } from "../session.ts";
@@ -244,7 +244,8 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
244244 relation !== undefined && relation.state === "diverged" && !relation.clean
245245 ? convergeState(f.app, repo, relation.parent)
246246 : undefined;
247 standing = await followStanding(f.app, repo, f.user);
247 // The sentence the page's standing line says (#14462); the plain line where it is silent.
248 standing = (await followWords(f.app, repo, f.user)) ?? (await followStanding(f.app, repo, f.user));

The terminal now omits 'last took', which followStanding gave it; the page keeps it. Both doors must say the same.

248249 failed = getRepoById(f.db, repo.id)?.origin?.fetchError ?? "";
249250 mode = relation === undefined ? undefined : await followModeOf(f.app, repo);
250251 following = followingRows(relation, converge, mode);
@@ -336,7 +337,7 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
336337 },
337338 render(area, s) {
338339 const c = ctx.theme.c;
339 const [head, line, body] = split(area, "v", [len(1), len(standing === undefined && failed === "" ? 0 : 1), fill(1)]);
340 const [head, line, body] = split(area, "v", [len(1), len(failed !== "" ? 1 : standing === undefined ? 0 : wrap(standing, area.w).slice(0, 2).length), fill(1)]);
340341 const list = rows();
341342 s.text(
342343 head!.x,
@@ -351,10 +352,10 @@ export function forksScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
351352 if (failed !== "") {
352353 s.text(line!.x, line!.y, truncate(`The last sync failed: ${failed}`, line!.w), style(c.danger, c.bg), line!.x + line!.w);
353354 } else if (standing !== undefined) {
354 // The same word the web header says, then how far behind when the relation was read.
355 const word = mode === undefined ? "" : `${FOLLOW_WORD[mode]} · `;
356 const behind = relation === undefined ? "" : ` · ${relation.behind} behind`;
357 s.text(line!.x, line!.y, truncate(`${word}${standing}${behind}`, line!.w), style(c.mutedFg, c.bg), line!.x + line!.w);
355 // The sentence the page says, wrapped on a narrow screen so the follow effect is not cut.
356 wrap(standing, line!.w).slice(0, 2).forEach((row, i) => {
357 s.text(line!.x, line!.y + i, row, style(c.mutedFg, c.bg), line!.x + line!.w);
outdated

mode word · sentence runs past 80 columns and truncate cuts the follow effect off. Wrap onto a second row or drop the redundant mode word.

358 });
358359 }
359360 if (list.length === 0) {
360361 emptyState(s, body!, c, {
src/web/pages/fork-standing.ts +4 −4
@@ -8,7 +8,7 @@
88 * leave a line that still says the fork is level.
99 */
1010
11 import { followStanding } from "../../actions/follow.ts";
11 import { followWords } from "../../actions/follow.ts";
1212 import type { Repo } from "../../core/repos.ts";
1313 import { STANDING_EVENTS } from "../../core/standing_events.ts";
1414 import { getFollow } from "../../core/upstream_follow.ts";
@@ -46,13 +46,13 @@ function failedLine(repo: Repo): Html | null {
4646 * they are silent.
4747 */
4848 async function lines(ctx: Ctx, repo: Repo): Promise<Html> {
49 const standing = await followStanding(ctx.app, repo, ctx.auth.user);
5049 const behind = behindLine(ctx, repo);
5150 const ahead = originAheadLine(ctx, repo);
51 const words = await followWords(ctx.app, repo, ctx.auth.user);
5252 const plain =
53 standing === undefined
53 words === undefined
5454 ? null
55 : html`<div class="small muted" data-follow-standing>${icon("sync")} <a href="${repoBase(repo)}/forks#following">${standing}</a></div>`;
55 : html`<div class="small muted" data-follow-standing>${icon("sync")} <a href="${repoBase(repo)}/forks#following">${words}</a></div>`;
outdated

The 'last took' suffix is built here, in the page, from lastTookAt/agoWords; followStandingLine already did this. Move it into the shared words so the terminal and the page agree (the terminal now drops it).

5656 return html`${failedLine(repo)}${behind}${ahead}${behind === null && ahead === null ? plain : null}`;
5757 }
5858
test/fork-counts.test.ts +1 −1
@@ -112,7 +112,7 @@ describe("fork counts hold only the forks the viewer may read", () => {
112112 const api = await fetch(`${base}/api/v1/repos/alice/lib/forks`, {
113113 headers: { cookie: cookies[who]! },
114114 });
115 expect(await api.json()).toEqual({ parent: null, items: [], next_cursor: null });
115 expect(await api.json()).toEqual({ parent: null, words: null, items: [], next_cursor: null });
116116 }
117117 const owners = await page("/alice/lib/forks", "bob");
118118 expect(owners).toContain("1 fork");
test/fork-follow-word.test.ts +1 −1
@@ -124,7 +124,7 @@ test("the terminal's forks screen says the same word and how far behind", async
124124 await settleApp(tui);
125125 const frame = tui.screen.toText();
126126 tui.stop?.();
127 expect(frame).toContain("proposes · Sends offers to alice/lib · 1 behind");
127 expect(frame).toContain("1 change behind and 1 ahead of alice/lib; following will apply nothing until you take it.");
128128 });
129129
130130 const behindOf = async (path: string): Promise<string | null> =>
test/fork-standing-line.test.ts +74 −8
@@ -7,8 +7,8 @@ import { afterAll, beforeAll, expect, test } from "bun:test";
77 import { mkdtemp, rm } from "node:fs/promises";
88 import { tmpdir } from "node:os";
99 import { join } from "node:path";
10 import { followStanding } from "../src/actions/follow.ts";
11 import { agoWords, followStandingLine } from "../src/actions/follow_words.ts";
10 import { followStanding, followWords } from "../src/actions/follow.ts";
11 import { agoWords, driftWords, followStandingLine } from "../src/actions/follow_words.ts";
1212 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
1313 import { createApp, type App } from "../src/app.ts";
1414 import { setForkFollowMode } from "../src/core/fork_follow.ts";
@@ -70,13 +70,13 @@ test("the words: each mode, with and without a last take", () => {
7070
7171 test("a fork's page says its mode, links to the following card, and a root says nothing", async () => {
7272 const bob = getRepo(app.db, "bob", "lib")!;
73 expect(await lineOf("/bob/lib")).toBe("Sends offers to alice/lib");
73 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; following has nothing to apply.");
7474 const page = await (await fetch(`${servers.url}/bob/lib`)).text();
7575 expect(page).toContain('href="/bob/lib/forks#following"');
7676 setForkFollowMode(app.db, bob.id, "take-updates");

Principle of a test that would fail without the change: all three modes now expect the identical 'Up to date' string, so they no longer test the modes. Create drift (a commit on alice/lib) and assert the distinct sentence per mode on the page.

77 expect(await lineOf("/bob/lib")).toBe("Takes updates from alice/lib");
77 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; following has nothing to apply.");
7878 setForkFollowMode(app.db, bob.id, "dont-follow");
79 expect(await lineOf("/bob/lib")).toBe("Not following alice/lib");
79 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied.");
8080 expect(await lineOf("/alice/lib")).toBeNull();
8181 });
8282
@@ -86,7 +86,7 @@ test("the last take is told, and the MCP's words are the page's", async () => {
8686 kind: "push", repoId: bob.id, actorId: bob.ownerId,
8787 payload: { updates: [], followed: "alice/lib" },
8888 });
89 expect(await lineOf("/bob/lib")).toBe("Not following alice/lib · last took just now");
89 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied. Last took just now.");
9090 expect(await followStanding(app, bob, undefined)).toBe("Not following alice/lib · last took just now");
9191 expect(await followStanding(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined();
9292 });
@@ -95,7 +95,7 @@ test("a private upstream is not named to a reader who cannot read it", async ()
9595 const bob = getRepo(app.db, "bob", "lib")!;
9696 app.db.query("UPDATE repo SET visibility = 'private' WHERE owner_id = (SELECT id FROM user WHERE username = 'alice') AND name = 'lib'").run();
9797 const seen = await lineOf("/bob/lib");
98 expect(seen).toContain("Not following its upstream");
98 expect(seen).toContain("its upstream");
9999 expect(seen).not.toContain("alice");
100100 expect(await followStanding(app, bob, undefined)).not.toContain("alice");
101101 });
@@ -174,5 +174,71 @@ test("the terminal's forks screen says the line", async () => {
174174 await settleApp(tui);
175175 const text = tui.screen.toText();
176176 tui.stop?.();
177 expect(text).toContain("Takes updates from alice/lib");
177 expect(text).toContain("2 changes ahead of alice/lib");
178 });
179
180 test("one sentence: ahead, behind and what each follow mode will do (#14462)", () => {
181 const w = driftWords;
182 expect(w("take-updates", "a/b", 0, 0)).toBe("Up to date with a/b; following has nothing to apply.");
183 expect(w("take-updates", "a/b", 0, 3)).toBe("3 changes behind a/b; following will apply 3 changes.");
184 expect(w("take-updates", "a/b", 0, 1)).toBe("1 change behind a/b; following will apply 1 change.");
185 expect(w("take-updates", "a/b", 2, 0)).toBe("2 changes ahead of a/b; following has nothing to apply.");
186 expect(w("take-updates", "a/b", 2, 3)).toBe("3 changes behind and 2 ahead of a/b; following will merge 3 changes, or open an issue on a conflict.");
187 expect(w("tell-me", "a/b", 0, 3)).toBe("3 changes behind a/b; following will apply nothing until you take the 3.");
188 expect(w("tell-me", "a/b", 2, 1)).toBe("1 change behind and 2 ahead of a/b; following will apply nothing until you take it.");
189 expect(w("dont-follow", "a/b", 0, 3)).toBe("3 changes behind a/b; not following, so nothing will be applied.");
190 expect(w("dont-follow", "a/b", 1, 0)).toBe("1 change ahead of a/b; not following, so nothing will be applied.");
191 expect(w("tell-me", undefined, 0, 0)).toBe("Up to date with its upstream; following has nothing to apply.");
192 expect(w("dont-follow", "a/b", 0, 0)).toBe("Up to date with a/b; not following, so nothing will be applied.");
193 expect(w("tell-me", "a/b", null, null)).toBe("Not known how far this is from a/b; following will wait for you to take it.");
194 expect(w("take-updates", "a/b", null, null)).toBe("Not known how far this is from a/b; following will take what it can.");
195 expect(w("dont-follow", undefined, null, null)).toBe("Not known how far this is from its upstream; not following, so nothing will be applied.");
196 });
197
198 test("the page, the MCP forks answer, the API and the terminal say one exact sentence for real drift", async () => {
199 const { createToken } = await import("../src/core/tokens.ts");
200 const { mcpTool } = await import("./helpers/mcp.ts");
201 const { getUserByName } = await import("../src/core/users.ts");
202 const { createForgeApp } = await import("../src/tui/forge.ts");
203 const { forksScreen } = await import("../src/tui/screens/forks.ts");
outdated

This regex accepts almost any sentence, and the fork is probably 'up to date' so the behind/ahead path is not exercised through the doors. Assert the exact string against real drift.

204 const { headlessTerminal } = await import("../src/tui/term/terminal.ts");
205 const { settleApp } = await import("./helpers/tui.ts");
206 app.db.query("UPDATE repo SET visibility = 'public' WHERE name = 'lib'").run();
207 const alice = getUserByName(app.db, "alice")!;
208 const bob = getRepo(app.db, "bob", "lib")!;
209 // Not following, so the parent's push is not taken in the background; bob is 2 ahead, 1 behind.
210 setForkFollowMode(app.db, bob.id, "dont-follow");
211 const more = await commitToBranch(app, alice, getRepo(app.db, "alice", "lib")!, { message: "Three", files: [{ path: "three.txt", content: "3\n" }] });
212 expect(more.ok).toBe(true);
213 const apart = "1 change behind and 2 ahead of alice/lib";
214 const tail = " Last took just now.";
215 const want: Record<"take-updates" | "tell-me" | "dont-follow", string> = {
216 "take-updates": `${apart}; following will merge 1 change, or open an issue on a conflict.${tail}`,
217 "tell-me": `${apart}; following will apply nothing until you take it.${tail}`,
218 "dont-follow": `${apart}; not following, so nothing will be applied.${tail}`,
219 };
220 const token = createToken(app.db, getUserByName(app.db, "bob")!.id, "bob", "admin").token;
221 for (const mode of ["take-updates", "tell-me", "dont-follow"] as const) {
222 setForkFollowMode(app.db, bob.id, mode);
223 expect(await followWords(app, bob, undefined)).toBe(want[mode]);
224 expect(await lineOf("/bob/lib")).toBe(want[mode]);
225 expect((await mcpTool(servers.url, token, "forks", { repo: "bob/lib" })).value.words).toBe(want[mode]);
226 const api = await (await fetch(`${servers.url}/api/v1/repos/bob/lib/forks`, { headers: { authorization: `Bearer ${token}` } })).json() as { words: string };
227 expect(api.words).toBe(want[mode]);
228 }
229 // The terminal, 80 columns: the sentence wraps over two rows, its effect and last take intact.
230 setForkFollowMode(app.db, bob.id, "tell-me");
231 const terminal = headlessTerminal(80, 30);
232 const { app: tui, session } = createForgeApp(
233 app,
234 { sshUsername: "bob", remoteAddress: "127.0.0.1", fingerprint: "SHA256:test", user: getUserByName(app.db, "bob")! },
235 { terminal, exitHooks: false },
236 );
237 tui.start();
238 tui.ctx.push(forksScreen(session, tui.ctx, getRepo(app.db, "bob", "lib")!));
239 await settleApp(tui);
240 const flat = tui.screen.toText().replace(/\s+/g, " ");
241 tui.stop?.();
242 expect(flat).toContain(want["tell-me"].replace(/\s+/g, " "));
243 expect(await followWords(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined();
178244 });
test/standing-live.test.ts +3 −3
@@ -61,7 +61,7 @@ const line = async (path: string): Promise<string> =>
6161 test("the card's line is a live region of the page's own stream, with no script of its own", async () => {
6262 const page = await (await fetch(`${servers.url}/bob/lib`)).text();
6363 expect(page).toMatch(/<div id="fork-standing" data-live="push,repo\.synced[^"]*" data-live-repo="bob\/lib" data-live-src="\/bob\/lib\/standing-line">/);
64 expect(page).toContain("Sends offers to alice/lib");
64 expect(page).toContain("Up to date with alice/lib");
6565 expect(page).not.toContain("/standing-line.js");
6666 // A repository that stands against nothing carries no region.
6767 expect(await (await fetch(`${servers.url}/alice/lib`)).text()).not.toContain('id="fork-standing"');
@@ -69,9 +69,9 @@ test("the card's line is a live region of the page's own stream, with no script
6969
7070 test("a take appended to the stream changes what the region's address answers", async () => {
7171 const bob = getRepo(app.db, "bob", "lib")!;
72 expect(await line("/bob/lib")).not.toContain("last took");
72 expect(await line("/bob/lib")).not.toContain("Last took");
7373 app.bus.append({ kind: "push", repoId: bob.id, actorId: bob.ownerId, payload: { updates: [], followed: "alice/lib" } });
74 expect(await line("/bob/lib")).toContain("Sends offers to alice/lib · last took just now");
74 expect(await line("/bob/lib")).toContain("Up to date with alice/lib; following has nothing to apply. Last took just now.");
7575 });
7676
7777 test("the fragment is not served to someone who cannot read the repository", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs