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 64 --json
JSON
/christopher/abso-core/versions/64?format=json

join: a folder prepared with abso key install --server is joined where it is again (Pinch's catch on 63).

of shared·trials··Not checked

  • --agent keeps 'here' as the default, as before 63, so scripts that join into a prepared folder still do. The ./<project> rule is only for a join with no --agent.
  • A folder holding only abso's own state folder (.abso, or the older .avcs) counts as empty.
  • New tests: joinFolder's rule (empty, only .abso, files here, --agent, --dir, a taken ./<project>), and a runJoin test that installs a key with --server and joins with --agent and no --dir: it joins here and sends that key (the shared token is wrong, so only the key gets through). The git line-endings test is back to joining without --dir.
  • Issue numbers taken out of the new code comments and test names.

Version 63 · Files at version 64

4 files, 60 lines added, 31 removed.

--- a/client/src/box.ts
+++ b/client/src/box.ts
@@ -277,13 +277,13 @@
277277 return { key, id };
278278}
279279
280−/** The agent name abso join takes when none is given (abso issue 351): the box's name, lower-cased. */
280+/** The agent name abso join takes when none is given: the box's name, lower-cased. */
281281export function defaultAgentName(): string {
282282 return boxName().toLowerCase();
283283}
284284
285285/**
286− * abso join with no --agent (abso issue 351): mints a key under `base`, else `base`-2, -3 and so on. Names this
286+ * abso join with no --agent: mints a key under `base`, else `base`-2, -3 and so on. Names this
287287 * box already holds in the project are skipped without asking, since minting one again would replace that agent's
288288 * key and cut off its folder. A name the server says is taken (409) moves on to the next; any other refusal, the
289289 * box's agent limit among them, is said as it is.
--- a/client/src/join-commands.ts
+++ b/client/src/join-commands.ts
@@ -18,10 +18,10 @@
1818import { type FullMode, foldModes, writeKnownModes } from "./modes.ts";
1919import { projectFileName, readProjectFile, startingProjectFileText, writeStartingProjectFile } from "./project-file.ts";
2020import { refusedText } from "./safety.ts";
21−import { stateDir } from "./state-dir.ts";
21+import { OLD_STATE_DIR, STATE_DIR, stateDir } from "./state-dir.ts";
2222
2323/**
24− * The server to join or start on (abso issue 349): --server, then ABSO_SERVER, then the server this box is signed in
24+ * The server to join or start on: --server, then ABSO_SERVER, then the server this box is signed in
2525 * to (abso login wrote it), then https://api.abso.dev. A box signed in to more than one server has to say which.
2626 */
2727export function serverFrom(args: Parsed, env: Pick<Env, "env">, home?: string): string {
@@ -106,13 +106,16 @@
106106}
107107
108108/**
109− * Where abso join writes (abso issue 351): --dir, else here when this folder is empty, else ./<project>, which has
110− * to be new or empty so nobody's files are written over.
109+ * Where abso join writes: --dir, else here when --agent is given (as before, so a folder prepared with
110+ * abso key install --server is joined where its key is). With no --agent: here when this folder is empty, else
111+ * ./<project>, which has to be new or empty so nobody's files are written over. A folder holding only abso's own
112+ * state folder counts as empty.
111113 */
112−function joinFolder(args: Parsed, env: Env, project: string): string {
114+export function joinFolder(args: Parsed, env: Pick<Env, "cwd">, project: string): string {
113115 const dir = str(args, "dir");
114116 if (dir !== undefined) return resolve(env.cwd, dir);
115− const empty = (path: string) => readdirSync(path).length === 0;
117+ if (str(args, "agent") !== undefined) return resolve(env.cwd);
118+ const empty = (path: string) => readdirSync(path).every((name) => name === STATE_DIR || name === OLD_STATE_DIR);
116119 if (empty(env.cwd)) return resolve(env.cwd);
117120 const sub = resolve(env.cwd, project);
118121 if (existsSync(sub) && (!statSync(sub).isDirectory() || !empty(sub)))
@@ -140,7 +143,7 @@
140143 agent = agentFrom(args);
141144 minted = box && !hasKey ? await mintKey(box, project, agent) : undefined;
142145 } else {
143− // abso issue 351: no --agent takes the box's name, or the next free -2, -3.
146+ // No --agent: the box's name, or the next free -2, -3.
144147 if (!box) throw new UsageError("abso login signs this box in first (or give --agent <name>)");
145148 if (hasKey) throw new UsageError(`${root} already has a key: give its agent's name with --agent <name>`);
146149 const free = await mintFreeName(box, project, defaultAgentName());
--- a/client/test/box.test.ts
+++ b/client/test/box.test.ts
@@ -284,7 +284,7 @@
284284 assert.equal(forgetBox(SERVER, h), false);
285285});
286286
287−test("join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev (abso issue 349)", () => {
287+test("join and init pick the server: --server, ABSO_SERVER, the box's sign-in, then api.abso.dev", () => {
288288 const h = home();
289289 const args = (server?: string) => ({ positionals: [], flags: new Map(server ? [["server", server]] : []) });
290290 const none = { env: {} };
@@ -307,7 +307,7 @@
307307 assert.equal(serverFrom(args(SERVER), none, h), SERVER, "--server settles it");
308308});
309309
310−test("join with no --agent takes the box's name, skips names this box holds, and moves past a taken one (abso issue 351)", async () => {
310+test("join with no --agent takes the box's name, skips names this box holds, and moves past a taken one", async () => {
311311 const seen: Seen = [];
312312 const fetcher = server(
313313 [
--- a/client/test/client.test.ts
+++ b/client/test/client.test.ts
@@ -23,7 +23,7 @@
2323import { createServer as createHttpServer } from "node:http";
2424import { type AddressInfo, createServer as createTcpServer } from "node:net";
2525import { tmpdir } from "node:os";
26−import { dirname, join, relative, sep } from "node:path";
26+import { dirname, join, relative, resolve, sep } from "node:path";
2727import { after, before, describe, it } from "node:test";
2828import { fileURLToPath } from "node:url";
2929import { Api, LOG_PAGE, PUBLISH_TIMEOUT_MS, timeoutFor } from "../src/api.ts";
@@ -33,6 +33,7 @@
3333import { restoreLines, sinceTest } from "../src/changes.ts";
3434import { ciText } from "../src/ci.ts";
3535import { collisionText, parallelScript, runCommand, sameVersionHint, undoGitBashPaths } from "../src/commands.ts";
36+import { installKey } from "../src/config.ts";
3637import {
3738 isLocalOnly,
3839 isSkippedPart,
@@ -48,6 +49,7 @@
4849import { unifiedDiff } from "../src/diff.ts";
4950import { absolute, knownPath, unrecorded, writeFileAtomic } from "../src/folder.ts";
5051import { runHook } from "../src/hook.ts";
52+import { joinFolder } from "../src/join-commands.ts";
5153import { tryFolderLock } from "../src/lock.ts";
5254import { boxServer, commandTable, main } from "../src/main.ts";
5355import { argvFor, confineCall, mcpTools } from "../src/mcp.ts";
@@ -525,7 +527,7 @@
525527 git("init", "-q");
526528 git("config", "core.autocrlf", "false");
527529 write(bob, { ".gitattributes": "*.txt eol=crlf\n*.bin -text\n" });
528− assert.equal((await avcs(bob, "join", name, "--agent", "bob", "--server", fake.url, "--dir", ".")).exit, 0);
530+ assert.equal((await avcs(bob, "join", name, "--agent", "bob", "--server", fake.url)).exit, 0);
529531 write(folders.alice!, { "a.txt": "one\ntwo\n", "b.md": "one\ntwo\n", "c.bin": "x\ny\n" });
530532 assert.equal((await avcs(folders.alice!, "publish", "-m", "three files")).exit, 0);
531533 assert.equal((await avcs(bob, "sync")).exit, 0);
@@ -2542,29 +2544,53 @@
25422544 assert.doesNotMatch(without.stdout, /Nothing is installed/);
25432545 });
25442546
2545− it("join writes here when this folder is empty, else into ./<project>, never over someone's files (abso issue 351)", async () => {
2546− const { name } = await project({ "a.ts": "one\n" }, "alice");
2547− const run = (cwd: string, agent: string) =>
2548− main(["join", name, "--agent", agent, "--server", fake.url], { cwd, env: ENV, write: () => {} });
2547+ it("join with no --agent writes here when this folder is empty, else into ./<project>, never over someone's files", () => {
2548+ const args = (...words: string[]) => parseArgs("join", ["p", ...words], { agent: "string", dir: "string" });
25492549 const empty = temp();
2550− const here = await run(empty, "bob");
2551− assert.equal(here.exit, 0, here.stderr);
2552− assert.equal(read(empty, "a.ts"), "one\n", "an empty folder: here");
2553− assert.doesNotMatch(here.stdout, /^cd /m);
2550+ assert.equal(joinFolder(args(), { cwd: empty }, "p"), resolve(empty));
2551+ const prepared = temp();
2552+ mkdirSync(join(prepared, ".abso"));
2553+ assert.equal(joinFolder(args(), { cwd: prepared }, "p"), resolve(prepared), "only abso's own folder: still empty");
25542554 const busy = temp();
25552555 write(busy, { "notes.md": "mine\n" });
2556− const sub = await run(busy, "carol");
2557− assert.equal(sub.exit, 0, sub.stderr);
2558− assert.equal(read(join(busy, name), "a.ts"), "one\n", "a folder with files in it: ./<project>");
2559− assert.equal(read(busy, "notes.md"), "mine\n");
2560− assert.match(sub.stdout, new RegExp(`^cd ${name}$`, "m"));
2561− const taken = temp();
2562− write(taken, { "notes.md": "mine\n", [`${name}/other.md`]: "theirs\n" });
2563− const refused = await run(taken, "dave");
2564− assert.notEqual(refused.exit, 0);
2565− assert.match(refused.stderr, /already has files in it: say where to join with --dir <folder>/);
2556+ assert.equal(joinFolder(args(), { cwd: busy }, "p"), resolve(busy, "p"), "files here: ./<project>");
2557+ assert.equal(joinFolder(args("--agent", "bob"), { cwd: busy }, "p"), resolve(busy), "--agent: here, as before");
2558+ assert.equal(joinFolder(args("--dir", "x"), { cwd: busy }, "p"), resolve(busy, "x"));
2559+ write(busy, { "p/other.md": "theirs\n" });
2560+ assert.throws(
2561+ () => joinFolder(args(), { cwd: busy }, "p"),
2562+ /already has files in it: say where to join with --dir <folder>/,
2563+ );
25662564 });
25672565
2566+ it("join --agent joins a folder prepared with abso key install --server where it is, and sends that key", async () => {
2567+ const KEY = "abso_sk_prepared-before-join-0123456789";
2568+ const keyed = await startFake(0, KEY);
2569+ try {
2570+ const seed = temp();
2571+ write(seed, { "a.ts": "one\n" });
2572+ const env = { ...ENV, AVCS_TOKEN: KEY };
2573+ const init = await main(["init", "--server", keyed.url, "--project", "prep", "--agent", "alice"], {
2574+ cwd: seed,
2575+ env,
2576+ write: () => {},
2577+ });
2578+ assert.equal(init.exit, 0, init.stderr);
2579+ const dir = temp();
2580+ installKey(dir, JSON.stringify({ key: KEY, id: "k_0123abcd" }), keyed.url);
2581+ const joined = await main(["join", "prep", "--agent", "bob", "--server", keyed.url], {
2582+ cwd: dir,
2583+ env: { ...ENV, AVCS_TOKEN: "not-the-key" },
2584+ write: () => {},
2585+ });
2586+ assert.equal(joined.exit, 0, joined.stderr);
2587+ assert.equal(read(dir, "a.ts"), "one\n", "joined here, not in ./prep");
2588+ assert.doesNotMatch(joined.stdout, /^cd /m);
2589+ } finally {
2590+ await keyed.close();
2591+ }
2592+ });
25682594 it("gives a call more time by what it sends: 1 s per 100 KB over the base (abso issue 34)", () => {
25692595 assert.equal(timeoutFor(30_000, undefined), 30_000);
25702596 assert.equal(timeoutFor(30_000, "{}"), 30_000);