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

A person added to an organization's forge gets their own forge that follows the organization's: what exists today is proven in one test and the gap is filed #12480

Merged opened this

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

Merged

scout/forge:scout/12475-a-person-added-to-an-organization-s-forg → main 1 commit fork

  • Merged. scout/12475-a-person-added-to-an-organization-s-forg was merged into main as a4115da.

Review

Sign in to review this change.
1 file changed +84 −0
test/org-person-forge.test.ts added +84
@@ -0,0 +1,84 @@
1 /**
2 * VISION P4: "they add their people; each new person gets their own forge
3 * that follows the organization's." This pins what exists TODAY (#12475):
4 * an accepted invite makes a plain account, and nothing more. The invite
5 * names no organization, so the person is in no team, owns no repository,
6 * and nothing forks the organization's app for them, so nothing follows it.
7 * The gap is filed as its own issue; when it is built these assertions are
8 * the ones to turn into the proof that the person's app follows the
9 * organization's in the `proposes` mode (FORK_DEFAULT_MODE, `tell-me`).
10 */
11 import { afterAll, beforeAll, expect, test } from "bun:test";
12 import { mkdtemp, rm } from "node:fs/promises";
13 import { tmpdir } from "node:os";
14 import { join } from "node:path";
15 import { createApp, type App } from "../src/app.ts";
16 import { newApp } from "../src/actions/apps.ts";
17 import { createOrg as createOrgAction } from "../src/actions/orgs.ts";
18 import { mint } from "../src/actions/invites.ts";
19 import { FORK_DEFAULT_MODE } from "../src/core/fork_follow.ts";
20 import { isOrgMember } from "../src/core/orgs.ts";
21 import { listReposOwnedBy } from "../src/core/repos.ts";
22 import { getUserByName } from "../src/core/users.ts";
23 import { serve, type Servers } from "../src/http/server.ts";
24 import { setLimit } from "../src/settings/limits.ts";
25 import { setSignup } from "../src/settings/signup.ts";
26 import { seedAdmin } from "./helpers/admin.ts";
27 import { quietLogs } from "./helpers/globals.ts";
28
29 quietLogs();
30
31 let dir = "";
32 let app: App;
33 let servers: Servers;
34
35 beforeAll(async () => {
36 dir = await mkdtemp(join(tmpdir(), "forge-org-person-"));
37 app = createApp({ dataDir: dir, port: 0 });
38 servers = await serve(app);
39 });
40 afterAll(async () => {
41 servers.stop();
42 app.close();
43 await rm(dir, { recursive: true, force: true });
44 });
45
46 test("an invited person gets an account, not yet a forge that follows the organization's", async () => {
47 const admin = await seedAdmin(app, { username: "olive", email: "[email protected]", password: "an-invited-passphrase" });
48 if (!admin.ok) throw new Error(admin.error);
49 setSignup(app.db, "invite", admin.value.id);
50 setLimit(app.db, "signup.per_source", 1000, admin.value.id);
51
52 // An organization forge with one app.
53 const org = createOrgAction(app, admin.value, "acme");
54 if (!org.ok) throw new Error(org.error);
55 const made = await newApp(app, admin.value, { name: "board", owner: "acme", visibility: "public" });
56 if (!made.ok) throw new Error(made.error);
57 const orgRepo = made.value.repo;
58 expect(listReposOwnedBy(app.db, org.value.id).map((r) => r.name)).toEqual(["board"]);
59
60 // An invite is accepted.
61 const invite = mint(app, admin.value, 7);
62 if (!invite.ok) throw new Error(invite.error);
63 const res = await fetch(`${servers.url}/signup?invite=${invite.value.token}`, {
64 method: "POST",
65 body: new URLSearchParams({ username: "ivy", email: "[email protected]", password: "an-invited-passphrase" }),
66 redirect: "manual",
67 });
68 expect(res.status).toBe(303);
69 const ivy = getUserByName(app.db, "ivy");
70 expect(ivy).toBeDefined();
71
72 // Today: the invite carries no organization, so the person is not in it...
73 expect(Object.keys(invite.value.invite)).not.toContain("org");
74 expect(isOrgMember(app.db, org.value.id, ivy!.id)).toBe(false);
75 // ...owns no repository (no forge of their own with an app in it)...
76 expect(listReposOwnedBy(app.db, ivy!.id)).toEqual([]);
77 // ...and nothing in the forge is a fork of the organization's app.
78 const forks = app.db
79 .query<{ n: number }, [string]>("SELECT COUNT(*) AS n FROM repo WHERE fork_parent_id = ?1")
80 .get(orgRepo.id)!;
81 expect(forks.n).toBe(0);
82 // The mode such a fork would follow in, once it exists.
83 expect(FORK_DEFAULT_MODE).toBe("tell-me");
84 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs