Public: anyone can read this; the crew can change it.
A fork says in one plain sentence how it follows its upstream, and the sentence is the same on the page and in the MCP #16072
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/16051-a-fork-says-in-one-plain-sentence-how-it → main 0 commits fork 4 threads · 4 unresolved
4 files
changed +92
−13
src/actions/follow_words.ts +1 −1
| @@ -114,7 +114,7 @@ export function agoWords(iso: string, now: number = Date.now()): string { | ||
| 114 | 114 | */ |
| 115 | 115 | export function followLineWords(mode: ForkFollowMode, upstream: string): string { |
| 116 | 116 | if (mode === "take-updates") return `Follows ${upstream} automatically`; |
| 117 | if (mode === "dont-follow") return "Severed"; | |
| 117 | if (mode === "dont-follow") return `Severed from ${upstream}; it no longer follows it`; | |
| 118 | 118 | return "Proposes changes only"; |
| 119 | 119 | } |
| 120 | 120 |
test/follow-words-parity.test.ts added +88
| @@ -0,0 +1,88 @@ | ||
| 1 | /** | |
| 2 | * A fork says in one plain sentence how it follows its upstream, and the repository page and the | |
| 3 | * MCP repo read (`follows`, from `followLine`) print the same words for each mode (#16051). | |
| 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 { readFileSync } from "node:fs"; | |
| 9 | import { join } from "node:path"; | |
| 10 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; | |
| 11 | import { createApp, type App } from "../src/app.ts"; | |
| 12 | import { setForkFollowMode, type ForkFollowMode } from "../src/core/fork_follow.ts"; | |
| 13 | import { getRepo } from "../src/core/repos.ts"; | |
| 14 | import { createUser, type User } from "../src/core/users.ts"; | |
| 15 | import type { Ctx } from "../src/http/context.ts"; | |
| 16 | import { tool } from "../src/http/mcp/tools/repo.ts"; | |
| 17 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 18 | import { promote } from "./helpers/members.ts"; | |
| 19 | ||
| 20 | let dataDir = ""; | |
| 21 | let app: App; | |
| 22 | let servers: Servers; | |
| 23 | let forkId = ""; | |
| 24 | let bea: User; | |
| 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 | ||
| 31 | beforeAll(async () => { | |
| 32 | dataDir = await mkdtemp(join(tmpdir(), "forge-fwparity-")); | |
| 33 | app = createApp({ dataDir, port: 0 }); | |
| 34 | const ann = must(await createUser(app.db, { origin: "seed", trusted: true, username: "ann", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true })); | |
| 35 | bea = must(await createUser(app.db, { origin: "seed", trusted: true, username: "bea", email: "[email protected]", password: "a-good-passphrase" })); | |
| 36 | promote(app.db, ann); | |
| 37 | promote(app.db, bea); | |
| 38 | const lib = must(await createRepo(app, ann, { name: "lib", visibility: "public" })); | |
| 39 | must(await commitToBranch(app, ann, lib, { message: "start", files: [{ path: "a.txt", content: "a\n" }] })); | |
| 40 | const fork = must(await forkRepo(app, bea, lib, undefined, { visibility: "public" })); | |
| 41 | forkId = getRepo(app.db, "bea", "lib")?.id ?? fork.id; | |
| 42 | servers = await serve(app); | |
| 43 | }, 30_000); | |
| 44 | ||
| 45 | afterAll(async () => { | |
| 46 | servers?.stop(); | |
| 47 | app?.close(); | |
| 48 | await rm(dataDir, { recursive: true, force: true }); | |
| 49 | }); | |
| 50 | ||
| 51 | const EXPECTED: ReadonlyArray<[ForkFollowMode, string]> = [ | |
| 52 | ["take-updates", "Follows ann/lib automatically"], | |
| 53 | ["tell-me", "Proposes changes only"], | |
| 54 | ["dont-follow", "Severed from ann/lib; it no longer follows it"], | |
| 55 | ]; | |
| 56 | ||
| 57 | /** What the repo-read tool says in `follows`, through its handler. */ | |
outdated
The test asserts literals and calls followLine directly. Cover the MCP tool's real output, and scope the page regex to the fork header. |
||
| 58 | async function inMcp(): Promise<string | null> { | |
| 59 | const url = new URL(`${servers.url}/mcp`); | |
| 60 | const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: bea, scope: "ro", via: "token" }, theme: undefined }; | |
| 61 | const r = await tool.run(ctx, bea, { repo: "bea/lib" }); | |
| 62 | return (r as { value: { follows: string | null } }).value.follows; | |
| 63 | } | |
| 64 | ||
| 65 | /** The sentence inside the fork header's lineage line, not elsewhere on the page. */ | |
outdated
Redundant: it follows from the two assertions above. |
||
| 66 | async function onPage(): Promise<string | undefined> { | |
| 67 | const html = await (await fetch(`${servers.url}/bea/lib`)).text(); | |
| 68 | const header = /<p[^>]*data-lineage[^>]*>([\s\S]*?)<\/p>/.exec(html)?.[1] ?? ""; | |
| 69 | return /<(?:a|span)[^>]*data-follow-word[^>]*>([\s\S]*?)<\/(?:a|span)>/.exec(header)?.[1]?.trim(); | |
| 70 | } | |
| 71 | ||
| 72 | test("the page and the MCP read tool say the same sentence for each mode", async () => { | |
| 73 | for (const [mode, words] of EXPECTED) { | |
| 74 | setForkFollowMode(app.db, forkId, mode); | |
| 75 | expect(await onPage()).toBe(words); | |
| 76 | expect(await inMcp()).toBe(words); | |
| 77 | } | |
| 78 | }); | |
| 79 | ||
| 80 | // A forge link (`forgeLinkOf`) names the forge's own repository, which has no fork parent, so | |
| 81 | // `followLine` is null there and the page draws no sentence: the two readers of the mode cannot | |
| 82 | // differ for a fork. | |
| 83 | test("both doors take the sentence from followLineWords, whatever its wording", () => { | |
Non-blocking: this test greps source text. It would pass if followLineWords were called and its result discarded. The first test already covers behaviour; consider a TUI fork-tree assertion here instead. |
||
| 84 | const read = (f: string) => readFileSync(join(import.meta.dir, "..", f), "utf8"); | |
| 85 | expect(read("src/web/chrome.ts")).toContain("followLineWords("); | |
| 86 | expect(read("src/actions/follow.ts")).toMatch(/return followLineWords\(/); | |
| 87 | expect(read("src/http/mcp/tools/repo.ts")).toContain("followLine("); | |
| 88 | }); |
test/fork-follow-line.test.ts +2 −11
| @@ -9,7 +9,6 @@ import { join } from "node:path"; | ||
| 9 | 9 | import { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts"; |
| 10 | 10 | import { forkTreeRows } from "../src/actions/fork_tree_rows.ts"; |
| 11 | 11 | import { createApp, type App } from "../src/app.ts"; |
| 12 | import type { Ctx } from "../src/http/context.ts"; | |
| 13 | 12 | import { setForkFollowMode, type ForkFollowMode } from "../src/core/fork_follow.ts"; |
| 14 | 13 | import { getRepo } from "../src/core/repos.ts"; |
| 15 | 14 | import { createUser } from "../src/core/users.ts"; |
| @@ -121,22 +120,14 @@ test("the terminal's fork tree opens with the sentence for a fork, and not for a | ||
| 121 | 120 | expect(root).not.toContain("Proposes upstream"); |
| 122 | 121 | }); |
| 123 | 122 | |
| 124 | test("the three states read the same on the page and in the MCP repo answer (#15767)", async () => { | |
| 125 | const { tool } = await import("../src/http/mcp/tools/repo.ts"); | |
| 126 | const said = async (): Promise<string> => { | |
| 127 | const url = new URL("http://forge.test/mcp"); | |
| 128 | const ctx: Ctx = { app, request: new Request(url.href), url, params: {}, auth: { user: users["bea"], scope: "ro", via: "token" }, theme: undefined }; | |
| 129 | const r = await tool.run(ctx, users["bea"], { repo: "bea/lib" }); | |
| 130 | return (r as { value: { follows: string } }).value.follows; | |
| 131 | }; | |
| 123 | test("the three states read as one plain sentence on the page (#15767; the MCP side is pinned in follow-words-parity)", async () => { | |
| 132 | 124 | const states: [string, string][] = [ |
| 133 | 125 | ["take-updates", "Follows ann/lib automatically"], |
| 134 | 126 | ["tell-me", "Proposes changes only"], |
| 135 | ["dont-follow", "Severed"], | |
| 127 | ["dont-follow", "Severed from ann/lib; it no longer follows it"], | |
| 136 | 128 | ]; |
| 137 | 129 | for (const [mode, words] of states) { |
| 138 | 130 | setForkFollowMode(app.db, forkId, mode as ForkFollowMode); |
| 139 | 131 | expect(line(await page("/bea/lib", "bea"))).toContain(words); |
| 140 | expect(await said()).toBe(words); | |
| 141 | 132 | } |
| 142 | 133 | }); |
test/fork-follow-word.test.ts +1 −1
| @@ -72,7 +72,7 @@ test("each mode is one plain sentence in the lineage line, on the code tab and o | ||
| 72 | 72 | const want: [Parameters<typeof setForkFollowMode>[2], string][] = [ |
| 73 | 73 | ["tell-me", "Proposes changes only"], |
| 74 | 74 | ["take-updates", "Follows alice/lib automatically"], |
| 75 | ["dont-follow", "Severed"], | |
| 75 | ["dont-follow", "Severed from alice/lib; it no longer follows it"], | |
| 76 | 76 | ]; |
| 77 | 77 | for (const [mode, word] of want) { |
| 78 | 78 | setForkFollowMode(app.db, fork.id, mode); |
new above
offline
Type this as User, not any.