{"draft":null,"from":63,"to":64,"files":[{"path":"client/test/client.test.ts","added":46,"removed":20,"diff":"--- a/client/test/client.test.ts\n+++ b/client/test/client.test.ts\n@@ -23,7 +23,7 @@\n import { createServer as createHttpServer } from \"node:http\";\n import { type AddressInfo, createServer as createTcpServer } from \"node:net\";\n import { tmpdir } from \"node:os\";\n-import { dirname, join, relative, sep } from \"node:path\";\n+import { dirname, join, relative, resolve, sep } from \"node:path\";\n import { after, before, describe, it } from \"node:test\";\n import { fileURLToPath } from \"node:url\";\n import { Api, LOG_PAGE, PUBLISH_TIMEOUT_MS, timeoutFor } from \"../src/api.ts\";\n@@ -33,6 +33,7 @@\n import { restoreLines, sinceTest } from \"../src/changes.ts\";\n import { ciText } from \"../src/ci.ts\";\n import { collisionText, parallelScript, runCommand, sameVersionHint, undoGitBashPaths } from \"../src/commands.ts\";\n+import { installKey } from \"../src/config.ts\";\n import {\n \tisLocalOnly,\n \tisSkippedPart,\n@@ -48,6 +49,7 @@\n import { unifiedDiff } from \"../src/diff.ts\";\n import { absolute, knownPath, unrecorded, writeFileAtomic } from \"../src/folder.ts\";\n import { runHook } from \"../src/hook.ts\";\n+import { joinFolder } from \"../src/join-commands.ts\";\n import { tryFolderLock } from \"../src/lock.ts\";\n import { boxServer, commandTable, main } from \"../src/main.ts\";\n import { argvFor, confineCall, mcpTools } from \"../src/mcp.ts\";\n@@ -525,7 +527,7 @@\n \t\tgit(\"init\", \"-q\");\n \t\tgit(\"config\", \"core.autocrlf\", \"false\");\n \t\twrite(bob, { \".gitattributes\": \"*.txt eol=crlf\\n*.bin -text\\n\" });\n-\t\tassert.equal((await avcs(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url, \"--dir\", \".\")).exit, 0);\n+\t\tassert.equal((await avcs(bob, \"join\", name, \"--agent\", \"bob\", \"--server\", fake.url)).exit, 0);\n \t\twrite(folders.alice!, { \"a.txt\": \"one\\ntwo\\n\", \"b.md\": \"one\\ntwo\\n\", \"c.bin\": \"x\\ny\\n\" });\n \t\tassert.equal((await avcs(folders.alice!, \"publish\", \"-m\", \"three files\")).exit, 0);\n \t\tassert.equal((await avcs(bob, \"sync\")).exit, 0);\n@@ -2542,29 +2544,53 @@\n \t\tassert.doesNotMatch(without.stdout, /Nothing is installed/);\n \t});\n \n-\tit(\"join writes here when this folder is empty, else into ./<project>, never over someone's files (abso issue 351)\", async () => {\n-\t\tconst { name } = await project({ \"a.ts\": \"one\\n\" }, \"alice\");\n-\t\tconst run = (cwd: string, agent: string) =>\n-\t\t\tmain([\"join\", name, \"--agent\", agent, \"--server\", fake.url], { cwd, env: ENV, write: () => {} });\n+\tit(\"join with no --agent writes here when this folder is empty, else into ./<project>, never over someone's files\", () => {\n+\t\tconst args = (...words: string[]) => parseArgs(\"join\", [\"p\", ...words], { agent: \"string\", dir: \"string\" });\n \t\tconst empty = temp();\n-\t\tconst here = await run(empty, \"bob\");\n-\t\tassert.equal(here.exit, 0, here.stderr);\n-\t\tassert.equal(read(empty, \"a.ts\"), \"one\\n\", \"an empty folder: here\");\n-\t\tassert.doesNotMatch(here.stdout, /^cd /m);\n+\t\tassert.equal(joinFolder(args(), { cwd: empty }, \"p\"), resolve(empty));\n+\t\tconst prepared = temp();\n+\t\tmkdirSync(join(prepared, \".abso\"));\n+\t\tassert.equal(joinFolder(args(), { cwd: prepared }, \"p\"), resolve(prepared), \"only abso's own folder: still empty\");\n \t\tconst busy = temp();\n \t\twrite(busy, { \"notes.md\": \"mine\\n\" });\n-\t\tconst sub = await run(busy, \"carol\");\n-\t\tassert.equal(sub.exit, 0, sub.stderr);\n-\t\tassert.equal(read(join(busy, name), \"a.ts\"), \"one\\n\", \"a folder with files in it: ./<project>\");\n-\t\tassert.equal(read(busy, \"notes.md\"), \"mine\\n\");\n-\t\tassert.match(sub.stdout, new RegExp(`^cd ${name}$`, \"m\"));\n-\t\tconst taken = temp();\n-\t\twrite(taken, { \"notes.md\": \"mine\\n\", [`${name}/other.md`]: \"theirs\\n\" });\n-\t\tconst refused = await run(taken, \"dave\");\n-\t\tassert.notEqual(refused.exit, 0);\n-\t\tassert.match(refused.stderr, /already has files in it: say where to join with --dir <folder>/);\n+\t\tassert.equal(joinFolder(args(), { cwd: busy }, \"p\"), resolve(busy, \"p\"), \"files here: ./<project>\");\n+\t\tassert.equal(joinFolder(args(\"--agent\", \"bob\"), { cwd: busy }, \"p\"), resolve(busy), \"--agent: here, as before\");\n+\t\tassert.equal(joinFolder(args(\"--dir\", \"x\"), { cwd: busy }, \"p\"), resolve(busy, \"x\"));\n+\t\twrite(busy, { \"p/other.md\": \"theirs\\n\" });\n+\t\tassert.throws(\n+\t\t\t() => joinFolder(args(), { cwd: busy }, \"p\"),\n+\t\t\t/already has files in it: say where to join with --dir <folder>/,\n+\t\t);\n \t});\n \n+\tit(\"join --agent joins a folder prepared with abso key install --server where it is, and sends that key\", async () => {\n+\t\tconst KEY = \"abso_sk_prepared-before-join-0123456789\";\n+\t\tconst keyed = await startFake(0, KEY);\n+\t\ttry {\n+\t\t\tconst seed = temp();\n+\t\t\twrite(seed, { \"a.ts\": \"one\\n\" });\n+\t\t\tconst env = { ...ENV, AVCS_TOKEN: KEY };\n+\t\t\tconst init = await main([\"init\", \"--server\", keyed.url, \"--project\", \"prep\", \"--agent\", \"alice\"], {\n+\t\t\t\tcwd: seed,\n+\t\t\t\tenv,\n+\t\t\t\twrite: () => {},\n+\t\t\t});\n+\t\t\tassert.equal(init.exit, 0, init.stderr);\n+\t\t\tconst dir = temp();\n+\t\t\tinstallKey(dir, JSON.stringify({ key: KEY, id: \"k_0123abcd\" }), keyed.url);\n+\t\t\tconst joined = await main([\"join\", \"prep\", \"--agent\", \"bob\", \"--server\", keyed.url], {\n+\t\t\t\tcwd: dir,\n+\t\t\t\tenv: { ...ENV, AVCS_TOKEN: \"not-the-key\" },\n+\t\t\t\twrite: () => {},\n+\t\t\t});\n+\t\t\tassert.equal(joined.exit, 0, joined.stderr);\n+\t\t\tassert.equal(read(dir, \"a.ts\"), \"one\\n\", \"joined here, not in ./prep\");\n+\t\t\tassert.doesNotMatch(joined.stdout, /^cd /m);\n+\t\t} finally {\n+\t\t\tawait keyed.close();\n+\t\t}\n+\t});\n+\n \tit(\"gives a call more time by what it sends: 1 s per 100 KB over the base (abso issue 34)\", () => {\n \t\tassert.equal(timeoutFor(30_000, undefined), 30_000);\n \t\tassert.equal(timeoutFor(30_000, \"{}\"), 30_000);"}],"unmatched":[]}