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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15595-a-fork-s-page-names-when-it-last-followe → main 0 commits fork 9 threads · 9 unresolved
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 | ||
| 324 | 324 | the secret once on its own screen; `x` asks before it revokes the one under |
| 325 | 325 | the cursor ("Revoke the token for <child>?", Keep selected): `y` revokes, |
| 326 | 326 | `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 | |
| 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 | ||
| 4 | 4 | --- |
| 5 | 5 | # What a fork's last follow did |
| 6 | 6 | |
| 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). | |
| 8 | 8 | |
| 9 | 9 | - **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. |
| 10 | 10 | - **Nothing new:** `Checked 5 minutes ago: nothing new.` |
| @@ -15,11 +15,15 @@ A newer take of code replaces an older check or conflict clause. | ||
| 15 | 15 | |
| 16 | 16 | ## Where |
| 17 | 17 | |
| 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). | |
| 20 | 20 | - **MCP:** `following` returns `lastFollow`, the clause on a take that took nothing, else `null`; `line` has the last took. |
| 21 | 21 | - **Terminal:** the forks screen reads the same sentence. |
| 22 | 22 | |
| 23 | 23 | ## How it is stored |
| 24 | 24 | |
| 25 | 25 | 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/actions/follow.ts +14 −5
| @@ -193,22 +193,31 @@ export function lastFollowSaid(app: App, repo: Repo): string { | ||
| 193 | 193 | * is no fork. |
| 194 | 194 | */ |
| 195 | 195 | 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> { | |
| 196 | 209 | if (repo.forkParentId === null) return undefined; |
| 197 | 210 | const parent = forkParentFor(app.db, repo, viewer); |
| 198 | 211 | const drift = |
| 199 | 212 | parent === undefined || repo.archivedAt !== null |
| 200 | 213 | ? { ahead: null, behind: null } |
| 201 | 214 | : (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 |
||
| 202 | const sentence = driftWords( | |
| 215 | return driftWords( | |
| 203 | 216 | await followModeOf(app, repo), |
| 204 | 217 | parent === undefined ? undefined : `${parent.ownerName}/${parent.name}`, |
| 205 | 218 | drift.ahead, |
| 206 | 219 | drift.behind, |
| 207 | 220 | ); |
| 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}`; | |
| 212 | 221 | } |
| 213 | 222 | |
| 214 | 223 | export type FollowModeError = SeverError | "invalid_mode" | "severed" | "updating"; |
src/actions/follow_words.ts +18
| @@ -226,3 +226,21 @@ export function lastFollowClause( | ||
| 226 | 226 | ? `A take ${agoWords(last.at, now)} hit a conflict that no one holds yet.` |
| 227 | 227 | : `A take ${agoWords(last.at, now)} hit a conflict the crew holds as ${last.on.kind} #${last.on.number}.`; |
| 228 | 228 | } |
| 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 @@ | ||
| 13 | 13 | */ |
| 14 | 14 | |
| 15 | 15 | import type { Database } from "bun:sqlite"; |
| 16 | import { FOLLOW_WORD } from "./follow_words.ts"; | |
| 16 | import { FOLLOW_WORD, followedWords } from "./follow_words.ts"; | |
| 17 | 17 | import { keptBehind, type Following } from "../core/following.ts"; |
| 18 | import { lastFollows } from "../core/last_follow.ts"; | |
| 18 | 19 | import { FORK_DEFAULT_MODE, forkFollowModes, lastTookAts } from "../core/fork_follow.ts"; |
| 19 | 20 | import { canRead, forkParentFor, visibleForksByParent, type Repo } from "../core/repos.ts"; |
| 20 | 21 | import type { User } from "../core/users.ts"; |
| @@ -46,8 +47,8 @@ export interface TreeNode { | ||
| 46 | 47 | * tips. |
| 47 | 48 | */ |
| 48 | 49 | 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
|
||
| 51 | 52 | /** Set on a root that is a fork of something the caller may not read: a hidden fork, not a gap. |
| 52 | 53 | * The parent is not named. */ |
| 53 | 54 | readonly hiddenParent?: true; |
| @@ -119,6 +120,7 @@ export function forkTree( | ||
| 119 | 120 | const hidden = root.forkParentId !== null && !keep.has(root.forkParentId); |
| 120 | 121 | const modes = forkFollowModes(db, rows.slice(hidden ? 0 : 1).map((r) => r.repo.id)); |
| 121 | 122 | 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)); | |
| 122 | 124 | const nodes: TreeNode[] = rows.map((r) => { |
| 123 | 125 | const hides = hidden && r.parent === null; |
| 124 | 126 | // A root whose link the owner cut reads "severed", not nothing. |
| @@ -132,7 +134,7 @@ export function forkTree( | ||
| 132 | 134 | follow: mode === undefined ? "autonomous" : treeFollow(modes.get(r.repo.id)), |
| 133 | 135 | word: mode === undefined ? "" : FOLLOW_WORD[mode], |
| 134 | 136 | 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) }), | |
| 136 | 138 | ...(hides ? { hiddenParent: true as const } : {}), |
| 137 | 139 | }; |
| 138 | 140 | }); |
src/core/last_follow.ts +26 −3
| @@ -22,6 +22,26 @@ export const FOLLOWED_EVENT = "fork.followed"; | ||
| 22 | 22 | |
| 23 | 23 | const isOutcome = (v: unknown): v is FollowOutcome => v === "nothing_new" || v === "conflict"; |
| 24 | 24 | |
| 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 | ||
| 25 | 45 | /** The newest follow recorded for this repository, or null when it never followed. */ |
| 26 | 46 | export function lastFollow(db: Database, repoId: string): LastFollow | null { |
| 27 | 47 | const row = db |
| @@ -29,10 +49,13 @@ export function lastFollow(db: Database, repoId: string): LastFollow | null { | ||
| 29 | 49 | "SELECT created_at AS at, payload FROM event WHERE repo_id = ?1 AND kind = ?2 ORDER BY seq DESC LIMIT 1", |
| 30 | 50 | ) |
| 31 | 51 | .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 { | |
| 33 | 56 | let p: Record<string, unknown>; |
| 34 | 57 | try { |
| 35 | p = JSON.parse(row.payload) as Record<string, unknown>; | |
| 58 | p = JSON.parse(payload) as Record<string, unknown>; | |
| 36 | 59 | } catch { |
| 37 | 60 | return null; |
| 38 | 61 | } |
| @@ -40,7 +63,7 @@ export function lastFollow(db: Database, repoId: string): LastFollow | null { | ||
| 40 | 63 | const on = p["on"] as { kind?: unknown; number?: unknown } | null | undefined; |
| 41 | 64 | return { |
| 42 | 65 | outcome: p["outcome"], |
| 43 | at: row.at, | |
| 66 | at, | |
| 44 | 67 | on: |
| 45 | 68 | on && (on.kind === "pull" || on.kind === "issue") && Number.isInteger(on.number) |
| 46 | 69 | ? { kind: on.kind, number: on.number as number } |
src/tui/screens/fork_tree.ts +2 −2
| @@ -4,7 +4,7 @@ | ||
| 4 | 4 | * the tool does: a repo the session's person may not read has no tree. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | import { HIDDEN_FORK_WORD, agoWords, treeFollowPhrase } from "../../actions/follow_words.ts"; | |
| 7 | import { HIDDEN_FORK_WORD, treeFollowPhrase } from "../../actions/follow_words.ts"; | |
| 8 | 8 | import { behindChip } from "../../actions/fork_tree_rows.ts"; |
| 9 | 9 | import { forkTree, type ForkTree } from "../../actions/fork_tree.ts"; |
| 10 | 10 | import { followLine } from "../../actions/follow.ts"; |
| @@ -25,7 +25,7 @@ export function treeLines(tree: ForkTree | undefined, asked: string, width = 80, | ||
| 25 | 25 | const lines = tree.nodes.map((n) => { |
| 26 | 26 | const phrase = n.word === "" ? "" : treeFollowPhrase(n.follow); |
| 27 | 27 | 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. |
||
| 29 | 29 | const follow = (phrase === "" ? "" : ` ${phrase}${behind}${took}`) + (n.hiddenParent === true ? ` ${HIDDEN_FORK_WORD}` : ""); |
| 30 | 30 | const you = n.repo !== asked && viewer !== undefined && n.repo.startsWith(`${viewer}/`) ? " (you)" : ""; |
| 31 | 31 | 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 @@ | ||
| 8 | 8 | * leave a line that still says the fork is level. |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | import { followWords } from "../../actions/follow.ts"; | |
| 11 | import { driftSentence } from "../../actions/follow.ts"; | |
| 12 | import { followedWords } from "../../actions/follow_words.ts"; | |
| 12 | 13 | import { keptStanding } from "../../core/following.ts"; |
| 13 | 14 | import { forkFollowMode, lastTookAt } from "../../core/fork_follow.ts"; |
| 14 | 15 | import { linkWord, sayLink } from "../../flows/link_word.ts"; |
| 15 | 16 | import { getRepoById } from "../../core/repos.ts"; |
| 16 | 17 | import type { Repo } from "../../core/repos.ts"; |
| 18 | import { lastFollow } from "../../core/last_follow.ts"; | |
| 17 | 19 | import { STANDING_EVENTS } from "../../core/standing_events.ts"; |
| 18 | 20 | import { getFollow } from "../../core/upstream_follow.ts"; |
| 19 | 21 | import { notePhase, takeSessionTime } from "../../core/route_timing.ts"; |
| @@ -60,15 +62,25 @@ function wordOf(ctx: Ctx, repo: Repo): Html | null { | ||
| 60 | 62 | * 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. |
||
| 61 | 63 | * they are silent. |
| 62 | 64 | */ |
| 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 | ||
| 63 | 75 | async function lines(ctx: Ctx, repo: Repo): Promise<Html> { |
| 64 | 76 | 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. |
||
| 65 | 77 | 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); | |
| 67 | 79 | const plain = |
| 68 | 80 | words === undefined |
| 69 | 81 | ? null |
| 70 | 82 | : 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)}`; | |
| 72 | 84 | } |
| 73 | 85 | |
| 74 | 86 | /** 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 { | ||
| 47 | 47 | takeUpdates, |
| 48 | 48 | type ForkDrift, |
| 49 | 49 | } from "../../actions/forks.ts"; |
| 50 | import { lastFollows } from "../../core/last_follow.ts"; | |
| 50 | 51 | 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"; | |
| 52 | 53 | import { behindChip } from "../../actions/fork_tree_rows.ts"; |
| 53 | 54 | import { keptBehind, lineageOf, MINE_ANCHOR, ownsInTree } from "../../core/following.ts"; |
| 54 | 55 | import { |
| @@ -189,6 +190,8 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 189 | 190 | const forkIds = [...tree, ...tree.flatMap((n) => n.forks)].map((n) => n.repo.id); |
| 190 | 191 | const forkModes = forkFollowModes(ctx.app.db, forkIds); |
| 191 | 192 | 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)])); | |
| 192 | 195 | notePhase(ctx.request, "fork-tree", performance.now() - t); |
| 193 | 196 | t = performance.now(); |
| 194 | 197 | // The whole family, from the oldest ancestor this viewer may see: who |
| @@ -221,7 +224,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 221 | 224 | 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.", |
| 222 | 225 | bind: BIND.rest, |
| 223 | 226 | }) |
| 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)} | |
| 225 | 228 | <h3 class="mt">The family, by who follows whom</h3> |
| 226 | 229 | ${lineageCard(lineage, repo.id, ctx.auth.user?.id)}`}`; |
| 227 | 230 | const res = page({ |
| @@ -247,10 +250,10 @@ function forkRanking( | ||
| 247 | 250 | modes: ReadonlyMap<string, ForkFollowMode> = new Map(), |
| 248 | 251 | /** Commits a nested fork lacks from its parent, as last counted; never asks git. */ |
| 249 | 252 | 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(), | |
| 252 | 255 | ): 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) ?? ""; | |
| 254 | 257 | const modeOf = (id: string): ForkFollowMode => modes.get(id) ?? FORK_DEFAULT_MODE; |
| 255 | 258 | const below = (n: ForkNode, parent: Repo): Html => { |
| 256 | 259 | const behind = behindOf(n.repo, parent); |
| @@ -260,7 +263,7 @@ function forkRanking( | ||
| 260 | 263 | title: html`<a href="/${n.repo.ownerName}/${n.repo.name}" |
| 261 | 264 | >${n.repo.ownerName}/${n.repo.name}</a |
| 262 | 265 | >`, |
| 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 | |
| 264 | 267 | ? html`` |
| 265 | 268 | : html` · <a href="/${n.repo.ownerName}/${n.repo.name}/forks" |
| 266 | 269 | >and ${n.deeper} more fork${n.deeper === 1 ? "" : "s"} below</a |
| @@ -277,7 +280,7 @@ function forkRanking( | ||
| 277 | 280 | >`, |
| 278 | 281 | meta: html`<span>${FOLLOW_PHRASE[modeOf(f.fork.id)]}</span>${[ |
| 279 | 282 | ranked.archived ? "" : driftWords(f.drift), |
| 280 | took(f.fork.id), | |
| 283 | followedLine(f.fork.id), | |
| 281 | 284 | f.pushedAt === null ? "" : html`pushed ${time(f.pushedAt)}`, |
| 282 | 285 | ] |
| 283 | 286 | .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"; | ||
| 9 | 9 | import { tmpdir } from "node:os"; |
| 10 | 10 | import { join } from "node:path"; |
| 11 | 11 | 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"; | |
| 13 | 13 | import { addToCrew, createAgent } from "../src/actions/crew.ts"; |
| 14 | 14 | import { forkTree } from "../src/actions/fork_tree.ts"; |
| 15 | import { noteCheck, putFollow } from "../src/core/upstream_follow.ts"; | |
| 15 | 16 | import { treeLines } from "../src/tui/screens/fork_tree.ts"; |
| 16 | 17 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 17 | 18 | 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 | ||
| 82 | 83 | const fork = must(await forkRepo(app, bob, fresh(parent), "game-bob")); |
| 83 | 84 | expect(lastFollow(app.db, fork.id)).toBeNull(); |
| 84 | 85 | 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$/); | |
| 86 | 88 | |
| 87 | 89 | must(await takeOrTell(app, bob, fresh(fork))); |
| 88 | 90 | 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"); | |
| 90 | 95 | |
| 91 | 96 | // Code taken is the push marked followed: "Last took", and the older check is not repeated. |
| 92 | 97 | 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 | ||
| 109 | 114 | const conflict = await takeOrTell(app, bob, fresh(fork)); |
| 110 | 115 | expect(conflict.ok).toBe(false); |
| 111 | 116 | 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/); | |
| 113 | 128 | }, 30_000); |
| 114 | 129 | |
| 115 | 130 | test("the tree says when each fork last took, on the web page and in the terminal", async () => { |
| 116 | 131 | 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"); | |
| 118 | 133 | await commit(alice, parent, "t.txt", "t\n"); |
| 119 | 134 | must(await takeOrTell(app, alice, fresh(fork))); |
| 120 | 135 | 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"); | |
| 124 | 141 | const page = await (await fetch(`${servers.url}/alice/game/forks`)).text().catch(() => ""); |
| 125 | 142 | const root = await (await fetch(`${servers.url}/alice/game`)).text(); |
| 126 | 143 | expect(root + page).toContain(said); |
test/fork-standing-line.test.ts +12 −2
| @@ -53,6 +53,10 @@ afterAll(async () => { | ||
| 53 | 53 | await rm(dataDir, { recursive: true, force: true }); |
| 54 | 54 | }); |
| 55 | 55 | |
| 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 | ||
| 56 | 60 | const lineOf = async (path: string): Promise<string | null> => { |
| 57 | 61 | const page = await (await fetch(`${servers.url}${path}`)).text(); |
| 58 | 62 | 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 | ||
| 79 | 83 | setForkFollowMode(app.db, bob.id, "dont-follow"); |
| 80 | 84 | expect(await lineOf("/bob/lib")).toBe("Up to date with alice/lib; not following, so nothing will be applied."); |
| 81 | 85 | expect(await lineOf("/alice/lib")).toBeNull(); |
| 86 | expect(await followedOf("/bob/lib")).toBe("never followed"); | |
| 87 | expect(await followedOf("/alice/lib")).toBeNull(); | |
| 82 | 88 | }); |
| 83 | 89 | |
| 84 | 90 | 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 () => { | ||
| 87 | 93 | kind: "push", repoId: bob.id, actorId: bob.ownerId, |
| 88 | 94 | payload: { updates: [], followed: "alice/lib" }, |
| 89 | 95 | }); |
| 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"); | |
| 91 | 100 | expect(await followStanding(app, bob, undefined)).toBe("Not following alice/lib · last took just now"); |
| 92 | 101 | expect(await followStanding(app, getRepo(app.db, "alice", "lib")!, undefined)).toBeUndefined(); |
| 93 | 102 | }); |
| @@ -222,7 +231,8 @@ test("the page, the MCP forks answer, the API and the terminal say one exact sen | ||
| 222 | 231 | for (const mode of ["take-updates", "tell-me", "dont-follow"] as const) { |
| 223 | 232 | setForkFollowMode(app.db, bob.id, mode); |
| 224 | 233 | 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"); | |
| 226 | 236 | expect((await mcpTool(servers.url, token, "forks", { repo: "bob/lib" })).value.words).toBe(want[mode]); |
| 227 | 237 | const api = await (await fetch(`${servers.url}/api/v1/repos/bob/lib/forks`, { headers: { authorization: `Bearer ${token}` } })).json() as { words: string }; |
| 228 | 238 | expect(api.words).toBe(want[mode]); |
test/fork-tree-reader.test.ts +4 −4
| @@ -64,9 +64,9 @@ describe("forkTree", () => { | ||
| 64 | 64 | expect(t.truncated).toBe(false); |
| 65 | 65 | const by = Object.fromEntries(t.nodes.map((n) => [n.repo, n])); |
| 66 | 66 | 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" }); | |
| 68 | 68 | 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" }); | |
| 70 | 70 | }); |
| 71 | 71 | |
| 72 | 72 | 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", () => { | ||
| 146 | 146 | const { treeLines } = await import("../src/tui/screens/fork_tree.ts"); |
| 147 | 147 | const lines = treeLines(forkTree(app.db, org, users["dan"]!, app), "bob/app"); |
| 148 | 148 | 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"); | |
| 150 | 150 | 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"); | |
| 152 | 152 | expect(lines.join("\n")).not.toContain("offers"); |
| 153 | 153 | expect(lines.join("\n")).not.toContain("secret"); |
| 154 | 154 | 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 | ||
| 69 | 69 | |
| 70 | 70 | test("a take appended to the stream changes what the region's address answers", async () => { |
| 71 | 71 | 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"); | |
| 73 | 73 | 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"); | |
| 75 | 76 | }); |
| 76 | 77 | |
| 77 | 78 | test("the fragment is not served to someone who cannot read the repository", async () => { |
Says a fork's page uses
followedWords; it does not as shipped. Make the doc match.