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

Every way to create a repository or app defaults to private, and one test names each way #15705

Merged opened this

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

Merged

mason/forge:mason/15681-every-way-to-create-a-repository-or-app → main 0 commits fork

  • Merged. mason/15681-every-way-to-create-a-repository-or-app was merged into main as e5fb3e6.

Review

Sign in to review this change.
69 files changed +563 −126
docs/features/visibility-line.md +11 −3
@@ -5,9 +5,17 @@ row: Who can see it, in one line
55 # Who can see it, in one line
66
77 Every repository starts private: a new repository, a new app and its
8 repository, a fork of a private repository (whatever the fork asks for) and the
9 preview of a private app's pull. Each surface then says who can see it in the
10 same words, all read from `audienceFor` in `src/core/audience.ts`:
8 repository, a copy from a template, a migration, a person's fork of any
9 repository (`forkBornAs` in `src/actions/repos.ts`; the terminal's fork screen
10 says so before it forks), a spawned forge's fresh app and its copy of an app
11 the spawner does not own (its own code is no more public than the parent's),
12 and the preview of a private app's pull. Nothing is public until its owner
13 makes it so. A few doors are public by choice: the start call's app, a guest's
14 contribution fork, a crew member's working fork of a public repository, a
15 mirror of a public source, and a spawner's own public app.
16 `test/private-by-default.test.ts` lists every door named for making something,
17 and fails on a new one that is not listed. Each surface then says who can see
18 it in the same words, all read from `audienceFor` in `src/core/audience.ts`:
1119
1220 ```json
1321 "audience": { "level": "private", "who": "owner", "sentence": "Private: only you and the crew." }
src/actions/repos.ts +15
@@ -204,6 +204,20 @@ const doorPayload = (actorId: string): Record<string, string> => {
204204
205205 export { FORKS_PER_DAY };
206206
207 /**
208 * The visibility a fork is born with when none is asked for (#15681): a
209 * person's fork is theirs alone until they make it public, since a public
210 * parent's visibility is not a choice they made. Two are public by choice: a
211 * guest's contribution fork (help offered on a public repository, `GUESTS`),
212 * and a crew member's fork, the working copy behind a pull on the parent, read
213 * as the parent is. A private parent's fork is private whatever this says.
214 */
215 export function forkBornAs(app: App, user: User, parent: Repo): "public" | "private" {
216 if (parent.visibility === "private") return "private";
217 if (user.kind === "agent") return parent.visibility;
218 return requireAbility(app, user, "make_it_yours").ok ? "private" : "public";
219 }
220
207221 export async function forkRepo(
208222 app: App,
209223 actor: User | undefined,
@@ -243,6 +257,7 @@ export async function forkRepo(
243257 }
244258 : {
245259 ...options,
260 visibility: options.visibility ?? forkBornAs(app, user.value, parent),
246261 ...(user.value.kind === "agent" || user.value.isAdmin ? {} : { perDay: FORKS_PER_DAY }),
247262 },
248263 );
src/actions/spawn.ts +4 −1
@@ -35,6 +35,7 @@ import {
3535 createRepo,
3636 getRepo,
3737 isGo,
38 ownsRepo,
3839 updateRepoSettings,
3940 type Repo,
4041 } from "../core/repos.ts";
@@ -600,7 +601,9 @@ async function copyInto(
600601 const made = await createRepo(child.db, child.reposRoot, {
601602 ownerId: org.id,
602603 name: n,
603 visibility: parent.visibility,
604 // Public in the child only by its admin's choice: the spawner's own public app
605 // stays public, a copy of someone else's starts private (#15681).
606 visibility: ownsRepo(app.db, parent, owner) ? parent.visibility : "private",
604607 description: parent.description,
605608 defaultBranch: parent.defaultBranch,
606609 });
src/core/repos.ts +11
@@ -1494,6 +1494,17 @@ export function canAdmin(
14941494 return accessAllows(orgAccessFor(db, repo, user), "admin");
14951495 }
14961496
1497 /**
1498 * Whether the repository is the user's own: theirs, or an organization's they
1499 * administer. Unlike `canAdmin`, a site admin owns only what is theirs, so
1500 * what they may manage is not what they chose (#15681).
1501 */
1502 export function ownsRepo(db: Database, repo: Repo, user: User | undefined): boolean {
1503 if (user === undefined) return false;
1504 // Read as a member: `orgAccess` lets a site admin administer every organization.
1505 return user.id === repo.ownerId || accessAllows(orgAccessFor(db, repo, { ...user, isAdmin: false }), "admin");
1506 }
1507
14971508 /** Who answers the decisions a repository asks of its owner. */
14981509 export const DECISIONS_BY = ["me", "decider", "decider_tell"] as const;
14991510 export type DecisionsBy = (typeof DECISIONS_BY)[number];
src/spawn/forge_code.ts +2 −2
@@ -71,8 +71,8 @@ export async function forkForgeCode(
7171 const made = await createRepo(child.db, child.reposRoot, {
7272 ownerId: org.id,
7373 name: FORGE_CODE_NAME,
74 // A template's code is no more public in the child than it is here.
75 visibility: template === undefined ? "public" : parent.visibility,
74 // The forge's code, or a template's, is no more public in the child than it is here.
75 visibility: parent.visibility,
7676 description:
7777 template === undefined
7878 ? `A fork of ${o}/${n}: the forge's own code, following its parent.`
src/tui/screens/newrepo.ts +15 −1
@@ -5,7 +5,7 @@
55
66 import { GUEST_REFUSALS, isGuestRefusal } from "../../core/contribute.ts";
77 import { storageLimitMessage } from "../../core/storage.ts";
8 import { createRepo, forkRepo, repositoryLimitMessage, resolveOwner } from "../../actions/repos.ts";
8 import { createRepo, forkBornAs, forkRepo, repositoryLimitMessage, resolveOwner } from "../../actions/repos.ts";
99 import { listOrgsForUser } from "../../core/orgs.ts";
1010 import type { Repo } from "../../core/repos.ts";
1111 import type { Ctx, Screen } from "../app/app.ts";
@@ -155,6 +155,12 @@ export function newRepoScreen(f: Session, ctx: Ctx, owner?: string): Screen {
155155 };
156156 }
157157
158 /** Who will read the fork, said before it is made (#15681). */
159 export const forkSeenBy = (born: "public" | "private"): string =>
160 born === "private"
161 ? "Private: only you can read it, until you make it public."
162 : "Public: anyone who can read the parent can read it.";
163
158164 export function forkScreen(f: Session, ctx: Ctx, parent: Repo): Screen {
159165 let name = parent.name;
160166 let error: string | undefined;
@@ -208,6 +214,14 @@ export function forkScreen(f: Session, ctx: Ctx, parent: Repo): Screen {
208214 : { error }),
209215 },
210216 );
217 if (f.user !== undefined)
218 s.text(
219 area.x,
220 area.y + 6,
221 truncate(forkSeenBy(forkBornAs(f.app, f.user, parent)), area.w),
222 style(c.mutedFg, c.bg),
223 area.x + area.w,
224 );
211225 ctx.setCursor(cursor);
212226 },
213227 key(e) {
test/app-forks-card.test.ts +2 −2
@@ -53,7 +53,7 @@ describe("an app's forks", () => {
5353 }
5454 servers = await serve(app);
5555 for (const [who, at] of [["bob", "2026-01-01T00:00:00.000Z"], ["carol", "2026-03-01T00:00:00.000Z"], ["dan", "2026-02-01T00:00:00.000Z"]] as const) {
56 const forked = await forkRepo(app, users[who]!, lib);
56 const forked = await forkRepo(app, users[who]!, lib, undefined, { visibility: "public" });
5757 if (!forked.ok) throw new Error(String(forked.error));
5858 app.db.query("UPDATE repo SET created_at = ?1 WHERE id = ?2").run(at, forked.value.id);
5959 if (who === "dan") {
@@ -144,7 +144,7 @@ describe("an app's forks", () => {
144144 });
145145 if (!made.ok) throw new Error(made.error);
146146 promote(app.db, made.value);
147 const forked = await forkRepo(app, made.value, lib);
147 const forked = await forkRepo(app, made.value, lib, undefined, { visibility: "public" });
148148 if (!forked.ok) throw new Error(String(forked.error));
149149 }
150150 const { total, shown } = forksOfApp(app.db, lib, undefined);
test/atom-feeds.test.ts +1 −1
@@ -174,7 +174,7 @@ describe("forks.atom", () => {
174174 if (!r.ok) throw new Error(String(r.error));
175175 if (name === "lonely") continue;
176176 await commitToBranch(app, alice, r.value, { message: "seed", files: [{ path: "README.md", content: "hi\n" }] });
177 const open = await forkRepo(app, bob, r.value, "openfork");
177 const open = await forkRepo(app, bob, r.value, "openfork", { visibility: "public" });
178178 if (!open.ok) throw new Error(String(open.error));
179179 const priv = await forkRepo(app, carol, r.value, "hiddenfork", { visibility: "private" });
180180 if (!priv.ok) throw new Error(String(priv.error));
test/boundary-fork-objects.test.ts +1 −1
@@ -199,7 +199,7 @@ async function pair(
199199 });
200200 if (!made.ok) throw new Error(String(made.error));
201201 const shared = await land(alice, made.value, "main", "README.md");
202 const forked = await forkRepo(app, bob, made.value);
202 const forked = await forkRepo(app, bob, made.value, undefined, { visibility: "public" });
203203 if (!forked.ok) throw new Error(String(forked.error));
204204 return { parent: made.value, fork: forked.value, shared };
205205 }
test/contribute-refusals.test.ts +8 −4
@@ -84,15 +84,19 @@ describe("contribute refusals", () => {
8484 const count = (sql: string): number =>
8585 app.db.query<{ n: number }, []>(sql).get()?.n ?? -1;
8686
87 /** The fork's branches at the origin, read as its owner: a fork starts private. */
88 const forkBranches = (): Promise<Response> =>
89 fetch(`${originServers.url}/api/v1/repos/${ME}/gears/branches`, {
90 headers: { authorization: `Bearer ${originToken}` },
91 });
92
8793 /** Everything a half-made contribution would have left behind. */
8894 const world = async () => ({
8995 fakeRepos: fake.state.repos.map((r) => r.fullName).sort(),
9096 fakeBranches: [...fake.state.branches.entries()],
9197 fakeCommits: [...fake.state.commits.entries()],
9298 fakeWrites: fake.state.requests.filter((r) => r.method !== "GET").length,
93 forkBranches: await (
94 await fetch(`${originServers.url}/api/v1/repos/${ME}/gears/branches`)
95 ).text(),
99 forkBranches: await (await forkBranches()).text(),
96100 repos: count("SELECT COUNT(*) AS n FROM repo"),
97101 pulls: count("SELECT COUNT(*) AS n FROM pull"),
98102 });
@@ -252,7 +256,7 @@ describe("contribute refusals", () => {
252256
253257 // The commit is not a claim: it is on the fork at the origin.
254258 const branches = await read<{ items: { name: string; oid: string }[] }>(
255 await fetch(`${originServers.url}/api/v1/repos/${ME}/gears/branches`),
259 await forkBranches(),
256260 );
257261 expect(branches.items.find((b) => b.name === "fix-typo")?.oid).toBe(
258262 failed.commit.commitOid,
test/crew-direction.test.ts +1 −1
@@ -469,7 +469,7 @@ describe("every other door that queues a run", () => {
469469 });
470470
471471 test("a reader cannot converge a fork, in the action, over HTTP or over MCP", async () => {
472 const forked = await forkRepo(app, alice, fresh(), "square-fork");
472 const forked = await forkRepo(app, alice, fresh(), "square-fork", { visibility: "public" });
473473 if (!forked.ok) throw new Error(String(forked.error));
474474 expect(
475475 (await convergeFork(app, forked.value, fresh(), mallory)).kind,
test/explore-first-view.test.ts +1 −1
@@ -38,7 +38,7 @@ beforeAll(async () => {
3838 }
3939 const parent = (await import("../src/core/repos.ts")).getRepo(app.db, "alice", "app-0");
4040 if (parent === undefined) throw new Error("no app-0");
41 const forked = await forkRepo(app, made.value, parent, "app-0-copy");
41 const forked = await forkRepo(app, made.value, parent, "app-0-copy", { visibility: "public" });
4242 if (!forked.ok) throw new Error(String(forked.error));
4343 html = await (await fetch(`${servers.url}/explore?kind=app`)).text();
4444 const page = await explorePage(app, undefined, { kind: "app", sort: "score", text: "", archived: false, updated: "all" }, null);
test/family-api.test.ts +3 −3
@@ -50,9 +50,9 @@ beforeAll(async () => {
5050 adminToken = createToken(app.db, users["alice"]!.id, "admin", "admin").token;
5151 bobToken = createToken(app.db, users["bob"]!.id, "bob", "ro").token;
5252 const upstream = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" }));
53 const bob = must(await forkRepo(app, users["bob"]!, upstream));
54 const dan = must(await forkRepo(app, users["dan"]!, bob));
55 must(await forkRepo(app, users["gus"]!, dan));
53 const bob = must(await forkRepo(app, users["bob"]!, upstream, undefined, { visibility: "public" }));
54 const dan = must(await forkRepo(app, users["dan"]!, bob, undefined, { visibility: "public" }));
55 must(await forkRepo(app, users["gus"]!, dan, undefined, { visibility: "public" }));
5656 must(await forkRepo(app, users["fay"]!, upstream, "secret", { visibility: "private" }));
5757 }, 60_000);
5858
test/feeds.test.ts +1 −1
@@ -66,7 +66,7 @@ describe("a repository's feed", () => {
6666 title: 'the "boss" <level> is too hard & long',
6767 });
6868 if (!issue.ok) throw new Error(String(issue.error));
69 const forked = await forkRepo(app, bob, made.value);
69 const forked = await forkRepo(app, bob, made.value, undefined, { visibility: "public" });
7070 if (!forked.ok) throw new Error(String(forked.error));
7171 const hook = createWebhook(app, alice, made.value, {
7272 url: "https://hooks.example.test/T0/s3cr3t",
test/following-card.test.ts +1 −1
@@ -48,7 +48,7 @@ beforeAll(async () => {
4848 });
4949 if (!bob.ok) throw new Error(bob.error);
5050 promote(app.db, bob.value);
51 const forked = await forkRepo(app, bob.value, lib.value);
51 const forked = await forkRepo(app, bob.value, lib.value, undefined, { visibility: "public" });
5252 if (!forked.ok) throw new Error(String(forked.error));
5353 }, 60_000);
5454
test/following-etag.test.ts +1 −1
@@ -70,7 +70,7 @@ beforeAll(async () => {
7070 if (!up.ok) throw new Error("repo");
7171 upstream = up.value;
7272 await commit(alice, upstream, "one.txt");
73 const fork = await forkRepo(app, bob, upstream);
73 const fork = await forkRepo(app, bob, upstream, undefined, { visibility: "public" });
7474 if (!fork.ok) throw new Error(JSON.stringify(fork.error));
7575 await Bun.write(
7676 join(dataDir, "parent.json"),
test/following-proposals-etag.test.ts +1 −1
@@ -61,7 +61,7 @@ beforeAll(async () => {
6161 if (!up.ok) throw new Error("repo");
6262 const solo = await createRepo(app, alice, { name: "solo", visibility: "private" });
6363 if (!solo.ok) throw new Error("repo");
64 const fork = await forkRepo(app, b, up.value);
64 const fork = await forkRepo(app, b, up.value, undefined, { visibility: "public" });
6565 if (!fork.ok) throw new Error(JSON.stringify(fork.error));
6666 bobId = fork.value.id;
6767 await Bun.write(
test/following.test.ts +7 −7
@@ -114,7 +114,7 @@ describe("a fork that follows its parent", () => {
114114 parent = made.value;
115115 const seeded = await commit(alice, parent, "README.md", "# game\n");
116116 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
117 const forked = await forkRepo(app, bob, parent);
117 const forked = await forkRepo(app, bob, parent, undefined, { visibility: "public" });
118118 if (!forked.ok) throw new Error(String(forked.error));
119119 fork = forked.value;
120120 }, 30_000);
@@ -434,7 +434,7 @@ describe("a fork that follows its parent", () => {
434434 });
435435 if (!c.ok) throw new Error(c.error);
436436 promote(app.db, c.value);
437 const forked = await forkRepo(app, c.value, fresh(parent), "game-carol");
437 const forked = await forkRepo(app, c.value, fresh(parent), "game-carol", { visibility: "public" });
438438 if (!forked.ok) throw new Error(String(forked.error));
439439 const carols = forked.value;
440440 expect(addToCrew(app, c.value, carols, "bot").ok).toBe(true);
@@ -473,7 +473,7 @@ describe("a fork that follows its parent", () => {
473473 });
474474 if (!d.ok) throw new Error(d.error);
475475 promote(app.db, d.value);
476 const forked = await forkRepo(app, d.value, fresh(parent), "game-dan");
476 const forked = await forkRepo(app, d.value, fresh(parent), "game-dan", { visibility: "public" });
477477 if (!forked.ok) throw new Error(String(forked.error));
478478 const dans = forked.value;
479479 app.db
@@ -703,7 +703,7 @@ describe("a fork that follows its parent", () => {
703703 });
704704 if (!f.ok) throw new Error(f.error);
705705 promote(app.db, f.value);
706 const grand = await forkRepo(app, f.value, fresh(fork), "game-fay");
706 const grand = await forkRepo(app, f.value, fresh(fork), "game-fay", { visibility: "public" });
707707 if (!grand.ok) throw new Error(String(grand.error));
708708
709709 const tree = await lineageOf(app, fresh(fork), () => true);
@@ -835,7 +835,7 @@ describe("a fork that follows its parent", () => {
835835 app.db.query("UPDATE repo SET landing = 'merge' WHERE id = ?").run(made.value.id);
836836 const lamp = getRepoById(app.db, made.value.id)!;
837837 await commit(alice, lamp, "README.md", "# lamp\n");
838 const forked = await forkRepo(app, bob, lamp);
838 const forked = await forkRepo(app, bob, lamp, undefined, { visibility: "public" });
839839 if (!forked.ok) throw new Error(String(forked.error));
840840 const mine = forked.value;
841841 const land = async (title: string, file: string): Promise<void> => {
@@ -958,8 +958,8 @@ describe("a landed pull moves the forks, like the push it amounts to", () => {
958958 ],
959959 });
960960 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
961 const one = await forkRepo(app, bob, parent);
962 const two = await forkRepo(app, carol, parent);
961 const one = await forkRepo(app, bob, parent, undefined, { visibility: "public" });
962 const two = await forkRepo(app, carol, parent, undefined, { visibility: "public" });
963963 if (!one.ok || !two.ok) throw new Error("fork");
964964 untouched = one.value;
965965 worked = two.value;
test/fork-chain.test.ts +4 −4
@@ -61,8 +61,8 @@ beforeAll(async () => {
6161 }
6262 a = must(await createRepo(app, users["ann"]!, { name: "app", visibility: "public" }));
6363 await commit("ann", a, "one.txt");
64 b = must(await forkRepo(app, users["ben"]!, a));
65 c = must(await forkRepo(app, users["cy"]!, b));
64 b = must(await forkRepo(app, users["ben"]!, a, undefined, { visibility: "public" }));
65 c = must(await forkRepo(app, users["cy"]!, b, undefined, { visibility: "public" }));
6666 }, 60_000);
6767
6868 afterAll(async () => {
@@ -93,8 +93,8 @@ describe("a private middle", () => {
9393 beforeAll(async () => {
9494 top = must(await createRepo(app, users["ann"]!, { name: "pub", visibility: "public" }));
9595 await commit("ann", top, "x.txt");
96 mid = must(await forkRepo(app, users["ben"]!, top, "pub"));
97 grand = must(await forkRepo(app, users["cy"]!, mid, "pub"));
96 mid = must(await forkRepo(app, users["ben"]!, top, "pub", { visibility: "public" }));
97 grand = must(await forkRepo(app, users["cy"]!, mid, "pub", { visibility: "public" }));
9898 // The middle goes private after the grandchild forked it.
9999 must(await updateRepoSettings(app, users["ben"]!, mid, { visibility: "private" }));
100100 });
test/fork-children.test.ts +3 −3
@@ -55,13 +55,13 @@ describe("a repository's direct forks", () => {
5555 many = await withCode("many");
5656 bare = await mk("bare");
5757 servers = await serve(app);
58 const bob = await forkRepo(app, users["bob"]!, tree);
59 const carol = await forkRepo(app, users["carol"]!, tree);
58 const bob = await forkRepo(app, users["bob"]!, tree, undefined, { visibility: "public" });
59 const carol = await forkRepo(app, users["carol"]!, tree, undefined, { visibility: "public" });
6060 if (!bob.ok || !carol.ok) throw new Error("fork failed");
6161 const closed = await updateRepoSettings(app, users["carol"]!, carol.value, { visibility: "private" });
6262 if (!closed.ok) throw new Error(String(closed.error));
6363 // A grandchild is not a direct fork of `tree`.
64 const grand = await forkRepo(app, users["dan"]!, bob.value);
64 const grand = await forkRepo(app, users["dan"]!, bob.value, undefined, { visibility: "public" });
6565 if (!grand.ok) throw new Error(String(grand.error));
6666 for (let i = 0; i < FORKS_SHOWN_ON_CODE + 2; i++) {
6767 app.db.query(
test/fork-counts.test.ts +1 −1
@@ -142,7 +142,7 @@ describe("fork counts hold only the forks the viewer may read", () => {
142142 const alice = (await import("../src/core/users.ts")).getUserByName(app.db, "alice")!;
143143 let parent = lib;
144144 for (let depth = 1; depth <= 6; depth++) {
145 const next = await forkRepo(app, alice, parent, `deep${depth}`);
145 const next = await forkRepo(app, alice, parent, `deep${depth}`, { visibility: "public" });
146146 if (!next.ok) throw new Error(String(next.error));
147147 parent = next.value;
148148 }
test/fork-flow-journey.test.ts +1 −1
@@ -72,7 +72,7 @@ beforeAll(async () => {
7272 bobToken = createToken(app.db, bob.id, "t", "admin").token;
7373 lib = must(await createRepo(app, alice, { name: "lib", visibility: "public" }));
7474 must(await commitToBranch(app, alice, lib, { branch: "main", message: "Start", files: [{ path: "README.md", content: "hi\n" }] }));
75 fork = must(await forkRepo(app, bob, lib));
75 fork = must(await forkRepo(app, bob, lib, undefined, { visibility: "public" }));
7676 }, 60_000);
7777
7878 afterAll(async () => {
test/fork-flow.test.ts +9 −4
@@ -1,3 +1,4 @@
1 import { getRepo, updateRepoSettings } from "../src/core/repos.ts";
12 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23 import { mkdtemp, rm, writeFile } from "node:fs/promises";
34 import { tmpdir } from "node:os";
@@ -381,14 +382,15 @@ describe("the fork flow", () => {
381382 expect(result.pull?.local).toBeNull();
382383
383384 // The branch really landed on the fork's git, at the commit we made.
384 const branches = await (await read<{ items: { name: string; oid: string }[] }>(await fetch(`${originServers.url}/api/v1/repos/${ORIGIN_LOGIN}/gears/branches`))).items;
385 const branches = await (await read<{ items: { name: string; oid: string }[] }>(await upstream(`/api/v1/repos/${ORIGIN_LOGIN}/gears/branches`, { as: ORIGIN_LOGIN }))).items;
385386 const landed = branches.find((b) => b.name === "fix-typo");
386387 expect(landed?.oid).toBe(result.commit.commitOid);
387388
388389 // …and it started from the CURRENT upstream main, not from the fork's
389390 // copy of it: the file the upstream added after the fork is in the tree.
390 const moved = await fetch(
391 `${originServers.url}/api/v1/repos/${ORIGIN_LOGIN}/gears/contents/moved.txt?ref=fix-typo`,
391 const moved = await upstream(
392 `/api/v1/repos/${ORIGIN_LOGIN}/gears/contents/moved.txt?ref=fix-typo`,
393 { as: ORIGIN_LOGIN },
392394 );
393395 expect(moved.status).toBe(200);
394396
@@ -488,7 +490,7 @@ describe("the fork flow", () => {
488490 }>(response);
489491 expect(result.via).toBe("fork");
490492
491 const branches = await (await read<{ items: { name: string; oid: string }[] }>(await fetch(`${originServers.url}/api/v1/repos/${ORIGIN_LOGIN}/widgets/branches`))).items;
493 const branches = await (await read<{ items: { name: string; oid: string }[] }>(await upstream(`/api/v1/repos/${ORIGIN_LOGIN}/widgets/branches`, { as: ORIGIN_LOGIN }))).items;
492494 expect(branches.find((b) => b.name === "gh-fix")?.oid).toBe(
493495 result.commit.commitOid,
494496 );
@@ -722,6 +724,9 @@ describe("the fork flow", () => {
722724 origin: unknown;
723725 }>(forked);
724726 expect(fork.origin).toBeNull();
727 // A fork is its owner's alone until they make it public (#15681): Bob
728 // makes his public so Alice, who sends the pull, may read its branch.
729 updateRepoSettings(app.db, getRepo(app.db, fork.ownerName, fork.name)!, { visibility: "public" });
725730 const committed = await api(
726731 `/api/v1/repos/${fork.ownerName}/${fork.name}/contents`,
727732 {
test/fork-follow-line.test.ts +1 −1
@@ -43,7 +43,7 @@ beforeAll(async () => {
4343 }
4444 const lib = must(await createRepo(app, users["ann"], { name: "lib", visibility: "public" }));
4545 must(await commitToBranch(app, users["ann"], lib, { message: "start", files: [{ path: "a.txt", content: "a\n" }] }));
46 const fork = must(await forkRepo(app, users["bea"], lib));
46 const fork = must(await forkRepo(app, users["bea"], lib, undefined, { visibility: "public" }));
4747 forkId = getRepo(app.db, "bea", "lib")?.id ?? fork.id;
4848 servers = await serve(app);
4949 for (const name of ["bea", "cal"]) {
test/fork-follow-word.test.ts +1 −1
@@ -41,7 +41,7 @@ beforeAll(async () => {
4141 if (!lib.ok) throw new Error(String(lib.error));
4242 const first = await commitToBranch(app, alice.value, lib.value, { message: "Start", files: [{ path: "README.md", content: "# lib\n" }] });
4343 if (!first.ok) throw new Error(JSON.stringify(first.error));
44 const forked = await forkRepo(app, bob.value, lib.value);
44 const forked = await forkRepo(app, bob.value, lib.value, undefined, { visibility: "public" });
4545 if (!forked.ok) throw new Error(String(forked.error));
4646 // The fork's own commit first: a fork with work of its own is diverged, so a parent that moves
4747 // is behind, never fast-forwarded.
test/fork-last-follow.test.ts +2 −2
@@ -80,7 +80,7 @@ test("the words: each outcome says once, a later take of code or no record says
8080 });
8181
8282 test("a fork that never followed says nothing false; each take that took nothing is said once", async () => {
83 const fork = must(await forkRepo(app, bob, fresh(parent), "game-bob"));
83 const fork = must(await forkRepo(app, bob, fresh(parent), "game-bob", { visibility: "public" }));
8484 expect(lastFollow(app.db, fork.id)).toBeNull();
8585 expect(lastFollowSaid(app, fresh(fork))).toBe("");
8686 expect(await standing(fork)).not.toMatch(/followed upstream|Checked|conflict|waiting/);
@@ -128,7 +128,7 @@ test("a fork that never followed says nothing false; each take that took nothing
128128 }, 30_000);
129129
130130 test("the tree says when each fork last took, on the web page and in the terminal", async () => {
131 const fork = must(await forkRepo(app, alice, fresh(parent), "game-alice"));
131 const fork = must(await forkRepo(app, alice, fresh(parent), "game-alice", { visibility: "public" }));
132132 expect(forkTree(app.db, fresh(parent), alice, app)!.nodes.find((n) => n.repo === "alice/game-alice")!.followed).toBe("never followed");
133133 await commit(alice, parent, "t.txt", "t\n");
134134 must(await takeOrTell(app, alice, fresh(fork)));
test/fork-offer-receipt.test.ts +1 −1
@@ -65,7 +65,7 @@ beforeAll(async () => {
6565 const r = await createRepo(app, users[1]!, { name: "yard", visibility: "public" });
6666 if (!r.ok) throw new Error(String(r.error));
6767 await commitToBranch(app, users[1]!, r.value, { message: "first", files: [{ path: "a.txt", content: "a\n" }] });
68 const f = await forkRepo(app, users[2]!, r.value);
68 const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" });
6969 if (!f.ok) throw new Error(String(f.error));
7070 }, 30_000);
7171
test/fork-offer-size.test.ts +1 −1
@@ -53,7 +53,7 @@ describe("fork offer size", () => {
5353 message: "Start", files: [{ path: "README.md", content: "# lib\nold\n" }],
5454 });
5555 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
56 const f = await forkRepo(app, bob, up);
56 const f = await forkRepo(app, bob, up, undefined, { visibility: "public" });
5757 if (!f.ok) throw new Error(String(f.error));
5858 fork = f.value;
5959 });
test/fork-offers-sent.test.ts +1 −1
@@ -58,7 +58,7 @@ describe("sent offers", () => {
5858 message: "Start", files: [{ path: "README.md", content: "# lib\n" }],
5959 });
6060 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
61 const f = await forkRepo(app, bob, up);
61 const f = await forkRepo(app, bob, up, undefined, { visibility: "public" });
6262 if (!f.ok) throw new Error(String(f.error));
6363 fork = f.value;
6464 });
test/fork-offers.test.ts +3 −3
@@ -45,7 +45,7 @@ describe("fork offers", () => {
4545 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
4646 for (const [who, visibility] of [["bob", "public"], ["carol", "private"]] as const) {
4747 const user = users[who]!;
48 const fork = await forkRepo(app, user, lib);
48 const fork = await forkRepo(app, user, lib, undefined, { visibility: "public" });
4949 if (!fork.ok) throw new Error(String(fork.error));
5050 if (visibility === "private") {
5151 const closed = await updateRepoSettings(app, user, fork.value, { visibility });
@@ -103,7 +103,7 @@ describe("fork offers", () => {
103103 message: "Start", files: [{ path: "README.md", content: "# x\n" }],
104104 });
105105 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
106 const fork = await forkRepo(app, users["bob"]!, up.value);
106 const fork = await forkRepo(app, users["bob"]!, up.value, undefined, { visibility: "public" });
107107 if (!fork.ok) throw new Error(String(fork.error));
108108 return { up: up.value, fork: fork.value };
109109 };
@@ -122,7 +122,7 @@ describe("fork offers", () => {
122122
123123 test("a fork of a fork is not listed on the upstream", async () => {
124124 const { up, fork } = await upstreamWithFork("deep");
125 const deeper = await forkRepo(app, users["dave"]!, fork);
125 const deeper = await forkRepo(app, users["dave"]!, fork, undefined, { visibility: "public" });
126126 if (!deeper.ok) throw new Error(String(deeper.error));
127127 await offerFrom(users["bob"]!, up, fork, "direct", "Direct");
128128 // the pull flow refuses a grandchild's head, so point a direct one at it
test/fork-standing-line.test.ts +1 −1
@@ -43,7 +43,7 @@ beforeAll(async () => {
4343 message: "Start", files: [{ path: "README.md", content: "# lib\n" }],
4444 });
4545 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
46 const forked = await forkRepo(app, bob, lib.value);
46 const forked = await forkRepo(app, bob, lib.value, undefined, { visibility: "public" });
4747 if (!forked.ok) throw new Error(String(forked.error));
4848 }, 60_000);
4949
test/fork-tree-chip.test.ts +1 −1
@@ -29,7 +29,7 @@ beforeAll(async () => {
2929 }
3030 const lib = must(await createRepo(app, users["ann"], { name: "lib", visibility: "public" }));
3131 must(await commitToBranch(app, users["ann"], lib, { message: "start", files: [{ path: "a.txt", content: "a\n" }] }));
32 must(await forkRepo(app, users["bea"], lib));
32 must(await forkRepo(app, users["bea"], lib, undefined, { visibility: "public" }));
3333 // The fork must not follow on its own, or it would catch up as the parent moves: `tell-me` still
3434 // fast-forwards a fork with no work of its own, in the background, so the count raced it.
3535 setForkFollowMode(app.db, getRepo(app.db, "bea", "lib")!.id, "dont-follow");
test/fork-tree-follow.test.ts +4 −4
@@ -42,10 +42,10 @@ beforeAll(async () => {
4242 must(setRole(app, ann, "cal", "member"));
4343 top = must(await createRepo(app, ann, { name: "yard", visibility: "public" }));
4444 must(await commitToBranch(app, ann, top, { message: "first", files: [{ path: "a.txt", content: "a\n" }] }));
45 mid = must(await forkRepo(app, bea, top));
45 mid = must(await forkRepo(app, bea, top, undefined, { visibility: "public" }));
4646 // Work of its own, so the parent moving later cannot fast-forward it under the counts.
4747 must(await commitToBranch(app, bea, mid, { message: "own", files: [{ path: "own.txt", content: "o\n" }] }));
48 leaf = must(await forkRepo(app, cal, mid));
48 leaf = must(await forkRepo(app, cal, mid, undefined, { visibility: "public" }));
4949 // mid moves one commit on; leaf, which does not follow, has not taken it.
5050 setForkFollowMode(app.db, leaf.id, "dont-follow");
5151 must(await commitToBranch(app, bea, mid, { message: "more", files: [{ path: "more.txt", content: "m\n" }] }));
@@ -58,7 +58,7 @@ beforeAll(async () => {
5858 // Forked after the last push: level, and following automatically, with nothing to take.
5959 const dan = must(await createUser(app.db, { origin: "seed", trusted: true, username: "dan", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false }));
6060 must(setRole(app, ann, "dan", "member"));
61 twin = must(await forkRepo(app, dan, top));
61 twin = must(await forkRepo(app, dan, top, undefined, { visibility: "public" }));
6262 setForkFollowMode(app.db, twin.id, "take-updates");
6363 }, 60_000);
6464
@@ -79,7 +79,7 @@ test("a count nobody has made is null, not a git walk on the request", async ()
7979 must(await commitToBranch(fresh, u, parent, { message: "first", files: [{ path: "a.txt", content: "a\n" }] }));
8080 const fay = must(await createUser(fresh.db, { origin: "seed", trusted: true, username: "fay", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false }));
8181 must(setRole(fresh, u, "fay", "member"));
82 const child = must(await forkRepo(fresh, fay, parent));
82 const child = must(await forkRepo(fresh, fay, parent, undefined, { visibility: "public" }));
8383 // The parent moves after the fork, so no count exists for this pair of tips.
8484 must(await commitToBranch(fresh, u, parent, { message: "second", files: [{ path: "b.txt", content: "b\n" }] }));
8585 const t = forkTree(fresh.db, parent, u, fresh);
test/fork-tree-here.test.ts +4 −4
@@ -60,14 +60,14 @@ beforeAll(async () => {
6060 for (const n of ["bea", "cal", "eve", "dee"]) must(setRole(app, ann, n, "member"));
6161 const root = must(await createRepo(app, ann, { name: "yard", visibility: "public" }));
6262 must(await commitToBranch(app, ann, root, { message: "first", files: [{ path: "a.txt", content: "a\n" }] }));
63 must(await forkRepo(app, bea, root));
64 must(await forkRepo(app, cal, root));
63 must(await forkRepo(app, bea, root, undefined, { visibility: "public" }));
64 must(await forkRepo(app, cal, root, undefined, { visibility: "public" }));
6565 // A deeper fork: dee forks bea's fork, so dee has no direct fork of yard.
66 must(await forkRepo(app, dee, getRepo(app.db, "bea", "yard")!));
66 must(await forkRepo(app, dee, getRepo(app.db, "bea", "yard")!, undefined, { visibility: "public" }));
6767 // A family with one fork only.
6868 const pond = must(await createRepo(app, ann, { name: "pond", visibility: "public" }));
6969 must(await commitToBranch(app, ann, pond, { message: "first", files: [{ path: "a.txt", content: "a\n" }] }));
70 must(await forkRepo(app, bea, pond));
70 must(await forkRepo(app, bea, pond, undefined, { visibility: "public" }));
7171 }, 60_000);
7272
7373 afterAll(async () => {
test/fork-tree-mode.test.ts +2 −2
@@ -43,7 +43,7 @@ beforeAll(async () => {
4343 for (const [user, mode] of [["bea", "take-updates"], ["cal", "tell-me"], ["dan", "dont-follow"]] as const) {
4444 const u = await mk(user, false);
4545 must(setRole(app, ann, user, "member"));
46 const fork = must(await forkRepo(app, u, root));
46 const fork = must(await forkRepo(app, u, root, undefined, { visibility: "public" }));
4747 setForkFollowMode(app.db, fork.id, mode);
4848 kids.set(mode, fork);
4949 }
@@ -97,7 +97,7 @@ test("a nested fork row says its phrase on the web and in the terminal", async (
9797 const bea = kids.get("take-updates")!;
9898 const eve = must(await createUser(app.db, { origin: "seed", trusted: true, username: "eve", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false }));
9999 must(setRole(app, ann, "eve", "member"));
100 const deep = must(await forkRepo(app, eve, bea));
100 const deep = must(await forkRepo(app, eve, bea, undefined, { visibility: "public" }));
101101 setForkFollowMode(app.db, deep.id, "tell-me");
102102 const html = await (await fetch(`${servers.url}/ann/yard/forks`)).text();
103103 const at = html.indexOf(`href="/${name(deep)}"`);
test/fork-tree-reader.test.ts +4 −4
@@ -42,9 +42,9 @@ beforeAll(async () => {
4242 promote(app.db, users[name]!);
4343 }
4444 forge = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" }));
45 org = must(await forkRepo(app, users["bob"]!, forge));
46 must(await forkRepo(app, users["carol"]!, forge));
47 person = must(await forkRepo(app, users["dan"]!, org));
45 org = must(await forkRepo(app, users["bob"]!, forge, undefined, { visibility: "public" }));
46 must(await forkRepo(app, users["carol"]!, forge, undefined, { visibility: "public" }));
47 person = must(await forkRepo(app, users["dan"]!, org, undefined, { visibility: "public" }));
4848 hidden = must(await forkRepo(app, users["erin"]!, org, "secret", { visibility: "private" }));
4949 must(await forkRepo(app, users["erin"]!, hidden, "under", { visibility: "public" }));
5050 setForkFollowMode(app.db, person.id, "take-updates");
@@ -108,7 +108,7 @@ describe("forkTree", () => {
108108 await createUser(app.db, { origin: "seed", trusted: true, username: `deep${i}`, email: `deep${i}@f.dev`, password: "a-good-passphrase" }),
109109 );
110110 promote(app.db, u);
111 at = must(await forkRepo(app, u, at));
111 at = must(await forkRepo(app, u, at, undefined, { visibility: "public" }));
112112 }
113113 const t = forkTree(app.db, at, users["alice"]!, app, { depth: 1 })!;
114114 const me = t.nodes.find((n) => n.repo === "deep4/app")!;
test/fork-tree-web.test.ts +2 −2
@@ -86,8 +86,8 @@ beforeAll(async () => {
8686 files: [{ path: "a.txt", content: "a\n" }],
8787 }),
8888 );
89 middle = must(await forkRepo(app, bea, original));
90 must(await forkRepo(app, cal, middle));
89 middle = must(await forkRepo(app, bea, original, undefined, { visibility: "public" }));
90 must(await forkRepo(app, cal, middle, undefined, { visibility: "public" }));
9191 }, 60_000);
9292
9393 afterAll(async () => {
test/fork-tree-words.test.ts +1 −1
@@ -37,7 +37,7 @@ beforeAll(async () => {
3737 for (const [user, mode] of [["bea", "take-updates"], ["cal", "tell-me"], ["dan", "dont-follow"]] as const) {
3838 const u = await mk(user, false);
3939 must(setRole(app, ann, user, "member"));
40 setForkFollowMode(app.db, must(await forkRepo(app, u, root)).id, mode);
40 setForkFollowMode(app.db, must(await forkRepo(app, u, root, undefined, { visibility: "public" })).id, mode);
4141 }
4242 }, 60_000);
4343
test/fork-tree.test.ts +4 −4
@@ -42,10 +42,10 @@ describe("the forks page draws the tree", () => {
4242 promote(app.db, users[name]!);
4343 }
4444 const upstream = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" }));
45 const bob = must(await forkRepo(app, users["bob"]!, upstream));
46 must(await forkRepo(app, users["carol"]!, upstream));
47 const dan = must(await forkRepo(app, users["dan"]!, bob));
48 must(await forkRepo(app, users["erin"]!, dan));
45 const bob = must(await forkRepo(app, users["bob"]!, upstream, undefined, { visibility: "public" }));
46 must(await forkRepo(app, users["carol"]!, upstream, undefined, { visibility: "public" }));
47 const dan = must(await forkRepo(app, users["dan"]!, bob, undefined, { visibility: "public" }));
48 must(await forkRepo(app, users["erin"]!, dan, undefined, { visibility: "public" }));
4949 must(await forkRepo(app, users["fay"]!, dan, "secret", { visibility: "private" }));
5050 }, 60_000);
5151
test/forks-api-drift.test.ts +2 −2
@@ -36,7 +36,7 @@ test("a fork one commit ahead reads ahead 1, behind 0, with the parent named", a
3636 const made = await createRepo(app, alice, { name: "app", visibility: "public" });
3737 if (!made.ok) throw new Error("repo");
3838 await commitToBranch(app, alice, made.value, { message: "one", files: [{ path: "a.txt", content: "x\n" }] });
39 const fork = await forkRepo(app, bob, made.value);
39 const fork = await forkRepo(app, bob, made.value, undefined, { visibility: "public" });
4040 if (!fork.ok) throw new Error("fork");
4141 await commitToBranch(app, bob, fork.value, { message: "two", files: [{ path: "b.txt", content: "y\n" }] });
4242 const res = await fetch(`${servers.url}/api/v1/repos/alice/app/forks`);
@@ -71,7 +71,7 @@ test("drift is read for the page being answered, not for every fork", async () =
7171 if (!made.ok) throw new Error("repo");
7272 await commitToBranch(app, carol, made.value, { message: "one", files: [{ path: "a.txt", content: "x\n" }] });
7373 for (const [who, n] of [[dan, 1], [erin, 2]] as const) {
74 const f = await forkRepo(app, who, made.value);
74 const f = await forkRepo(app, who, made.value, undefined, { visibility: "public" });
7575 if (!f.ok) throw new Error("fork");
7676 for (let i = 0; i < n; i++)
7777 await commitToBranch(app, who, f.value, { message: `m${i}`, files: [{ path: `f${i}.txt`, content: "y\n" }] });
test/forks-etag.test.ts +3 −3
@@ -45,7 +45,7 @@ beforeAll(async () => {
4545 if (!made.ok) throw new Error("repo");
4646 parent = made.value;
4747 await commitToBranch(app, alice, parent, { message: "one", files: [{ path: "a.txt", content: "x\n" }] });
48 const f = await forkRepo(app, bob, parent);
48 const f = await forkRepo(app, bob, parent, undefined, { visibility: "public" });
4949 if (!f.ok) throw new Error("fork");
5050 bobFork = f.value;
5151 });
@@ -77,7 +77,7 @@ test("a fork pushed, a fork made, the parent moving and a fork deleted each chan
7777 let tag = await tagOf();
7878 await commitToBranch(app, bob, bobFork, { message: "two", files: [{ path: "b.txt", content: "y\n" }] });
7979 tag = await changed(tag, "fork pushed");
80 const c = await forkRepo(app, carol, parent);
80 const c = await forkRepo(app, carol, parent, undefined, { visibility: "public" });
8181 if (!c.ok) throw new Error("fork");
8282 tag = await changed(tag, "fork made");
8383 await commitToBranch(app, alice, parent, { message: "three", files: [{ path: "c.txt", content: "z\n" }] });
@@ -88,7 +88,7 @@ test("a fork pushed, a fork made, the parent moving and a fork deleted each chan
8888 });
8989
9090 test("limit and cursor make different tags", async () => {
91 const d = await forkRepo(app, alice, parent, "mine");
91 const d = await forkRepo(app, alice, parent, "mine", { visibility: "public" });
9292 expect(d.ok).toBe(true);
9393 const all = await tagOf();
9494 const one = await tagOf("?limit=1");
test/forks-lineage-timing.test.ts +2 −2
@@ -29,7 +29,7 @@ beforeAll(async () => {
2929 let parent = must(await createRepo(app, admin.value, { name: "r0", visibility: "public", description: "" }));
3030 chain = [parent];
3131 for (let i = 1; i < 4; i++) {
32 parent = must(await forkRepo(app, admin.value, parent, `r${i}`));
32 parent = must(await forkRepo(app, admin.value, parent, `r${i}`, { visibility: "public" }));
3333 chain.push(parent);
3434 }
3535 for (let i = 0; i < 30; i++) {
@@ -37,7 +37,7 @@ beforeAll(async () => {
3737 await createUser(app.db, { origin: "seed", trusted: true, username: `u${i}`, email: `u${i}@f.dev`, password: "a-good-passphrase" }),
3838 );
3939 promote(app.db, who);
40 must(await forkRepo(app, who, chain[2]!, `leaf${i}`));
40 must(await forkRepo(app, who, chain[2]!, `leaf${i}`, { visibility: "public" }));
4141 }
4242 });
4343
test/forks-ranking.test.ts +4 −4
@@ -79,10 +79,10 @@ describe("the forks page ranks", () => {
7979 );
8080 };
8181 await commit("alice", upstream, 1);
82 const bob = must(await forkRepo(app, users["bob"]!, upstream));
83 const carol = must(await forkRepo(app, users["carol"]!, upstream));
84 const dan = must(await forkRepo(app, users["dan"]!, upstream));
85 const erin = must(await forkRepo(app, users["erin"]!, upstream));
82 const bob = must(await forkRepo(app, users["bob"]!, upstream, undefined, { visibility: "public" }));
83 const carol = must(await forkRepo(app, users["carol"]!, upstream, undefined, { visibility: "public" }));
84 const dan = must(await forkRepo(app, users["dan"]!, upstream, undefined, { visibility: "public" }));
85 const erin = must(await forkRepo(app, users["erin"]!, upstream, undefined, { visibility: "public" }));
8686 await commit("bob", bob, 1);
8787 await commit("carol", carol, 2);
8888 await commit("dan", dan, 3);
test/forks-tree-api.test.ts +3 −3
@@ -42,12 +42,12 @@ test("a three-deep tree nests, a private fork hides itself and what is under it,
4242 let parent = root.value;
4343 const chain = [parent];
4444 for (const u of users.slice(1, 4)) {
45 const f = await forkRepo(app, u, parent);
45 const f = await forkRepo(app, u, parent, undefined, { visibility: "public" });
4646 if (!f.ok) throw new Error("fork");
4747 parent = f.value;
4848 chain.push(parent);
4949 }
50 const side = await forkRepo(app, users[4]!, root.value);
50 const side = await forkRepo(app, users[4]!, root.value, undefined, { visibility: "public" });
5151 if (!side.ok) throw new Error("fork");
5252
5353 const tree = await get("u0/app");
@@ -80,7 +80,7 @@ test("a three-deep tree nests, a private fork hides itself and what is under it,
8080
8181 // Extend to seven generations: u3 → u5 → u6 → u7. Depth 5 lists u1..u5's generation, then cuts.
8282 for (const u of users.slice(5)) {
83 const f = await forkRepo(app, u, parent);
83 const f = await forkRepo(app, u, parent, undefined, { visibility: "public" });
8484 if (!f.ok) throw new Error("fork");
8585 parent = f.value;
8686 }
test/forks.test.ts +1 −1
@@ -56,7 +56,7 @@ describe("forks", () => {
5656 return r.value;
5757 };
5858 const forkAs = async (who: string, parent: Repo, name?: string) =>
59 must(await forkRepo(app, users[who]!, parent, name));
59 must(await forkRepo(app, users[who]!, parent, name, { visibility: "public" }));
6060 const commitAs = async (who: string, repo: Repo, file: string, message: string) =>
6161 must(
6262 await commitToBranch(app, users[who]!, repo, {
test/here-manifest.test.ts +2 −2
@@ -207,7 +207,7 @@ describe("the manifest: what you can do here, as who you are", () => {
207207 });
208208
209209 test("a writer of a fork is offered how it follows its parent; a reader and a plain repository's writer are not", async () => {
210 const fork = await forkRepo(app, usersByName["wes"]!, getRepo(app.db, "acme", "game")!);
210 const fork = await forkRepo(app, usersByName["wes"]!, getRepo(app.db, "acme", "game")!, undefined, { visibility: "public" });
211211 if (!fork.ok) throw new Error(String(fork.error));
212212 const path = "/wes/game";
213213 const moves = [
@@ -519,7 +519,7 @@ describe("the manifest: what you can do here, as who you are", () => {
519519 test("a pull page says whether the pull's code runs, or waits for a writer's approval", async () => {
520520 const game = getRepo(app.db, "acme", "game")!;
521521 const carol = usersByName["carol"]!;
522 const forked = await forkRepo(app, carol, game);
522 const forked = await forkRepo(app, carol, game, undefined, { visibility: "public" });
523523 if (!forked.ok) throw new Error(String(forked.error));
524524 const committed = await commitToBranch(app, carol, forked.value, {
525525 branch: "idea",
test/iterations-etag.test.ts +2 −2
@@ -60,7 +60,7 @@ beforeAll(async () => {
6060 if (!made.ok) throw new Error("repo");
6161 parent = made.value;
6262 await pin(parent, alice, "v1", await commit(parent, alice, "one"));
63 const f = await forkRepo(app, bob, parent);
63 const f = await forkRepo(app, bob, parent, undefined, { visibility: "public" });
6464 if (!f.ok) throw new Error("fork");
6565 bobFork = f.value;
6666 await pin(bobFork, bob, "b1", await commit(bobFork, bob, "bob one"), { parent: "alice/app:v1" });
@@ -106,7 +106,7 @@ test("a fork pushed, the parent pushed, a fork made and a fork deleted each chan
106106 tag = await changed(tag, "fork pushed");
107107 await commit(parent, alice, "side parent", "wip");
108108 tag = await changed(tag, "parent pushed");
109 const c = await forkRepo(app, carol, parent);
109 const c = await forkRepo(app, carol, parent, undefined, { visibility: "public" });
110110 if (!c.ok) throw new Error("fork");
111111 tag = await changed(tag, "fork made");
112112 expect((await deleteRepo(app, carol, c.value)).ok).toBe(true);
test/iterations.test.ts +1 −1
@@ -123,7 +123,7 @@ describe("iterations page", () => {
123123 await pin(game(), alice, "v1", one, { note: "first <b>playable</b>" });
124124 await pin(game(), alice, "v2", two, { parent: "v1" });
125125 await pin(game(), alice, "side", two, { parent: "v1" });
126 const forked = await forkRepo(app, bob, game(), "game");
126 const forked = await forkRepo(app, bob, game(), "game", { visibility: "public" });
127127 if (!forked.ok) throw new Error(String(forked.error));
128128 const mine = getRepo(app.db, "bob", "game")!;
129129 await pin(mine, bob, "b1", await commit(mine, bob, "bob one"), { parent: "alice/game:v2" });
test/list-pages.test.ts +2 −2
@@ -51,9 +51,9 @@ describe("forks, labels and webhooks are pages", () => {
5151 files: [{ path: "README.md", content: "# lib\n" }],
5252 });
5353 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
54 const bobs = await forkRepo(app, users["bob"]!, lib);
54 const bobs = await forkRepo(app, users["bob"]!, lib, undefined, { visibility: "public" });
5555 if (!bobs.ok) throw new Error(String(bobs.error));
56 const carols = await forkRepo(app, users["carol"]!, lib);
56 const carols = await forkRepo(app, users["carol"]!, lib, undefined, { visibility: "public" });
5757 if (!carols.ok) throw new Error(String(carols.error));
5858 const closed = await updateRepoSettings(app, users["carol"]!, carols.value, { visibility: "private" });
5959 if (!closed.ok) throw new Error(String(closed.error));
test/llms-forks.test.ts +1 −1
@@ -38,7 +38,7 @@ test("one line with the visible forks counted; a fork of a hidden root stands al
3838 await make(sam, "tools");
3939 const fork = async (who: typeof alice, from: string) => {
4040 const [o, n] = from.split("/");
41 const r = await forkRepo(app, who, getRepo(app.db, o!, n!)!);
41 const r = await forkRepo(app, who, getRepo(app.db, o!, n!)!, undefined, { visibility: "public" });
4242 if (!r.ok) throw new Error(JSON.stringify(r));
4343 return r.value;
4444 };
test/mcp-forge-reads.test.ts +1 −1
@@ -212,7 +212,7 @@ describe("the forge over MCP: reads", () => {
212212 message: "seed",
213213 files: [{ path: "README.md", content: "# open\n" }],
214214 });
215 const forked = await forkRepo(app, bob, pub.value);
215 const forked = await forkRepo(app, bob, pub.value, undefined, { visibility: "public" });
216216 if (!forked.ok) throw new Error(String(forked.error));
217217 const fresh = (r: Repo) => getRepoById(app.db, r.id)!;
218218
test/mcp-forks-card.test.ts +2 −2
@@ -46,8 +46,8 @@ describe("MCP fork_tree card", () => {
4646 token = createToken(app.db, users["alice"]!.id, "admin", "admin").token;
4747 bobToken = createToken(app.db, users["bob"]!.id, "bob", "ro").token;
4848 const upstream = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" }));
49 const bob = must(await forkRepo(app, users["bob"]!, upstream));
50 must(await forkRepo(app, users["dan"]!, bob));
49 const bob = must(await forkRepo(app, users["bob"]!, upstream, undefined, { visibility: "public" }));
50 must(await forkRepo(app, users["dan"]!, bob, undefined, { visibility: "public" }));
5151 // A private fork alice cannot read (only its owner reads it).
5252 must(await forkRepo(app, users["fay"]!, upstream, "secret", { visibility: "private" }));
5353 }, 60_000);
test/mcp-forks-chain.test.ts +5 −5
@@ -53,17 +53,17 @@ beforeAll(async () => {
5353 aliceToken = createToken(app.db, alice.id, "t", "admin").token;
5454 carolToken = createToken(app.db, carol.id, "t", "admin").token;
5555 const root = must(await createRepo(app, alice, { name: "lib", visibility: "public" }));
56 const mid = must(await forkRepo(app, alice, root, "lib-mid"));
57 const leaf = must(await forkRepo(app, alice, mid, "lib-leaf"));
58 must(await forkRepo(app, alice, leaf, "lib-tip"));
56 const mid = must(await forkRepo(app, alice, root, "lib-mid", { visibility: "public" }));
57 const leaf = must(await forkRepo(app, alice, mid, "lib-leaf", { visibility: "public" }));
58 must(await forkRepo(app, alice, leaf, "lib-tip", { visibility: "public" }));
5959 const secret = must(await forkRepo(app, bob, leaf, "lib-secret"));
6060 app.db.run("UPDATE repo SET visibility = 'private' WHERE id = ?1", [secret.id]);
6161 await setFollowMode(app, alice, leaf, "take-updates");
6262 // A fork cut loose the way detach does it.
63 const cut = must(await forkRepo(app, bob, root, "lib-cut"));
63 const cut = must(await forkRepo(app, bob, root, "lib-cut", { visibility: "public" }));
6464 clearForkParent(app.db, cut.id);
6565 app.bus.append({ kind: "repo.detached", repoId: cut.id, actorId: bob.id, payload: { parentId: root.id } });
66 must(await forkRepo(app, alice, cut, "lib-after"));
66 must(await forkRepo(app, alice, cut, "lib-after", { visibility: "public" }));
6767 }, 30_000);
6868
6969 afterAll(async () => {
test/mcp-tree.test.ts +2 −2
@@ -54,8 +54,8 @@ beforeAll(async () => {
5454 aliceToken = createToken(app.db, alice.id, "t", "admin").token;
5555 bobToken = createToken(app.db, carol.id, "t", "admin").token;
5656 const root = must(await createRepo(app, alice, { name: "lib", visibility: "public" }));
57 const mid = must(await forkRepo(app, alice, root, "lib-mid"));
58 must(await forkRepo(app, alice, mid, "lib-leaf"));
57 const mid = must(await forkRepo(app, alice, root, "lib-mid", { visibility: "public" }));
58 must(await forkRepo(app, alice, mid, "lib-leaf", { visibility: "public" }));
5959 const secret = must(await forkRepo(app, bob, mid, "lib-secret"));
6060 app.db.run("UPDATE repo SET visibility = 'private' WHERE id = ?1", [secret.id]);
6161 await setFollowMode(app, alice, mid, "take-updates");
test/migrate-trail.test.ts +6
@@ -141,4 +141,10 @@ describe("migrate: trail", () => {
141141 });
142142 expect(getProvenance(app.db, repo.id)?.shown).toBe(true);
143143 });
144
145 test("a migration that asks for no visibility is private, even from a public source (#15681)", async () => {
146 const job = await migrate(alice, { source: { originId, fullName: "octo/arm" }, name: "arm-quiet" });
147 expect(job?.error).toBeUndefined();
148 expect(getRepo(app.db, "alice", "arm-quiet")!.visibility).toBe("private");
149 });
144150 });
test/offer-commit.test.ts +1 −1
@@ -69,7 +69,7 @@ beforeAll(async () => {
6969 const r = await createRepo(app, users[1]!, { name: "yard", visibility: "public" });
7070 if (!r.ok) throw new Error(String(r.error));
7171 await commitToBranch(app, users[1]!, r.value, { message: "first", files: [{ path: "a.txt", content: "a\n" }] });
72 const f = await forkRepo(app, users[2]!, r.value);
72 const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" });
7373 if (!f.ok) throw new Error(String(f.error));
7474 for (const n of ["one", "two", "three"]) {
7575 const c = await commitToBranch(app, users[2]!, forkOf(), {
test/offer-pull.test.ts +1 −1
@@ -69,7 +69,7 @@ beforeAll(async () => {
6969 const r = await createRepo(app, owner, { name: "yard", visibility: "public" });
7070 if (!r.ok) throw new Error(String(r.error));
7171 await commitToBranch(app, owner, r.value, { message: "first", files: [{ path: "a.txt", content: "a\n" }] });
72 const f = await forkRepo(app, ravi, r.value);
72 const f = await forkRepo(app, ravi, r.value, undefined, { visibility: "public" });
7373 if (!f.ok) throw new Error(String(f.error));
7474 fork = getRepo(app.db, "ravi", "yard")!;
7575 merged = await shipIn(fork, ravi, "feat", "Adds a feature, for everyone.", true);
test/offer-upstream.test.ts +1 −1
@@ -70,7 +70,7 @@ beforeAll(async () => {
7070 message: "first",
7171 files: [{ path: "a.txt", content: "a\n" }],
7272 });
73 const f = await forkRepo(app, users[2]!, r.value);
73 const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" });
7474 if (!f.ok) throw new Error(String(f.error));
7575 });
7676
test/parity.test.ts +3 −1
@@ -14,7 +14,7 @@ import { join } from "node:path";
1414 import { createApp, type App } from "../src/app.ts";
1515 import { listEvents } from "../src/core/events.ts";
1616 import { createSession, pruneSessions } from "../src/core/sessions.ts";
17 import { getRepo } from "../src/core/repos.ts";
17 import { getRepo, updateRepoSettings } from "../src/core/repos.ts";
1818 import { serve, type Servers } from "../src/http/server.ts";
1919 import { gitClientEnv } from "./helpers/git-client.ts";
2020 import { proveAll } from "./helpers/verified.ts";
@@ -682,6 +682,8 @@ describe("parity: full control through actions and the API", () => {
682682 body: {},
683683 });
684684 expect(fork.status).toBe(201);
685 // A fork is its owner's alone until they make it public (#15681).
686 updateRepoSettings(app.db, getRepo(app.db, "bob", "pub")!, { visibility: "public" });
685687 await call("POST", "/api/v1/repos/bob/pub/contents", {
686688 token: bobRw,
687689 body: {
test/private-by-default.test.ts added +367
@@ -0,0 +1,367 @@
1 /**
2 * Every way to make a repository makes it private (#15681): nobody but its
3 * owner and members reads it until the owner makes it public. Each door is
4 * walked here as a person walks it (the web form, the API, the MCP tool, the
5 * terminal, a spawn), and a stranger and another member are refused it.
6 *
7 * `DOORS` names every route and MCP tool whose name says it makes something
8 * (`new`, `create`, `fork`, `spawn`, `start`, `claim`, `mirror`, `migrate`,
9 * `import`, `copy`, `template`, `repos`, `apps`, `forges`), read from the live
10 * route tables and the tool list, and says what it is: walked here, made
11 * private and proven in a named test file, public by an explicit choice (with
12 * why), or no repository at all. A new door with such a name fails the first
13 * test until it is listed, so it is never public by default unnoticed.
14 */
15 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
16 import { existsSync, readFileSync } from "node:fs";
17 import { mkdtemp, rm } from "node:fs/promises";
18 import { tmpdir } from "node:os";
19 import { join } from "node:path";
20 import { createApp, type App } from "../src/app.ts";
21 import { commitToBranch, createRepo, forkBornAs, updateRepoSettings } from "../src/actions/repos.ts";
22 import { getRepo } from "../src/core/repos.ts";
23 import { createSession } from "../src/core/sessions.ts";
24 import { createToken } from "../src/core/tokens.ts";
25 import { createUser, type User } from "../src/core/users.ts";
26 import { TOOLS } from "../src/http/mcp/tools.ts";
27 import { buildApiRouter, buildRouter, serve, type Servers } from "../src/http/server.ts";
28 import { ok } from "../src/kernel/result.ts";
29 import { FORGE_CODE_NAME } from "../src/spawn/forge_code.ts";
30 import { usePlacement, useProbe } from "../src/spawn/door.ts";
31 import { forkSeenBy } from "../src/tui/screens/newrepo.ts";
32 import { quietLogs } from "./helpers/globals.ts";
33 import { mcpTool } from "./helpers/mcp.ts";
34 import { promote } from "./helpers/members.ts";
35 import { proveAll } from "./helpers/verified.ts";
36
37 quietLogs();
38
39 type Door =
40 /** Walked in this file: the test named `walked` makes a repository through it. */
41 | { readonly walked: string }
42 /** Made private, proven in that test file, which holds `says`. */
43 | { readonly proven: string; readonly says: string }
44 /** Public on purpose: why, and the test file that holds it. */
45 | { readonly publicByChoice: string; readonly proven: string; readonly says: string }
46 /** Makes no repository. */
47 | { readonly noRepository: string };
48
49 const WEB = "the web form";
50 const API = "the API";
51 const MCP = "the MCP tool";
52 const FORK = "a fork";
53 const SPAWN = "a spawn";
54 const TEMPLATE = "a template";
55
56 /** Every creation door, by `METHOD pattern` or MCP `tool` / `tool action`. Sorted. */
57 const DOORS: Readonly<Record<string, Door>> = {
58 "POST /:owner/:name/forge": { walked: SPAWN },
59 "POST /:owner/:name/fork": { walked: FORK },
60 "POST /:owner/:name/issues/new": { noRepository: "an issue" },
61 "POST /:owner/:name/make-it-yours": { proven: "test/make-it-yours.test.ts", says: 'getRepo(app.db, "frank", "garden")!.visibility).toBe("private")' },
62 "POST /:owner/:name/pulls/new": { noRepository: "a pull" },
63 "POST /admin/agent-start": { noRepository: "the setting that opens the start call" },
64 "POST /api/v1/admin/app-templates": { noRepository: "marks a repository a template; its copies are walked as a template" },
65 "POST /api/v1/apps": { walked: API },
66 "POST /api/v1/forges": { walked: SPAWN },
67 "POST /api/v1/migrate": { proven: "test/migrate-trail.test.ts", says: "a migration that asks for no visibility is private" },
68 "POST /api/v1/repos": { walked: API },
69 "POST /api/v1/repos/:owner/:name/app/domains/:host/claim": { noRepository: "a domain" },
70 "POST /api/v1/repos/:owner/:name/data-import": { noRepository: "an app's data" },
71 "POST /api/v1/repos/:owner/:name/forks": { walked: FORK },
72 "POST /api/v1/repos/:owner/:name/make-it-yours": { proven: "test/make-it-yours.test.ts", says: 'made.value.made.repo.visibility).toBe("private")' },
73 "POST /api/v1/runner/claim": { noRepository: "a check job" },
74 "POST /api/v1/start": {
75 publicByChoice: "the start call shows an agent's app under its name (#10912, actions/start.ts): public is what it is for",
76 proven: "test/start.test.ts",
77 says: 'expect(repo.visibility).toBe("public")',
78 },
79 "POST /api/v1/user/origin-apps": { noRepository: "an OAuth app for connecting origins" },
80 "POST /api/v1/user/origins/:id/fork": { noRepository: "a fork at the origin, not here" },
81 "POST /api/v1/user/origins/:id/mirror": {
82 publicByChoice: "a mirror follows its source's own visibility; a private or read-only source's mirror is private (#10520)",
83 proven: "test/origins.test.ts",
84 says: 'expect(repo.visibility).toBe("public")',
85 },
86 "POST /apps/new": { walked: WEB },
87 "POST /boards/new": { noRepository: "a board, a file in the forge's own private boards repository" },
88 "POST /claim": { noRepository: "takes a spawned forge's founder account" },
89 "POST /claim/start/:token": {
90 publicByChoice: "takes a start call's account; its app stays as public as the start made it",
91 proven: "test/start.test.ts",
92 says: 'expect(repo.visibility).toBe("public")',
93 },
94 "POST /forges/new": { walked: SPAWN },
95 "POST /forges/start": { walked: SPAWN },
96 "POST /migrate": { proven: "test/migrate-trail.test.ts", says: "a migration that asks for no visibility is private" },
97 "POST /new": { walked: WEB },
98 "POST /organizations/new": { noRepository: "an organization" },
99 "POST /origins/:id/r/:owner/:name/fork": { noRepository: "a fork at the origin, not here" },
100 "POST /origins/:id/r/:owner/:name/mirror": {
101 publicByChoice: "a mirror follows its source's own visibility; a private or read-only source's mirror is private (#10520)",
102 proven: "test/origins.test.ts",
103 says: 'expect(repo.visibility).toBe("public")',
104 },
105 "POST /packs/:name/repos": { noRepository: "the list of a pack's repositories" },
106 "POST /packs/mirror": {
107 publicByChoice: "a read-only mirror of an open-source pack's upstream, which is public where it lives",
108 proven: "test/packs-mirror.test.ts",
109 says: 'expect(repo.visibility).toBe("public")',
110 },
111 "POST /packs/new": { noRepository: "a pack, a list of repositories" },
112 "POST /settings/app-templates": { noRepository: "marks a repository a template; its copies are walked as a template" },
113 "POST /settings/backups/mirror": { noRepository: "the snapshot mirror's destination" },
114 "POST /settings/origins/:id/mirror": {
115 publicByChoice: "a mirror follows its source's own visibility; a private or read-only source's mirror is private (#10520)",
116 proven: "test/origins.test.ts",
117 says: 'expect(repo.visibility).toBe("public")',
118 },
119 "POST /settings/origins/apps": { noRepository: "an OAuth app for connecting origins" },
120 "POST /talk/new": { noRepository: "a conversation" },
121 "mcp app_data_import": { noRepository: "an app's data" },
122 "mcp branches create": { noRepository: "a branch" },
123 "mcp claim_link": { noRepository: "a spawned forge's claim link" },
124 "mcp fork": { walked: FORK },
125 "mcp fork_tree": { noRepository: "reads the fork tree" },
126 "mcp forks": { noRepository: "reads the forks" },
127 "mcp make_it_yours": { proven: "test/make-it-yours.test.ts", says: 'plan.value.visibility).toBe("private")' },
128 "mcp migrate": { proven: "test/migrate-trail.test.ts", says: "a migration that asks for no visibility is private" },
129 "mcp migrate_data": { noRepository: "an app's data" },
130 "mcp mirror_now": { noRepository: "a snapshot to the mirror" },
131 "mcp mirror_set": { noRepository: "the snapshot mirror's destination" },
132 "mcp new_app": { walked: MCP },
133 "mcp org_create": { noRepository: "an organization" },
134 "mcp org_teams create": { noRepository: "a team" },
135 "mcp restore_drill start": { noRepository: "a restore drill" },
136 "mcp say new": { noRepository: "a conversation" },
137 "mcp spawn": { walked: SPAWN },
138 "mcp templates": { noRepository: "lists the templates" },
139 };
140
141 const ROUTE_VERB = /(?:^|-)(new|create|fork|forks|spawn|start|claim|mirror|migrate|yours|forge|forges|repos|apps|import|template|templates|copy)$/;
142 const TOOL_VERB = /(?:^|_)(new|create|fork|forks|spawn|start|claim|mirror|migrate|yours|import|template|templates|copy)(?:_|$)/;
143 const lastLiteral = (pattern: string) =>
144 pattern.split("/").filter((s) => s !== "" && !s.startsWith(":") && !s.startsWith("*")).pop() ?? "";
145
146 /** The doors the routers and the MCP tool list name with a making verb. */
147 function scanned(): string[] {
148 const found = new Set<string>();
149 for (const r of [...buildRouter().routes(), ...buildApiRouter().routes()])
150 if ((r.method === "POST" || r.method === "PUT") && ROUTE_VERB.test(lastLiteral(r.pattern)))
151 found.add(`${r.method} ${r.pattern}`);
152 for (const tool of TOOLS) {
153 if (TOOL_VERB.test(tool.name)) found.add(`mcp ${tool.name}`);
154 const props = (tool.inputSchema as { properties?: Record<string, { enum?: unknown[] }> }).properties ?? {};
155 for (const a of [...(props["action"]?.enum ?? []), ...(props["kind"]?.enum ?? [])])
156 if (typeof a === "string" && TOOL_VERB.test(a)) found.add(`mcp ${tool.name} ${a}`);
157 }
158 return [...found].sort();
159 }
160
161 const walkedHere = new Set<string>();
162
163 describe("every door that makes a repository is listed", () => {
164 test("each route and MCP tool named for making something is in DOORS, and DOORS names nothing else", () => {
165 const seen = scanned();
166 const listed = Object.keys(DOORS);
167 expect(seen.filter((k) => !listed.includes(k)), "a new door: add it to DOORS, walked here or proven private elsewhere").toEqual([]);
168 expect(listed.filter((k) => !seen.includes(k)), "no such door any more: delete its line").toEqual([]);
169 expect(listed).toEqual([...listed].sort());
170 });
171
172 test("a door proven elsewhere, or public by choice, is held by the test file it names", () => {
173 for (const [door, d] of Object.entries(DOORS)) {
174 if (!("proven" in d)) continue;
175 expect(existsSync(d.proven), `${door}: ${d.proven} is gone`).toBe(true);
176 expect(readFileSync(d.proven, "utf8"), `${door}: ${d.proven} no longer holds ${d.says}`).toContain(d.says);
177 }
178 });
179 });
180
181 describe("each door yields a repository only its owner and members read", () => {
182 let dir = "";
183 let app: App;
184 let servers: Servers;
185 let base = "";
186 let placed = 0;
187 const cells = process.env["FORGE_CELLS"];
188 const users: Record<string, User> = {};
189 const tokens: Record<string, string> = {};
190 const cookies: Record<string, string> = {};
191
192 /**
193 * Nobody but the owner reads it: a stranger's page and another member's API call are both 404.
194 */
195 const sealed = async (owner: string, name: string, outsider: string) => {
196 expect(getRepo(app.db, owner, name)?.visibility, `${owner}/${name}`).toBe("private");
197 const page = await fetch(`${base}/${owner}/${name}`);
198 await page.body?.cancel();
199 expect(page.status, `a stranger reads ${owner}/${name}`).toBe(404);
200 const api = await fetch(`${base}/api/v1/repos/${owner}/${name}`, { headers: { authorization: `Bearer ${tokens[outsider]}` } });
201 await api.body?.cancel();
202 expect(api.status, `${outsider} reads ${owner}/${name}`).toBe(404);
203 const mine = await fetch(`${base}/api/v1/repos/${owner}/${name}`, { headers: { authorization: `Bearer ${tokens[owner]}` } });
204 await mine.body?.cancel();
205 expect(mine.status, `${owner} reads their own ${name}`).toBe(200);
206 };
207
208 const form = (who: string, path: string, fields: Record<string, string>) =>
209 fetch(`${base}${path}`, {
210 method: "POST",
211 redirect: "manual",
212 headers: { cookie: cookies[who]!, origin: new URL(base).origin },
213 body: new URLSearchParams(fields),
214 });
215 const post = (who: string, path: string, body: unknown) =>
216 fetch(`${base}${path}`, {
217 method: "POST",
218 headers: { authorization: `Bearer ${tokens[who]}`, "content-type": "application/json" },
219 body: JSON.stringify(body),
220 });
221
222 beforeAll(async () => {
223 process.env["FORGE_CELLS"] = "off";
224 dir = await mkdtemp(join(tmpdir(), "forge-private-default-"));
225 app = createApp({ dataDir: dir, port: 0, forgeRepo: "alice/forge-code" });
226 for (const name of ["alice", "bob", "carol", "dave", "erin"]) {
227 const made = await createUser(app.db, {
228 origin: "seed",
229 trusted: true,
230 username: name,
231 email: `${name}@x.test`,
232 password: "a-good-passphrase",
233 adminIfFirst: name === "alice",
234 });
235 if (!made.ok) throw new Error(made.error);
236 users[name] = made.value;
237 tokens[name] = createToken(app.db, made.value.id, "rw", "rw").token;
238 cookies[name] = `forge_session=${createSession(app.db, made.value.id).token}`;
239 }
240 proveAll(app);
241 promote(app.db);
242 servers = await serve(app);
243 base = servers.url;
244 useProbe(app, () => async () => true);
245 usePlacement(app, {
246 place: async () => ok({ url: `https://kid${placed + 1}.fake.test`, bodyId: `fake-${++placed}` }),
247 retire: async () => ok(),
248 });
249 const alice = users["alice"]!;
250 const bob = users["bob"]!;
251 // Public by their owners' choice: what the forks and the spawn copy.
252 for (const [who, name, visibility] of [
253 [alice, "lib", "public"],
254 [alice, "kit", "public"],
255 [alice, "forge-code", "private"],
256 [bob, "tools", "public"],
257 ] as const) {
258 const made = await createRepo(app, who, { name, visibility });
259 if (!made.ok) throw new Error(`${name}: ${made.error}`);
260 await commitToBranch(app, who, made.value, {
261 message: "seed",
262 files: [{ path: "README.md", content: `${name}\n` }, { path: "forge.json", content: '{"app":{"run":"bun main.ts"}}' }],
263 });
264 }
265 const kit = await updateRepoSettings(app, alice, getRepo(app.db, "alice", "kit")!, { template: true });
266 if (!kit.ok) throw new Error("template");
267 }, 60_000);
268
269 afterAll(async () => {
270 servers?.stop();
271 app?.close();
272 await rm(dir, { recursive: true, force: true });
273 if (cells === undefined) delete process.env["FORGE_CELLS"];
274 else process.env["FORGE_CELLS"] = cells;
275 });
276
277 test(WEB, async () => {
278 walkedHere.add(WEB);
279 const repo = await form("alice", "/new", { name: "by-form" });
280 await repo.body?.cancel();
281 expect(repo.status).toBe(303);
282 await sealed("alice", "by-form", "bob");
283 const made = await form("alice", "/apps/new", { name: "app-by-form" });
284 await made.body?.cancel();
285 expect(made.status).toBe(303);
286 await sealed("alice", "app-by-form", "bob");
287 });
288
289 test(API, async () => {
290 walkedHere.add(API);
291 expect((await post("alice", "/api/v1/repos", { name: "by-api" })).status).toBe(201);
292 await sealed("alice", "by-api", "bob");
293 expect((await post("alice", "/api/v1/apps", { name: "app-by-api" })).status).toBe(201);
294 await sealed("alice", "app-by-api", "bob");
295 });
296
297 test(MCP, async () => {
298 walkedHere.add(MCP);
299 const made = await mcpTool(base, tokens["alice"]!, "new_app", { name: "app-by-mcp" });
300 expect(made.error).toBeUndefined();
301 await sealed("alice", "app-by-mcp", "bob");
302 });
303
304 test(TEMPLATE, async () => {
305 walkedHere.add(TEMPLATE);
306 const res = await post("bob", "/api/v1/apps", { name: "from-kit", template: "alice/kit" });
307 expect(res.status).toBe(201);
308 await sealed("bob", "from-kit", "erin");
309 });
310
311 test(FORK, async () => {
312 walkedHere.add(FORK);
313 // A public parent's fork, at each door: the web button, the API, the MCP tool.
314 const web = await form("bob", "/alice/lib/fork", {});
315 await web.body?.cancel();
316 expect(web.status).toBe(303);
317 await sealed("bob", "lib", "erin");
318 expect((await post("carol", "/api/v1/repos/alice/lib/forks", {})).status).toBe(201);
319 await sealed("carol", "lib", "erin");
320 expect((await mcpTool(base, tokens["dave"]!, "fork", { repo: "alice/lib" })).error).toBeUndefined();
321 await sealed("dave", "lib", "erin");
322 // The terminal's fork screen goes through the same action, and says so first.
323 expect(forkBornAs(app, users["erin"]!, getRepo(app.db, "alice", "lib")!)).toBe("private");
324 expect(forkSeenBy("private")).toContain("only you");
325 // Until the owner makes it public; then a stranger reads it.
326 const fork = getRepo(app.db, "bob", "lib")!;
327 expect((await updateRepoSettings(app, users["bob"]!, fork, { visibility: "public" })).ok).toBe(true);
328 const page = await fetch(`${base}/bob/lib`);
329 await page.body?.cancel();
330 expect(page.status).toBe(200);
331 });
332
333 test(SPAWN, async () => {
334 walkedHere.add(SPAWN);
335 const res = await post("alice", "/api/v1/forges", {
336 name: "kid",
337 apps: ["alice/lib", "bob/tools"],
338 fresh: "A booking page",
339 dryRun: false,
340 });
341 expect(res.status, await res.clone().text()).toBe(201);
342 const child = createApp({ dataDir: join(dir, "children", `fake-${placed}`) });
343 try {
344 const repos = child.db
345 .query<{ name: string; visibility: string }, []>("SELECT name, visibility FROM repo ORDER BY name")
346 .all();
347 const of = (name: string) => repos.find((r) => r.name === name)?.visibility;
348 // The forge's own code is no more public in the child than it is here.
349 expect(of(FORGE_CODE_NAME)).toBe("private");
350 // Someone else's app starts private in the spawner's new forge.
351 expect(of("tools")).toBe("private");
352 // The fresh app is new: private.
353 const fresh = repos.filter((r) => !["lib", "tools", FORGE_CODE_NAME].includes(r.name));
354 expect(fresh.length).toBeGreaterThan(0);
355 for (const r of fresh) expect(r.visibility, r.name).toBe("private");
356 // Public by choice: the spawner's own public app, sent as they made it.
357 expect(of("lib")).toBe("public");
358 } finally {
359 child.close();
360 }
361 });
362
363 test("every door DOORS says is walked here was walked", () => {
364 const named = new Set(Object.values(DOORS).flatMap((d) => ("walked" in d ? [d.walked] : [])));
365 expect([...named].filter((w) => !walkedHere.has(w)).sort()).toEqual([]);
366 });
367 });
test/repo-fork-bar.test.ts +1 −1
@@ -64,7 +64,7 @@ beforeAll(async () => {
6464 message: "first",
6565 files: [{ path: "a.txt", content: "a\n" }],
6666 });
67 const f = await forkRepo(app, users[2]!, r.value);
67 const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" });
6868 if (!f.ok) throw new Error(String(f.error));
6969 });
7070
test/repo-head-quiet.test.ts +1 −1
@@ -73,7 +73,7 @@ const asViewer = async (who: "owner" | "peer" | "guest", path: string): Promise<
7373 test("the palette holds the head's links and no others, for the owner, a reader and a guest, on a repository with forks, an app with an API, and the terminal on", async () => {
7474 const plain = f.repos[6]!; // public
7575 const appRepo = f.repos[3]!; // public, made an app below
76 const forked = await forkRepo(f.app, f.peer, plain);
76 const forked = await forkRepo(f.app, f.peer, plain, undefined, { visibility: "public" });
7777 expect(forked.ok).toBe(true);
7878 const made = createApp(f.app.db, { repoId: appRepo.id, slug: "three", access: "public" });
7979 if (!made.ok) throw new Error(made.error);
test/standing-live.test.ts +1 −1
@@ -45,7 +45,7 @@ beforeAll(async () => {
4545 message: "Start", files: [{ path: "README.md", content: "# lib\n" }],
4646 });
4747 if (!seeded.ok) throw new Error(JSON.stringify(seeded.error));
48 const forked = await forkRepo(app, bob, lib.value);
48 const forked = await forkRepo(app, bob, lib.value, undefined, { visibility: "public" });
4949 if (!forked.ok) throw new Error(String(forked.error));
5050 }, 60_000);
5151
test/suspended-hidden.test.ts +3 −1
@@ -8,7 +8,7 @@ import { commitToBranch, createRepo } from "../src/actions/repos.ts";
88 import { resolveAppHostname } from "../src/apps/proxy.ts";
99 import { setFront } from "../src/actions/front.ts";
1010 import { createApp as createAppRecord } from "../src/core/apps.ts";
11 import { getRepo } from "../src/core/repos.ts";
11 import { getRepo, updateRepoSettings } from "../src/core/repos.ts";
1212 import { createSession } from "../src/core/sessions.ts";
1313 import { createToken } from "../src/core/tokens.ts";
1414 import { createUser, type User } from "../src/core/users.ts";
@@ -135,6 +135,8 @@ describe("a suspended account's repositories leave every list", () => {
135135 });
136136 if (forked.status !== 201 && forked.status !== 202)
137137 throw new Error(`fork: ${forked.status} ${await forked.text()}`);
138 // A fork is its owner's alone until they make it public (#15681).
139 updateRepoSettings(app.db, getRepo(app.db, "sam", "base-mine")!, { visibility: "public" });
138140 // sam's repository has a commit, is an app with a public host, and rita
139141 // has forked it.
140142 const committed = await commitToBranch(app, sam, getRepo(app.db, "sam", "tools")!, {
test/tui-forks-offers.test.ts +2 −2
@@ -66,7 +66,7 @@ describe("the forks screen lists offers from forks", () => {
6666 const lib = must(await createRepo(app, users["alice"]!, { name: "lib", visibility: "public" }));
6767 must(await commitToBranch(app, users["alice"]!, lib, { message: "base", files: [{ path: "a.txt", content: "a\n" }] }));
6868 for (const who of ["bob", "carol"]) {
69 const fork = must(await forkRepo(app, users[who]!, lib));
69 const fork = must(await forkRepo(app, users[who]!, lib, undefined, { visibility: "public" }));
7070 if (who === "carol") must(await updateRepoSettings(app, users[who]!, fork, { visibility: "private" }));
7171 must(await commitToBranch(app, users[who]!, fork, { branch: "f", message: "f", files: [{ path: `${who}.txt`, content: "x\n" }] }));
7272 must(await openPull(app, users[who]!, lib, { title: `From ${who}`, baseBranch: "main", headBranch: "f", headRepo: fork }));
@@ -108,7 +108,7 @@ describe("the forks screen lists the offers a fork sent upstream", () => {
108108 const bob = await mk("bob");
109109 const lib = must(await createRepo(app, alice, { name: "lib", visibility: "public" }));
110110 must(await commitToBranch(app, alice, lib, { message: "base", files: [{ path: "a.txt", content: "a\n" }] }));
111 const fork = must(await forkRepo(app, bob, lib));
111 const fork = must(await forkRepo(app, bob, lib, undefined, { visibility: "public" }));
112112 must(await commitToBranch(app, bob, fork, { branch: "f", message: "f", files: [{ path: "b.txt", content: "x\n" }] }));
113113 must(await openPull(app, bob, lib, { title: "Mine", baseBranch: "main", headBranch: "f", headRepo: fork }));
114114 for (const [branch, title] of [["g", "Took"], ["h", "Refused"]] as const) {
test/tui-forks-take.test.ts +2 −2
@@ -96,8 +96,8 @@ describe("the terminal's forks screen takes the parent's updates with t", () =>
9696 }
9797 upstream = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" }));
9898 must(await commitToBranch(app, users["alice"]!, upstream, { message: "one", files: [{ path: "a.txt", content: "a\n" }] }));
99 must(await forkRepo(app, users["bob"]!, upstream));
100 const dan = must(await forkRepo(app, users["dan"]!, upstream));
99 must(await forkRepo(app, users["bob"]!, upstream, undefined, { visibility: "public" }));
100 const dan = must(await forkRepo(app, users["dan"]!, upstream, undefined, { visibility: "public" }));
101101 must(
102102 await commitToBranch(app, users["dan"]!, dan, {
103103 message: "dan shared",
test/tui-iterations.test.ts +1 −1
@@ -58,7 +58,7 @@ beforeAll(async () => {
5858 const hush = await forkRepo(app, carol, game, "hush", { visibility: "private" });
5959 if (!hush.ok) throw new Error(String(hush.error));
6060 await pin(hush.value, carol, "hidden-pin", await commit(hush.value, carol, "h"), "alice/game:v2");
61 const open = await forkRepo(app, bob, game, "open");
61 const open = await forkRepo(app, bob, game, "open", { visibility: "public" });
6262 if (!open.ok) throw new Error(String(open.error));
6363 await pin(open.value, bob, "shown-pin", await commit(open.value, bob, "o"), "alice/game:v1");
6464 }, 60_000);
test/web-workflows.test.ts +1 −1
@@ -394,7 +394,7 @@ describe("fork at the origin, and propose a change through it", () => {
394394 // The branch really landed on the fork's git.
395395 const branches = (
396396 (await (
397 await fetch(`${upServers.url}/api/v1/repos/me/gears/branches`)
397 await upstream("/api/v1/repos/me/gears/branches", { as: "me" })
398398 ).json()) as { items: { name: string }[] }
399399 ).items;
400400 expect(branches.map((b) => b.name)).toContain("alice/fix-typo");

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs