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

An owner sets a fork's follow mode from the fork's own page: follow automatically or propose only, one confirmed action with a receipt #13469

opened this

Closed 17d 2h ago

scout/forge:scout/13443-an-owner-sets-a-fork-s-follow-mode-from → main 2 commits fork 2 threads · 2 unresolved

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
4 files changed +57 −3
src/actions/follow.ts +4 −2
@@ -18,7 +18,7 @@ import { FOLLOWS_NOTHING, followModeWords, followStandingLine } from "./follow_w
1818 import { FORK_FOLLOW_MODES, forkFollowMode, lastTookAt, isForkFollowMode, setForkFollowMode, type ForkFollowMode } from "../core/fork_follow.ts";
1919 import { requireUser } from "./access.ts";
2020 import { getFollow, setFollowTaking } from "../core/upstream_follow.ts";
21 import { severUpstream } from "./upstream_follow.ts";
21 import { isChecking, severUpstream } from "./upstream_follow.ts";
2222 import { takeFromParent, type Taken } from "../spawn/take.ts";
2323 import { takeUpdates, type ForkSync, type TakeUpdatesError } from "./forks.ts";
2424 import { convergeFollowed } from "./upstream_sync.ts";
@@ -148,7 +148,7 @@ export async function followStanding(app: App, repo: Repo, viewer: User | undefi
148148 );
149149 }
150150
151 export type FollowModeError = SeverError | "invalid_mode" | "severed";
151 export type FollowModeError = SeverError | "invalid_mode" | "severed" | "updating";
152152
153153 /** The one answer every door gives a refused mode change, with the status an HTTP door sends. */
154154 export const FOLLOW_MODE_REFUSALS: Record<FollowModeError, { status: number; message: string }> = {
@@ -157,6 +157,7 @@ export const FOLLOW_MODE_REFUSALS: Record<FollowModeError, { status: number; mes
157157 not_following: { status: 404, message: FAMILY_WORDS.not_following },
158158 invalid_mode: { status: 422, message: `mode is one of: ${FORK_FOLLOW_MODES.join(", ")}; a spawned forge takes ${FOLLOW_MODES.join(" or ")} and severs instead of not following` },
159159 severed: { status: 409, message: "this forge is severed and follows nothing; there is no mode to change" },
160 updating: { status: 409, message: "An update from upstream is running here; change how this fork follows when it has finished." },
160161 };
161162
162163 /**
@@ -173,6 +174,7 @@ export async function setFollowMode(
173174 ): Promise<Result<ForkFollowMode, FollowModeError>> {
174175 const who = requireUser(actor);
175176 if (!who.ok) return err("unauthorized");
177 if (canAdmin(app.db, repo, who.value) && canWrite(app.db, repo, who.value) && isChecking(repo.id)) return err("updating");

Unrequested refusal. It can lock an owner out of the mode switch for as long as a check hangs, and it duplicates the permission check that follows. Remove it.

176178 const carries = (await chainOfRepo(app, repo)) !== undefined;
177179 // A repository that is no fork but follows an upstream (an app a spawn sent down) takes the same
178180 // choice.
src/actions/upstream_follow.ts +6
@@ -159,6 +159,12 @@ export function mayCarryCredential(upstreamUrl: string, webUrl: string): boolean
159159 /** Repositories with a check in flight: one at a time each, whoever asked. */
160160 const checking = new Set<string>();
161161
162 /**
163 * Whether an update check of this repository is running now (its upstream's or any other source's).
164 */
165 export const isChecking = (repoId: string): boolean =>

Prefix-matching on the key format leaks the internals of checking. Remove it with the refusal, or have this module own the question.

166 [...checking].some((k) => k === repoId || k.startsWith(`${repoId}:`));
167
162168 /**
163169 * One check, of one repository. The claim is taken before the first await,
164170 * so a double click and the clock never both run: the second is `busy`.
src/http/mcp/tools/follow_mode.ts +1 −1
@@ -5,7 +5,7 @@ import { good, bad, type Tool, REPO_ARG, repoArg, isAnswer } from "../shared.ts"
55
66 export const tool: Tool = {
77 name: "follow_mode",
8 doc: "`{ repo, mode }`: choose how a fork follows its parent: `take-updates`, `tell-me` or `dont-follow` (a spawned forge: the first two; it severs instead); the admin only; answers `{ says, mode, line }`; refused `unauthorized`, `forbidden`, `not_following`, `invalid_mode` or `severed`",
8 doc: "`{ repo, mode }`: choose how a fork follows its parent: `take-updates`, `tell-me` or `dont-follow` (a spawned forge: the first two; it severs instead); the admin only; answers `{ says, mode, line }`; refused `unauthorized`, `forbidden`, `not_following`, `invalid_mode`, `severed` or `updating` (an update is running)",
99 description:
1010 "How a fork follows its parent: take updates, tell me, or don't follow.",
1111 inputSchema: {
test/follow-mode-updating.test.ts added +46
@@ -0,0 +1,46 @@
1 /**
2 * A follow-mode change while an update check is running is refused in a plain sentence (#13443).
3 */
4 import { afterAll, beforeAll, expect, test } from "bun:test";
5 import { mkdtemp, rm } from "node:fs/promises";
6 import { tmpdir } from "node:os";
7 import { join } from "node:path";
8 import { createApp, type App } from "../src/app.ts";
9 import { commitToBranch, createRepo } from "../src/actions/repos.ts";
10 import { FOLLOW_MODE_REFUSALS, setFollowMode } from "../src/actions/follow.ts";
11 import { checkUpstream, setFollowUpstream } from "../src/actions/upstream_follow.ts";
12 import { getRepo } from "../src/core/repos.ts";
13 import { createUser } from "../src/core/users.ts";
14
15 let dir = "";
16 let app: App;
17
18 beforeAll(async () => {
19 dir = await mkdtemp(join(tmpdir(), "forge-follow-busy-"));
20 app = createApp({ dataDir: dir, port: 0 });
21 });
22 afterAll(async () => {
23 app.close();
24 await rm(dir, { recursive: true, force: true });
25 });
26
27 test("while an update is running the mode does not change; after it, it does", async () => {
28 const made = await createUser(app.db, { origin: "seed", trusted: true, username: "alice", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: true });
29 if (!made.ok) throw new Error("user");
30 const owner = made.value;
31 const r = await createRepo(app, owner, { name: "square", visibility: "public" });
32 if (!r.ok) throw new Error("repo");
33 await commitToBranch(app, owner, r.value, { message: "Start", files: [{ path: "README.md", content: "# s\n" }] });
34 const repo = getRepo(app.db, "alice", "square")!;
35 const set = setFollowUpstream(app, owner, repo, { url: "https://example.com/up/stream.git", branch: "main", enabled: true });
36 expect(set.ok).toBe(true);
37
38 const running = checkUpstream(app, repo);
39 const refused = await setFollowMode(app, owner, repo, "take-updates");
40 expect(refused).toEqual({ ok: false, error: "updating" });
41 expect(FOLLOW_MODE_REFUSALS.updating.message).toContain("update from upstream is running");
42 await running;
43
44 const done = await setFollowMode(app, owner, repo, "take-updates");
45 expect(done.ok).toBe(true);
46 }, 60_000);

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs