Public: anyone can read this; the crew can change it.
The fork tree names each fork's follow mode in one word (follows, proposes, severed), from the same record the setting writes #15695
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/15654-the-fork-tree-names-each-fork-s-follow-m → main 0 commits fork
1 file
changed +71
−0
test/fork-tree-words.test.ts added +71
| @@ -0,0 +1,71 @@ | ||
| 1 | /** | |
| 2 | * #15654: one fork in each follow mode; the tree page and the MCP fork read say follows, proposes, | |
| 3 | * severed from the stored mode. | |
| 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 { createApp, type App } from "../src/app.ts"; | |
| 10 | import { setRole } from "../src/actions/roles.ts"; | |
| 11 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 12 | import { setForkFollowMode } from "../src/core/fork_follow.ts"; | |
| 13 | import { createToken } from "../src/core/tokens.ts"; | |
| 14 | import { createUser } from "../src/core/users.ts"; | |
| 15 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 16 | ||
| 17 | let dataDir: string; | |
| 18 | let app: App; | |
| 19 | let servers: Servers; | |
| 20 | let token: string; | |
| 21 | ||
| 22 | const must = <T>(r: { ok: true; value: T } | { ok: false; error: unknown }): T => { | |
| 23 | if (!r.ok) throw new Error(JSON.stringify(r.error)); | |
| 24 | return r.value; | |
| 25 | }; | |
| 26 | ||
| 27 | beforeAll(async () => { | |
| 28 | dataDir = await mkdtemp(join(tmpdir(), "forge-tree-words-")); | |
| 29 | app = createApp({ dataDir, port: 0 }); | |
| 30 | servers = await serve(app); | |
| 31 | const mk = async (username: string, first: boolean) => | |
| 32 | must(await createUser(app.db, { origin: "seed", trusted: true, username, email: `${username}@forge.local`, password: "a-good-passphrase", adminIfFirst: first })); | |
| 33 | const ann = await mk("ann", true); | |
| 34 | token = createToken(app.db, ann.id, "admin", "admin").token; | |
| 35 | const root = must(await createRepo(app, ann, { name: "yard", visibility: "public" })); | |
| 36 | must(await commitToBranch(app, ann, root, { message: "first", files: [{ path: "a.txt", content: "a\n" }] })); | |
| 37 | for (const [user, mode] of [["bea", "take-updates"], ["cal", "tell-me"], ["dan", "dont-follow"]] as const) { | |
| 38 | const u = await mk(user, false); | |
| 39 | must(setRole(app, ann, user, "member")); | |
| 40 | setForkFollowMode(app.db, must(await forkRepo(app, u, root)).id, mode); | |
| 41 | } | |
| 42 | }, 60_000); | |
| 43 | ||
| 44 | afterAll(async () => { | |
| 45 | servers?.stop(); | |
| 46 | app?.close(); | |
| 47 | await rm(dataDir, { recursive: true, force: true }); | |
| 48 | }); | |
| 49 | ||
| 50 | const WORDS: Record<string, string> = { "bea/yard": "follows", "cal/yard": "proposes", "dan/yard": "severed" }; | |
| 51 | ||
| 52 | test("the tree page names each fork's mode in its row", async () => { | |
| 53 | const html = await (await fetch(`${servers.url}/ann/yard/forks`)).text(); | |
| 54 | for (const [repo, word] of Object.entries(WORDS)) { | |
| 55 | const at = html.indexOf(`href="/${repo}"`); | |
| 56 | expect(at).toBeGreaterThan(0); | |
| 57 | const row = html.slice(html.lastIndexOf("<li", at), html.indexOf("</li>", at)); | |
| 58 | expect(row).toContain(`>${word}`); | |
| 59 | } | |
| 60 | }); | |
| 61 | ||
| 62 | test("the MCP fork_tree answers the same word in `word`", async () => { | |
| 63 | const res = await fetch(`${servers.url}/mcp`, { | |
| 64 | method: "POST", | |
| 65 | headers: { "content-type": "application/json", accept: "application/json, text/event-stream", authorization: `Bearer ${token}` }, | |
| 66 | body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: "fork_tree", arguments: { repo: "ann/yard" } } }), | |
| 67 | }); | |
| 68 | const json = JSON.parse(((await res.json()) as any).result.content[0].text); | |
| 69 | const by = Object.fromEntries(json.nodes.map((n: any) => [n.repo, n.word])); | |
| 70 | expect(by).toMatchObject(WORDS); | |
| 71 | }); |
new above
offline