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

Merged opened this

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

Merged

mason/forge:mason/14048-the-fork-tree-shows-each-fork-s-follow-m → main 7 commits fork 3 threads · 3 unresolved

  • Merged. mason/14048-the-fork-tree-shows-each-fork-s-follow-m was merged into main as 7353978.

Review

Sign in to review this change.
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).
3030 - [An app with no description says its README](readme-description.md)
3131 - [Arcade carts](arcade-carts.md)
3232 - [How far behind a followed fork is](fork-behind.md)
33 - [How far behind each fork in the tree is](fork-tree-behind.md)
3334 - [Changelog](changelog.md)
3435 - [Tell the crew from any shell with ssh and tell](tell-from-ssh.md)
3536 - [/docs](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 @@
1414
1515 import type { Database } from "bun:sqlite";
1616 import { FOLLOW_WORD } from "./follow_words.ts";
17 import { keptBehind, type Following } from "../core/following.ts";
1718 import { FORK_DEFAULT_MODE, forkFollowModes } from "../core/fork_follow.ts";
1819 import { canRead, forkParentFor, visibleForksByParent, type Repo } from "../core/repos.ts";
1920 import type { User } from "../core/users.ts";
@@ -39,6 +40,12 @@ export interface TreeNode {
3940 readonly follow: TreeFollow;
4041 /** The same fact in the one word every door says (`FOLLOW_WORD`); empty for the root. */
4142 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;
4249 /** Set on a root that is a fork of something the caller may not read: a hidden fork, not a gap.
4350 * The parent is not named. */
4451 readonly hiddenParent?: true;
@@ -60,6 +67,7 @@ export function forkTree(
6067 db: Database,
6168 repo: Repo,
6269 user: User | undefined,
70 forge: Pick<Following, "reposRoot">,
6371 opts: { depth?: number; limit?: number } = {},
6472 ): ForkTree | undefined {
6573 if (!canRead(db, repo, user)) return undefined;
@@ -112,7 +120,7 @@ export function forkTree(
112120 const hides = hidden && r.parent === null;
113121 // A root whose link the owner cut reads "severed", not nothing.
114122 if (r.parent === null && !hides && severedRoot(db, r.repo))

Same conditional spread repeated; remove it with a required forge.

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 };
116124 const mode = r.parent === null && !hides ? undefined : (modes.get(r.repo.id) ?? FORK_DEFAULT_MODE);
117125 return {
118126 repo: nameOf(r.repo),
@@ -120,6 +128,7 @@ export function forkTree(
120128 depth: r.depth,
121129 follow: mode === undefined ? "autonomous" : treeFollow(modes.get(r.repo.id)),
122130 word: mode === undefined ? "" : FOLLOW_WORD[mode],
131 behind: r.parent === null ? null : (keptBehind(forge, r.repo, r.parent) ?? null),
outdated

The optional forge makes the node shape vary. Make behind always present and the forge required.

123132 ...(hides ? { hiddenParent: true as const } : {}),
124133 };
125134 });
src/http/api/family.ts +1 −1
@@ -34,7 +34,7 @@ export function familyRoutes(router: Router<Handler>): void {
3434 const opts: { depth?: number; limit?: number } = {};
3535 if (depth !== undefined) opts.depth = depth;
3636 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));
3838 return json(tree ?? { root: null, nodes: [], truncated: false });
3939 });
4040 }
src/http/mcp/tools/fork_tree.ts +2 −2
@@ -4,7 +4,7 @@ import { good, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts";
44 /** The whole tree a repo sits in, as the caller may read it. */
55 export const tool: Tool = {
66 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",
88 description: "The fork tree around a repo: ancestors, siblings and descendants you may read.",
99 inputSchema: {
1010 type: "object",
@@ -22,7 +22,7 @@ export const tool: Tool = {
2222 const opts: { depth?: number; limit?: number } = {};
2323 if (typeof args["depth"] === "number") opts.depth = args["depth"];
2424 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);
2626 return good(tree ?? { root: null, nodes: [], truncated: false });
2727 },
2828 };
src/tui/screens/fork_tree.ts +3 −2
@@ -22,7 +22,8 @@ export function treeLines(tree: ForkTree | undefined, asked: string, width = 80,
2222 if (tree === undefined) return ["Nothing to show."];
2323 const lines = tree.nodes.map((n) => {
2424 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}` : "");
2627 const you = n.repo !== asked && viewer !== undefined && n.repo.startsWith(`${viewer}/`) ? " (you)" : "";
2728 return truncate(`${" ".repeat(n.depth)}${n.repo === asked ? "* " : ""}${n.repo}${you}${follow}`, width);
2829 });
@@ -38,7 +39,7 @@ export function forkTreeScreen(f: Session, ctx: Ctx, repo: Repo): Screen {
3839 keys: [binding(["j", "k"], "scroll"), binding(["esc"], "back")],
3940 render(area, s) {
4041 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);
4243 const from = scroll.window(area.h, lines.length);
4344 for (let i = 0; i < area.h; i++) {
4445 const line = lines[from + i];
src/web/pages/repo.ts +10 −6
@@ -44,7 +44,7 @@ import {
4444 } from "../../actions/forks.ts";
4545 import { FORK_DEFAULT_MODE, forkFollowModes, type ForkFollowMode } from "../../core/fork_follow.ts";
4646 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";
4848 import {
4949 archivedParentLine,
5050 followingCard,
@@ -208,7 +208,7 @@ export async function forksPage(ctx: Ctx): Promise<Response> {
208208 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.",
209209 bind: BIND.rest,
210210 })
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))}
212212 <h3 class="mt">The family, by who follows whom</h3>
213213 ${lineageCard(lineage, repo.id, ctx.auth.user?.id)}`}`;
214214 const res = page({
@@ -232,25 +232,29 @@ function forkRanking(
232232 bind: string,
233233 /** How each fork follows its parent; a fork without a row follows the default. */
234234 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,
235237 ): Html {
236238 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({
239242 lead: icon("fork"),
240243 ...(isSevered(modeOf(n.repo.id)) ? { data: { severed: "" } } : {}),
241244 title: html`<a href="/${n.repo.ownerName}/${n.repo.name}"
242245 >${n.repo.ownerName}/${n.repo.name}</a
243246 >`,
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
245248 ? html``
246249 : html` · <a href="/${n.repo.ownerName}/${n.repo.name}/forks"
247250 >and ${n.deeper} more fork${n.deeper === 1 ? "" : "s"} below</a
248251 >`}`,
249252 });
253 };
250254 const line = (f: RankedFork, offer: boolean): Html =>
251255 row({
252256 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)),
254258 lead: icon("fork"),
255259 title: html`<a href="/${f.fork.ownerName}/${f.fork.name}"
256260 >${f.fork.ownerName}/${f.fork.name}</a
test/fork-chain.test.ts +1 −1
@@ -32,7 +32,7 @@ const users: Record<string, User> = {};
3232 let a: Repo, b: Repo, c: Repo;
3333
3434 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)!;
3636 const commit = async (who: string, repo: Repo, path: string) =>
3737 must(await commitToBranch(app, users[who]!, repo, { message: path, files: [{ path, content: `${path}\n` }] }));
3838 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
8585
8686 test("a root that was never a fork reads no severed word", async () => {
8787 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("");
8989 });
9090
9191 test("the severed fork's own tree row reads severed; the words offer the way back", () => {
9292 const cut = getRepo(app.db, "alice", "cut")!;
93 const tree = forkTree(app.db, cut, alice)!;
93 const tree = forkTree(app.db, cut, alice, app)!;
9494 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)!;
9696 expect(attached.nodes.find((n) => n.repo === "alice/root")!.word).toBe("");
9797 expect(detachPlanWords({ parent: "alice/root", borrows: false, dryRun: true })).toContain(DETACH_AGAIN);
9898 });
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-mode.test.ts +2 −2
@@ -82,7 +82,7 @@ test("the terminal's forks rows say the same phrase from the same table", async
8282 });
8383
8484 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);
8686 for (const [mode, repo] of kids) expect(lines.find((l) => l.includes(name(repo)))).toContain(FOLLOW_PHRASE[mode]);
8787 });
8888
@@ -103,7 +103,7 @@ test("a nested fork row says its phrase on the web and in the terminal", async (
103103 const at = html.indexOf(`href="/${name(deep)}"`);
104104 expect(at).toBeGreaterThan(0);
105105 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)));
107107 expect(line).toContain(FOLLOW_PHRASE["tell-me"]);
108108 expect(line!.startsWith(" ")).toBe(true);
109109 });
test/fork-tree-reader.test.ts +18 −18
@@ -59,20 +59,20 @@ const names = (t: { nodes: { repo: string }[] }) => t.nodes.map((n) => n.repo);
5959
6060 describe("forkTree", () => {
6161 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)!;
6363 expect(t.root).toBe("alice/app");
6464 expect(t.truncated).toBe(false);
6565 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 });
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" });
69 expect(by["dan/app"]).toEqual({ repo: "dan/app", parent: "bob/app", depth: 2, follow: "take-updates", word: "follows", behind: null });
7070 });
7171
7272 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)!;
7676 expect(owner).toContain("erin/secret");
7777 expect(owner).toContain("erin/under");
7878 for (const t of [stranger, anon]) {
@@ -84,18 +84,18 @@ describe("forkTree", () => {
8484 });
8585
8686 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();
8888 });
8989
9090 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 })!;
9292 expect(t.nodes.every((n) => n.depth <= 1)).toBe(true);
9393 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);
9595 });
9696
9797 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 })!;
9999 expect(t.nodes.length).toBe(3);
100100 expect(t.truncated).toBe(true);
101101 expect(MAX_NODES).toBe(200);
@@ -110,11 +110,11 @@ describe("forkTree", () => {
110110 promote(app.db, u);
111111 at = must(await forkRepo(app, u, at));
112112 }
113 const t = forkTree(app.db, at, users["alice"]!, { depth: 1 })!;
113 const t = forkTree(app.db, at, users["alice"]!, app, { depth: 1 })!;
114114 const me = t.nodes.find((n) => n.repo === "deep4/app")!;
115115 expect(me.depth).toBe(5);
116116 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 })!;
118118 expect(tiny.nodes.some((n) => n.repo === "deep4/app")).toBe(true);
119119 });
120120
@@ -129,10 +129,10 @@ describe("forkTree", () => {
129129 c === "id" ? `'bulk${i}'` : c === "name" ? `'bulk${i}'` : c === "fork_parent_id" ? `'${base}'` : c;
130130 app.db.query(`INSERT INTO repo (${cols.join(",")}) SELECT ${list(sub)} FROM repo WHERE id = ?1`).run(base);
131131 }
132 forkTree(app.db, forge, users["bob"]!);
132 forkTree(app.db, forge, users["bob"]!, app);
133133 let t!: NonNullable<ReturnType<typeof forkTree>>;
134134 const n = await once(app.db, () => {
135 t = forkTree(app.db, forge, users["bob"]!)!;
135 t = forkTree(app.db, forge, users["bob"]!, app)!;
136136 });
137137 expect(t.nodes.length).toBe(200);
138138 expect(t.truncated).toBe(true);
@@ -144,13 +144,13 @@ describe("forkTree", () => {
144144 describe("the terminal screen", () => {
145145 test("draws the tree from the reader, marks the asked repo, and shows nothing for an unreadable one", async () => {
146146 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");
148148 expect(lines).toContain("alice/app");
149149 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");
151151 expect(own).toContain(" * dan/app follows automatically");
152152 expect(lines.join("\n")).not.toContain("offers");
153153 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."]);
155155 });
156156 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs