Skip to content

abso-core

Public

abso is version control for agents: the client, the engine and a server you can run on your own Cloudflare account.

Check passed
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/client/test/orgs.test.ts?draft=login-wait&format=json
198 linespinch 100%0 versions changed it
1// abso orgs and abso org: reads as the person who approved the box's sign-in, and the changes say where the
2// website makes them. The server here is a stand-in that answers the org routes' documented shapes.
3
4import assert from "node:assert/strict";
5import { mkdtempSync } from "node:fs";
6import { tmpdir } from "node:os";
7import { join } from "node:path";
8import { describe, it } from "node:test";
9import { parseArgs } from "../src/args.ts";
10import { writeBox } from "../src/box.ts";
11import { commandTable } from "../src/main.ts";
12import { initInOrg, runOrg, runOrgs, siteOf } from "../src/orgs.ts";
14const SERVER = "https://api.example.dev";
15const CREDENTIAL = "abso_bx_test0000000000";
17function signedIn(): string {
18 const home = mkdtempSync(join(tmpdir(), "abso-orgs-"));
19 writeBox(
20 {
21 server: SERVER,
22 id: "box_1",
23 credential: CREDENTIAL,
24 grant: { projects: [{ project: "web", role: "writer" }], max_agents: 3 },
25 expiresAt: Date.now() + 86_400_000,
26 },
27 home,
28 );
29 return home;
32/** A stand-in server: answers from `routes` by path, and keeps what was asked. */
33function server(routes: Record<string, { status: number; body: unknown }>) {
34 const asked: { url: string; method: string; auth: string | null }[] = [];
35 const fetcher = (async (url: string | URL | Request, init?: RequestInit) => {
36 const u = new URL(String(url));
37 asked.push({
38 url: String(url),
39 method: init?.method ?? "GET",
40 auth: new Headers(init?.headers).get("authorization"),
41 });
42 const r = routes[u.pathname] ?? { status: 404, body: { error: "no such route" } };
43 return new Response(JSON.stringify(r.body), { status: r.status });
44 }) as typeof fetch;
45 return { fetcher, asked };
48const args = (line: string[]) => parseArgs("org", line, commandTable().org!.flags);
50describe("abso orgs", () => {
51 it("lists yours with your role, and invitations waiting, reading with the box's sign-in", async () => {
52 const home = signedIn();
53 const s = server({
54 "/orgs": {
55 status: 200,
56 body: {
57 orgs: [
58 { name: "acme-labs", displayName: "Acme Labs", role: "owner" },
59 { name: "beta", displayName: "beta", role: "member" },
60 ],
61 invitations: [{ id: "inv_1", org: "gamma", role: "member", expiresAt: "2026-10-16T10:00:00.000Z" }],
62 },
63 },
64 });
65 const out = await runOrgs(SERVER, { home, fetch: s.fetcher });
66 assert.equal(
67 out.text,
68 [
69 "Your organizations (2):",
70 " acme-labs (Acme Labs): owner",
71 " beta: member",
72 "Invited to:",
73 " gamma as member, until 2026-10-16 10:00 UTC",
74 "Accept them on the website, signed in: https://example.dev.",
75 ].join("\n"),
76 );
77 assert.deepEqual(s.asked, [{ url: `${SERVER}/orgs`, method: "GET", auth: `Box ${CREDENTIAL}` }]);
78 });
80 it("says so when the box isn't signed in, the sign-in isn't taken, or orgs aren't on", async () => {
81 const empty = mkdtempSync(join(tmpdir(), "abso-orgs-"));
82 await assert.rejects(runOrgs(SERVER, { home: empty, fetch: server({}).fetcher }), /abso login signs it in/);
83 const home = signedIn();
84 const expired = server({ "/orgs": { status: 401, body: { error: "missing or wrong token" } } });
85 await assert.rejects(runOrgs(SERVER, { home, fetch: expired.fetcher }), /abso login renews it/);
86 const off = server({ "/orgs": { status: 404, body: { error: "organizations aren't on here yet" } } });
87 await assert.rejects(runOrgs(SERVER, { home, fetch: off.fetcher }), /api\.example\.dev: organizations aren't on/);
88 });
90 it("never prints the credential, even when the server echoes it", async () => {
91 const home = signedIn();
92 const s = server({ "/orgs": { status: 500, body: `oops ${CREDENTIAL}` } });
93 await assert.rejects(runOrgs(SERVER, { home, fetch: s.fetcher }), (e: Error) => !e.message.includes(CREDENTIAL));
94 });
95});
97describe("abso org <name>", () => {
98 const acme = {
99 name: "acme-labs",
100 displayName: "Acme Labs",
101 description: "We make labs.",
102 role: "owner",
103 membersCan: "write",
104 whoMakesProjects: "members",
105 members: [
106 { id: "cf-1", role: "owner", name: "sam", raised: [] },
107 { id: "cf-2", role: "member", name: null, raised: [{ project: "web", role: "owner" }] },
108 ],
109 projects: ["api", "web"],
110 invites: [{ id: "inv_2", role: "member", kind: "link", for: null, expiresAt: "2026-10-16T10:00:00.000Z" }],
111 };
113 it("shows its projects, people, settings and open invites to a member, never a person's id", async () => {
114 const home = signedIn();
115 const s = server({ "/orgs/acme-labs": { status: 200, body: acme } });
116 const out = await runOrg(args(["acme-labs"]), SERVER, { home, fetch: s.fetcher });
117 assert.equal(
118 out.text,
119 [
120 "acme-labs (Acme Labs)",
121 " We make labs.",
122 "You're an owner. Members can write every project; members make projects.",
123 "Projects (2): api, web",
124 "People (2):",
125 " sam: owner",
126 " (no name yet): member, raised to owner in web",
127 "Open invites:",
128 " a link, as member, until 2026-10-16 10:00 UTC",
129 ].join("\n"),
130 );
131 assert.equal(out.text.includes("cf-"), false);
132 });
134 it("shows a non-member only what the org shows everyone", async () => {
135 const home = signedIn();
136 const s = server({
137 "/orgs/acme-labs": { status: 200, body: { name: "acme-labs", displayName: "Acme Labs", description: null } },
138 });
139 const out = await runOrg(args(["acme-labs"]), SERVER, { home, fetch: s.fetcher });
140 assert.equal(out.text, "acme-labs (Acme Labs)\nYou aren't a member, so its people and settings aren't shown.");
141 });
143 it("says when there's no such org", async () => {
144 const home = signedIn();
145 await assert.rejects(runOrg(args(["nope"]), SERVER, { home, fetch: server({}).fetcher }), /^.*nope: no such route/);
146 });
148 it("sends no change: each says where on the website it is made, and nothing reaches the server", async () => {
149 const home = signedIn();
150 const s = server({});
151 const cases: [string[], RegExp][] = [
152 [["acme-labs", "--invite", "sam"], /--invite is on acme-labs's People tab: https:\/\/example\.dev\/acme-labs\./],
153 [["acme-labs", "--invite", "link"], /People tab/],
154 [["acme-labs", "--role", "sam=owner"], /--role is on acme-labs's People tab/],
155 [["acme-labs", "--remove", "jo"], /--remove is on/],
156 [["acme-labs", "--leave"], /--leave is on acme-labs's People tab/],
157 [["acme-labs", "--members", "read"], /--members is on acme-labs's Settings tab/],
158 [["acme-labs", "--projects-by", "owners"], /--projects-by is on acme-labs's Settings tab/],
159 [["new", "acme-labs", "--name", "Acme Labs"], /Make acme-labs at https:\/\/example\.dev\/orgs\/new\./],
160 ];
161 for (const [line, said] of cases) {
162 await assert.rejects(runOrg(args(line), SERVER, { home, fetch: s.fetcher }), said, line.join(" "));
163 await assert.rejects(runOrg(args(line), SERVER, { home, fetch: s.fetcher }), /changed on the website for now/);
164 }
165 assert.deepEqual(s.asked, []);
166 });
168 it("takes one change at a time, and --as only with --invite", async () => {
169 const home = signedIn();
170 const s = server({});
171 await assert.rejects(
172 runOrg(args(["acme-labs", "--remove", "jo", "--leave"]), SERVER, { home, fetch: s.fetcher }),
173 /one change at a time: --remove and --leave were given together/,
174 );
175 await assert.rejects(
176 runOrg(args(["acme-labs", "--as", "owner"]), SERVER, { home, fetch: s.fetcher }),
177 /--as goes with --invite/,
178 );
179 await assert.rejects(runOrg(args([]), SERVER, { home, fetch: s.fetcher }), /abso org <name>/);
180 });
181});
183describe("the website for a server", () => {
184 it("is the site api. serves, or the server itself", () => {
185 assert.equal(siteOf("https://api.abso.dev"), "https://abso.dev");
186 assert.equal(siteOf("https://staging.example.workers.dev/"), "https://staging.example.workers.dev");
187 assert.equal(siteOf("http://localhost:8787"), "http://localhost:8787");
188 });
189});
191describe("abso init --org", () => {
192 it("says the project is made on the website for now, with the org as its owner", () => {
193 assert.throws(
194 () => initInOrg("acme-labs", SERVER),
195 /made on the website for now: New project at https:\/\/example\.dev, with acme-labs as its owner/,
196 );
197 });
198});