Public: anyone can read this; the crew can change it.
The fork tree shows each fork's follow mode and how many upstream changes it is behind #14111
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/14048-the-fork-tree-shows-each-fork-s-follow-m → main 7 commits fork 3 threads · 3 unresolved
13 files
changed +186
−37
docs/features/README.md +1
| @@ -30,6 +30,7 @@ Read with the guide page [What a forge is](../guide-what-a-forge-is.md). | ||
| 30 | 30 | - [](readme-description.md) |
| 31 | 31 | - [](arcade-carts.md) |
| 32 | 32 | - [](fork-behind.md) |
| 33 | - [](fork-tree-behind.md) | |
| 33 | 34 | - [](changelog.md) |
| 34 | 35 | - [](tell-from-ssh.md) |
| 35 | 36 | - [](docs-link.md) |
docs/features/fork-tree-behind.md added +11
| @@ -0,0 +1,11 @@ | ||
| 1 | # How far behind each fork in the tree is | |
| 2 | ||
| 3 | Each node of the fork tree says its follow word and, once the check has been | |
| 4 | counted, `N behind`. It is read from the counts the follow already stored, | |
| 5 | never from git on the request. | |
| 6 | ||
| 7 | - On the web: open an app's `/forks` page. | |
| 8 | - In the terminal: the fork tree screen shows the same words per node. | |
| 9 | - For tools: the `fork_tree` MCP tool and the family API return the same | |
| 10 | field per node. | |
| 11 | - A fork never counted shows its follow word alone. |
src/actions/fork_tree.ts +10 −1
| @@ -14,6 +14,7 @@ | ||
| 14 | 14 | |
| 15 | 15 | import type { Database } from "bun:sqlite"; |
| 16 | 16 | import { FOLLOW_WORD } from "./follow_words.ts"; |
| 17 | import { keptBehind, type Following } from "../core/following.ts"; | |
| 17 | 18 | import { FORK_DEFAULT_MODE, forkFollowModes } from "../core/fork_follow.ts"; |
| 18 | 19 | import { canRead, forkParentFor, visibleForksByParent, type Repo } from "../core/repos.ts"; |
| 19 | 20 | import type { User } from "../core/users.ts"; |
| @@ -39,6 +40,12 @@ export interface TreeNode { | ||
| 39 | 40 | readonly follow: TreeFollow; |
| 40 | 41 | /** The same fact in the one word every door says (`FOLLOW_WORD`); empty for the root. */ |
| 41 | 42 | readonly word: string; |
| 43 | /** | |
| 44 | * Commits this fork lacks from its parent, as last counted: read from the ref files and the | |
| 45 | * kept count, never a git walk. Null for the root, and when nothing has counted this pair of | |
| 46 | * tips. | |
| 47 | */ | |
| 48 | readonly behind: number | null; | |
| 42 | 49 | /** Set on a root that is a fork of something the caller may not read: a hidden fork, not a gap. |
| 43 | 50 | * The parent is not named. */ |
| 44 | 51 | readonly hiddenParent?: true; |
| @@ -60,6 +67,7 @@ export function forkTree( | ||
| 60 | 67 | db: Database, |
| 61 | 68 | repo: Repo, |
| 62 | 69 | user: User | undefined, |
| 70 | forge: Pick<Following, "reposRoot">, | |
| 63 | 71 | opts: { depth?: number; limit?: number } = {}, |
| 64 | 72 | ): ForkTree | undefined { |
| 65 | 73 | if (!canRead(db, repo, user)) return undefined; |
| @@ -112,7 +120,7 @@ export function forkTree( | ||
| 112 | 120 | const hides = hidden && r.parent === null; |
| 113 | 121 | // A root whose link the owner cut reads "severed", not nothing. |
| 114 | 122 | if (r.parent === null && !hides && severedRoot(db, r.repo)) |
| 115 | return { repo: nameOf(r.repo), parent: null, depth: r.depth, follow: "dont-follow" as const, word: FOLLOW_WORD["dont-follow"] }; | |
| 123 | return { repo: nameOf(r.repo), parent: null, depth: r.depth, follow: "dont-follow" as const, word: FOLLOW_WORD["dont-follow"], behind: null }; | |
| 116 | 124 | const mode = r.parent === null && !hides ? undefined : (modes.get(r.repo.id) ?? FORK_DEFAULT_MODE); |
| 117 | 125 | return { |
| 118 | 126 | repo: nameOf(r.repo), |
| @@ -120,6 +128,7 @@ export function forkTree( | ||
| 120 | 128 | depth: r.depth, |
| 121 | 129 | follow: mode === undefined ? "autonomous" : treeFollow(modes.get(r.repo.id)), |
| 122 | 130 | word: mode === undefined ? "" : FOLLOW_WORD[mode], |
| 131 | behind: r.parent === null ? null : (keptBehind(forge, r.repo, r.parent) ?? null), | |
outdated
The optional |
||
| 123 | 132 | ...(hides ? { hiddenParent: true as const } : {}), |
| 124 | 133 | }; |
| 125 | 134 | }); |
src/http/api/family.ts +1 −1
| @@ -34,7 +34,7 @@ export function familyRoutes(router: Router<Handler>): void { | ||
| 34 | 34 | const opts: { depth?: number; limit?: number } = {}; |
| 35 | 35 | if (depth !== undefined) opts.depth = depth; |
| 36 | 36 | if (limit !== undefined) opts.limit = limit; |
| 37 | const tree = timePhase(ctx.request, "tree", () => forkTree(ctx.app.db, repo, ctx.auth.user, opts)); | |
| 37 | const tree = timePhase(ctx.request, "tree", () => forkTree(ctx.app.db, repo, ctx.auth.user, ctx.app, opts)); | |
| 38 | 38 | return json(tree ?? { root: null, nodes: [], truncated: false }); |
| 39 | 39 | }); |
| 40 | 40 | } |
src/http/mcp/tools/fork_tree.ts +2 −2
| @@ -4,7 +4,7 @@ import { good, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"; | ||
| 4 | 4 | /** The whole tree a repo sits in, as the caller may read it. */ |
| 5 | 5 | export const tool: Tool = { |
| 6 | 6 | name: "fork_tree", |
| 7 | doc: "`{ repo, depth?, limit? }`: `{ root, nodes: [{ repo, parent, depth, follow, word, hiddenParent? }], truncated }`, the fork tree around a repo from its topmost readable ancestor down: ancestors, siblings and descendants the caller may read, nothing else; `follow` is `autonomous` (the root), `take-updates`, `offers` or `dont-follow`, `word` its plain word (follows, proposes, severed); `depth` 1-8 (default 4), `limit` 1-200 nodes (default 200); `hiddenParent: true` on a root that is a fork of a repo you cannot read (not named); `truncated` is true when more exists than is shown; drawn as the `ui://forge/forks` card", | |
| 7 | doc: "`{ repo, depth?, limit? }`: `{ root, nodes: [{ repo, parent, depth, follow, word, behind, hiddenParent? }], truncated }`, the fork tree around a repo from its topmost readable ancestor down: ancestors, siblings and descendants the caller may read, nothing else; `follow` is `autonomous` (the root), `take-updates`, `offers` or `dont-follow`, `word` its plain word (follows, proposes, severed), `behind` the commits it lacks from its parent as last counted (null when not counted; never a git walk); `depth` 1-8 (default 4), `limit` 1-200 nodes (default 200); `hiddenParent: true` on a root that is a fork of a repo you cannot read (not named); `truncated` is true when more exists than is shown; drawn as the `ui://forge/forks` card", | |
| 8 | 8 | description: "The fork tree around a repo: ancestors, siblings and descendants you may read.", |
| 9 | 9 | inputSchema: { |
| 10 | 10 | type: "object", |
| @@ -22,7 +22,7 @@ export const tool: Tool = { | ||
| 22 | 22 | const opts: { depth?: number; limit?: number } = {}; |
| 23 | 23 | if (typeof args["depth"] === "number") opts.depth = args["depth"]; |
| 24 | 24 | if (typeof args["limit"] === "number") opts.limit = args["limit"]; |
| 25 | const tree = forkTree(ctx.app.db, repo, user, opts); | |
| 25 | const tree = forkTree(ctx.app.db, repo, user, ctx.app, opts); | |
| 26 | 26 | return good(tree ?? { root: null, nodes: [], truncated: false }); |
| 27 | 27 | }, |
| 28 | 28 | }; |
src/tui/screens/fork_tree.ts +3 −2
| @@ -22,7 +22,8 @@ export function treeLines(tree: ForkTree | undefined, asked: string, width = 80, | ||
| 22 | 22 | if (tree === undefined) return ["Nothing to show."]; |
| 23 | 23 | const lines = tree.nodes.map((n) => { |
| 24 | 24 | const phrase = n.word === "" ? "" : treeFollowPhrase(n.follow); |
| 25 | const follow = (phrase === "" ? "" : ` ${phrase}`) + (n.hiddenParent === true ? ` ${HIDDEN_FORK_WORD}` : ""); | |
| 25 | const behind = n.behind === null ? "" : ` · ${n.behind} behind`; | |
| 26 | const follow = (phrase === "" ? "" : ` ${phrase}${behind}`) + (n.hiddenParent === true ? ` ${HIDDEN_FORK_WORD}` : ""); | |
| 26 | 27 | const you = n.repo !== asked && viewer !== undefined && n.repo.startsWith(`${viewer}/`) ? " (you)" : ""; |
| 27 | 28 | return truncate(`${" ".repeat(n.depth)}${n.repo === asked ? "* " : ""}${n.repo}${you}${follow}`, width); |
| 28 | 29 | }); |
| @@ -38,7 +39,7 @@ export function forkTreeScreen(f: Session, ctx: Ctx, repo: Repo): Screen { | ||
| 38 | 39 | keys: [binding(["j", "k"], "scroll"), binding(["esc"], "back")], |
| 39 | 40 | render(area, s) { |
| 40 | 41 | const c = ctx.theme.c; |
| 41 | lines = treeLines(forkTree(f.db, repo, f.user), `${repo.ownerName}/${repo.name}`, area.w - 4, f.user?.username); | |
| 42 | lines = treeLines(forkTree(f.db, repo, f.user, f.app), `${repo.ownerName}/${repo.name}`, area.w - 4, f.user?.username); | |
| 42 | 43 | const from = scroll.window(area.h, lines.length); |
| 43 | 44 | for (let i = 0; i < area.h; i++) { |
| 44 | 45 | const line = lines[from + i]; |
src/web/pages/repo.ts +10 −6
| @@ -44,7 +44,7 @@ import { | ||
| 44 | 44 | } from "../../actions/forks.ts"; |
| 45 | 45 | import { FORK_DEFAULT_MODE, forkFollowModes, type ForkFollowMode } from "../../core/fork_follow.ts"; |
| 46 | 46 | import { FOLLOW_PHRASE, isSevered } from "../../actions/follow_words.ts"; |
| 47 | import { lineageOf, MINE_ANCHOR, ownsInTree } from "../../core/following.ts"; | |
| 47 | import { keptBehind, lineageOf, MINE_ANCHOR, ownsInTree } from "../../core/following.ts"; | |
| 48 | 48 | import { |
| 49 | 49 | archivedParentLine, |
| 50 | 50 | followingCard, |
| @@ -208,7 +208,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> { | ||
| 208 | 208 | 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.", |
| 209 | 209 | bind: BIND.rest, |
| 210 | 210 | }) |
| 211 | : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes)} | |
| 211 | : html`${forkRanking(ranked, new Map(tree.map((n) => [n.repo.id, n])), BIND.rest, forkModes, (fork, parent) => keptBehind(ctx.app, fork, parent))} | |
| 212 | 212 | <h3 class="mt">The family, by who follows whom</h3> |
| 213 | 213 | ${lineageCard(lineage, repo.id, ctx.auth.user?.id)}`}`; |
| 214 | 214 | const res = page({ |
| @@ -232,25 +232,29 @@ function forkRanking( | ||
| 232 | 232 | bind: string, |
| 233 | 233 | /** How each fork follows its parent; a fork without a row follows the default. */ |
| 234 | 234 | modes: ReadonlyMap<string, ForkFollowMode> = new Map(), |
| 235 | /** Commits a nested fork lacks from its parent, as last counted; never asks git. */ | |
| 236 | behindOf: (fork: Repo, parent: Repo) => number | undefined = () => undefined, | |
| 235 | 237 | ): Html { |
| 236 | 238 | const modeOf = (id: string): ForkFollowMode => modes.get(id) ?? FORK_DEFAULT_MODE; |
| 237 | const below = (n: ForkNode): Html => | |
| 238 | row({ | |
| 239 | const below = (n: ForkNode, parent: Repo): Html => { | |
| 240 | const behind = behindOf(n.repo, parent); | |
| 241 | return row({ | |
| 239 | 242 | lead: icon("fork"), |
| 240 | 243 | ...(isSevered(modeOf(n.repo.id)) ? { data: { severed: "" } } : {}), |
| 241 | 244 | title: html`<a href="/${n.repo.ownerName}/${n.repo.name}" |
| 242 | 245 | >${n.repo.ownerName}/${n.repo.name}</a |
| 243 | 246 | >`, |
| 244 | meta: html`<span>${FOLLOW_PHRASE[modeOf(n.repo.id)]}</span>${n.deeper === 0 | |
| 247 | meta: html`<span>${FOLLOW_PHRASE[modeOf(n.repo.id)]}</span>${behind === undefined ? "" : html` · ${behind} behind`}${n.deeper === 0 | |
| 245 | 248 | ? html`` |
| 246 | 249 | : html` · <a href="/${n.repo.ownerName}/${n.repo.name}/forks" |
| 247 | 250 | >and ${n.deeper} more fork${n.deeper === 1 ? "" : "s"} below</a |
| 248 | 251 | >`}`, |
| 249 | 252 | }); |
| 253 | }; | |
| 250 | 254 | const line = (f: RankedFork, offer: boolean): Html => |
| 251 | 255 | row({ |
| 252 | 256 | data: { row: "", ...(isSevered(modeOf(f.fork.id)) ? { severed: "" } : {}) }, |
| 253 | children: (tree.get(f.fork.id)?.forks ?? []).map(below), | |
| 257 | children: (tree.get(f.fork.id)?.forks ?? []).map((n) => below(n, f.fork)), | |
| 254 | 258 | lead: icon("fork"), |
| 255 | 259 | title: html`<a href="/${f.fork.ownerName}/${f.fork.name}" |
| 256 | 260 | >${f.fork.ownerName}/${f.fork.name}</a |
test/fork-chain.test.ts +1 −1
| @@ -32,7 +32,7 @@ const users: Record<string, User> = {}; | ||
| 32 | 32 | let a: Repo, b: Repo, c: Repo; |
| 33 | 33 | |
| 34 | 34 | const full = (r: Repo) => `${r.ownerName}/${r.name}`; |
| 35 | const tree = (r: Repo, who?: User) => forkTree(app.db, r, who)!; | |
| 35 | const tree = (r: Repo, who?: User) => forkTree(app.db, r, who, app)!; | |
| 36 | 36 | const commit = async (who: string, repo: Repo, path: string) => |
| 37 | 37 | must(await commitToBranch(app, users[who]!, repo, { message: path, files: [{ path, content: `${path}\n` }] })); |
| 38 | 38 | const settle = async (fork: Repo, parent: Repo, state: string) => { |
test/fork-sever.test.ts +3 −3
| @@ -85,14 +85,14 @@ test("a severed fork is told nothing when its upstream changes; an attached sibl | ||
| 85 | 85 | |
| 86 | 86 | test("a root that was never a fork reads no severed word", async () => { |
| 87 | 87 | const plain = ok(await createRepo(app, alice, { name: "plainroot", visibility: "public" })); |
| 88 | expect(forkTree(app.db, getRepo(app.db, "alice", plain.name)!, alice)!.nodes[0]!.word).toBe(""); | |
| 88 | expect(forkTree(app.db, getRepo(app.db, "alice", plain.name)!, alice, app)!.nodes[0]!.word).toBe(""); | |
| 89 | 89 | }); |
| 90 | 90 | |
| 91 | 91 | test("the severed fork's own tree row reads severed; the words offer the way back", () => { |
| 92 | 92 | const cut = getRepo(app.db, "alice", "cut")!; |
| 93 | const tree = forkTree(app.db, cut, alice)!; | |
| 93 | const tree = forkTree(app.db, cut, alice, app)!; | |
| 94 | 94 | expect(tree.nodes[0]).toMatchObject({ repo: "alice/cut", follow: "dont-follow", word: "severed" }); |
| 95 | const attached = forkTree(app.db, getRepo(app.db, "bob", "kept")!, alice)!; | |
| 95 | const attached = forkTree(app.db, getRepo(app.db, "bob", "kept")!, alice, app)!; | |
| 96 | 96 | expect(attached.nodes.find((n) => n.repo === "alice/root")!.word).toBe(""); |
| 97 | 97 | expect(detachPlanWords({ parent: "alice/root", borrows: false, dryRun: true })).toContain(DETACH_AGAIN); |
| 98 | 98 | }); |
test/fork-tree-follow.test.ts added +123
| @@ -0,0 +1,123 @@ | ||
| 1 | /** | |
| 2 | * #14048: the fork tree says how each fork follows and how far behind it is, from stored state: | |
| 3 | * the tool's answer, the terminal's lines and the web page, over a three-level chain. | |
| 4 | */ | |
| 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { forkTree } from "../src/actions/fork_tree.ts"; | |
| 10 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 11 | import { setRole } from "../src/actions/roles.ts"; | |
| 12 | import { createApp, type App } from "../src/app.ts"; | |
| 13 | import { forkRelation } from "../src/core/following.ts"; | |
| 14 | import { setForkFollowMode } from "../src/core/fork_follow.ts"; | |
| 15 | import type { Repo } from "../src/core/repos.ts"; | |
| 16 | import { createUser, type User } from "../src/core/users.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { treeLines } from "../src/tui/screens/fork_tree.ts"; | |
| 19 | ||
| 20 | let dataDir: string; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | let ann: User; | |
| 24 | let top: Repo, mid: Repo, leaf: Repo, twin: Repo; | |
| 25 | ||
| 26 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 27 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 28 | return r.value; | |
| 29 | }; | |
| 30 | const name = (r: Repo) => `${r.ownerName}/${r.name}`; | |
| 31 | ||
| 32 | beforeAll(async () => { | |
| 33 | dataDir = await mkdtemp(join(tmpdir(), "forge-tree-follow-")); | |
| 34 | app = createApp({ dataDir, port: 0 }); | |
| 35 | servers = await serve(app); | |
| 36 | const mk = async (username: string, first: boolean) => | |
| 37 | must(await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first })); | |
| 38 | ann = await mk("ann", true); | |
| 39 | const bea = await mk("bea", false); | |
| 40 | const cal = await mk("cal", false); | |
| 41 | must(setRole(app, ann, "bea", "member")); | |
| 42 | must(setRole(app, ann, "cal", "member")); | |
| 43 | top = must(await createRepo(app, ann, { name: "yard", visibility: "public" })); | |
| 44 | must(await commitToBranch(app, ann, top, { message: "first", files: [{ path: "a.txt", content: "a\n" }] })); | |
| 45 | mid = must(await forkRepo(app, bea, top)); | |
| 46 | // Work of its own, so the parent moving later cannot fast-forward it under the counts. | |
| 47 | must(await commitToBranch(app, bea, mid, { message: "own", files: [{ path: "own.txt", content: "o\n" }] })); | |
| 48 | leaf = must(await forkRepo(app, cal, mid)); | |
| 49 | // mid moves one commit on; leaf, which does not follow, has not taken it. | |
| 50 | setForkFollowMode(app.db, leaf.id, "dont-follow"); | |
| 51 | must(await commitToBranch(app, bea, mid, { message: "more", files: [{ path: "more.txt", content: "m\n" }] })); | |
| 52 | // The top moves two commits on; mid has not taken them. | |
| 53 | must(await commitToBranch(app, ann, top, { message: "two", files: [{ path: "b.txt", content: "b\n" }] })); | |
| 54 | must(await commitToBranch(app, ann, top, { message: "three", files: [{ path: "c.txt", content: "c\n" }] })); | |
| 55 | // A fork that only proposes stays where it is while the counts are made. | |
| 56 | setForkFollowMode(app.db, mid.id, "tell-me"); | |
| 57 | setForkFollowMode(app.db, leaf.id, "dont-follow"); | |
| 58 | // Forked after the last push: level, and following automatically, with nothing to take. | |
| 59 | const dan = must(await createUser(app.db, { origin: "seed", trusted: true, username: "dan", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false })); | |
| 60 | must(setRole(app, ann, "dan", "member")); | |
| 61 | twin = must(await forkRepo(app, dan, top)); | |
| 62 | setForkFollowMode(app.db, twin.id, "take-updates"); | |
| 63 | }, 60_000); | |
| 64 | ||
| 65 | afterAll(async () => { | |
| 66 | servers?.stop(); | |
| 67 | app?.close(); | |
| 68 | await rm(dataDir, { recursive: true, force: true }); | |
| 69 | }); | |
| 70 | ||
| 71 | const nodeOf = (t: ReturnType<typeof forkTree>, r: Repo) => t!.nodes.find((n) => n.repo === name(r))!; | |
| 72 | ||
| 73 | test("a count nobody has made is null, not a git walk on the request", async () => { | |
| 74 | const dir = await mkdtemp(join(tmpdir(), "forge-tree-fresh-")); | |
| 75 | const fresh = createApp({ dataDir: dir, port: 0 }); | |
| 76 | try { | |
| 77 | const u = must(await createUser(fresh.db, { origin: "seed", trusted: true, username: "eve", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true })); | |
| 78 | const parent = must(await createRepo(fresh, u, { name: "src", visibility: "public" })); | |
| 79 | must(await commitToBranch(fresh, u, parent, { message: "first", files: [{ path: "a.txt", content: "a\n" }] })); | |
| 80 | const fay = must(await createUser(fresh.db, { origin: "seed", trusted: true, username: "fay", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false })); | |
| 81 | must(setRole(fresh, u, "fay", "member")); | |
| 82 | const child = must(await forkRepo(fresh, fay, parent)); | |
| 83 | // The parent moves after the fork, so no count exists for this pair of tips. | |
| 84 | must(await commitToBranch(fresh, u, parent, { message: "second", files: [{ path: "b.txt", content: "b\n" }] })); | |
| 85 | const t = forkTree(fresh.db, parent, u, fresh); | |
| 86 | expect(t!.nodes.map((n) => [n.repo, n.behind])).toEqual([[name(parent), null], [name(child), null]]); | |
| 87 | } finally { | |
| 88 | fresh.close(); | |
| 89 | await rm(dir, { recursive: true, force: true }); | |
| 90 | } | |
| 91 | }); | |
| 92 | ||
| 93 | test("each node of a three-level chain carries its mode and the stored count behind", async () => { | |
| 94 | const counted = (await forkRelation(app, mid, top))!.behind; | |
| 95 | expect((await forkRelation(app, leaf, mid))!.behind).toBe(1); | |
| 96 | expect(counted).toBeGreaterThan(0); | |
| 97 | const t = forkTree(app.db, top, ann, app); | |
| 98 | expect(t!.nodes.map((n) => [n.depth, n.follow])).toEqual([ | |
outdated
Conditional expectation: passes either way. Assert the real count. |
||
| 99 | [0, "autonomous"], | |
| 100 | [1, "offers"], | |
| 101 | [1, "take-updates"], | |
| 102 | [2, "dont-follow"], | |
| 103 | ]); | |
| 104 | expect(nodeOf(t, twin).behind).toBe(0); | |
| 105 | expect(nodeOf(t, top).behind).toBeNull(); | |
| 106 | expect(nodeOf(t, mid).behind).toBe(counted); | |
| 107 | expect(nodeOf(t, leaf).behind).toBe(1); | |
| 108 | }); | |
| 109 | ||
| 110 | test("the terminal and the web page say the same: N behind once counted, 0 included", async () => { | |
| 111 | await forkRelation(app, mid, top); | |
| 112 | expect((await forkRelation(app, leaf, mid))!.behind).toBe(1); | |
| 113 | const tree = forkTree(app.db, top, ann, app); | |
| 114 | const lines = treeLines(tree, name(top), 160); | |
| 115 | expect(lines.find((l) => l.includes(name(leaf)))).toContain("1 behind"); | |
| 116 | expect(lines.find((l) => l.includes(name(twin)))).toContain("0 behind"); | |
| 117 | expect(lines.find((l) => l.includes(name(top)))).not.toContain("behind"); | |
| 118 | expect(lines.find((l) => l.includes(name(mid)))).toContain(`${nodeOf(tree, mid).behind} behind`); | |
| 119 | const html = await (await fetch(`${servers.url}/${name(top)}/forks`)).text(); | |
| 120 | const at = html.indexOf(`href="/${name(leaf)}"`); | |
| 121 | expect(at).toBeGreaterThan(0); | |
| 122 | expect(html.slice(at, html.indexOf("</li>", at))).toContain("1 behind"); | |
| 123 | }); |
test/fork-tree-links.test.ts +1 −1
| @@ -92,7 +92,7 @@ test("every readable node links, the viewer's own says you, a private fork is ab | ||
| 92 | 92 | |
| 93 | 93 | test("the terminal tree marks the viewer's own forks, not the asked one, as the page does", async () => { |
| 94 | 94 | const { treeLines } = await import("../src/tui/screens/fork_tree.ts"); |
| 95 | const node = (repo: string, parent: string | null, depth: number) => ({ repo, parent, depth, follow: "autonomous" as const, word: "" }); | |
| 95 | const node = (repo: string, parent: string | null, depth: number) => ({ repo, parent, depth, follow: "autonomous" as const, word: "", behind: null }); | |
| 96 | 96 | const tree = { |
| 97 | 97 | root: "ann/yard", |
| 98 | 98 | truncated: false, |
test/fork-tree-mode.test.ts +2 −2
| @@ -82,7 +82,7 @@ test("the terminal's forks rows say the same phrase from the same table", async | ||
| 82 | 82 | }); |
| 83 | 83 | |
| 84 | 84 | test("the terminal's tree lines say the phrase beside each node", () => { |
| 85 | const lines = treeLines(forkTree(app.db, root, ann), name(root), 120); | |
| 85 | const lines = treeLines(forkTree(app.db, root, ann, app), name(root), 120); | |
| 86 | 86 | for (const [mode, repo] of kids) expect(lines.find((l) => l.includes(name(repo)))).toContain(FOLLOW_PHRASE[mode]); |
| 87 | 87 | }); |
| 88 | 88 | |
| @@ -103,7 +103,7 @@ test("a nested fork row says its phrase on the web and in the terminal", async ( | ||
| 103 | 103 | const at = html.indexOf(`href="/${name(deep)}"`); |
| 104 | 104 | expect(at).toBeGreaterThan(0); |
| 105 | 105 | expect(html.slice(at, html.indexOf("</li>", at))).toContain(`>${FOLLOW_PHRASE["tell-me"]}<`); |
| 106 | const line = treeLines(forkTree(app.db, root, ann), name(root), 160).find((l) => l.includes(name(deep))); | |
| 106 | const line = treeLines(forkTree(app.db, root, ann, app), name(root), 160).find((l) => l.includes(name(deep))); | |
| 107 | 107 | expect(line).toContain(FOLLOW_PHRASE["tell-me"]); |
| 108 | 108 | expect(line!.startsWith(" ")).toBe(true); |
| 109 | 109 | }); |
test/fork-tree-reader.test.ts +18 −18
| @@ -59,20 +59,20 @@ const names = (t: { nodes: { repo: string }[] }) => t.nodes.map((n) => n.repo); | ||
| 59 | 59 | |
| 60 | 60 | describe("forkTree", () => { |
| 61 | 61 | test("read from the middle node: root, siblings, descendants, with parent, depth and follow", () => { |
| 62 | const t = forkTree(app.db, org, users["alice"]!)!; | |
| 62 | const t = forkTree(app.db, org, users["alice"]!, app)!; | |
| 63 | 63 | expect(t.root).toBe("alice/app"); |
| 64 | 64 | expect(t.truncated).toBe(false); |
| 65 | 65 | const by = Object.fromEntries(t.nodes.map((n) => [n.repo, n])); |
| 66 | expect(by["alice/app"]).toEqual({ repo: "alice/app", parent: null, depth: 0, follow: "autonomous", word: "" }); | |
| 67 | expect(by["bob/app"]).toEqual({ repo: "bob/app", parent: "alice/app", depth: 1, follow: "offers", word: "proposes" }); | |
| 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 }); | |
| 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" }); | |
| 69 | expect(by["dan/app"]).toEqual({ repo: "dan/app", parent: "bob/app", depth: 2, follow: "take-updates", word: "follows", behind: null }); | |
| 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", () => { |
| 73 | const owner = names(forkTree(app.db, org, users["erin"]!)!); | |
| 74 | const stranger = forkTree(app.db, org, users["dan"]!)!; | |
| 75 | const anon = forkTree(app.db, org, undefined)!; | |
| 73 | const owner = names(forkTree(app.db, org, users["erin"]!, app)!); | |
| 74 | const stranger = forkTree(app.db, org, users["dan"]!, app)!; | |
| 75 | const anon = forkTree(app.db, org, undefined, app)!; | |
| 76 | 76 | expect(owner).toContain("erin/secret"); |
| 77 | 77 | expect(owner).toContain("erin/under"); |
| 78 | 78 | for (const t of [stranger, anon]) { |
| @@ -84,18 +84,18 @@ describe("forkTree", () => { | ||
| 84 | 84 | }); |
| 85 | 85 | |
| 86 | 86 | test("a repo the caller cannot read yields nothing", () => { |
| 87 | expect(forkTree(app.db, hidden, users["dan"]!)).toBeUndefined(); | |
| 87 | expect(forkTree(app.db, hidden, users["dan"]!, app)).toBeUndefined(); | |
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | 90 | test("depth limits generations and says it truncated", () => { |
| 91 | const t = forkTree(app.db, forge, users["alice"]!, { depth: 1 })!; | |
| 91 | const t = forkTree(app.db, forge, users["alice"]!, app, { depth: 1 })!; | |
| 92 | 92 | expect(t.nodes.every((n) => n.depth <= 1)).toBe(true); |
| 93 | 93 | expect(t.truncated).toBe(true); |
| 94 | expect(forkTree(app.db, forge, users["alice"]!, { depth: 99 })!.nodes.length).toBeGreaterThan(4); | |
| 94 | expect(forkTree(app.db, forge, users["alice"]!, app, { depth: 99 })!.nodes.length).toBeGreaterThan(4); | |
| 95 | 95 | }); |
| 96 | 96 | |
| 97 | 97 | test("a limit cuts the nodes and says so; the cap is 200", () => { |
| 98 | const t = forkTree(app.db, forge, users["alice"]!, { limit: 3 })!; | |
| 98 | const t = forkTree(app.db, forge, users["alice"]!, app, { limit: 3 })!; | |
| 99 | 99 | expect(t.nodes.length).toBe(3); |
| 100 | 100 | expect(t.truncated).toBe(true); |
| 101 | 101 | expect(MAX_NODES).toBe(200); |
| @@ -110,11 +110,11 @@ describe("forkTree", () => { | ||
| 110 | 110 | promote(app.db, u); |
| 111 | 111 | at = must(await forkRepo(app, u, at)); |
| 112 | 112 | } |
| 113 | const t = forkTree(app.db, at, users["alice"]!, { depth: 1 })!; | |
| 113 | const t = forkTree(app.db, at, users["alice"]!, app, { depth: 1 })!; | |
| 114 | 114 | const me = t.nodes.find((n) => n.repo === "deep4/app")!; |
| 115 | 115 | expect(me.depth).toBe(5); |
| 116 | 116 | expect(t.nodes.some((n) => n.repo === "deep3/app")).toBe(true); |
| 117 | const tiny = forkTree(app.db, at, users["alice"]!, { limit: 1 })!; | |
| 117 | const tiny = forkTree(app.db, at, users["alice"]!, app, { limit: 1 })!; | |
| 118 | 118 | expect(tiny.nodes.some((n) => n.repo === "deep4/app")).toBe(true); |
| 119 | 119 | }); |
| 120 | 120 | |
| @@ -129,10 +129,10 @@ describe("forkTree", () => { | ||
| 129 | 129 | c === "id" ? `'bulk${i}'` : c === "name" ? `'bulk${i}'` : c === "fork_parent_id" ? `'${base}'` : c; |
| 130 | 130 | app.db.query(`INSERT INTO repo (${cols.join(",")}) SELECT ${list(sub)} FROM repo WHERE id = ?1`).run(base); |
| 131 | 131 | } |
| 132 | forkTree(app.db, forge, users["bob"]!); | |
| 132 | forkTree(app.db, forge, users["bob"]!, app); | |
| 133 | 133 | let t!: NonNullable<ReturnType<typeof forkTree>>; |
| 134 | 134 | const n = await once(app.db, () => { |
| 135 | t = forkTree(app.db, forge, users["bob"]!)!; | |
| 135 | t = forkTree(app.db, forge, users["bob"]!, app)!; | |
| 136 | 136 | }); |
| 137 | 137 | expect(t.nodes.length).toBe(200); |
| 138 | 138 | expect(t.truncated).toBe(true); |
| @@ -144,13 +144,13 @@ describe("forkTree", () => { | ||
| 144 | 144 | describe("the terminal screen", () => { |
| 145 | 145 | test("draws the tree from the reader, marks the asked repo, and shows nothing for an unreadable one", async () => { |
| 146 | 146 | const { treeLines } = await import("../src/tui/screens/fork_tree.ts"); |
| 147 | const lines = treeLines(forkTree(app.db, org, users["dan"]!), "bob/app"); | |
| 147 | const lines = treeLines(forkTree(app.db, org, users["dan"]!, app), "bob/app"); | |
| 148 | 148 | expect(lines).toContain("alice/app"); |
| 149 | 149 | expect(lines).toContain(" * bob/app proposes only"); |
| 150 | const own = treeLines(forkTree(app.db, person, users["dan"]!), "dan/app"); | |
| 150 | const own = treeLines(forkTree(app.db, person, users["dan"]!, app), "dan/app"); | |
| 151 | 151 | expect(own).toContain(" * dan/app follows automatically"); |
| 152 | 152 | expect(lines.join("\n")).not.toContain("offers"); |
| 153 | 153 | expect(lines.join("\n")).not.toContain("secret"); |
| 154 | expect(treeLines(forkTree(app.db, hidden, users["dan"]!), "erin/secret")).toEqual(["Nothing to show."]); | |
| 154 | expect(treeLines(forkTree(app.db, hidden, users["dan"]!, app), "erin/secret")).toEqual(["Nothing to show."]); | |
| 155 | 155 | }); |
| 156 | 156 | }); |
new above
offline
Same conditional spread repeated; remove it with a required forge.