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
show on this site's /mcp
CLI
abso show 185 --json
JSON
/christopher/abso-core/versions/185?format=json

abso init, init --org and org new from a signed-in box (abso 663). On a server this box is signed in to and with no token for it, abso init makes the project as the person who approved the box, through the server's POST /box/projects (the website's own create): its folder (up to 24 MB) is the first version, --public or --private picks visibility (private by default), --org makes it an organization's project, and one Idempotency-Key per folder (kept in .abso/init-key until it finishes) makes a retry the same project. The folder then joins at once with its own key from the box (--agent, else the box's name). abso org new <name> [--name] makes an organization through POST /box/orgs. abso box and login say 'all of yours, now and later' for a member-all grant. Without a box, init and init --org say to abso login. Tests: orgs, box, help; full suite passes.

of shared·box-grants··Not checked

Version 184 · Files at version 185

6 files, 310 lines added, 29 removed.

--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -21,8 +21,15 @@
2121 */
2222export interface Grant {
2323 readonly projects: readonly { readonly project: string; readonly role: string }[];
24+ /** Version 2 grants (abso 663): member-all is every project of the approver's, now and later, at most this role. */
25+ readonly scopes?: readonly { readonly kind: string; readonly role: string }[];
2426}
2527
28+/** The role a box has in all its approver's projects, now and later, or null when its grant is a list (abso 663). */
29+export function allProjectsRole(grant: Grant): string | null {
30+ return grant.scopes?.find((scope) => scope.kind === "member-all")?.role ?? null;
31+}
2633/** Requested access is a suggestion for the person approving, never an authorization. */
2734export interface LoginRequest {
2835 readonly projects?: readonly { readonly project: string; readonly role: "reader" | "writer" | "owner" }[];
@@ -154,6 +161,7 @@
154161 body: unknown,
155162 credential: string | undefined,
156163 fetcher: typeof fetch,
164+ headers: Readonly<Record<string, string>> = {},
157165): Promise<Answer> {
158166 const secrets = credential ? [credential] : [];
159167 let response: Response;
@@ -162,6 +170,7 @@
162170 method: "POST",
163171 headers: {
164172 "content-type": "application/json",
173+ ...headers,
165174 ...(credential ? { authorization: `Box ${credential}` } : {}),
166175 },
167176 body: JSON.stringify(body),
@@ -316,6 +325,60 @@
316325 return { key, id };
317326}
318327
328+/** What a new project from this box starts with (abso 663): the website's own create, as the person who approved the box. */
329+export interface NewProject {
330+ readonly name: string;
331+ readonly owner?: string;
332+ readonly visibility?: "public" | "private";
333+ readonly files?: readonly (
334+ | { readonly path: string; readonly text: string }
335+ | { readonly path: string; readonly base64: string }
336+ )[];
337+}
339+/**
340+ * Makes a project as the person who approved this box (abso init, abso 663). One key for every try, so a retry after
341+ * a lost answer or a pending one is the same project, never a second.
342+ */
343+export async function boxCreateProject(
344+ record: BoxRecord,
345+ project: NewProject,
346+ key: string,
347+ fetcher: typeof fetch = fetch,
348+ sleep: (ms: number) => Promise<void> = (ms) => new Promise((done) => setTimeout(done, ms)),
349+): Promise<Record<string, unknown>> {
350+ for (let attempt = 1; ; attempt++) {
351+ const a = await call(record.server, "/box/projects", project, record.credential, fetcher, {
352+ "Idempotency-Key": key,
353+ });
354+ const pending = (a.body.operation as { state?: unknown } | undefined)?.state === "pending";
355+ if (!pending) return a.body;
356+ if (attempt >= 10)
357+ throw new UsageError(
358+ `${originOf(record.server)} is still making ${project.name}. Run the same abso init again in a minute: it picks up where this left off.`,
359+ );
360+ await sleep(1000 * attempt);
361+ }
362+}
364+/** Makes an organization as the person who approved this box (abso org new, abso 663). */
365+export async function boxCreateOrg(
366+ record: BoxRecord,
367+ name: string,
368+ displayName: string | undefined,
369+ fetcher: typeof fetch = fetch,
370+): Promise<Record<string, unknown>> {
371+ return (
372+ await call(
373+ record.server,
374+ "/box/orgs",
375+ { name, ...(displayName === undefined ? {} : { displayName }) },
376+ record.credential,
377+ fetcher,
378+ )
379+ ).body;
380+}
319382/** The agent name abso join takes when none is given: the box's name, lower-cased. */
320383export function defaultAgentName(): string {
321384 return boxName().toLowerCase();
@@ -375,9 +438,12 @@
375438 if (!record) return `This box isn't signed in to ${originOf(server)}. abso login signs it in.`;
376439 const g = record.grant;
377440 const expired = record.expiresAt <= now;
441+ const all = allProjectsRole(g);
378442 return [
379443 `Signed in to ${record.server} as box ${record.id}${expired ? ", but the sign-in has expired. abso login renews it." : "."}`,
380− `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(", ")}.`,
444+ all === null
445+ ? `Projects: ${g.projects.map((p) => `${p.project} (${p.role})`).join(", ")}.`
446+ : `Projects: all of yours, now and later (${all} at most). abso init makes a new one; abso org new makes an organization.`,
381447 `${expired ? "Expired" : "Expires"} ${day(record.expiresAt)} UTC.`,
382448 ].join("\n");
383449}
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -1,11 +1,20 @@
11// abso init and abso join: start a project from a folder, or join one into a folder.
22
3−import { existsSync, mkdirSync, readdirSync, rmSync, statSync, writeFileSync } from "node:fs";
3+import { randomUUID } from "node:crypto";
4+import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
45import { join, relative, resolve } from "node:path";
56import { Api, ApiError } from "./api.ts";
67import { bool, type Parsed, str, UsageError } from "./args.ts";
78import { writeKnownBlobs } from "./blobs.ts";
8−import { defaultAgentName, mintFreeName, mintKey, readBox } from "./box.ts";
9+import {
10+ type BoxRecord,
11+ boxCreateProject,
12+ defaultAgentName,
13+ mintFreeName,
14+ mintKey,
15+ type NewProject,
16+ readBox,
17+} from "./box.ts";
918import { STARTING_ABSOIGNORE } from "./check-ignore.ts";
1019import { CLIENT_DIR } from "./client-version.ts";
1120import { type Env, type Output, plural } from "./command-env.ts";
@@ -16,7 +25,7 @@
1625import { clearKnown, loadIgnore, readFolder, writeKnown } from "./folder.ts";
1726import { modInstalled } from "./install.ts";
1827import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
19−import { siteOf } from "./orgs.ts";
28+import { initInOrg, siteOf } from "./orgs.ts";
2029import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
2130import { refusedText } from "./safety.ts";
2231import { chooseServer, serverFlag } from "./server-choice.ts";
@@ -48,6 +57,15 @@
4857 if (findRoot(root) === root) throw new UsageError(`${root} already has .abso/config.json`);
4958 const project = str(args, "project");
5059 if (!project) throw new UsageError("give the project a name with --project <name>");
60+ if (bool(args, "public") && bool(args, "private")) throw new UsageError("--public or --private, not both");
61+ // A box signed in here, and no token for this server: the project is made as the person who approved the box,
62+ // the way the website makes one (abso 663).
63+ const server = serverFrom(args, env);
64+ const box = readBox(server);
65+ if (box && !tokenFor(server, env.env) && !fromEnv(env.env, "KEY_FILE"))
66+ return initFromBox(args, env, root, project, server, box);
67+ const org = str(args, "org");
68+ if (org !== undefined) return initInOrg(org, server);
5169 const config = makeSettings(args, env, project);
5270 const asIs = bool(args, "as-is");
5371 const absoignore = join(root, ".absoignore");
@@ -99,7 +117,107 @@
99117 };
100118}
101119
120+/** The most a new project's folder may be from a box: the server takes a body up to 25 MB, base64 and JSON included. */
121+const BOX_INIT_MAX = 24 * 1024 * 1024;
122+/** The Idempotency-Key of an abso init that didn't finish, so running it again makes the same project (abso 663). */
123+const INIT_KEY = "init-key";
102125/**
126+ * abso init from a signed-in box (abso 663): the server makes the project as the person who approved the box, the way the
127+ * website's New project does (owner, visibility, address), with the folder as its first version. This folder then
128+ * joins it like abso join, with its own key from the box, so it works at once with no new approval.
129+ */
130+async function initFromBox(
131+ args: Parsed,
132+ env: Env,
133+ root: string,
134+ project: string,
135+ server: string,
136+ box: BoxRecord,
137+): Promise<Output> {
138+ if (!NAME.test(project))
139+ throw new UsageError(
140+ `project names are letters, digits, dot, dash and underscore (got ${JSON.stringify(project)})`,
141+ );
142+ const named = str(args, "agent");
143+ if (named !== undefined) agentFrom(args);
144+ const asIs = bool(args, "as-is");
145+ const absoignore = join(root, ".absoignore");
146+ const wroteIgnore = !asIs && !existsSync(absoignore) && !existsSync(join(root, ".avcsignore"));
147+ if (wroteIgnore) writeFileSync(absoignore, STARTING_ABSOIGNORE);
148+ const wroteProject = asIs ? "exists" : writeStartingProjectFile(root);
149+ const { files, blobs, leftOut } = readFolder(root, loadIgnore(root));
150+ const listed: NonNullable<NewProject["files"]>[number][] = [
151+ ...[...files].map(([path, text]) => ({ path, text })),
152+ ...[...blobs].map(([path, b]) => ({ path, base64: Buffer.from(b.bytes).toString("base64") })),
153+ ];
154+ const org = str(args, "org");
155+ const body: NewProject = {
156+ name: project,
157+ ...(org === undefined ? {} : { owner: org }),
158+ ...(bool(args, "public")
159+ ? { visibility: "public" as const }
160+ : bool(args, "private")
161+ ? { visibility: "private" as const }
162+ : {}),
163+ ...(listed.length > 0 ? { files: listed } : {}),
164+ };
165+ if (JSON.stringify(body).length > BOX_INIT_MAX)
166+ throw new UsageError(
167+ `${root} is over 24 MB to send. Make ${project} with abso init on a smaller folder (or on the website), then copy the rest in and push.`,
168+ );
169+ // One key per folder until it finishes: running the same abso init again is the same project, never a second.
170+ const keyPath = join(stateDir(root), INIT_KEY);
171+ let key = existsSync(keyPath) ? readFileSync(keyPath, "utf8").trim() : "";
172+ if (!/^[0-9a-f-]{36}$/.test(key)) {
173+ key = randomUUID();
174+ mkdirSync(stateDir(root), { recursive: true });
175+ writeFileSync(keyPath, key);
176+ }
177+ const made = await boxCreateProject(box, body, key);
178+ const visibility = typeof made.visibility === "string" ? made.visibility : "private";
179+ const minted =
180+ named !== undefined
181+ ? { ...(await mintKey(box, project, named)), agent: named }
182+ : await mintFreeName(box, project, defaultAgentName());
183+ const config = { server, project, agent: minted.agent };
184+ writeConfig(root, config);
185+ clearKnown(root);
186+ installKey(root, JSON.stringify({ key: minted.key, id: minted.id }));
187+ rmSync(keyPath, { force: true });
188+ const synced = await syncFolder(root, new Api(readConfig(root, env.env)), true);
189+ const owner = org ?? "you";
190+ return {
191+ text: [
192+ `Created project ${project} (${visibility}, owned by ${owner}) at version ${synced.version} from ${plural(listed.length, "file")} in ${root}.`,
193+ ...leftOutText(leftOut),
194+ ...(wroteIgnore
195+ ? ["Wrote a starting .absoignore (Claude Code state and operating system files); edit it like .gitignore."]
196+ : []),
197+ ...startingProjectFileText(wroteProject),
198+ `This folder is agent ${minted.agent}, with its own key, ${minted.id}, made from this box's sign-in. Settings are in .abso/config.json.`,
199+ ...refusedText(synced.refused),
200+ ...(synced.written.length > 0 ? [`Wrote ${plural(synced.written.length, "file")} from shared.`] : []),
201+ hookHint(env.env),
202+ ].join("\n"),
203+ json: {
204+ project,
205+ id: made.id ?? null,
206+ owner: made.owner ?? null,
207+ visibility,
208+ version: synced.version,
209+ files: listed.length,
210+ root,
211+ agent: minted.agent,
212+ key_id: minted.id,
213+ wroteAbsoignore: wroteIgnore,
214+ wroteProjectFile: typeof wroteProject === "string" ? null : wroteProject,
215+ leftOut,
216+ },
217+ };
218+}
220+/**
103221 * Where abso join writes: --dir, else here when --agent is given (as before, so a folder prepared with
104222 * abso key install --server is joined where its key is). With no --agent: here when this folder is empty, else
105223 * ./<project>, which has to be new or empty so nobody's files are written over. A folder holding only abso's own
--- a/client/src/main.ts
+++ b/client/src/main.ts
@@ -46,7 +46,7 @@
4646import { runAck, runAnswer, runAsk, runIssue, runIssues, runReply, runSearch, runWaiting } from "./issues.ts";
4747import { adminToken, issuedPublic, keyList, keyListText, keyNew, keyRevoke } from "./key-admin.ts";
4848import { browserSkip, openInBrowser } from "./open-browser.ts";
49−import { initInOrg, runOrg, runOrgs } from "./orgs.ts";
49+import { runOrg, runOrgs } from "./orgs.ts";
5050import { runUnqueue } from "./queue.ts";
5151import { runNote, runNotes, runReview } from "./review.ts";
5252import {
@@ -97,14 +97,19 @@
9797
9898const COMMANDS: Readonly<Record<string, CommandDef>> = {
9999 init: {
100− flags: { server: "string", project: "string", agent: "string", "as-is": "boolean", org: "string" },
101− usage: "abso init [folder] --project <name> --agent <name> [--as-is] [--org <org>]",
102− about:
103− "Create a project on the server from a folder's text files The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). --org <org> makes it an organization's project: for now that is done on the website, and abso says where.",
104− run: (args, env) => {
105− const org = str(args, "org");
106− return org === undefined ? runInit(args, env) : initInOrg(org, boxServer(args, env));
100+ flags: {
101+ server: "string",
102+ project: "string",
103+ agent: "string",
104+ "as-is": "boolean",
105+ org: "string",
106+ public: "boolean",
107+ private: "boolean",
107108 },
109+ usage: "abso init [folder] --project <name> [--agent <name>] [--as-is] [--org <org>] [--public|--private]",
110+ about:
111+ "Create a project on the server from a folder's text files The folder becomes that agent's folder. It writes a starting .absoignore, and, when the folder has no avcs.json and package.json gives a check or a build to guess, an avcs.json (setup, check, build and out): what the server's CI runs on each new version of shared. Without one, CI runs what it can guess itself, or nothing. --as-is writes neither: the folder goes up exactly as it is (an import). On a server this box is signed in to (abso login, approving all your projects), the project is made as you, the way the website's New project makes it: you own it, it's private unless you say --public, and the folder joins it at once with its own key (--agent names it; else the box's name). --org <org> makes it that organization's project. Elsewhere it needs --agent and the server's token.",
112+ run: (args, env) => runInit(args, env),
108113 },
109114 key: {
110115 flags: {
@@ -278,7 +283,7 @@
278283 usage:
279284 "abso org <name> [--invite <person>|link [--as owner] | --role <person>=owner|member | --remove <person> | --leave | --members read|write | --projects-by members|owners] | abso org new <name> [--name <shown name>]",
280285 about:
281− "An organization: its projects, people, open invites and settings, as the person who approved this box's sign-in sees them (people and settings only to members). One change at a time. Changes and abso org new are made on the website for now, and abso says where.",
286+ "An organization: its projects, people, open invites and settings, as the person who approved this box's sign-in sees them (people and settings only to members). One change at a time. abso org new makes one as that person, from a box approved for all their projects; other changes are made on the website, and abso says where.",
282287 run: (args, env) => runOrg(args, boxServer(args, env)),
283288 },
284289 skill: {
--- a/client/src/orgs.ts
+++ b/client/src/orgs.ts
@@ -1,11 +1,12 @@
11// Organizations from the CLI: abso orgs and abso org <name>. They read as the
2−// person who approved this box's sign-in (abso login). Changing an org (new,
3−// invite, role, remove, leave, settings) and making a project in one are done on
4−// the website for now: a box sits where agents run, and its sign-in was given
5−// for project work, so the server takes only reads from it.
2+// person who approved this box's sign-in (abso login). abso org new makes one, and
3+// abso init --org makes a project in one, from a box approved for all its
4+// person's projects (abso 663). Changing an org (invite, role, remove, leave,
5+// settings) stays on the website: a box sits where agents run, so the server takes
6+// no other org change from it.
67
7−import { type Parsed, UsageError } from "./args.ts";
8−import { type Answer, boxGet, originOf, readBox } from "./box.ts";
8+import { type Parsed, str, UsageError } from "./args.ts";
9+import { type Answer, boxCreateOrg, boxGet, originOf, readBox } from "./box.ts";
910import type { Output } from "./commands.ts";
1011
1112/** The website for an API server: api.<site> serves <site>; any other server serves its own pages. */
@@ -30,7 +31,7 @@
3031];
3132
3233const WEBSITE_ONLY =
33− "Organizations are changed on the website for now; from the CLI they can only be read, as the person who approved this box's sign-in";
34+ "Organizations are changed on the website; from the CLI they can be read, and made with abso org new, as the person who approved this box's sign-in";
3435
3536/** Where the box's sign-in is read from and how the server is reached; tests pass their own. */
3637export interface OrgIo {
@@ -114,7 +115,18 @@
114115 const asked = CHANGES.filter((c) => args.flags.has(c.flag));
115116 if (first === "new") {
116117 if (second === undefined || more.length > 0) throw new UsageError('abso org new <name> [--name "<shown name>"]');
117− throw new UsageError(`${WEBSITE_ONLY}. Make ${second} at ${siteOf(server)}/orgs/new.`);
118+ if (asked.length > 0) throw new UsageError("abso org new takes --name only");
119+ const record = io.home === undefined ? readBox(server) : readBox(server, io.home);
120+ if (!record)
121+ throw new UsageError(
122+ `this box isn't signed in to ${originOf(server)}. abso login signs it in; approve all your projects to make organizations from here`,
123+ );
124+ const made = await boxCreateOrg(record, second, str(args, "name"), io.fetch);
125+ const name = typeof made.name === "string" ? made.name : second;
126+ return {
127+ text: `Made the organization ${name}; you own it. Its page: ${siteOf(server)}/${name}. abso init --org ${name} --project <name> makes a project in it.`,
128+ json: { org: made },
129+ };
118130 }
119131 if (first === undefined || second !== undefined)
120132 throw new UsageError("abso org <name> [one change], or abso org new <name>");
@@ -166,9 +178,9 @@
166178 return { text: lines.join("\n"), json: { org } };
167179}
168180
169−/** abso init --org: making a project in an org is a website step for now. */
181+/** abso init --org with no box signed in to the server: an org's project is made as the person who approved one (abso 663). */
170182export function initInOrg(org: string, server: string): never {
171183 throw new UsageError(
172− `projects in an organization are made on the website for now: New project at ${siteOf(server)}, with ${org} as its owner.`,
184+ `this box isn't signed in to ${originOf(server)}, and a project in ${org} is made as a signed-in person. abso login, approving all your projects, then abso init --org ${org} again; or New project at ${siteOf(server)}.`,
173185 );
174186}
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -9,6 +9,7 @@
99import { test } from "node:test";
1010import { parseArgs } from "../src/args.ts";
1111import {
12+ boxCreateProject,
1213 boxPublic,
1314 boxText,
1415 forgetBox,
@@ -419,3 +420,41 @@
419420 "snow is this box's already: never minted again, which would replace its key",
420421 );
421422});
424+test("abso init from a box (abso 663): one key for every try, waiting out a pending create; abso box says all projects", async () => {
425+ const record = { server: SERVER, id: "b_1", credential: CREDENTIAL, grant, expiresAt: Date.now() + 86_400_000 };
426+ const seen: { path: string; key: string | null; auth: string | null; body: string }[] = [];
427+ let calls = 0;
428+ const fetcher = (async (url: string | URL | Request, init?: RequestInit) => {
429+ const headers = new Headers(init?.headers);
430+ seen.push({
431+ path: new URL(String(url)).pathname,
432+ key: headers.get("idempotency-key"),
433+ auth: headers.get("authorization"),
434+ body: String(init?.body),
435+ });
436+ calls++;
437+ const body =
438+ calls < 3
439+ ? { operation: { id: "op", state: "pending" } }
440+ : { project: "made", id: "proj_1", visibility: "private" };
441+ return new Response(JSON.stringify(body), { status: calls < 3 ? 202 : 200 });
442+ }) as typeof fetch;
443+ const made = await boxCreateProject(
444+ record,
445+ { name: "made", files: [{ path: "a.txt", text: "hi\n" }] },
446+ "33333333-3333-4333-8333-333333333333",
447+ fetcher,
448+ async () => {},
449+ );
450+ assert.equal(made.id, "proj_1");
451+ assert.equal(seen.length, 3);
452+ assert.ok(seen.every((s) => s.path === "/box/projects" && s.key === "33333333-3333-4333-8333-333333333333"));
453+ assert.ok(seen.every((s) => s.auth === `Box ${CREDENTIAL}`));
454+ assert.deepEqual(JSON.parse(seen[0]!.body), { name: "made", files: [{ path: "a.txt", text: "hi\n" }] });
455+ const all = { ...record, grant: { projects: [], scopes: [{ kind: "member-all", role: "writer" }] } };
456+ assert.match(
457+ boxText(all, SERVER),
458+ /Projects: all of yours, now and later \(writer at most\)\. abso init makes a new one/,
459+ );
460+});
--- a/client/test/orgs.test.ts
+++ b/client/test/orgs.test.ts
@@ -31,13 +31,14 @@
3131
3232/** A stand-in server: answers from `routes` by path, and keeps what was asked. */
3333function server(routes: Record<string, { status: number; body: unknown }>) {
34− const asked: { url: string; method: string; auth: string | null }[] = [];
34+ const asked: { url: string; method: string; auth: string | null; body?: string }[] = [];
3535 const fetcher = (async (url: string | URL | Request, init?: RequestInit) => {
3636 const u = new URL(String(url));
3737 asked.push({
3838 url: String(url),
3939 method: init?.method ?? "GET",
4040 auth: new Headers(init?.headers).get("authorization"),
41+ ...(typeof init?.body === "string" ? { body: init.body } : {}),
4142 });
4243 const r = routes[u.pathname] ?? { status: 404, body: { error: "no such route" } };
4344 return new Response(JSON.stringify(r.body), { status: r.status });
@@ -156,11 +157,13 @@
156157 [["acme-labs", "--leave"], /--leave is on acme-labs's People tab/],
157158 [["acme-labs", "--members", "read"], /--members is on acme-labs's Settings tab/],
158159 [["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\./],
160160 ];
161161 for (const [line, said] of cases) {
162162 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/);
163+ await assert.rejects(
164+ runOrg(args(line), SERVER, { home, fetch: s.fetcher }),
165+ /Organizations are changed on the website/,
166+ );
164167 }
165168 assert.deepEqual(s.asked, []);
166169 });
@@ -188,11 +191,49 @@
188191 });
189192});
190193
191−describe("abso init --org", () => {
192− it("says the project is made on the website for now, with the org as its owner", () => {
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", () => {
193234 assert.throws(
194235 () => initInOrg("acme-labs", SERVER),
195− /made on the website for now: New project at https:\/\/example\.dev, with acme-labs as its owner/,
236+ /isn't signed in to https:\/\/api\.example\.dev.*abso init --org acme-labs again; or New project at https:\/\/example\.dev\./,
196237 );
197238 });
198239});