- MCP
- code on this site's /mcp
- CLI
- none: the JSON below is the answer
- JSON
- /christopher/abso-core/files/client/test/failed-start.test.ts?format=json
60 linespinch 100%Last change pinch in version 281, 1 version changed it
1// An init or join that fails against the server leaves the folder as it was, so the same command can run again:
2// no starting .absoignore or abso.json from init, no .abso/ from join (but a key already here stays).
4import assert from "node:assert/strict";
5import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, writeFileSync } from "node:fs";
6import { tmpdir } from "node:os";
7import { join } from "node:path";
8import { after, describe, it } from "node:test";
9import { main } from "../src/main.ts";
11// Nothing listens on port 1, so every call fails to connect.
12const DOWN = "http://127.0.0.1:1";
13const ENV = { ABSO_TOKEN: "test-token-not-secret", ABSO_SERVERS_FILE: "no-servers.json" };
15const dirs: string[] = [];
16after(() => {
17 for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
18});
20function temp(): string {
21 const d = mkdtempSync(join(tmpdir(), "abso-failed-start-"));
22 dirs.push(d);
23 return d;
24}
26async function run(cwd: string, ...argv: string[]): Promise<number> {
27 return (await main(argv, { cwd, env: ENV, write: () => {} })).exit;
28}
30describe("a failed start", () => {
31 it("init takes back the .absoignore and abso.json it wrote", async () => {
32 const dir = temp();
33 writeFileSync(join(dir, "package.json"), `${JSON.stringify({ scripts: { test: "node --test" } })}\n`);
34 assert.notEqual(await run(dir, "init", "--server", DOWN, "--project", "p", "--agent", "a"), 0);
35 assert.deepEqual(readdirSync(dir), ["package.json"]);
36 });
38 it("join leaves no .abso folder", async () => {
39 const dir = temp();
40 assert.notEqual(await run(dir, "join", "p", "--server", DOWN, "--agent", "a", "--dir", dir), 0);
41 assert.equal(existsSync(join(dir, ".abso")), false);
42 });
44 it("join keeps a key that was already here", async () => {
45 const dir = temp();
46 mkdirSync(join(dir, ".abso"));
47 const key = { server: DOWN, key: "abso_sk_not-a-real-key", id: "k_0123abcd" };
48 writeFileSync(join(dir, ".abso", "key"), `${JSON.stringify(key)}\n`);
49 assert.notEqual(await run(dir, "join", "p", "--server", DOWN, "--agent", "a", "--dir", dir), 0);
50 assert.deepEqual(readdirSync(join(dir, ".abso")), ["key"]);
51 });
53 it("join with a key it can't read leaves only that key", async () => {
54 const dir = temp();
55 mkdirSync(join(dir, ".abso"));
56 writeFileSync(join(dir, ".abso", "key"), "{}\n");
57 assert.notEqual(await run(dir, "join", "p", "--server", DOWN, "--agent", "a", "--dir", dir), 0);
58 assert.deepEqual(readdirSync(join(dir, ".abso")), ["key"]);
59 });
60});