Public: anyone can read this; the crew can change it.

The fork tree, browsable, and each fork chooses how it follows #994

Closed opened this in answer to
Closed without merging

scout/forge:scout/608-the-fork-tree-browsable-and-each-fork-ch → main 2 commits fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
15 files changed +380 −33
docs/FOLLOWING.md +13 −1
@@ -126,10 +126,22 @@ without any simply moves.
126126 - The converge run's assignee is set without the assignment event, so the
127127 run queues under its own reason and not as an ordinary assignment.
128128
129 ## How a fork follows
130
131 A fork's writer chooses, on the forks page (`/:owner/:name/forks`) or with the
132 MCP `follow {repo, mode}` tool; `following` returns the `mode`. Saved on the
133 repository as `follow_mode`:
134
135 - `auto` (the default, and what forks always did): a parent that moves is
136 followed when git can do it alone — fast-forward, and with autonomy on a
137 clean merge or the crew's converge.
138 - `tell`: nothing is moved; the fork hears `fork.parent_moved`.
139 - `off`: nothing happens. Pressing Take updates or Converge by hand still works.
140
129141 ## The way back up
130142
131143 A fork's own work goes upstream in one press. When a fork is ahead of what
132 it follows, its following card offers **Propose upstream**: one pull opens
144 it follows, the forks page offers **Offer this change** (the following card no longer carries a second button for it): one pull opens
133145 on the parent from the fork's default branch, its title the one landed
134146 change's title, or `N changes from owner/fork` when there are several, its
135147 body one line per change that landed here since the fork last proposed,
docs/MCP.md +2 −1
@@ -38,7 +38,8 @@ for a tunnel and a forge that sleeps.
3838 | `audit` | who can do what, per app, read from its contract.json in git: yes, own or no per door, and whether outsiders may direct its crew (`crewOutsiders`) | |
3939 | `outsiders` | `{ repo, on?, dryRun? }`: whether people who cannot write may direct the crew; with `on`, planned first (`dryRun` is true unless `false`); set only by the app's admin with an admin token, never an agent | yes |
4040 | `probe` | knock on a running app's doors as nobody, a user and an admin; the ones that disobey its contract | |
41 | `following` | where a fork stands against what it follows, and what the crew is doing about it | |
41 | `following` | where a fork stands against what it follows, its follow `mode`, and what the crew is doing about it | |
42 | `follow` | `{ repo, mode }`: `auto`, `tell` or `off`, how a fork follows its parent; a writer's to say | yes |
4243 | `spawn` | `{ name, apps?, crew?, dryRun? }`: a child forge, planned first (`dryRun` is true unless `false`); an admin's, and an `ro` token may plan but not make | yes |
4344 | `claim_link` | `{ name }`: a new claim link for a child you spawned that nobody has claimed; the old one stops working. An admin's | yes |
4445 | `take_updates` | a fork takes its parent's updates when git can do it alone; a conflict is refused | yes |
src/actions/forks.ts +24 −1
@@ -18,6 +18,8 @@ import {
1818 import {
1919 canRead,
2020 forkParentFor,
21 updateRepoSettings,
22 type FollowMode,
2123 type Repo,
2224 } from "../core/repos.ts";
2325 import { commitIdentity } from "../core/commit_identity.ts";
@@ -25,7 +27,7 @@ import type { User } from "../core/users.ts";
2527 import { divergence } from "../git/branches.ts";
2628 import { resolveOid } from "../git/merge.ts";
2729 import { repoDir } from "../git/repos.ts";
28 import { err, type Result } from "../kernel/result.ts";
30 import { err, ok, type Result } from "../kernel/result.ts";
2931 import { requireWriter, type AccessError } from "./access.ts";
3032
3133 export type { ForkRelation, ForkSync, TakeError } from "../core/following.ts";
@@ -65,6 +67,27 @@ export async function relationOf(
6567 return forkRelation(app, fork, parent);
6668 }
6769
70 /** Choose how a fork follows its parent; a writer's to say, a fork's only. */
71 export function setFollowMode(
72 app: App,
73 actor: User | undefined,
74 fork: Repo,
75 mode: FollowMode,
76 ): Result<Repo, AccessError | "not_a_fork"> {
77 const writer = requireWriter(app, actor, fork);
78 if (!writer.ok) return writer;
79 if (fork.forkParentId === null) return err("not_a_fork");
80 if (fork.followMode === mode) return ok(fork);
81 const saved = updateRepoSettings(app.db, fork, { followMode: mode });
82 app.bus.append({
83 kind: "repo.follow_mode",
84 repoId: fork.id,
85 actorId: writer.value.id,
86 payload: { from: fork.followMode, to: mode },
87 });
88 return ok(saved);
89 }
90
6891 export type TakeUpdatesError = AccessError | "not_a_fork" | TakeError;
6992
7093 /**
src/core/event_audience.ts +2 −1
@@ -42,7 +42,8 @@ export function eventAudience(kind: string): EventAudience {
4242 // theirs to see, never the readers' (`actions/reports.ts`).
4343 kind.startsWith("report.") ||
4444 kind === "repo.settings_updated" ||
45 kind === "repo.crew_outsiders"
45 kind === "repo.crew_outsiders" ||
46 kind === "repo.follow_mode"
4647 )
4748 return "admins";
4849 // A fleet operation spans repositories; its receipt is its actor's.
src/core/following.ts +17 −1
@@ -96,7 +96,22 @@ export function follow(forge: Following): () => void {
9696 }),
9797 );
9898 if (moved.some((m) => m.ref === `refs/heads/${repo.defaultBranch}`))
99 for (const fork of listForks(forge.db, repo.id))
99 for (const fork of listForks(forge.db, repo.id)) {
100 // The fork's owner chose how it follows: `off` is left alone, `tell`
101 // hears that the parent moved and nothing else happens.
102 if (fork.followMode === "off") continue;
103 if (fork.followMode === "tell") {
104 forge.bus.append({
105 kind: "fork.parent_moved",
106 repoId: fork.id,
107 actorId: actor,
108 payload: {
109 parent: `${repo.ownerName}/${repo.name}`,
110 parentId: repo.id,
111 },
112 });
113 continue;
114 }
100115 fastForwardFork(forge, fork, repo, actor)
101116 .then((followed) => {
102117 // A fork with work of its own cannot be moved; it is told the
@@ -120,6 +135,7 @@ export function follow(forge: Following): () => void {
120135 error: String(error),
121136 }),
122137 );
138 }
123139 });
124140 }
125141
src/core/repos.ts +17 −1
@@ -98,6 +98,8 @@ export interface Repo {
9898 readonly autonomyCeilingUsd: number;
9999 readonly autonomySlots: number;
100100 readonly autonomyBy: string | null;
101 /** How this fork follows its parent; see `FollowMode`. */
102 readonly followMode: FollowMode;
101103 /**
102104 * "Outsiders may trigger the crew": whether someone who cannot write here
103105 * may still start or steer a run by speaking (`crew/direct.ts`). Off by
@@ -124,6 +126,16 @@ export interface Repo {
124126 readonly counts?: RepoCounts;
125127 }
126128
129 /**
130 * How a fork follows its parent: `auto` takes what git can take alone,
131 * `tell` only says the parent moved, `off` leaves the fork as it is.
132 */
133 export const FOLLOW_MODES = ["auto", "tell", "off"] as const;
134 export type FollowMode = (typeof FOLLOW_MODES)[number];
135 export function isFollowMode(v: unknown): v is FollowMode {
136 return FOLLOW_MODES.includes(v as FollowMode);
137 }
138
127139 interface RepoRow {
128140 id: string;
129141 owner_id: string;
@@ -141,6 +153,7 @@ interface RepoRow {
141153 autonomy_slots: number;
142154 autonomy_by: string | null;
143155 crew_outsiders: number;
156 follow_mode: string;
144157 direction_issue_id: string | null;
145158 fork_parent_id: string | null;
146159 sealed_for: string | null;
@@ -177,6 +190,7 @@ function toRepo(row: RepoRow): Repo {
177190 autonomySlots: row.autonomy_slots,
178191 autonomyBy: row.autonomy_by,
179192 crewOutsiders: row.crew_outsiders === 1,
193 followMode: isFollowMode(row.follow_mode) ? row.follow_mode : "auto",
180194 directionIssueId: row.direction_issue_id,
181195 forkParentId: row.fork_parent_id,
182196 sealedFor: row.sealed_for,
@@ -983,6 +997,7 @@ export interface RepoSettings {
983997 autonomyBy?: string | null;
984998 /** Whether someone who cannot write here may start or steer a run. */
985999 crewOutsiders?: boolean;
1000 followMode?: FollowMode;
9861001 }
9871002
9881003 /** Update the mutable repo fields, leaving unspecified ones untouched. */
@@ -995,7 +1010,7 @@ export function updateRepoSettings(
9951010 `UPDATE repo SET visibility = ?1, description = ?2, protect_default = ?3,
9961011 default_branch = ?4, require_review = ?5, require_checks = ?7,
9971012 autonomy = ?8, autonomy_direction = ?9, autonomy_ceiling_usd = ?10,
998 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13
1013 autonomy_slots = ?11, autonomy_by = ?12, crew_outsiders = ?13, follow_mode = ?14
9991014 WHERE id = ?6`,
10001015 ).run(
10011016 settings.visibility ?? repo.visibility,
@@ -1011,6 +1026,7 @@ export function updateRepoSettings(
10111026 settings.autonomySlots ?? repo.autonomySlots,
10121027 settings.autonomyBy === undefined ? repo.autonomyBy : settings.autonomyBy,
10131028 (settings.crewOutsiders ?? repo.crewOutsiders) ? 1 : 0,
1029 settings.followMode ?? repo.followMode,
10141030 );
10151031 return getRepoById(db, repo.id)!;
10161032 }
src/core/schema.ts +6
@@ -1540,4 +1540,10 @@ export const migrations: readonly string[] = [
15401540 SELECT RAISE(ABORT, 'a sealed repository is never public');
15411541 END;
15421542 `,
1543 // 71 — how a fork follows its parent (#608): `auto` takes what git can
1544 // take on its own (today's behaviour), `tell` only says the parent moved,
1545 // `off` leaves the fork alone. Meaningless on a repository that is no fork.
1546 `
1547 ALTER TABLE repo ADD COLUMN follow_mode TEXT NOT NULL DEFAULT 'auto';
1548 `,
15431549 ];
src/crew/converge.ts +1 −1
@@ -207,7 +207,7 @@ export function followDivergence(app: App): () => void {
207207 const parent =
208208 typeof parentId === "string" ? getRepoById(app.db, parentId) : undefined;
209209 if (fork === undefined || parent === undefined) return;
210 if (fork.autonomy === "off") return;
210 if (fork.autonomy === "off" || fork.followMode !== "auto") return;
211211 diverged(app, fork, parent).catch((error) =>
212212 log.error("could not act on a diverged fork", {
213213 fork: `${fork.ownerName}/${fork.name}`,
src/design/activity.ts +1
@@ -111,6 +111,7 @@ const WORDS: Record<string, string> = {
111111 "repo.created": "created a repository",
112112 "repo.forked": "forked a repository",
113113 "repo.settings_updated": "changed repository settings",
114 "repo.follow_mode": "changed how the fork follows its parent",
114115 "repo.crew_outsiders": "changed who may trigger the crew",
115116 "repo.mirrored": "mirrored a repository",
116117 "repo.imported": "imported issues and pulls",
src/http/mcp.ts +34 −1
@@ -19,7 +19,7 @@
1919
2020 import { mayView, mayViewId, sealedScope } from "../core/sealed.ts";
2121 import { changeCapacity, listCapacity } from "../actions/capacity.ts";
22 import { relationOf, takeUpdates } from "../actions/forks.ts";
22 import { relationOf, setFollowMode, takeUpdates } from "../actions/forks.ts";
2323 import { watchMilestone } from "../actions/watches.ts";
2424 import {
2525 addCommentThrough,
@@ -66,6 +66,8 @@ import {
6666 canWrite,
6767 forkParentFor,
6868 getRepo,
69 FOLLOW_MODES,
70 isFollowMode,
6971 ownerFactRepoIds,
7072 type Repo,
7173 } from "../core/repos.ts";
@@ -742,9 +744,40 @@ const TOOLS: readonly Tool[] = [
742744 clean: relation.clean,
743745 conflicts: relation.conflicts,
744746 converge: converge?.kind ?? null,
747 mode: repo.followMode,
745748 });
746749 },
747750 },
751 {
752 name: "follow",
753 description:
754 "Choose how a fork follows the repository it came from: `auto` takes the updates git can take on its own, `tell` only notes that the parent moved, `off` leaves the fork alone. A writer's to say.",
755 inputSchema: {
756 type: "object",
757 properties: {
758 repo: REPO_ARG,
759 mode: { type: "string", enum: [...FOLLOW_MODES] },
760 },
761 required: ["repo", "mode"],
762 },
763 writes: true,
764 async run(ctx, user, args) {
765 const repo = repoArg(ctx, user, args);
766 if (isAnswer(repo)) return repo;
767 const mode = str(args["mode"]);
768 if (!isFollowMode(mode))
769 return bad("invalid", "mode is auto, tell or off");
770 const set = setFollowMode(ctx.app, user, repo, mode);
771 if (!set.ok)
772 return bad(
773 set.error,
774 set.error === "not_a_fork"
775 ? "this repository follows nothing"
776 : "only a writer chooses how a fork follows",
777 );
778 return good({ mode: set.value.followMode });
779 },
780 },
748781 {
749782 name: "spawn",
750783 description:
src/web/pages/following.ts +83 −21
@@ -13,11 +13,15 @@
1313 import { DIRECTION_NOTE } from "../../crew/direct.ts";
1414 import {
1515 relationOf,
16 setFollowMode,
1617 takeUpdates,
1718 type ForkRelation,
1819 } from "../../actions/forks.ts";
1920 import { listCrewRoles } from "../../core/agents.ts";
2021 import {
22 FOLLOW_MODES,
23 type FollowMode,
24 isFollowMode,
2125 canRead,
2226 canWrite,
2327 forkParentFor,
@@ -156,6 +160,67 @@ export function relationSentence(relation: ForkRelation): string {
156160 }
157161 }
158162
163 const MODE_WORDS: Record<FollowMode, [string, string]> = {
164 auto: ["Take green updates", "Updates git can take alone are taken."],
165 tell: ["Tell me", "The fork is only told when its parent moves."],
166 off: ["Don't follow", "The fork stays as it is."],
167 };
168
169 /**
170 * How this fork follows, and the one offer it can make: on the forks page,
171 * for a writer of a fork. Choosing the mode is the action; a fork ahead of
172 * its parent also offers its change up.
173 */
174 export async function followPanel(
175 ctx: Ctx,
176 repo: Repo,
177 ): Promise<Html | null> {
178 if (repo.forkParentId === null) return null;
179 if (!canWrite(ctx.app.db, repo, ctx.auth.user)) return null;
180 const following = await followingOf(ctx, repo);
181 if (following === undefined) return null;
182 const { relation } = following;
183 const parent = relation.parent;
184 const base = repoBase(repo);
185 const proposal =
186 relation.ahead > 0 ? openProposal(ctx.app, repo, parent) : undefined;
187 return html`<section class="card follow-panel" id="follow">
188 <div class="card-body">
189 <p class="following-sentence">${relationSentence(relation)}</p>
190 <form method="post" action="${base}/following" class="following-actions">
191 <input type="hidden" name="do" value="mode" />
192 ${FOLLOW_MODES.map((m) =>
193 btn(MODE_WORDS[m][0], {
194 size: "sm",
195 type: "submit",
196 name: "mode",
197 value: m,
198 variant: repo.followMode === m ? "primary" : "secondary",
199 }),
200 )}
201 </form>
202 <p class="muted small following-foot">${MODE_WORDS[repo.followMode][1]}</p>
203 ${relation.ahead === 0
204 ? null
205 : proposal === undefined
206 ? html`<form method="post" action="${base}/following" class="following-actions">
207 <input type="hidden" name="do" value="propose" />
208 ${btn("Offer this change", {
209 size: "sm",
210 type: "submit",
211 icon: "merge",
212 })}
213 </form>`
214 : html`<p class="following-actions">
215 ${btn("See the offer", {
216 size: "sm",
217 href: `/${parent.ownerName}/${parent.name}/pulls/${proposal.number}`,
218 })}
219 </p>`}
220 </div>
221 </section>`;
222 }
223
159224 /**
160225 * The card on a fork's home. `studio` swaps nothing but the words for the
161226 * crew's part; the mechanics are one and the same.
@@ -212,27 +277,6 @@ export function followingCard(
212277 }),
213278 );
214279
215 // The fork's own work, offered upstream in one click: the words come
216 // from what landed here, so nothing waits on the crew.
217 if (writer && relation.ahead > 0) {
218 const proposal = openProposal(ctx.app, repo, parent);
219 actions.push(
220 proposal === undefined
221 ? html`<form method="post" action="${base}/following">
222 <input type="hidden" name="do" value="propose" />
223 ${btn("Propose upstream", {
224 size: "sm",
225 type: "submit",
226 icon: "merge",
227 })}
228 </form>`
229 : btn("See the upstream proposal", {
230 size: "sm",
231 href: `/${parent.ownerName}/${parent.name}/pulls/${proposal.number}`,
232 }),
233 );
234 }
235
236280 const foot: Html | null =
237281 converge === undefined
238282 ? conflict
@@ -321,6 +365,24 @@ export async function followingSubmit(ctx: Ctx): Promise<Response> {
321365 });
322366 const parentName = `${parent.ownerName}/${parent.name}`;
323367
368 if (field(form, "do") === "mode") {
369 const mode = field(form, "mode");
370 const to = `${base}/forks`;
371 if (!isFollowMode(mode))
372 return flashOrJson(ctx, to, {
373 tone: "danger",
374 message: "Choose take green updates, tell me, or don't follow.",
375 });
376 const set = setFollowMode(ctx.app, ctx.auth.user, repo, mode);
377 if (!set.ok)
378 return flashOrJson(ctx, to, {
379 tone: "danger",
380 message: "You need write access to choose how this follows.",
381 });
382 return flashOrJson(ctx, to, {
383 message: `${MODE_WORDS[mode][0]}: ${MODE_WORDS[mode][1]}`,
384 });
385 }
324386 if (field(form, "do") === "converge") {
325387 if (!canWrite(ctx.app.db, repo, ctx.auth.user))
326388 return flashOrJson(ctx, base, {
src/web/pages/repo.ts +3 −1
@@ -12,7 +12,7 @@ import { canRead, listForks, type Repo } from "../../core/repos.ts";
1212 import { FORKS_PER_DAY, forkRepo } from "../../actions/repos.ts";
1313 import { forkDrift, takeUpdates, type ForkDrift } from "../../actions/forks.ts";
1414 import { lineageOf } from "../../core/following.ts";
15 import { followingCard, followingOf, lineageCard } from "./following.ts";
15 import { followingCard, followingOf, followPanel, lineageCard } from "./following.ts";
1616 import { pinRepo, syncRepoNow, unpinRepo } from "../../actions/origins.ts";
1717 import {
1818 canAdmin,
@@ -132,7 +132,9 @@ export async function forksPage(ctx: Ctx): Promise<Response> {
132132 const lineage = await lineageOf(ctx.app, repo, (r) =>
133133 canRead(ctx.app.db, r, ctx.auth.user),
134134 );
135 const panel = await followPanel(ctx, repo);
135136 const body = html`${repoHeader(ctx, repo, "forks")}
137 ${panel}
136138 <div class="page-head mt">
137139 <h2>${forks.length} fork${forks.length === 1 ? "" : "s"}</h2>
138140 </div>
test/follow_mode.test.ts added +173
@@ -0,0 +1,173 @@
1 /**
2 * How a fork chooses to follow (#608): saved from the forks page and from
3 * MCP, and honoured when the parent moves.
4 */
5 import { afterAll, beforeAll, describe, 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 { commitToBranch, createRepo, forkRepo } from "../src/actions/repos.ts";
11 import { listEvents } from "../src/core/events.ts";
12 import { forkRelation } from "../src/core/following.ts";
13 import { getRepoById, type Repo } from "../src/core/repos.ts";
14 import { createToken } from "../src/core/tokens.ts";
15 import { createUser, type User } from "../src/core/users.ts";
16 import { serve, type Servers } from "../src/http/server.ts";
17
18 describe("a fork chooses how it follows", () => {
19 let dataDir: string;
20 let app: App;
21 let servers: Servers;
22 let base: string;
23 let alice: User;
24 let bob: User;
25 let eve: User;
26 let bobToken: string;
27 let eveToken: string;
28 let parent: Repo;
29 const forks: Record<string, Repo> = {};
30 const tokens: Record<string, string> = {};
31 const fresh = (r: Repo) => getRepoById(app.db, r.id)!;
32 const commit = (who: User, repo: Repo, path: string) =>
33 commitToBranch(app, who, repo, {
34 message: path,
35 files: [{ path, content: `${path}\n` }],
36 });
37 const post = (token: string, repo: string, body: string) =>
38 fetch(`${base}/${repo}/following`, {
39 method: "POST",
40 headers: {
41 authorization: `Bearer ${token}`,
42 "content-type": "application/x-www-form-urlencoded",
43 accept: "application/json",
44 },
45 body,
46 });
47 const mcp = async (token: string, name: string, args: unknown) => {
48 const res = await fetch(`${base}/mcp`, {
49 method: "POST",
50 headers: {
51 authorization: `Bearer ${token}`,
52 "content-type": "application/json",
53 },
54 body: JSON.stringify({
55 jsonrpc: "2.0",
56 id: 1,
57 method: "tools/call",
58 params: { name, arguments: args },
59 }),
60 });
61 const r = (await res.json()) as any;
62 const text: string = r.result.content[0].text;
63 return r.result.isError === true
64 ? { error: text }
65 : { value: JSON.parse(text) };
66 };
67
68 beforeAll(async () => {
69 dataDir = await mkdtemp(join(tmpdir(), "forge-follow-mode-"));
70 app = createApp({ dataDir, port: 0 });
71 servers = await serve(app);
72 base = servers.url;
73 const mk = async (username: string, first = false) => {
74 const u = await createUser(app.db, {
75 trusted: true,
76 username,
77 email: `${username}@forge.local`,
78 password: "a-good-passphrase",
79 adminIfFirst: first,
80 });
81 if (!u.ok) throw new Error(u.error);
82 tokens[username] = createToken(app.db, u.value.id, "t", "rw").token;
83 return u.value;
84 };
85 alice = await mk("alice", true);
86 bob = await mk("bob");
87 eve = await mk("eve");
88 bobToken = tokens["bob"]!;
89 eveToken = tokens["eve"]!;
90 const made = await createRepo(app, alice, { name: "game", visibility: "public" });
91 if (!made.ok) throw new Error(String(made.error));
92 parent = made.value;
93 await commit(alice, parent, "README.md");
94 for (const name of ["auto", "tell", "off"]) {
95 const f = await forkRepo(app, name === "off" ? bob : await mk(`f${name}`), parent);
96 if (!f.ok) throw new Error(String(f.error));
97 forks[name] = f.value;
98 }
99 }, 30_000);
100
101 afterAll(async () => {
102 servers.stop();
103 app.close();
104 await rm(dataDir, { recursive: true, force: true });
105 });
106
107 test("the owner saves a mode from the forks page; a stranger cannot", async () => {
108 expect(fresh(forks["auto"]!).followMode).toBe("auto");
109 const page = await fetch(`${base}/ftell/game/forks`, {
110 headers: { authorization: `Bearer ${tokens["ftell"]}`, accept: "text/html" },
111 }).then((r) => r.text());
112 expect(page).toContain("Take green updates");
113 expect(page).toContain("Tell me");
114 expect(page).toContain("Don&#39;t follow");
115 expect((await post(tokens["ftell"]!, "ftell/game", "do=mode&mode=tell")).status).toBe(200);
116 expect((await post(bobToken, "bob/game", "do=mode&mode=off")).status).toBe(200);
117 expect(fresh(forks["tell"]!).followMode).toBe("tell");
118 expect(fresh(forks["off"]!).followMode).toBe("off");
119
120 expect((await post(tokens["fauto"]!, "fauto/game", "do=mode&mode=bogus")).status).toBe(422);
121 expect((await post(eveToken, "fauto/game", "do=mode&mode=off")).status).toBe(422);
122 expect(fresh(forks["auto"]!).followMode).toBe("auto");
123
124 // A stranger's view of the same page carries no controls.
125 const seen = await fetch(`${base}/ftell/game/forks`, {
126 headers: { authorization: `Bearer ${eveToken}`, accept: "text/html" },
127 }).then((r) => r.text());
128 expect(seen).not.toContain("Tell me");
129 });
130
131 test("converge honours each mode when the parent moves", async () => {
132 await commit(alice, parent, "levels.txt");
133 const tip = async (f: Repo) =>
134 (await forkRelation(app, fresh(f), fresh(parent)))!;
135 const until = async (f: Repo) => {
136 for (let i = 0; i < 100; i++) {
137 if ((await tip(f)).state === "synced") return true;
138 await Bun.sleep(40);
139 }
140 return false;
141 };
142 expect(await until(forks["auto"]!)).toBe(true);
143 // Give the others the same time; they must not have moved.
144 await Bun.sleep(300);
145 expect((await tip(forks["tell"]!)).state).toBe("behind");
146 expect((await tip(forks["off"]!)).state).toBe("behind");
147
148 const told = (f: Repo) =>
149 listEvents(app.db, { repoId: f.id }).filter((e) => e.kind === "fork.parent_moved");
150 expect(told(forks["tell"]!).length).toBe(1);
151 expect(told(forks["off"]!).length).toBe(0);
152 expect(told(forks["auto"]!).length).toBe(0);
153 });
154
155 test("a fork ahead offers its change up from the forks page", async () => {
156 await commit(bob, forks["off"]!, "mine.txt");
157 const page = () =>
158 fetch(`${base}/bob/game/forks`, {
159 headers: { authorization: `Bearer ${bobToken}`, accept: "text/html" },
160 }).then((r) => r.text());
161 expect(await page()).toContain("Offer this change");
162 });
163
164 test("MCP reads and sets the mode", async () => {
165 expect((await mcp(bobToken, "following", { repo: "bob/game" })).value.mode).toBe("off");
166 const set = await mcp(bobToken, "follow", { repo: "bob/game", mode: "auto" });
167 expect(set.value.mode).toBe("auto");
168 expect(fresh(forks["off"]!).followMode).toBe("auto");
169 expect((await mcp(bobToken, "follow", { repo: "bob/game", mode: "x" })).error).toBeDefined();
170 expect((await mcp(eveToken, "follow", { repo: "bob/game", mode: "off" })).error).toBeDefined();
171 expect((await mcp(bobToken, "follow", { repo: "alice/game", mode: "off" })).error).toBeDefined();
172 });
173 });
test/following.test.ts +3 −3
@@ -606,11 +606,11 @@ describe("a fork that follows its parent", () => {
606606 expect(k.opened).toBe(false);
607607 expect(k.number).toBe(j.number);
608608
609 // The card offers the way to it now, not another proposal.
609 // The forks page offers the way to it now, not another proposal.
610610 const page = await (
611 await fetch(`${base}/bob/game`, { headers: as(bobToken) })
611 await fetch(`${base}/bob/game/forks`, { headers: as(bobToken) })
612612 ).text();
613 expect(page).toContain("See the upstream proposal");
613 expect(page).toContain("See the offer");
614614 expect(page).not.toContain('value="propose"');
615615 });
616616
test/mcp.test.ts +1
@@ -170,6 +170,7 @@ describe("the forge over MCP", () => {
170170 "outsiders",
171171 "probe",
172172 "following",
173 "follow",
173174 "spawn",
174175 "forges",
175176 "claim_link",

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs