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

A fork's page names when it last followed upstream, in one line, from the sync record #15600

Merged opened this

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

Merged

scout/forge:scout/15595-a-fork-s-page-names-when-it-last-followe → main 0 commits fork 9 threads · 9 unresolved

  • Merged. scout/15595-a-fork-s-page-names-when-it-last-followe was merged into main as 9efc458.

Review

Sign in to review this change.
14 files changed +222 −43
docs/FOLLOWING.md +10
@@ -324,3 +324,13 @@ The check cell's memory is on the same page under **Check cell**, and in the ter
324324 the secret once on its own screen; `x` asks before it revokes the one under
325325 the cursor ("Revoke the token for <child>?", Keep selected): `y` revokes,
326326 `n`, esc or enter keeps it.
327
328 ## When it last followed
329
330 A fork's page (its own row under the standing sentence, on every fork), the Forks tab, the
outdated

Says a fork's page uses followedWords; it does not as shipped. Make the doc match.

331 terminal's tree and `fork_tree`'s `followed` say it in one line from the follow record (no
332 new table): "followed upstream 3 hours ago", "never followed", or "waiting for the crew"
333 when its newest follow hit a conflict no later take has cleared (`followedWords`,
334 `src/actions/follow_words.ts`). The page's standing sentence then says only the drift
335 (`driftSentence`); the API, MCP and terminal forks screen keep the whole sentence, with the
336 pull or issue that holds a conflict.
docs/features/fork-last-follow.md +7 −3
@@ -4,7 +4,7 @@ row: What a fork's last follow did
44 ---
55 # What a fork's last follow did
66
7 A fork's standing sentence (the one under its header, #14462) says what its last follow of the upstream did, once, in the same sentence that says how far behind it is:
7 A fork's standing sentence (#14462) says what its last follow of the upstream did, once, in the same sentence that says how far behind it is. The API's and MCP's `words` and the terminal's forks screen say that whole sentence; the fork's page says the drift part alone and puts the record on its own row (below).
88
99 - **Code came in:** `Last took 3 hours ago.` This reads the push the take recorded, so it holds for every way a fork takes: the Take button, the API, the MCP `take_updates` tool, the terminal, and a fork that follows automatically.
1010 - **Nothing new:** `Checked 5 minutes ago: nothing new.`
@@ -15,11 +15,15 @@ A newer take of code replaces an older check or conflict clause.
1515
1616 ## Where
1717
18 - **Fork's page:** the live standing line under the header; a take updates it without a reload.
19 - **Fork trees:** each fork's row on the repository page says `last took …`; the terminal's fork tree line and `fork_tree` nodes (`tookAt`) carry it too.
18 - **Fork's page:** the live block under the header: the drift sentence, and the followed row (below) on every fork; a take updates both without a reload.
19 - **Fork trees:** each fork's row on the Forks tab, the terminal's fork tree line, and the `fork_tree` nodes (`followed`) carry the followed words (below).
2020 - **MCP:** `following` returns `lastFollow`, the clause on a take that took nothing, else `null`; `line` has the last took.
2121 - **Terminal:** the forks screen reads the same sentence.
2222
2323 ## How it is stored
2424
2525 A take that took nothing (nothing new, or a conflict) stores one `fork.followed` event (`{outcome, on}`) from `takeOrTell`. Taking code is already a `push` event marked `followed`. Nothing runs git to read it: the page makes one indexed query.
26
27 ## One line: when it last followed
28
29 Everywhere but the standing sentence, the record is said in one vocabulary, `followedWords` (`src/actions/follow_words.ts`, #15595): "followed upstream 3 hours ago" (the newest take or check of nothing new), "waiting for the crew" (the newest follow hit a conflict no later take cleared), or "never followed". It is the fork page's own row (`data-followed`, `src/web/pages/fork-standing.ts`), shown on every fork whatever the behind or ahead lines say; each fork on the Forks tab (`src/web/pages/repo.ts`); the terminal's tree (`src/tui/screens/fork_tree.ts`); and `fork_tree`'s `followed`. The tree and the Forks tab read every fork's record in one statement (`lastFollows`).
outdated

Cites src/web/pages/fork-standing.ts, which this diff does not change, and claims the page says 'waiting for the crew'. Correct after the page fix.

src/actions/follow.ts +14 −5
@@ -193,22 +193,31 @@ export function lastFollowSaid(app: App, repo: Repo): string {
193193 * is no fork.
194194 */
195195 export async function followWords(app: App, repo: Repo, viewer: User | undefined): Promise<string | undefined> {
196 const sentence = await driftSentence(app, repo, viewer);
197 if (sentence === undefined) return undefined;
198 const took = lastTookAt(app.db, repo.id);
199 const said = took === null ? sentence : `${sentence} Last took ${agoWords(took)}.`;
200 const clause = lastFollowClause(lastFollow(app.db, repo.id), took);
201 return clause === "" ? said : `${said} ${clause}`;
202 }
203
204 /**
205 * The drift and what following will do, without the follow record: the fork's page says the
206 * record on its own line (`followedWords`, #15595). Undefined for a repository that is no fork.
207 */
208 export async function driftSentence(app: App, repo: Repo, viewer: User | undefined): Promise<string | undefined> {
196209 if (repo.forkParentId === null) return undefined;
197210 const parent = forkParentFor(app.db, repo, viewer);
198211 const drift =
199212 parent === undefined || repo.archivedAt !== null
200213 ? { ahead: null, behind: null }
201214 : (await driftOfForks(app, parent, [repo]))[0]!.drift;
outdated

Principle 1: this appends 'Never followed.' to a sentence that already carries the clause, and the page still lacks 'waiting for the crew'. The fork page should render followedWords once, always, instead of bolting a fragment onto the standing sentence.

202 const sentence = driftWords(
215 return driftWords(
203216 await followModeOf(app, repo),
204217 parent === undefined ? undefined : `${parent.ownerName}/${parent.name}`,
205218 drift.ahead,
206219 drift.behind,
207220 );
208 const took = lastTookAt(app.db, repo.id);
209 const said = took === null ? sentence : `${sentence} Last took ${agoWords(took)}.`;
210 const clause = lastFollowClause(lastFollow(app.db, repo.id), took);
211 return clause === "" ? said : `${said} ${clause}`;
212221 }
213222
214223 export type FollowModeError = SeverError | "invalid_mode" | "severed" | "updating";
src/actions/follow_words.ts +18
@@ -226,3 +226,21 @@ export function lastFollowClause(
226226 ? `A take ${agoWords(last.at, now)} hit a conflict that no one holds yet.`
227227 : `A take ${agoWords(last.at, now)} hit a conflict the crew holds as ${last.on.kind} #${last.on.number}.`;
228228 }
229
230 /**
231 * When a fork last followed its upstream, in one line from the sync record (#15595): a conflict
232 * newer than any take reads "waiting for the crew"; else the newest take or check of nothing new
233 * reads "followed upstream 3 hours ago"; no record at all reads "never followed".
234 */
235 export function followedWords(

The right single source, but the fork page does not use it. Wire the page to this so page, list and terminal say the same words.

236 last: { outcome: "nothing_new" | "conflict"; at: string } | null,
237 tookAt: string | null,
238 now: number = Date.now(),
239 ): string {
240 const took = tookAt === null ? Number.NaN : Date.parse(tookAt);
241 const checked = last === null ? Number.NaN : Date.parse(last.at);
242 if (last?.outcome === "conflict" && !(took >= checked)) return "waiting for the crew";
243 const newest = Math.max(Number.isFinite(took) ? took : -Infinity, Number.isFinite(checked) ? checked : -Infinity);
244 if (newest === -Infinity) return "never followed";
245 return `followed upstream ${agoWords(new Date(newest).toISOString(), now)}`;
246 }
src/actions/fork_tree.ts +6 −4
@@ -13,8 +13,9 @@
1313 */
1414
1515 import type { Database } from "bun:sqlite";
16 import { FOLLOW_WORD } from "./follow_words.ts";
16 import { FOLLOW_WORD, followedWords } from "./follow_words.ts";
1717 import { keptBehind, type Following } from "../core/following.ts";
18 import { lastFollows } from "../core/last_follow.ts";
1819 import { FORK_DEFAULT_MODE, forkFollowModes, lastTookAts } from "../core/fork_follow.ts";
1920 import { canRead, forkParentFor, visibleForksByParent, type Repo } from "../core/repos.ts";
2021 import type { User } from "../core/users.ts";
@@ -46,8 +47,8 @@ export interface TreeNode {
4647 * tips.
4748 */
4849 readonly behind: number | null;
49 /** When it last took code from its parent (ISO); absent when it never has. */
50 readonly tookAt?: string;
50 /** When it last followed, in one line from the sync record; absent for the root. */
51 readonly followed?: string;
outdated

tookAt is now unused outside a test assertion; remove it.

5152 /** Set on a root that is a fork of something the caller may not read: a hidden fork, not a gap.
5253 * The parent is not named. */
5354 readonly hiddenParent?: true;
@@ -119,6 +120,7 @@ export function forkTree(
119120 const hidden = root.forkParentId !== null && !keep.has(root.forkParentId);
120121 const modes = forkFollowModes(db, rows.slice(hidden ? 0 : 1).map((r) => r.repo.id));
121122 const took = lastTookAts(db, rows.slice(hidden ? 0 : 1).map((r) => r.repo.id));
123 const follows = lastFollows(db, rows.slice(hidden ? 0 : 1).map((r) => r.repo.id));
122124 const nodes: TreeNode[] = rows.map((r) => {
123125 const hides = hidden && r.parent === null;
124126 // A root whose link the owner cut reads "severed", not nothing.
@@ -132,7 +134,7 @@ export function forkTree(
132134 follow: mode === undefined ? "autonomous" : treeFollow(modes.get(r.repo.id)),
133135 word: mode === undefined ? "" : FOLLOW_WORD[mode],
134136 behind: r.parent === null ? null : (keptBehind(forge, r.repo, r.parent) ?? null),
135 ...(took.has(r.repo.id) && !(r.parent === null && !hides) ? { tookAt: took.get(r.repo.id)! } : {}),
137 ...(r.parent === null ? {} : { followed: followedWords(follows.get(r.repo.id) ?? null, took.get(r.repo.id) ?? null) }),
136138 ...(hides ? { hiddenParent: true as const } : {}),
137139 };
138140 });
src/core/last_follow.ts +26 −3
@@ -22,6 +22,26 @@ export const FOLLOWED_EVENT = "fork.followed";
2222
2323 const isOutcome = (v: unknown): v is FollowOutcome => v === "nothing_new" || v === "conflict";
2424
25 /**
26 * The newest follow of each of these repositories, in one statement; absent when it never followed.
27 */
28 export function lastFollows(db: Database, repoIds: readonly string[]): Map<string, LastFollow> {
29 const out = new Map<string, LastFollow>();
30 if (repoIds.length === 0) return out;
31 const rows = db
32 .query<{ id: string; at: string | null; payload: string | null }, [string, string]>(
33 `SELECT j.value AS id, e.created_at AS at, e.payload AS payload FROM json_each(?1) j
34 LEFT JOIN event e ON e.seq = (SELECT seq FROM event WHERE repo_id = j.value AND kind = ?2 ORDER BY seq DESC LIMIT 1)`,
35 )
36 .all(JSON.stringify(repoIds), FOLLOWED_EVENT);
37 for (const r of rows) {
38 if (r.at === null || r.payload === null) continue;
39 const f = parseFollow(r.at, r.payload);
40 if (f !== null) out.set(r.id, f);
41 }
42 return out;
43 }
44
2545 /** The newest follow recorded for this repository, or null when it never followed. */
2646 export function lastFollow(db: Database, repoId: string): LastFollow | null {
2747 const row = db
@@ -29,10 +49,13 @@ export function lastFollow(db: Database, repoId: string): LastFollow | null {
2949 "SELECT created_at AS at, payload FROM event WHERE repo_id = ?1 AND kind = ?2 ORDER BY seq DESC LIMIT 1",
3050 )
3151 .get(repoId, FOLLOWED_EVENT);
32 if (row === null) return null;
52 return row === null ? null : parseFollow(row.at, row.payload);
53 }
54
55 function parseFollow(at: string, payload: string): LastFollow | null {
3356 let p: Record<string, unknown>;
3457 try {
35 p = JSON.parse(row.payload) as Record<string, unknown>;
58 p = JSON.parse(payload) as Record<string, unknown>;
3659 } catch {
3760 return null;
3861 }
@@ -40,7 +63,7 @@ export function lastFollow(db: Database, repoId: string): LastFollow | null {
4063 const on = p["on"] as { kind?: unknown; number?: unknown } | null | undefined;
4164 return {
4265 outcome: p["outcome"],
43 at: row.at,
66 at,
4467 on:
4568 on && (on.kind === "pull" || on.kind === "issue") && Number.isInteger(on.number)
4669 ? { kind: on.kind, number: on.number as number }
src/tui/screens/fork_tree.ts +2 −2
@@ -4,7 +4,7 @@
44 * the tool does: a repo the session's person may not read has no tree.
55 */
66
7 import { HIDDEN_FORK_WORD, agoWords, treeFollowPhrase } from "../../actions/follow_words.ts";
7 import { HIDDEN_FORK_WORD, treeFollowPhrase } from "../../actions/follow_words.ts";
88 import { behindChip } from "../../actions/fork_tree_rows.ts";
99 import { forkTree, type ForkTree } from "../../actions/fork_tree.ts";
1010 import { followLine } from "../../actions/follow.ts";
@@ -25,7 +25,7 @@ export function treeLines(tree: ForkTree | undefined, asked: string, width = 80,
2525 const lines = tree.nodes.map((n) => {
2626 const phrase = n.word === "" ? "" : treeFollowPhrase(n.follow);
2727 const behind = ` · ${behindChip(n.behind)}`;
28 const took = n.tookAt === undefined ? "" : ` · last took ${agoWords(n.tookAt)}`;
28 const took = n.followed === undefined ? "" : ` · ${n.followed}`;
outdated

Terminal row now carries 'last took X' and 'followed upstream X' together: redundant. Replace the took text with n.followed.

2929 const follow = (phrase === "" ? "" : ` ${phrase}${behind}${took}`) + (n.hiddenParent === true ? ` ${HIDDEN_FORK_WORD}` : "");
3030 const you = n.repo !== asked && viewer !== undefined && n.repo.startsWith(`${viewer}/`) ? " (you)" : "";
3131 return truncate(`${" ".repeat(n.depth)}${n.repo === asked ? "* " : ""}${n.repo}${you}${follow}`, width);
src/web/pages/fork-standing.ts +15 −3
@@ -8,12 +8,14 @@
88 * leave a line that still says the fork is level.
99 */
1010
11 import { followWords } from "../../actions/follow.ts";
11 import { driftSentence } from "../../actions/follow.ts";
12 import { followedWords } from "../../actions/follow_words.ts";
1213 import { keptStanding } from "../../core/following.ts";
1314 import { forkFollowMode, lastTookAt } from "../../core/fork_follow.ts";
1415 import { linkWord, sayLink } from "../../flows/link_word.ts";
1516 import { getRepoById } from "../../core/repos.ts";
1617 import type { Repo } from "../../core/repos.ts";
18 import { lastFollow } from "../../core/last_follow.ts";
1719 import { STANDING_EVENTS } from "../../core/standing_events.ts";
1820 import { getFollow } from "../../core/upstream_follow.ts";
1921 import { notePhase, takeSessionTime } from "../../core/route_timing.ts";
@@ -60,15 +62,25 @@ function wordOf(ctx: Ctx, repo: Repo): Html | null {
6062 * The block's lines: the sync failure, then the checks' own words, and the plain standing where
outdated

Principle 1: a second line with its own sync icon under the standing sentence, repeating what the conflict clause already says. One line, one icon.

Non-blocking: this docblock for lines() now sits above followedLine's own docblock. Move followedLine above it.

6163 * they are silent.
6264 */
65 /**
66 * When a fork last followed, in the lists' own words (`followedWords`, #15595); on every fork,
67 * whatever else the block says. Nothing for a repository with no parent.
68 */
69 function followedLine(ctx: Ctx, repo: Repo): Html | null {
70 if (repo.forkParentId === null) return null;
71 const said = followedWords(lastFollow(ctx.app.db, repo.id), lastTookAt(ctx.app.db, repo.id));
72 return html`<div class="small muted" data-followed>${icon("clock")} ${said}</div>`;
73 }
74
6375 async function lines(ctx: Ctx, repo: Repo): Promise<Html> {
6476 const behind = behindLine(ctx, repo);
outdated

The followed line is only emitted when behind/ahead are null; otherwise the fork page says nothing about when it last followed. Make it consistent.

6577 const ahead = originAheadLine(ctx, repo);
66 const words = await followWords(ctx.app, repo, ctx.auth.user);
78 const words = await driftSentence(ctx.app, repo, ctx.auth.user);
6779 const plain =
6880 words === undefined
6981 ? null
7082 : html`<div class="small muted" data-follow-standing>${icon("sync")} ${wordOf(ctx, repo)}<a href="${repoBase(repo)}/forks#following">${words}</a></div>`;
71 return html`${failedLine(repo)}${behind}${ahead}${behind === null && ahead === null ? plain : null}`;
83 return html`${failedLine(repo)}${behind}${ahead}${behind === null && ahead === null ? plain : null}${followedLine(ctx, repo)}`;
7284 }
7385
7486 /** The region as the page paints it first; null for a repository that stands against nothing. */
src/web/pages/repo.ts +10 −7
@@ -47,8 +47,9 @@ import {
4747 takeUpdates,
4848 type ForkDrift,
4949 } from "../../actions/forks.ts";
50 import { lastFollows } from "../../core/last_follow.ts";
5051 import { FORK_DEFAULT_MODE, forkFollowModes, lastTookAts, type ForkFollowMode } from "../../core/fork_follow.ts";
51 import { FOLLOW_PHRASE, agoWords, isSevered } from "../../actions/follow_words.ts";
52 import { FOLLOW_PHRASE, followedWords, isSevered } from "../../actions/follow_words.ts";
5253 import { behindChip } from "../../actions/fork_tree_rows.ts";
5354 import { keptBehind, lineageOf, MINE_ANCHOR, ownsInTree } from "../../core/following.ts";
5455 import {
@@ -189,6 +190,8 @@ export async function forksPage(ctx: Ctx): Promise<Response> {
189190 const forkIds = [...tree, ...tree.flatMap((n) => n.forks)].map((n) => n.repo.id);
190191 const forkModes = forkFollowModes(ctx.app.db, forkIds);
191192 const forkTook = lastTookAts(ctx.app.db, forkIds);
193 const forkLast = lastFollows(ctx.app.db, forkIds);
outdated

One lastFollow query per fork here; use lastFollows(db, forkIds), which you added for the tree.

194 const forkFollowed = new Map(forkIds.map((id) => [id, followedWords(forkLast.get(id) ?? null, forkTook.get(id) ?? null)]));
192195 notePhase(ctx.request, "fork-tree", performance.now() - t);
193196 t = performance.now();
194197 // The whole family, from the oldest ancestor this viewer may see: who
@@ -221,7 +224,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> {
221224 note: "A fork is a copy under another name that can propose changes back here, and follows this one until it has work of its own.",
222225 bind: BIND.rest,
223226 })
224 : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes, (fork, parent) => keptBehind(ctx.app, fork, parent), forkTook)}
227 : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes, (fork, parent) => keptBehind(ctx.app, fork, parent), forkFollowed)}
225228 <h3 class="mt">The family, by who follows whom</h3>
226229 ${lineageCard(lineage, repo.id, ctx.auth.user?.id)}`}`;
227230 const res = page({
@@ -247,10 +250,10 @@ function forkRanking(
247250 modes: ReadonlyMap<string, ForkFollowMode> = new Map(),
248251 /** Commits a nested fork lacks from its parent, as last counted; never asks git. */
249252 behindOf: (fork: Repo, parent: Repo) => number | undefined = () => undefined,
250 /** When each fork last took from its parent (ISO), from the pushes already recorded. */
251 tookAt: ReadonlyMap<string, string> = new Map(),
253 /** When each fork last followed, in one line from the sync record (`followedWords`). */
254 followedOf: ReadonlyMap<string, string> = new Map(),
252255 ): Html {
253 const took = (id: string): string => (tookAt.has(id) ? `last took ${agoWords(tookAt.get(id)!)}` : "");
256 const followedLine = (id: string): string => followedOf.get(id) ?? "";
254257 const modeOf = (id: string): ForkFollowMode => modes.get(id) ?? FORK_DEFAULT_MODE;
255258 const below = (n: ForkNode, parent: Repo): Html => {
256259 const behind = behindOf(n.repo, parent);
@@ -260,7 +263,7 @@ function forkRanking(
260263 title: html`<a href="/${n.repo.ownerName}/${n.repo.name}"
261264 >${n.repo.ownerName}/${n.repo.name}</a
262265 >`,
263 meta: html`<span>${FOLLOW_PHRASE[modeOf(n.repo.id)]}</span>${html` · ${behindChip(behind ?? null)}`}${took(n.repo.id) === "" ? "" : html` · ${took(n.repo.id)}`}${n.deeper === 0
266 meta: html`<span>${FOLLOW_PHRASE[modeOf(n.repo.id)]}</span>${html` · ${behindChip(behind ?? null)}`}${followedLine(n.repo.id) === "" ? "" : html` · ${followedLine(n.repo.id)}`}${n.deeper === 0
264267 ? html``
265268 : html` · <a href="/${n.repo.ownerName}/${n.repo.name}/forks"
266269 >and ${n.deeper} more fork${n.deeper === 1 ? "" : "s"} below</a
@@ -277,7 +280,7 @@ function forkRanking(
277280 >`,
278281 meta: html`<span>${FOLLOW_PHRASE[modeOf(f.fork.id)]}</span>${[
279282 ranked.archived ? "" : driftWords(f.drift),
280 took(f.fork.id),
283 followedLine(f.fork.id),
281284 f.pushedAt === null ? "" : html`pushed ${time(f.pushedAt)}`,
282285 ]
283286 .filter((p) => String(p) !== "")
test/following-followed-line.test.ts added +70
@@ -0,0 +1,70 @@
1 /**
2 * The one line on when a fork last followed upstream (#15595): three phrasings, from the record.
3 */
4 import { afterAll, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import { followedWords } from "../src/actions/follow_words.ts";
9 import { createRepo } from "../src/actions/repos.ts";
10 import { createApp } from "../src/app.ts";
11 import { FOLLOWED_EVENT, lastFollow, lastFollows } from "../src/core/last_follow.ts";
12 import { createUser } from "../src/core/users.ts";
13 import { promote } from "./helpers/members.ts";
14
15 const dirs: string[] = [];
16 afterAll(async () => {
17 for (const d of dirs) await rm(d, { recursive: true, force: true });
18 });
19
20 const now = Date.parse("2026-01-01T03:00:00Z");
21 const at = "2026-01-01T00:00:00Z";
22
23 test("never followed when the record is empty", () => {
24 expect(followedWords(null, null, now)).toBe("never followed");
25 });
26
27 test("followed upstream says when, from a take or a check", () => {
28 expect(followedWords(null, at, now)).toBe("followed upstream 3 hours ago");
29 expect(followedWords({ outcome: "nothing_new", at }, null, now)).toBe("followed upstream 3 hours ago");
30 expect(followedWords({ outcome: "nothing_new", at }, "2026-01-01T02:00:00Z", now)).toBe("followed upstream 1 hour ago");
31 });
32
33 test("a conflict newer than any take waits for the crew; a later take clears it", () => {
34 expect(followedWords({ outcome: "conflict", at }, null, now)).toBe("waiting for the crew");
35 expect(followedWords({ outcome: "conflict", at }, "2025-12-31T00:00:00Z", now)).toBe("waiting for the crew");
36 expect(followedWords({ outcome: "conflict", at }, "2026-01-01T01:00:00Z", now)).toBe("followed upstream 2 hours ago");
37 });
38
39 test("lastFollows equals lastFollow per id on the real event table, and leaves out one that never followed", async () => {
40 const dataDir = await mkdtemp(join(tmpdir(), "forge-followed-line-"));
41 dirs.push(dataDir);
42 const app = createApp({ dataDir, port: 0 });
43 try {
44 const u = await createUser(app.db, {
45 origin: "seed", trusted: true, username: "ann", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true,
46 });
47 if (!u.ok) throw new Error(u.error);
48 promote(app.db, u.value);
49 const repo = async (name: string) => {
50 const r = await createRepo(app, u.value, { name, visibility: "public" });
51 if (!r.ok) throw new Error(String(r.error));
52 return r.value.id;
53 };
54 const [a, b, c] = [await repo("a"), await repo("b"), await repo("c")];
55 const add = (repoId: string, kind: string, payload: Record<string, unknown>) =>
56 app.bus.append({ kind, repoId, actorId: u.value.id, payload });
57 add(a, FOLLOWED_EVENT, { outcome: "nothing_new" });
58 add(a, FOLLOWED_EVENT, { outcome: "conflict", on: { kind: "pull", number: 7 } });
59 add(b, FOLLOWED_EVENT, { outcome: "nothing_new" });
60 add(c, "push", { updates: [] });
61 const got = lastFollows(app.db, [a, b, c]);
62 for (const id of [a, b, c]) expect(got.get(id) ?? null).toEqual(lastFollow(app.db, id));
63 expect(got.get(a)?.outcome).toBe("conflict");
64 expect(got.get(a)?.on).toEqual({ kind: "pull", number: 7 });
65 expect([...got.keys()].sort()).toEqual([a, b].sort());
66 expect(lastFollows(app.db, []).size).toBe(0);
67 } finally {
68 app.close();
69 }
70 });
test/fork-last-follow.test.ts +25 −8
@@ -9,9 +9,10 @@ import { mkdtemp, rm } from "node:fs/promises";
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
1111 import { followWords, lastFollowSaid, takeOrTell } from "../src/actions/follow.ts";
12 import { lastFollowClause, agoWords } from "../src/actions/follow_words.ts";
12 import { lastFollowClause } from "../src/actions/follow_words.ts";
1313 import { addToCrew, createAgent } from "../src/actions/crew.ts";
1414 import { forkTree } from "../src/actions/fork_tree.ts";
15 import { noteCheck, putFollow } from "../src/core/upstream_follow.ts";
1516 import { treeLines } from "../src/tui/screens/fork_tree.ts";
1617 import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
1718 import { createApp, type App } from "../src/app.ts";
@@ -82,11 +83,15 @@ test("a fork that never followed says nothing false; each take that took nothing
8283 const fork = must(await forkRepo(app, bob, fresh(parent), "game-bob"));
8384 expect(lastFollow(app.db, fork.id)).toBeNull();
8485 expect(lastFollowSaid(app, fresh(fork))).toBe("");
85 expect(await standing(fork)).not.toMatch(/follow(ed)? upstream|Checked|conflict/);
86 expect(await standing(fork)).not.toMatch(/followed upstream|Checked|conflict|waiting/);
87 expect(await standing(fork)).toMatch(/never followed$/);
8688
8789 must(await takeOrTell(app, bob, fresh(fork)));
8890 expect(lastFollowSaid(app, fresh(fork))).toBe("Checked just now: nothing new.");
89 expect(await standing(fork)).toContain("Checked just now: nothing new.");
91 expect(await followWords(app, fresh(fork), bob)).toContain("Checked just now: nothing new.");
92 // The page says the record once, on its own row, in the lists' words.
93 expect(await standing(fork)).toMatch(/followed upstream just now$/);
94 expect(await standing(fork)).not.toContain("Checked");
9095
9196 // Code taken is the push marked followed: "Last took", and the older check is not repeated.
9297 await commit(bob, fork, "mine.txt", "mine\n");
@@ -109,18 +114,30 @@ test("a fork that never followed says nothing false; each take that took nothing
109114 const conflict = await takeOrTell(app, bob, fresh(fork));
110115 expect(conflict.ok).toBe(false);
111116 expect(lastFollowSaid(app, fresh(fork))).toMatch(/the crew holds as (issue|pull) #\d+\.$/);
112 expect(await standing(fork)).toMatch(/the crew holds as (issue|pull) #\d+\.$/);
117 expect(await followWords(app, fresh(fork), bob)).toMatch(/the crew holds as (issue|pull) #\d+\.$/);
118 expect(await standing(fork)).toMatch(/waiting for the crew$/);
119 // The Forks tab of the parent says it in the same words.
120 expect(await (await fetch(`${servers.url}/alice/game/forks`)).text()).toMatch(/bob\/game-bob[\s\S]*waiting for the crew/);
121 // The row shows on a fork whose behind line shows too (#15595: it showed only when that was
122 // silent).
123 putFollow(app.db, { repoId: fork.id, url: "https://github.com/trevato/forge.git", branch: "main", enabled: true, byId: bob.id, originId: "", via: "parent" });
124 noteCheck(app.db, fork.id, { at: new Date().toISOString(), behind: 2, error: "" });
125 const both = await (await fetch(`${servers.url}/bob/game-bob/standing-line`)).text();
126 expect(both).toContain("data-behind-upstream");
127 expect(both).toMatch(/data-followed>[\s\S]*waiting for the crew/);
113128 }, 30_000);
114129
115130 test("the tree says when each fork last took, on the web page and in the terminal", async () => {
116131 const fork = must(await forkRepo(app, alice, fresh(parent), "game-alice"));
117 expect(forkTree(app.db, fresh(parent), alice, app)!.nodes.find((n) => n.repo === "alice/game-alice")!.tookAt).toBeUndefined();
132 expect(forkTree(app.db, fresh(parent), alice, app)!.nodes.find((n) => n.repo === "alice/game-alice")!.followed).toBe("never followed");
118133 await commit(alice, parent, "t.txt", "t\n");
119134 must(await takeOrTell(app, alice, fresh(fork)));
120135 const node = forkTree(app.db, fresh(parent), alice, app)!.nodes.find((n) => n.repo === "alice/game-alice")!;
121 expect(node.tookAt).toBeDefined();
122 const said = `last took ${agoWords(node.tookAt!)}`;
123 expect(treeLines(forkTree(app.db, fresh(parent), alice, app), "alice/game", 120).join("\n")).toContain(said);
136 const said = node.followed!;
137 expect(said).toMatch(/^followed upstream /);
138 const text = treeLines(forkTree(app.db, fresh(parent), alice, app), "alice/game", 120).join("\n");
139 expect(text).toContain(said);
140 expect(text).not.toContain("last took");
124141 const page = await (await fetch(`${servers.url}/alice/game/forks`)).text().catch(() => "");
125142 const root = await (await fetch(`${servers.url}/alice/game`)).text();
126143 expect(root + page).toContain(said);
test/fork-standing-line.test.ts +12 −2
@@ -53,6 +53,10 @@ afterAll(async () => {
5353 await rm(dataDir, { recursive: true, force: true });
5454 });
5555
56 /** The fork page's followed row (`followedWords`), or null where the page has none. */
57 const followedOf = async (path: string): Promise<string | null> =>
58 (await (await fetch(`${servers.url}${path}`)).text()).match(/<div class="small muted" data-followed><svg.*?<\/svg> ([^<]*)<\/div>/)?.[1] ?? null;
59
5660 const lineOf = async (path: string): Promise<string | null> => {
5761 const page = await (await fetch(`${servers.url}${path}`)).text();
5862 return page.match(/<div class="small muted" data-follow-standing>[^<]*<svg.*?<\/svg> (?:<strong data-link-word="[^"]*">[^<]*<\/strong> · )?<a href="([^"]*)">([^<]*)<\/a><\/div>/)?.[2] ?? null;
@@ -79,6 +83,8 @@ test("a fork's page says its mode, links to the following card, and a root says
7983 setForkFollowMode(app.db, bob.id, "dont-follow");
8084 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied.");
8185 expect(await lineOf("/alice/lib")).toBeNull();
86 expect(await followedOf("/bob/lib")).toBe("never followed");
87 expect(await followedOf("/alice/lib")).toBeNull();
8288 });
8389
8490 test("the last take is told, and the MCP's words are the page's", async () => {
@@ -87,7 +93,10 @@ test("the last take is told, and the MCP's words are the page's", async () => {
8793 kind: "push", repoId: bob.id, actorId: bob.ownerId,
8894 payload: { updates: [], followed: "alice/lib" },
8995 });
90 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied. Last took just now.");
96 // The page's sentence is the drift alone; the take is said on the followed row, in the lists'
97 // words.
98 expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied.");
99 expect(await followedOf("/bob/lib")).toBe("followed upstream just now");
91100 expect(await followStanding(app, bob, undefined)).toBe("Not following alice/lib · last took just now");
92101 expect(await followStanding(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined();
93102 });
@@ -222,7 +231,8 @@ test("the page, the MCP forks answer, the API and the terminal say one exact sen
222231 for (const mode of ["take-updates", "tell-me", "dont-follow"] as const) {
223232 setForkFollowMode(app.db, bob.id, mode);
224233 expect(await followWords(app, bob, undefined)).toBe(want[mode]);
225 expect(await lineOf("/bob/lib")).toBe(want[mode]);
234 expect(await lineOf("/bob/lib")).toBe(want[mode].slice(0, -tail.length));
235 expect(await followedOf("/bob/lib")).toBe("followed upstream just now");
226236 expect((await mcpTool(servers.url, token, "forks", { repo: "bob/lib" })).value.words).toBe(want[mode]);
227237 const api = await (await fetch(`${servers.url}/api/v1/repos/bob/lib/forks`, { headers: { authorization: `Bearer ${token}` } })).json() as { words: string };
228238 expect(api.words).toBe(want[mode]);
test/fork-tree-reader.test.ts +4 −4
@@ -64,9 +64,9 @@ describe("forkTree", () => {
6464 expect(t.truncated).toBe(false);
6565 const by = Object.fromEntries(t.nodes.map((n) => [n.repo, n]));
6666 expect(by["alice/app"]).toEqual({ repo: "alice/app", parent: null, depth: 0, follow: "autonomous", word: "", behind: null });
67 expect(by["bob/app"]).toEqual({ repo: "bob/app", parent: "alice/app", depth: 1, follow: "offers", word: "proposes", behind: null });
67 expect(by["bob/app"]).toEqual({ repo: "bob/app", parent: "alice/app", depth: 1, follow: "offers", word: "proposes", behind: null, followed: "never followed" });
6868 expect(by["carol/app"]!.parent).toBe("alice/app");
69 expect(by["dan/app"]).toEqual({ repo: "dan/app", parent: "bob/app", depth: 2, follow: "take-updates", word: "follows", behind: null });
69 expect(by["dan/app"]).toEqual({ repo: "dan/app", parent: "bob/app", depth: 2, follow: "take-updates", word: "follows", behind: null, followed: "never followed" });
7070 });
7171
7272 test("a stranger and the owner of a private fork get different lists, and the stranger's has no trace", () => {
@@ -146,9 +146,9 @@ describe("the terminal screen", () => {
146146 const { treeLines } = await import("../src/tui/screens/fork_tree.ts");
147147 const lines = treeLines(forkTree(app.db, org, users["dan"]!, app), "bob/app");
148148 expect(lines).toContain("alice/app");
149 expect(lines).toContain(" * bob/app proposes only · behind unknown");
149 expect(lines).toContain(" * bob/app proposes only · behind unknown · never followed");
150150 const own = treeLines(forkTree(app.db, person, users["dan"]!, app), "dan/app");
151 expect(own).toContain(" * dan/app follows automatically · behind unknown");
151 expect(own).toContain(" * dan/app follows automatically · behind unknown · never followed");
152152 expect(lines.join("\n")).not.toContain("offers");
153153 expect(lines.join("\n")).not.toContain("secret");
154154 expect(treeLines(forkTree(app.db, hidden, users["dan"]!, app), "erin/secret")).toEqual(["Nothing to show."]);
test/standing-live.test.ts +3 −2
@@ -69,9 +69,10 @@ 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")).toContain("never followed");
7373 app.bus.append({ kind: "push", repoId: bob.id, actorId: bob.ownerId, payload: { updates: [], followed: "alice/lib" } });
74 expect(await line("/bob/lib")).toContain("Up to date with alice/lib; following has nothing to apply. Last took just now.");
74 expect(await line("/bob/lib")).toContain("Up to date with alice/lib; following has nothing to apply.");
75 expect(await line("/bob/lib")).toContain("followed upstream just now");
7576 });
7677
7778 test("the fragment is not served to someone who cannot read the repository", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs