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

Versions 5 to 318

Compare

+239 −0 in 1 place
new file, 239 lines
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+
4+import assert from "node:assert/strict";
5+import { mkdtempSync } from "node:fs";
6+import { tmpdir } from "node:os";
7+import { join } from "node:path";
8+import { describe, it } from "node:test";
9+import { parseArgs } from "../src/args.ts";
10+import { writeBox } from "../src/box.ts";
11+import { commandTable } from "../src/main.ts";
12+import { initInOrg, runOrg, runOrgs, siteOf } from "../src/orgs.ts";
14+const SERVER = "https://api.example.dev";
15+const CREDENTIAL = "abso_bx_test0000000000";
17+function 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" }] },
25+ expiresAt: Date.now() + 86_400_000,
26+ },
27+ home,
28+ );
29+ return home;
30+}
32+/** A stand-in server: answers from `routes` by path, and keeps what was asked. */
33+function server(routes: Record<string, { status: number; body: unknown }>) {
34+ const asked: { url: string; method: string; auth: string | null; body?: string }[] = [];
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+ ...(typeof init?.body === "string" ? { body: init.body } : {}),
42+ });
43+ const r = routes[u.pathname] ?? { status: 404, body: { error: "no such route" } };
44+ return new Response(JSON.stringify(r.body), { status: r.status });
45+ }) as typeof fetch;
46+ return { fetcher, asked };
47+}
49+const args = (line: string[]) => parseArgs("org", line, commandTable().org!.flags);
51+describe("abso orgs", () => {
52+ it("lists yours with your role, and invitations waiting, reading with the box's sign-in", async () => {
53+ const home = signedIn();
54+ const s = server({
55+ "/orgs": {
56+ status: 200,
57+ body: {
58+ orgs: [
59+ { name: "acme-labs", displayName: "Acme Labs", role: "owner" },
60+ { name: "beta", displayName: "beta", role: "member" },
61+ ],
62+ invitations: [{ id: "inv_1", org: "gamma", role: "member", expiresAt: "2026-10-16T10:00:00.000Z" }],
63+ },
64+ },
65+ });
66+ const out = await runOrgs(SERVER, { home, fetch: s.fetcher });
67+ assert.equal(
68+ out.text,
69+ [
70+ "Your organizations (2):",
71+ " acme-labs (Acme Labs): owner",
72+ " beta: member",
73+ "Invited to:",
74+ " gamma as member, until 2026-10-16 10:00 UTC",
75+ "Accept them on the website, signed in: https://example.dev.",
76+ ].join("\n"),
77+ );
78+ assert.deepEqual(s.asked, [{ url: `${SERVER}/orgs`, method: "GET", auth: `Box ${CREDENTIAL}` }]);
79+ });
81+ it("says so when the box isn't signed in, the sign-in isn't taken, or orgs aren't on", async () => {
82+ const empty = mkdtempSync(join(tmpdir(), "abso-orgs-"));
83+ await assert.rejects(runOrgs(SERVER, { home: empty, fetch: server({}).fetcher }), /abso login signs it in/);
84+ const home = signedIn();
85+ const expired = server({ "/orgs": { status: 401, body: { error: "missing or wrong token" } } });
86+ await assert.rejects(runOrgs(SERVER, { home, fetch: expired.fetcher }), /abso login renews it/);
87+ const off = server({ "/orgs": { status: 404, body: { error: "organizations aren't on here yet" } } });
88+ await assert.rejects(runOrgs(SERVER, { home, fetch: off.fetcher }), /api\.example\.dev: organizations aren't on/);
89+ });
91+ it("never prints the credential, even when the server echoes it", async () => {
92+ const home = signedIn();
93+ const s = server({ "/orgs": { status: 500, body: `oops ${CREDENTIAL}` } });
94+ await assert.rejects(runOrgs(SERVER, { home, fetch: s.fetcher }), (e: Error) => !e.message.includes(CREDENTIAL));
95+ });
96+});
98+describe("abso org <name>", () => {
99+ const acme = {
100+ name: "acme-labs",
101+ displayName: "Acme Labs",
102+ description: "We make labs.",
103+ role: "owner",
104+ membersCan: "write",
105+ whoMakesProjects: "members",
106+ members: [
107+ { id: "cf-1", role: "owner", name: "sam", raised: [] },
108+ { id: "cf-2", role: "member", name: null, raised: [{ project: "web", role: "owner" }] },
109+ ],
110+ projects: ["api", "web"],
111+ invites: [{ id: "inv_2", role: "member", kind: "link", for: null, expiresAt: "2026-10-16T10:00:00.000Z" }],
112+ };
114+ it("shows its projects, people, settings and open invites to a member, never a person's id", async () => {
115+ const home = signedIn();
116+ const s = server({ "/orgs/acme-labs": { status: 200, body: acme } });
117+ const out = await runOrg(args(["acme-labs"]), SERVER, { home, fetch: s.fetcher });
118+ assert.equal(
119+ out.text,
120+ [
121+ "acme-labs (Acme Labs)",
122+ " We make labs.",
123+ "You're an owner. Members can write every project; members make projects.",
124+ "Projects (2): api, web",
125+ "People (2):",
126+ " sam: owner",
127+ " (no name yet): member, raised to owner in web",
128+ "Open invites:",
129+ " a link, as member, until 2026-10-16 10:00 UTC",
130+ ].join("\n"),
131+ );
132+ assert.equal(out.text.includes("cf-"), false);
133+ });
135+ it("shows a non-member only what the org shows everyone", async () => {
136+ const home = signedIn();
137+ const s = server({
138+ "/orgs/acme-labs": { status: 200, body: { name: "acme-labs", displayName: "Acme Labs", description: null } },
139+ });
140+ const out = await runOrg(args(["acme-labs"]), SERVER, { home, fetch: s.fetcher });
141+ assert.equal(out.text, "acme-labs (Acme Labs)\nYou aren't a member, so its people and settings aren't shown.");
142+ });
144+ it("says when there's no such org", async () => {
145+ const home = signedIn();
146+ await assert.rejects(runOrg(args(["nope"]), SERVER, { home, fetch: server({}).fetcher }), /^.*nope: no such route/);
147+ });
149+ it("sends no change: each says where on the website it is made, and nothing reaches the server", async () => {
150+ const home = signedIn();
151+ const s = server({});
152+ const cases: [string[], RegExp][] = [
153+ [["acme-labs", "--invite", "sam"], /--invite is on acme-labs's People tab: https:\/\/example\.dev\/acme-labs\./],
154+ [["acme-labs", "--invite", "link"], /People tab/],
155+ [["acme-labs", "--role", "sam=owner"], /--role is on acme-labs's People tab/],
156+ [["acme-labs", "--remove", "jo"], /--remove is on/],
157+ [["acme-labs", "--leave"], /--leave is on acme-labs's People tab/],
158+ [["acme-labs", "--members", "read"], /--members is on acme-labs's Settings tab/],
159+ [["acme-labs", "--projects-by", "owners"], /--projects-by is on acme-labs's Settings tab/],
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(
164+ runOrg(args(line), SERVER, { home, fetch: s.fetcher }),
165+ /Organizations are changed on the website/,
166+ );
167+ }
168+ assert.deepEqual(s.asked, []);
169+ });
171+ it("takes one change at a time, and --as only with --invite", async () => {
172+ const home = signedIn();
173+ const s = server({});
174+ await assert.rejects(
175+ runOrg(args(["acme-labs", "--remove", "jo", "--leave"]), SERVER, { home, fetch: s.fetcher }),
176+ /one change at a time: --remove and --leave were given together/,
177+ );
178+ await assert.rejects(
179+ runOrg(args(["acme-labs", "--as", "owner"]), SERVER, { home, fetch: s.fetcher }),
180+ /--as goes with --invite/,
181+ );
182+ await assert.rejects(runOrg(args([]), SERVER, { home, fetch: s.fetcher }), /abso org <name>/);
183+ });
184+});
186+describe("the website for a server", () => {
187+ it("is the site api. serves, or the server itself", () => {
188+ assert.equal(siteOf("https://api.abso.dev"), "https://abso.dev");
189+ assert.equal(siteOf("https://staging.example.workers.dev/"), "https://staging.example.workers.dev");
190+ assert.equal(siteOf("http://localhost:8787"), "http://localhost:8787");
191+ });
192+});
194+describe("abso org new (abso 663)", () => {
195+ it("makes the org as the box's person, sending the box's sign-in and the shown name", async () => {
196+ const home = signedIn();
197+ const s = server({ "/box/orgs": { status: 200, body: { name: "acme-labs", displayName: "Acme Labs" } } });
198+ const out = await runOrg(args(["new", "acme-labs", "--name", "Acme Labs"]), SERVER, { home, fetch: s.fetcher });
199+ assert.match(
200+ out.text,
201+ /Made the organization acme-labs; you own it\. Its page: https:\/\/example\.dev\/acme-labs\./,
202+ );
203+ assert.equal(s.asked.length, 1);
204+ assert.equal(s.asked[0]?.method, "POST");
205+ assert.equal(s.asked[0]?.auth, `Box ${CREDENTIAL}`);
206+ assert.deepEqual(JSON.parse(s.asked[0]?.body ?? "{}"), { name: "acme-labs", displayName: "Acme Labs" });
207+ });
208+ it("says what the server says when the box's grant is a list, and never shows the credential", async () => {
209+ const home = signedIn();
210+ const s = server({
211+ "/box/orgs": { status: 403, body: { error: "only a box approved for all your projects makes organizations" } },
212+ });
213+ await assert.rejects(
214+ runOrg(args(["new", "acme-labs"]), SERVER, { home, fetch: s.fetcher }),
215+ (e: Error) =>
216+ /refused \(403\): only a box approved for all your projects/.test(e.message) && !e.message.includes(CREDENTIAL),
217+ );
218+ });
219+ it("needs a box signed in, and no other change flag", async () => {
220+ const empty = mkdtempSync(join(tmpdir(), "abso-orgs-"));
221+ await assert.rejects(
222+ runOrg(args(["new", "acme-labs"]), SERVER, { home: empty, fetch: server({}).fetcher }),
223+ /abso login signs it in/,
224+ );
225+ await assert.rejects(
226+ runOrg(args(["new", "acme-labs", "--leave"]), SERVER, { home: signedIn(), fetch: server({}).fetcher }),
227+ /takes --name only/,
228+ );
229+ });
230+});
232+describe("abso init --org with no box signed in", () => {
233+ it("says to sign in, or where the website makes it", () => {
234+ assert.throws(
235+ () => initInOrg("acme-labs", SERVER),
236+ /isn't signed in to https:\/\/api\.example\.dev.*abso init --org acme-labs again; or New project at https:\/\/example\.dev\./,
237+ );
238+ });
239+});
MCP
compare on this site's /mcp
CLI
abso diff 5 318 client/test/orgs.test.ts --json
JSON
/christopher/abso-core/compare/5..318?file=client%2Ftest%2Forgs.test.ts&format=json