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
Check · Review · Land · Live done — Landed and live in production.
mason/forge:mason/15681-every-way-to-create-a-repository-or-app → main 0 commits fork
69 files
changed +563
−126
docs/features/visibility-line.md +11 −3
| @@ -5,9 +5,17 @@ row: Who can see it, in one line | ||
| 5 | 5 | # Who can see it, in one line |
| 6 | 6 | |
| 7 | 7 | 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`: | |
| 11 | 19 | |
| 12 | 20 | json |
| 13 | 21 | "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> => { | ||
| 204 | 204 | |
| 205 | 205 | export { FORKS_PER_DAY }; |
| 206 | 206 | |
| 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 | ||
| 207 | 221 | export async function forkRepo( |
| 208 | 222 | app: App, |
| 209 | 223 | actor: User | undefined, |
| @@ -243,6 +257,7 @@ export async function forkRepo( | ||
| 243 | 257 | } |
| 244 | 258 | : { |
| 245 | 259 | ...options, |
| 260 | visibility: options.visibility ?? forkBornAs(app, user.value, parent), | |
| 246 | 261 | ...(user.value.kind === "agent" || user.value.isAdmin ? {} : { perDay: FORKS_PER_DAY }), |
| 247 | 262 | }, |
| 248 | 263 | ); |
src/actions/spawn.ts +4 −1
| @@ -35,6 +35,7 @@ import { | ||
| 35 | 35 | createRepo, |
| 36 | 36 | getRepo, |
| 37 | 37 | isGo, |
| 38 | ownsRepo, | |
| 38 | 39 | updateRepoSettings, |
| 39 | 40 | type Repo, |
| 40 | 41 | } from "../core/repos.ts"; |
| @@ -600,7 +601,9 @@ async function copyInto( | ||
| 600 | 601 | const made = await createRepo(child.db, child.reposRoot, { |
| 601 | 602 | ownerId: org.id, |
| 602 | 603 | 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", | |
| 604 | 607 | description: parent.description, |
| 605 | 608 | defaultBranch: parent.defaultBranch, |
| 606 | 609 | }); |
src/core/repos.ts +11
| @@ -1494,6 +1494,17 @@ export function canAdmin( | ||
| 1494 | 1494 | return accessAllows(orgAccessFor(db, repo, user), "admin"); |
| 1495 | 1495 | } |
| 1496 | 1496 | |
| 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 | ||
| 1497 | 1508 | /** Who answers the decisions a repository asks of its owner. */ |
| 1498 | 1509 | export const DECISIONS_BY = ["me", "decider", "decider_tell"] as const; |
| 1499 | 1510 | export type DecisionsBy = (typeof DECISIONS_BY)[number]; |
src/spawn/forge_code.ts +2 −2
| @@ -71,8 +71,8 @@ export async function forkForgeCode( | ||
| 71 | 71 | const made = await createRepo(child.db, child.reposRoot, { |
| 72 | 72 | ownerId: org.id, |
| 73 | 73 | 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, | |
| 76 | 76 | description: |
| 77 | 77 | template === undefined |
| 78 | 78 | ? `A fork of ${o}/${n}: the forge's own code, following its parent.` |
src/tui/screens/newrepo.ts +15 −1
| @@ -5,7 +5,7 @@ | ||
| 5 | 5 | |
| 6 | 6 | import { GUEST_REFUSALS, isGuestRefusal } from "../../core/contribute.ts"; |
| 7 | 7 | 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"; | |
| 9 | 9 | import { listOrgsForUser } from "../../core/orgs.ts"; |
| 10 | 10 | import type { Repo } from "../../core/repos.ts"; |
| 11 | 11 | import type { Ctx, Screen } from "../app/app.ts"; |
| @@ -155,6 +155,12 @@ export function newRepoScreen(f: Session, ctx: Ctx, owner?: string): Screen { | ||
| 155 | 155 | }; |
| 156 | 156 | } |
| 157 | 157 | |
| 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 | ||
| 158 | 164 | export function forkScreen(f: Session, ctx: Ctx, parent: Repo): Screen { |
| 159 | 165 | let name = parent.name; |
| 160 | 166 | let error: string | undefined; |
| @@ -208,6 +214,14 @@ export function forkScreen(f: Session, ctx: Ctx, parent: Repo): Screen { | ||
| 208 | 214 | : { error }), |
| 209 | 215 | }, |
| 210 | 216 | ); |
| 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 | ); | |
| 211 | 225 | ctx.setCursor(cursor); |
| 212 | 226 | }, |
| 213 | 227 | key(e) { |
test/app-forks-card.test.ts +2 −2
| @@ -53,7 +53,7 @@ describe("an app's forks", () => { | ||
| 53 | 53 | } |
| 54 | 54 | servers = await serve(app); |
| 55 | 55 | 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" }); | |
| 57 | 57 | if (!forked.ok) throw new Error(String(forked.error)); |
| 58 | 58 | app.db.query("UPDATE repo SET created_at = ?1 WHERE id = ?2").run(at, forked.value.id); |
| 59 | 59 | if (who === "dan") { |
| @@ -144,7 +144,7 @@ describe("an app's forks", () => { | ||
| 144 | 144 | }); |
| 145 | 145 | if (!made.ok) throw new Error(made.error); |
| 146 | 146 | 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" }); | |
| 148 | 148 | if (!forked.ok) throw new Error(String(forked.error)); |
| 149 | 149 | } |
| 150 | 150 | const { total, shown } = forksOfApp(app.db, lib, undefined); |
test/atom-feeds.test.ts +1 −1
| @@ -174,7 +174,7 @@ describe("forks.atom", () => { | ||
| 174 | 174 | if (!r.ok) throw new Error(String(r.error)); |
| 175 | 175 | if (name === "lonely") continue; |
| 176 | 176 | 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" }); | |
| 178 | 178 | if (!open.ok) throw new Error(String(open.error)); |
| 179 | 179 | const priv = await forkRepo(app, carol, r.value, "hiddenfork", { visibility: "private" }); |
| 180 | 180 | if (!priv.ok) throw new Error(String(priv.error)); |
test/boundary-fork-objects.test.ts +1 −1
| @@ -199,7 +199,7 @@ async function pair( | ||
| 199 | 199 | }); |
| 200 | 200 | if (!made.ok) throw new Error(String(made.error)); |
| 201 | 201 | 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" }); | |
| 203 | 203 | if (!forked.ok) throw new Error(String(forked.error)); |
| 204 | 204 | return { parent: made.value, fork: forked.value, shared }; |
| 205 | 205 | } |
test/contribute-refusals.test.ts +8 −4
| @@ -84,15 +84,19 @@ describe("contribute refusals", () => { | ||
| 84 | 84 | const count = (sql: string): number => |
| 85 | 85 | app.db.query<{ n: number }, []>(sql).get()?.n ?? -1; |
| 86 | 86 | |
| 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 | ||
| 87 | 93 | /** Everything a half-made contribution would have left behind. */ |
| 88 | 94 | const world = async () => ({ |
| 89 | 95 | fakeRepos: fake.state.repos.map((r) => r.fullName).sort(), |
| 90 | 96 | fakeBranches: [...fake.state.branches.entries()], |
| 91 | 97 | fakeCommits: [...fake.state.commits.entries()], |
| 92 | 98 | 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(), | |
| 96 | 100 | repos: count("SELECT COUNT(*) AS n FROM repo"), |
| 97 | 101 | pulls: count("SELECT COUNT(*) AS n FROM pull"), |
| 98 | 102 | }); |
| @@ -252,7 +256,7 @@ describe("contribute refusals", () => { | ||
| 252 | 256 | |
| 253 | 257 | // The commit is not a claim: it is on the fork at the origin. |
| 254 | 258 | const branches = await read<{ items: { name: string; oid: string }[] }>( |
| 255 | await fetch(`${originServers.url}/api/v1/repos/${ME}/gears/branches`), | |
| 259 | await forkBranches(), | |
| 256 | 260 | ); |
| 257 | 261 | expect(branches.items.find((b) => b.name === "fix-typo")?.oid).toBe( |
| 258 | 262 | failed.commit.commitOid, |
test/crew-direction.test.ts +1 −1
| @@ -469,7 +469,7 @@ describe("every other door that queues a run", () => { | ||
| 469 | 469 | }); |
| 470 | 470 | |
| 471 | 471 | 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" }); | |
| 473 | 473 | if (!forked.ok) throw new Error(String(forked.error)); |
| 474 | 474 | expect( |
| 475 | 475 | (await convergeFork(app, forked.value, fresh(), mallory)).kind, |
test/explore-first-view.test.ts +1 −1
| @@ -38,7 +38,7 @@ beforeAll(async () => { | ||
| 38 | 38 | } |
| 39 | 39 | const parent = (await import("../src/core/repos.ts")).getRepo(app.db, "alice", "app-0"); |
| 40 | 40 | 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" }); | |
| 42 | 42 | if (!forked.ok) throw new Error(String(forked.error)); |
| 43 | 43 | html = await (await fetch(`${servers.url}/explore?kind=app`)).text(); |
| 44 | 44 | 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 () => { | ||
| 50 | 50 | adminToken = createToken(app.db, users["alice"]!.id, "admin", "admin").token; |
| 51 | 51 | bobToken = createToken(app.db, users["bob"]!.id, "bob", "ro").token; |
| 52 | 52 | 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" })); | |
| 56 | 56 | must(await forkRepo(app, users["fay"]!, upstream, "secret", { visibility: "private" })); |
| 57 | 57 | }, 60_000); |
| 58 | 58 |
test/feeds.test.ts +1 −1
| @@ -66,7 +66,7 @@ describe("a repository's feed", () => { | ||
| 66 | 66 | title: 'the "boss" <level> is too hard & long', |
| 67 | 67 | }); |
| 68 | 68 | 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" }); | |
| 70 | 70 | if (!forked.ok) throw new Error(String(forked.error)); |
| 71 | 71 | const hook = createWebhook(app, alice, made.value, { |
| 72 | 72 | url: "https://hooks.example.test/T0/s3cr3t", |
test/following-card.test.ts +1 −1
| @@ -48,7 +48,7 @@ beforeAll(async () => { | ||
| 48 | 48 | }); |
| 49 | 49 | if (!bob.ok) throw new Error(bob.error); |
| 50 | 50 | 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" }); | |
| 52 | 52 | if (!forked.ok) throw new Error(String(forked.error)); |
| 53 | 53 | }, 60_000); |
| 54 | 54 |
test/following-etag.test.ts +1 −1
| @@ -70,7 +70,7 @@ beforeAll(async () => { | ||
| 70 | 70 | if (!up.ok) throw new Error("repo"); |
| 71 | 71 | upstream = up.value; |
| 72 | 72 | 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" }); | |
| 74 | 74 | if (!fork.ok) throw new Error(JSON.stringify(fork.error)); |
| 75 | 75 | await Bun.write( |
| 76 | 76 | join(dataDir, "parent.json"), |
test/following-proposals-etag.test.ts +1 −1
| @@ -61,7 +61,7 @@ beforeAll(async () => { | ||
| 61 | 61 | if (!up.ok) throw new Error("repo"); |
| 62 | 62 | const solo = await createRepo(app, alice, { name: "solo", visibility: "private" }); |
| 63 | 63 | 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" }); | |
| 65 | 65 | if (!fork.ok) throw new Error(JSON.stringify(fork.error)); |
| 66 | 66 | bobId = fork.value.id; |
| 67 | 67 | await Bun.write( |
test/following.test.ts +7 −7
| @@ -114,7 +114,7 @@ describe("a fork that follows its parent", () => { | ||
| 114 | 114 | parent = made.value; |
| 115 | 115 | const seeded = await commit(alice, parent, "README.md", "# game\n"); |
| 116 | 116 | 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" }); | |
| 118 | 118 | if (!forked.ok) throw new Error(String(forked.error)); |
| 119 | 119 | fork = forked.value; |
| 120 | 120 | }, 30_000); |
| @@ -434,7 +434,7 @@ describe("a fork that follows its parent", () => { | ||
| 434 | 434 | }); |
| 435 | 435 | if (!c.ok) throw new Error(c.error); |
| 436 | 436 | 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" }); | |
| 438 | 438 | if (!forked.ok) throw new Error(String(forked.error)); |
| 439 | 439 | const carols = forked.value; |
| 440 | 440 | expect(addToCrew(app, c.value, carols, "bot").ok).toBe(true); |
| @@ -473,7 +473,7 @@ describe("a fork that follows its parent", () => { | ||
| 473 | 473 | }); |
| 474 | 474 | if (!d.ok) throw new Error(d.error); |
| 475 | 475 | 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" }); | |
| 477 | 477 | if (!forked.ok) throw new Error(String(forked.error)); |
| 478 | 478 | const dans = forked.value; |
| 479 | 479 | app.db |
| @@ -703,7 +703,7 @@ describe("a fork that follows its parent", () => { | ||
| 703 | 703 | }); |
| 704 | 704 | if (!f.ok) throw new Error(f.error); |
| 705 | 705 | 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" }); | |
| 707 | 707 | if (!grand.ok) throw new Error(String(grand.error)); |
| 708 | 708 | |
| 709 | 709 | const tree = await lineageOf(app, fresh(fork), () => true); |
| @@ -835,7 +835,7 @@ describe("a fork that follows its parent", () => { | ||
| 835 | 835 | app.db.query("UPDATE repo SET landing = 'merge' WHERE id = ?").run(made.value.id); |
| 836 | 836 | const lamp = getRepoById(app.db, made.value.id)!; |
| 837 | 837 | 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" }); | |
| 839 | 839 | if (!forked.ok) throw new Error(String(forked.error)); |
| 840 | 840 | const mine = forked.value; |
| 841 | 841 | 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", () => { | ||
| 958 | 958 | ], |
| 959 | 959 | }); |
| 960 | 960 | 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" }); | |
| 963 | 963 | if (!one.ok || !two.ok) throw new Error("fork"); |
| 964 | 964 | untouched = one.value; |
| 965 | 965 | worked = two.value; |
test/fork-chain.test.ts +4 −4
| @@ -61,8 +61,8 @@ beforeAll(async () => { | ||
| 61 | 61 | } |
| 62 | 62 | a = must(await createRepo(app, users["ann"]!, { name: "app", visibility: "public" })); |
| 63 | 63 | 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" })); | |
| 66 | 66 | }, 60_000); |
| 67 | 67 | |
| 68 | 68 | afterAll(async () => { |
| @@ -93,8 +93,8 @@ describe("a private middle", () => { | ||
| 93 | 93 | beforeAll(async () => { |
| 94 | 94 | top = must(await createRepo(app, users["ann"]!, { name: "pub", visibility: "public" })); |
| 95 | 95 | 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" })); | |
| 98 | 98 | // The middle goes private after the grandchild forked it. |
| 99 | 99 | must(await updateRepoSettings(app, users["ben"]!, mid, { visibility: "private" })); |
| 100 | 100 | }); |
test/fork-children.test.ts +3 −3
| @@ -55,13 +55,13 @@ describe("a repository's direct forks", () => { | ||
| 55 | 55 | many = await withCode("many"); |
| 56 | 56 | bare = await mk("bare"); |
| 57 | 57 | 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" }); | |
| 60 | 60 | if (!bob.ok || !carol.ok) throw new Error("fork failed"); |
| 61 | 61 | const closed = await updateRepoSettings(app, users["carol"]!, carol.value, { visibility: "private" }); |
| 62 | 62 | if (!closed.ok) throw new Error(String(closed.error)); |
| 63 | 63 | // 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" }); | |
| 65 | 65 | if (!grand.ok) throw new Error(String(grand.error)); |
| 66 | 66 | for (let i = 0; i < FORKS_SHOWN_ON_CODE + 2; i++) { |
| 67 | 67 | 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", () => { | ||
| 142 | 142 | const alice = (await import("../src/core/users.ts")).getUserByName(app.db, "alice")!; |
| 143 | 143 | let parent = lib; |
| 144 | 144 | 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" }); | |
| 146 | 146 | if (!next.ok) throw new Error(String(next.error)); |
| 147 | 147 | parent = next.value; |
| 148 | 148 | } |
test/fork-flow-journey.test.ts +1 −1
| @@ -72,7 +72,7 @@ beforeAll(async () => { | ||
| 72 | 72 | bobToken = createToken(app.db, bob.id, "t", "admin").token; |
| 73 | 73 | lib = must(await createRepo(app, alice, { name: "lib", visibility: "public" })); |
| 74 | 74 | 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" })); | |
| 76 | 76 | }, 60_000); |
| 77 | 77 | |
| 78 | 78 | afterAll(async () => { |
test/fork-flow.test.ts +9 −4
| @@ -1,3 +1,4 @@ | ||
| 1 | import { getRepo, updateRepoSettings } from "../src/core/repos.ts"; | |
| 1 | 2 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 2 | 3 | import { mkdtemp, rm, writeFile } from "node:fs/promises"; |
| 3 | 4 | import { tmpdir } from "node:os"; |
| @@ -381,14 +382,15 @@ describe("the fork flow", () => { | ||
| 381 | 382 | expect(result.pull?.local).toBeNull(); |
| 382 | 383 | |
| 383 | 384 | // 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; | |
| 385 | 386 | const landed = branches.find((b) => b.name === "fix-typo"); |
| 386 | 387 | expect(landed?.oid).toBe(result.commit.commitOid); |
| 387 | 388 | |
| 388 | 389 | // …and it started from the CURRENT upstream main, not from the fork's |
| 389 | 390 | // 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 }, | |
| 392 | 394 | ); |
| 393 | 395 | expect(moved.status).toBe(200); |
| 394 | 396 | |
| @@ -488,7 +490,7 @@ describe("the fork flow", () => { | ||
| 488 | 490 | }>(response); |
| 489 | 491 | expect(result.via).toBe("fork"); |
| 490 | 492 | |
| 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; | |
| 492 | 494 | expect(branches.find((b) => b.name === "gh-fix")?.oid).toBe( |
| 493 | 495 | result.commit.commitOid, |
| 494 | 496 | ); |
| @@ -722,6 +724,9 @@ describe("the fork flow", () => { | ||
| 722 | 724 | origin: unknown; |
| 723 | 725 | }>(forked); |
| 724 | 726 | 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" }); | |
| 725 | 730 | const committed = await api( |
| 726 | 731 | `/api/v1/repos/${fork.ownerName}/${fork.name}/contents`, |
| 727 | 732 | { |
test/fork-follow-line.test.ts +1 −1
| @@ -43,7 +43,7 @@ beforeAll(async () => { | ||
| 43 | 43 | } |
| 44 | 44 | const lib = must(await createRepo(app, users["ann"], { name: "lib", visibility: "public" })); |
| 45 | 45 | 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" })); | |
| 47 | 47 | forkId = getRepo(app.db, "bea", "lib")?.id ?? fork.id; |
| 48 | 48 | servers = await serve(app); |
| 49 | 49 | for (const name of ["bea", "cal"]) { |
test/fork-follow-word.test.ts +1 −1
| @@ -41,7 +41,7 @@ beforeAll(async () => { | ||
| 41 | 41 | if (!lib.ok) throw new Error(String(lib.error)); |
| 42 | 42 | const first = await commitToBranch(app, alice.value, lib.value, { message: "Start", files: [{ path: "README.md", content: "# lib\n" }] }); |
| 43 | 43 | 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" }); | |
| 45 | 45 | if (!forked.ok) throw new Error(String(forked.error)); |
| 46 | 46 | // The fork's own commit first: a fork with work of its own is diverged, so a parent that moves |
| 47 | 47 | // 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 | ||
| 80 | 80 | }); |
| 81 | 81 | |
| 82 | 82 | 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" })); | |
| 84 | 84 | expect(lastFollow(app.db, fork.id)).toBeNull(); |
| 85 | 85 | expect(lastFollowSaid(app, fresh(fork))).toBe(""); |
| 86 | 86 | 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 | ||
| 128 | 128 | }, 30_000); |
| 129 | 129 | |
| 130 | 130 | 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" })); | |
| 132 | 132 | expect(forkTree(app.db, fresh(parent), alice, app)!.nodes.find((n) => n.repo === "alice/game-alice")!.followed).toBe("never followed"); |
| 133 | 133 | await commit(alice, parent, "t.txt", "t\n"); |
| 134 | 134 | must(await takeOrTell(app, alice, fresh(fork))); |
test/fork-offer-receipt.test.ts +1 −1
| @@ -65,7 +65,7 @@ beforeAll(async () => { | ||
| 65 | 65 | const r = await createRepo(app, users[1]!, { name: "yard", visibility: "public" }); |
| 66 | 66 | if (!r.ok) throw new Error(String(r.error)); |
| 67 | 67 | 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" }); | |
| 69 | 69 | if (!f.ok) throw new Error(String(f.error)); |
| 70 | 70 | }, 30_000); |
| 71 | 71 |
test/fork-offer-size.test.ts +1 −1
| @@ -53,7 +53,7 @@ describe("fork offer size", () => { | ||
| 53 | 53 | message: "Start", files: [{ path: "README.md", content: "# lib\nold\n" }], |
| 54 | 54 | }); |
| 55 | 55 | 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" }); | |
| 57 | 57 | if (!f.ok) throw new Error(String(f.error)); |
| 58 | 58 | fork = f.value; |
| 59 | 59 | }); |
test/fork-offers-sent.test.ts +1 −1
| @@ -58,7 +58,7 @@ describe("sent offers", () => { | ||
| 58 | 58 | message: "Start", files: [{ path: "README.md", content: "# lib\n" }], |
| 59 | 59 | }); |
| 60 | 60 | 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" }); | |
| 62 | 62 | if (!f.ok) throw new Error(String(f.error)); |
| 63 | 63 | fork = f.value; |
| 64 | 64 | }); |
test/fork-offers.test.ts +3 −3
| @@ -45,7 +45,7 @@ describe("fork offers", () => { | ||
| 45 | 45 | if (!seeded.ok) throw new Error(JSON.stringify(seeded.error)); |
| 46 | 46 | for (const [who, visibility] of [["bob", "public"], ["carol", "private"]] as const) { |
| 47 | 47 | const user = users[who]!; |
| 48 | const fork = await forkRepo(app, user, lib); | |
| 48 | const fork = await forkRepo(app, user, lib, undefined, { visibility: "public" }); | |
| 49 | 49 | if (!fork.ok) throw new Error(String(fork.error)); |
| 50 | 50 | if (visibility === "private") { |
| 51 | 51 | const closed = await updateRepoSettings(app, user, fork.value, { visibility }); |
| @@ -103,7 +103,7 @@ describe("fork offers", () => { | ||
| 103 | 103 | message: "Start", files: [{ path: "README.md", content: "# x\n" }], |
| 104 | 104 | }); |
| 105 | 105 | 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" }); | |
| 107 | 107 | if (!fork.ok) throw new Error(String(fork.error)); |
| 108 | 108 | return { up: up.value, fork: fork.value }; |
| 109 | 109 | }; |
| @@ -122,7 +122,7 @@ describe("fork offers", () => { | ||
| 122 | 122 | |
| 123 | 123 | test("a fork of a fork is not listed on the upstream", async () => { |
| 124 | 124 | 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" }); | |
| 126 | 126 | if (!deeper.ok) throw new Error(String(deeper.error)); |
| 127 | 127 | await offerFrom(users["bob"]!, up, fork, "direct", "Direct"); |
| 128 | 128 | // 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 () => { | ||
| 43 | 43 | message: "Start", files: [{ path: "README.md", content: "# lib\n" }], |
| 44 | 44 | }); |
| 45 | 45 | 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" }); | |
| 47 | 47 | if (!forked.ok) throw new Error(String(forked.error)); |
| 48 | 48 | }, 60_000); |
| 49 | 49 |
test/fork-tree-chip.test.ts +1 −1
| @@ -29,7 +29,7 @@ beforeAll(async () => { | ||
| 29 | 29 | } |
| 30 | 30 | const lib = must(await createRepo(app, users["ann"], { name: "lib", visibility: "public" })); |
| 31 | 31 | 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" })); | |
| 33 | 33 | // The fork must not follow on its own, or it would catch up as the parent moves: `tell-me` still |
| 34 | 34 | // fast-forwards a fork with no work of its own, in the background, so the count raced it. |
| 35 | 35 | 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 () => { | ||
| 42 | 42 | must(setRole(app, ann, "cal", "member")); |
| 43 | 43 | top = must(await createRepo(app, ann, { name: "yard", visibility: "public" })); |
| 44 | 44 | 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" })); | |
| 46 | 46 | // Work of its own, so the parent moving later cannot fast-forward it under the counts. |
| 47 | 47 | 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" })); | |
| 49 | 49 | // mid moves one commit on; leaf, which does not follow, has not taken it. |
| 50 | 50 | setForkFollowMode(app.db, leaf.id, "dont-follow"); |
| 51 | 51 | must(await commitToBranch(app, bea, mid, { message: "more", files: [{ path: "more.txt", content: "m\n" }] })); |
| @@ -58,7 +58,7 @@ beforeAll(async () => { | ||
| 58 | 58 | // Forked after the last push: level, and following automatically, with nothing to take. |
| 59 | 59 | const dan = must(await createUser(app.db, { origin: "seed", trusted: true, username: "dan", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false })); |
| 60 | 60 | 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" })); | |
| 62 | 62 | setForkFollowMode(app.db, twin.id, "take-updates"); |
| 63 | 63 | }, 60_000); |
| 64 | 64 | |
| @@ -79,7 +79,7 @@ test("a count nobody has made is null, not a git walk on the request", async () | ||
| 79 | 79 | must(await commitToBranch(fresh, u, parent, { message: "first", files: [{ path: "a.txt", content: "a\n" }] })); |
| 80 | 80 | const fay = must(await createUser(fresh.db, { origin: "seed", trusted: true, username: "fay", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false })); |
| 81 | 81 | 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" })); | |
| 83 | 83 | // The parent moves after the fork, so no count exists for this pair of tips. |
| 84 | 84 | must(await commitToBranch(fresh, u, parent, { message: "second", files: [{ path: "b.txt", content: "b\n" }] })); |
| 85 | 85 | const t = forkTree(fresh.db, parent, u, fresh); |
test/fork-tree-here.test.ts +4 −4
| @@ -60,14 +60,14 @@ beforeAll(async () => { | ||
| 60 | 60 | for (const n of ["bea", "cal", "eve", "dee"]) must(setRole(app, ann, n, "member")); |
| 61 | 61 | const root = must(await createRepo(app, ann, { name: "yard", visibility: "public" })); |
| 62 | 62 | 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" })); | |
| 65 | 65 | // 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" })); | |
| 67 | 67 | // A family with one fork only. |
| 68 | 68 | const pond = must(await createRepo(app, ann, { name: "pond", visibility: "public" })); |
| 69 | 69 | 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" })); | |
| 71 | 71 | }, 60_000); |
| 72 | 72 | |
| 73 | 73 | afterAll(async () => { |
test/fork-tree-links.test.ts +2 −2
| @@ -56,8 +56,8 @@ beforeAll(async () => { | ||
| 56 | 56 | for (const n of ["bea", "cal", "dee"]) must(setRole(app, ann, n, "member")); |
| 57 | 57 | const root = must(await createRepo(app, ann, { name: "yard", visibility: "public" })); |
| 58 | 58 | must(await commitToBranch(app, ann, root, { message: "first", files: [{ path: "a.txt", content: "a\n" }] })); |
| 59 | const middle = must(await forkRepo(app, bea, root)); | |
| 60 | must(await forkRepo(app, cal, middle)); | |
| 59 | const middle = must(await forkRepo(app, bea, root, undefined, { visibility: "public" })); | |
| 60 | must(await forkRepo(app, cal, middle, undefined, { visibility: "public" })); | |
| 61 | 61 | must(await forkRepo(app, dee, middle, undefined, { visibility: "private" })); |
| 62 | 62 | }, 60_000); |
| 63 | 63 |
test/fork-tree-mode.test.ts +2 −2
| @@ -43,7 +43,7 @@ beforeAll(async () => { | ||
| 43 | 43 | for (const [user, mode] of [["bea", "take-updates"], ["cal", "tell-me"], ["dan", "dont-follow"]] as const) { |
| 44 | 44 | const u = await mk(user, false); |
| 45 | 45 | 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" })); | |
| 47 | 47 | setForkFollowMode(app.db, fork.id, mode); |
| 48 | 48 | kids.set(mode, fork); |
| 49 | 49 | } |
| @@ -97,7 +97,7 @@ test("a nested fork row says its phrase on the web and in the terminal", async ( | ||
| 97 | 97 | const bea = kids.get("take-updates")!; |
| 98 | 98 | const eve = must(await createUser(app.db, { origin: "seed", trusted: true, username: "eve", email: "[email protected]", password: "a-good-passphrase", adminIfFirst: false })); |
| 99 | 99 | 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" })); | |
| 101 | 101 | setForkFollowMode(app.db, deep.id, "tell-me"); |
| 102 | 102 | const html = await (await fetch(`${servers.url}/ann/yard/forks`)).text(); |
| 103 | 103 | const at = html.indexOf(`href="/${name(deep)}"`); |
test/fork-tree-reader.test.ts +4 −4
| @@ -42,9 +42,9 @@ beforeAll(async () => { | ||
| 42 | 42 | promote(app.db, users[name]!); |
| 43 | 43 | } |
| 44 | 44 | 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" })); | |
| 48 | 48 | hidden = must(await forkRepo(app, users["erin"]!, org, "secret", { visibility: "private" })); |
| 49 | 49 | must(await forkRepo(app, users["erin"]!, hidden, "under", { visibility: "public" })); |
| 50 | 50 | setForkFollowMode(app.db, person.id, "take-updates"); |
| @@ -108,7 +108,7 @@ describe("forkTree", () => { | ||
| 108 | 108 | await createUser(app.db, { origin: "seed", trusted: true, username: `deep${i}`, email: `deep${i}@f.dev`, password: "a-good-passphrase" }), |
| 109 | 109 | ); |
| 110 | 110 | promote(app.db, u); |
| 111 | at = must(await forkRepo(app, u, at)); | |
| 111 | at = must(await forkRepo(app, u, at, undefined, { visibility: "public" })); | |
| 112 | 112 | } |
| 113 | 113 | const t = forkTree(app.db, at, users["alice"]!, app, { depth: 1 })!; |
| 114 | 114 | const me = t.nodes.find((n) => n.repo === "deep4/app")!; |
test/fork-tree-web.test.ts +2 −2
| @@ -86,8 +86,8 @@ beforeAll(async () => { | ||
| 86 | 86 | files: [{ path: "a.txt", content: "a\n" }], |
| 87 | 87 | }), |
| 88 | 88 | ); |
| 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" })); | |
| 91 | 91 | }, 60_000); |
| 92 | 92 | |
| 93 | 93 | afterAll(async () => { |
test/fork-tree-words.test.ts +1 −1
| @@ -37,7 +37,7 @@ beforeAll(async () => { | ||
| 37 | 37 | for (const [user, mode] of [["bea", "take-updates"], ["cal", "tell-me"], ["dan", "dont-follow"]] as const) { |
| 38 | 38 | const u = await mk(user, false); |
| 39 | 39 | 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); | |
| 41 | 41 | } |
| 42 | 42 | }, 60_000); |
| 43 | 43 |
test/fork-tree.test.ts +4 −4
| @@ -42,10 +42,10 @@ describe("the forks page draws the tree", () => { | ||
| 42 | 42 | promote(app.db, users[name]!); |
| 43 | 43 | } |
| 44 | 44 | 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" })); | |
| 49 | 49 | must(await forkRepo(app, users["fay"]!, dan, "secret", { visibility: "private" })); |
| 50 | 50 | }, 60_000); |
| 51 | 51 |
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 | ||
| 36 | 36 | const made = await createRepo(app, alice, { name: "app", visibility: "public" }); |
| 37 | 37 | if (!made.ok) throw new Error("repo"); |
| 38 | 38 | 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" }); | |
| 40 | 40 | if (!fork.ok) throw new Error("fork"); |
| 41 | 41 | await commitToBranch(app, bob, fork.value, { message: "two", files: [{ path: "b.txt", content: "y\n" }] }); |
| 42 | 42 | 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 () = | ||
| 71 | 71 | if (!made.ok) throw new Error("repo"); |
| 72 | 72 | await commitToBranch(app, carol, made.value, { message: "one", files: [{ path: "a.txt", content: "x\n" }] }); |
| 73 | 73 | 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" }); | |
| 75 | 75 | if (!f.ok) throw new Error("fork"); |
| 76 | 76 | for (let i = 0; i < n; i++) |
| 77 | 77 | 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 () => { | ||
| 45 | 45 | if (!made.ok) throw new Error("repo"); |
| 46 | 46 | parent = made.value; |
| 47 | 47 | 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" }); | |
| 49 | 49 | if (!f.ok) throw new Error("fork"); |
| 50 | 50 | bobFork = f.value; |
| 51 | 51 | }); |
| @@ -77,7 +77,7 @@ test("a fork pushed, a fork made, the parent moving and a fork deleted each chan | ||
| 77 | 77 | let tag = await tagOf(); |
| 78 | 78 | await commitToBranch(app, bob, bobFork, { message: "two", files: [{ path: "b.txt", content: "y\n" }] }); |
| 79 | 79 | 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" }); | |
| 81 | 81 | if (!c.ok) throw new Error("fork"); |
| 82 | 82 | tag = await changed(tag, "fork made"); |
| 83 | 83 | 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 | ||
| 88 | 88 | }); |
| 89 | 89 | |
| 90 | 90 | 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" }); | |
| 92 | 92 | expect(d.ok).toBe(true); |
| 93 | 93 | const all = await tagOf(); |
| 94 | 94 | const one = await tagOf("?limit=1"); |
test/forks-lineage-timing.test.ts +2 −2
| @@ -29,7 +29,7 @@ beforeAll(async () => { | ||
| 29 | 29 | let parent = must(await createRepo(app, admin.value, { name: "r0", visibility: "public", description: "" })); |
| 30 | 30 | chain = [parent]; |
| 31 | 31 | 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" })); | |
| 33 | 33 | chain.push(parent); |
| 34 | 34 | } |
| 35 | 35 | for (let i = 0; i < 30; i++) { |
| @@ -37,7 +37,7 @@ beforeAll(async () => { | ||
| 37 | 37 | await createUser(app.db, { origin: "seed", trusted: true, username: `u${i}`, email: `u${i}@f.dev`, password: "a-good-passphrase" }), |
| 38 | 38 | ); |
| 39 | 39 | 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" })); | |
| 41 | 41 | } |
| 42 | 42 | }); |
| 43 | 43 |
test/forks-ranking.test.ts +4 −4
| @@ -79,10 +79,10 @@ describe("the forks page ranks", () => { | ||
| 79 | 79 | ); |
| 80 | 80 | }; |
| 81 | 81 | 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" })); | |
| 86 | 86 | await commit("bob", bob, 1); |
| 87 | 87 | await commit("carol", carol, 2); |
| 88 | 88 | 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, | ||
| 42 | 42 | let parent = root.value; |
| 43 | 43 | const chain = [parent]; |
| 44 | 44 | 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" }); | |
| 46 | 46 | if (!f.ok) throw new Error("fork"); |
| 47 | 47 | parent = f.value; |
| 48 | 48 | chain.push(parent); |
| 49 | 49 | } |
| 50 | const side = await forkRepo(app, users[4]!, root.value); | |
| 50 | const side = await forkRepo(app, users[4]!, root.value, undefined, { visibility: "public" }); | |
| 51 | 51 | if (!side.ok) throw new Error("fork"); |
| 52 | 52 | |
| 53 | 53 | 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, | ||
| 80 | 80 | |
| 81 | 81 | // Extend to seven generations: u3 → u5 → u6 → u7. Depth 5 lists u1..u5's generation, then cuts. |
| 82 | 82 | 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" }); | |
| 84 | 84 | if (!f.ok) throw new Error("fork"); |
| 85 | 85 | parent = f.value; |
| 86 | 86 | } |
test/forks.test.ts +1 −1
| @@ -56,7 +56,7 @@ describe("forks", () => { | ||
| 56 | 56 | return r.value; |
| 57 | 57 | }; |
| 58 | 58 | 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" })); | |
| 60 | 60 | const commitAs = async (who: string, repo: Repo, file: string, message: string) => |
| 61 | 61 | must( |
| 62 | 62 | 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", () => { | ||
| 207 | 207 | }); |
| 208 | 208 | |
| 209 | 209 | 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" }); | |
| 211 | 211 | if (!fork.ok) throw new Error(String(fork.error)); |
| 212 | 212 | const path = "/wes/game"; |
| 213 | 213 | const moves = [ |
| @@ -519,7 +519,7 @@ describe("the manifest: what you can do here, as who you are", () => { | ||
| 519 | 519 | test("a pull page says whether the pull's code runs, or waits for a writer's approval", async () => { |
| 520 | 520 | const game = getRepo(app.db, "acme", "game")!; |
| 521 | 521 | const carol = usersByName["carol"]!; |
| 522 | const forked = await forkRepo(app, carol, game); | |
| 522 | const forked = await forkRepo(app, carol, game, undefined, { visibility: "public" }); | |
| 523 | 523 | if (!forked.ok) throw new Error(String(forked.error)); |
| 524 | 524 | const committed = await commitToBranch(app, carol, forked.value, { |
| 525 | 525 | branch: "idea", |
test/iterations-etag.test.ts +2 −2
| @@ -60,7 +60,7 @@ beforeAll(async () => { | ||
| 60 | 60 | if (!made.ok) throw new Error("repo"); |
| 61 | 61 | parent = made.value; |
| 62 | 62 | 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" }); | |
| 64 | 64 | if (!f.ok) throw new Error("fork"); |
| 65 | 65 | bobFork = f.value; |
| 66 | 66 | 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 | ||
| 106 | 106 | tag = await changed(tag, "fork pushed"); |
| 107 | 107 | await commit(parent, alice, "side parent", "wip"); |
| 108 | 108 | 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" }); | |
| 110 | 110 | if (!c.ok) throw new Error("fork"); |
| 111 | 111 | tag = await changed(tag, "fork made"); |
| 112 | 112 | expect((await deleteRepo(app, carol, c.value)).ok).toBe(true); |
test/iterations.test.ts +1 −1
| @@ -123,7 +123,7 @@ describe("iterations page", () => { | ||
| 123 | 123 | await pin(game(), alice, "v1", one, { note: "first <b>playable</b>" }); |
| 124 | 124 | await pin(game(), alice, "v2", two, { parent: "v1" }); |
| 125 | 125 | 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" }); | |
| 127 | 127 | if (!forked.ok) throw new Error(String(forked.error)); |
| 128 | 128 | const mine = getRepo(app.db, "bob", "game")!; |
| 129 | 129 | 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", () => { | ||
| 51 | 51 | files: [{ path: "README.md", content: "# lib\n" }], |
| 52 | 52 | }); |
| 53 | 53 | 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" }); | |
| 55 | 55 | 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" }); | |
| 57 | 57 | if (!carols.ok) throw new Error(String(carols.error)); |
| 58 | 58 | const closed = await updateRepoSettings(app, users["carol"]!, carols.value, { visibility: "private" }); |
| 59 | 59 | 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 | ||
| 38 | 38 | await make(sam, "tools"); |
| 39 | 39 | const fork = async (who: typeof alice, from: string) => { |
| 40 | 40 | 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" }); | |
| 42 | 42 | if (!r.ok) throw new Error(JSON.stringify(r)); |
| 43 | 43 | return r.value; |
| 44 | 44 | }; |
test/mcp-forge-reads.test.ts +1 −1
| @@ -212,7 +212,7 @@ describe("the forge over MCP: reads", () => { | ||
| 212 | 212 | message: "seed", |
| 213 | 213 | files: [{ path: "README.md", content: "# open\n" }], |
| 214 | 214 | }); |
| 215 | const forked = await forkRepo(app, bob, pub.value); | |
| 215 | const forked = await forkRepo(app, bob, pub.value, undefined, { visibility: "public" }); | |
| 216 | 216 | if (!forked.ok) throw new Error(String(forked.error)); |
| 217 | 217 | const fresh = (r: Repo) => getRepoById(app.db, r.id)!; |
| 218 | 218 |
test/mcp-forks-card.test.ts +2 −2
| @@ -46,8 +46,8 @@ describe("MCP fork_tree card", () => { | ||
| 46 | 46 | token = createToken(app.db, users["alice"]!.id, "admin", "admin").token; |
| 47 | 47 | bobToken = createToken(app.db, users["bob"]!.id, "bob", "ro").token; |
| 48 | 48 | 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" })); | |
| 51 | 51 | // A private fork alice cannot read (only its owner reads it). |
| 52 | 52 | must(await forkRepo(app, users["fay"]!, upstream, "secret", { visibility: "private" })); |
| 53 | 53 | }, 60_000); |
test/mcp-forks-chain.test.ts +5 −5
| @@ -53,17 +53,17 @@ beforeAll(async () => { | ||
| 53 | 53 | aliceToken = createToken(app.db, alice.id, "t", "admin").token; |
| 54 | 54 | carolToken = createToken(app.db, carol.id, "t", "admin").token; |
| 55 | 55 | 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" })); | |
| 59 | 59 | const secret = must(await forkRepo(app, bob, leaf, "lib-secret")); |
| 60 | 60 | app.db.run("UPDATE repo SET visibility = 'private' WHERE id = ?1", [secret.id]); |
| 61 | 61 | await setFollowMode(app, alice, leaf, "take-updates"); |
| 62 | 62 | // 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" })); | |
| 64 | 64 | clearForkParent(app.db, cut.id); |
| 65 | 65 | 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" })); | |
| 67 | 67 | }, 30_000); |
| 68 | 68 | |
| 69 | 69 | afterAll(async () => { |
test/mcp-tree.test.ts +2 −2
| @@ -54,8 +54,8 @@ beforeAll(async () => { | ||
| 54 | 54 | aliceToken = createToken(app.db, alice.id, "t", "admin").token; |
| 55 | 55 | bobToken = createToken(app.db, carol.id, "t", "admin").token; |
| 56 | 56 | 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" })); | |
| 59 | 59 | const secret = must(await forkRepo(app, bob, mid, "lib-secret")); |
| 60 | 60 | app.db.run("UPDATE repo SET visibility = 'private' WHERE id = ?1", [secret.id]); |
| 61 | 61 | await setFollowMode(app, alice, mid, "take-updates"); |
test/migrate-trail.test.ts +6
| @@ -141,4 +141,10 @@ describe("migrate: trail", () => { | ||
| 141 | 141 | }); |
| 142 | 142 | expect(getProvenance(app.db, repo.id)?.shown).toBe(true); |
| 143 | 143 | }); |
| 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 | }); | |
| 144 | 150 | }); |
test/offer-commit.test.ts +1 −1
| @@ -69,7 +69,7 @@ beforeAll(async () => { | ||
| 69 | 69 | const r = await createRepo(app, users[1]!, { name: "yard", visibility: "public" }); |
| 70 | 70 | if (!r.ok) throw new Error(String(r.error)); |
| 71 | 71 | 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" }); | |
| 73 | 73 | if (!f.ok) throw new Error(String(f.error)); |
| 74 | 74 | for (const n of ["one", "two", "three"]) { |
| 75 | 75 | const c = await commitToBranch(app, users[2]!, forkOf(), { |
test/offer-pull.test.ts +1 −1
| @@ -69,7 +69,7 @@ beforeAll(async () => { | ||
| 69 | 69 | const r = await createRepo(app, owner, { name: "yard", visibility: "public" }); |
| 70 | 70 | if (!r.ok) throw new Error(String(r.error)); |
| 71 | 71 | 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" }); | |
| 73 | 73 | if (!f.ok) throw new Error(String(f.error)); |
| 74 | 74 | fork = getRepo(app.db, "ravi", "yard")!; |
| 75 | 75 | 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 () => { | ||
| 70 | 70 | message: "first", |
| 71 | 71 | files: [{ path: "a.txt", content: "a\n" }], |
| 72 | 72 | }); |
| 73 | const f = await forkRepo(app, users[2]!, r.value); | |
| 73 | const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" }); | |
| 74 | 74 | if (!f.ok) throw new Error(String(f.error)); |
| 75 | 75 | }); |
| 76 | 76 |
test/parity.test.ts +3 −1
| @@ -14,7 +14,7 @@ import { join } from "node:path"; | ||
| 14 | 14 | import { createApp, type App } from "../src/app.ts"; |
| 15 | 15 | import { listEvents } from "../src/core/events.ts"; |
| 16 | 16 | 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"; | |
| 18 | 18 | import { serve, type Servers } from "../src/http/server.ts"; |
| 19 | 19 | import { gitClientEnv } from "./helpers/git-client.ts"; |
| 20 | 20 | import { proveAll } from "./helpers/verified.ts"; |
| @@ -682,6 +682,8 @@ describe("parity: full control through actions and the API", () => { | ||
| 682 | 682 | body: {}, |
| 683 | 683 | }); |
| 684 | 684 | 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" }); | |
| 685 | 687 | await call("POST", "/api/v1/repos/bob/pub/contents", { |
| 686 | 688 | token: bobRw, |
| 687 | 689 | 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 () => { | ||
| 64 | 64 | message: "first", |
| 65 | 65 | files: [{ path: "a.txt", content: "a\n" }], |
| 66 | 66 | }); |
| 67 | const f = await forkRepo(app, users[2]!, r.value); | |
| 67 | const f = await forkRepo(app, users[2]!, r.value, undefined, { visibility: "public" }); | |
| 68 | 68 | if (!f.ok) throw new Error(String(f.error)); |
| 69 | 69 | }); |
| 70 | 70 |
test/repo-head-quiet.test.ts +1 −1
| @@ -73,7 +73,7 @@ const asViewer = async (who: "owner" | "peer" | "guest", path: string): Promise< | ||
| 73 | 73 | 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 () => { |
| 74 | 74 | const plain = f.repos[6]!; // public |
| 75 | 75 | 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" }); | |
| 77 | 77 | expect(forked.ok).toBe(true); |
| 78 | 78 | const made = createApp(f.app.db, { repoId: appRepo.id, slug: "three", access: "public" }); |
| 79 | 79 | if (!made.ok) throw new Error(made.error); |
test/standing-live.test.ts +1 −1
| @@ -45,7 +45,7 @@ beforeAll(async () => { | ||
| 45 | 45 | message: "Start", files: [{ path: "README.md", content: "# lib\n" }], |
| 46 | 46 | }); |
| 47 | 47 | 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" }); | |
| 49 | 49 | if (!forked.ok) throw new Error(String(forked.error)); |
| 50 | 50 | }, 60_000); |
| 51 | 51 |
test/tui-forks-offers.test.ts +2 −2
| @@ -66,7 +66,7 @@ describe("the forks screen lists offers from forks", () => { | ||
| 66 | 66 | const lib = must(await createRepo(app, users["alice"]!, { name: "lib", visibility: "public" })); |
| 67 | 67 | must(await commitToBranch(app, users["alice"]!, lib, { message: "base", files: [{ path: "a.txt", content: "a\n" }] })); |
| 68 | 68 | 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" })); | |
| 70 | 70 | if (who === "carol") must(await updateRepoSettings(app, users[who]!, fork, { visibility: "private" })); |
| 71 | 71 | must(await commitToBranch(app, users[who]!, fork, { branch: "f", message: "f", files: [{ path: `${who}.txt`, content: "x\n" }] })); |
| 72 | 72 | 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", () => { | ||
| 108 | 108 | const bob = await mk("bob"); |
| 109 | 109 | const lib = must(await createRepo(app, alice, { name: "lib", visibility: "public" })); |
| 110 | 110 | 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" })); | |
| 112 | 112 | must(await commitToBranch(app, bob, fork, { branch: "f", message: "f", files: [{ path: "b.txt", content: "x\n" }] })); |
| 113 | 113 | must(await openPull(app, bob, lib, { title: "Mine", baseBranch: "main", headBranch: "f", headRepo: fork })); |
| 114 | 114 | 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", () => | ||
| 96 | 96 | } |
| 97 | 97 | upstream = must(await createRepo(app, users["alice"]!, { name: "app", visibility: "public" })); |
| 98 | 98 | 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" })); | |
| 101 | 101 | must( |
| 102 | 102 | await commitToBranch(app, users["dan"]!, dan, { |
| 103 | 103 | message: "dan shared", |
test/tui-iterations.test.ts +1 −1
| @@ -58,7 +58,7 @@ beforeAll(async () => { | ||
| 58 | 58 | const hush = await forkRepo(app, carol, game, "hush", { visibility: "private" }); |
| 59 | 59 | if (!hush.ok) throw new Error(String(hush.error)); |
| 60 | 60 | 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" }); | |
| 62 | 62 | if (!open.ok) throw new Error(String(open.error)); |
| 63 | 63 | await pin(open.value, bob, "shown-pin", await commit(open.value, bob, "o"), "alice/game:v1"); |
| 64 | 64 | }, 60_000); |
test/web-workflows.test.ts +1 −1
| @@ -394,7 +394,7 @@ describe("fork at the origin, and propose a change through it", () => { | ||
| 394 | 394 | // The branch really landed on the fork's git. |
| 395 | 395 | const branches = ( |
| 396 | 396 | (await ( |
| 397 | await fetch(`${upServers.url}/api/v1/repos/me/gears/branches`) | |
| 397 | await upstream("/api/v1/repos/me/gears/branches", { as: "me" }) | |
| 398 | 398 | ).json()) as { items: { name: string }[] } |
| 399 | 399 | ).items; |
| 400 | 400 | expect(branches.map((b) => b.name)).toContain("alice/fix-typo"); |
new above
offline