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 286 to 287

Compare

+140 −0 in 1 place
new file, 140 lines
1+// Local projects (abso init --local): a project whose history is in a store on this machine, answered by the open
2+// server's own code in the client's process. Every test here runs with fetch replaced by one that throws, so any
3+// call that would leave the machine fails the test.
4+
5+import assert from "node:assert/strict";
6+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
7+import { tmpdir } from "node:os";
8+import { join } from "node:path";
9+import { after, before, describe, it } from "node:test";
10+import { main } from "../src/main.ts";
11+import { stateDir } from "../src/state-dir.ts";
13+const dirs: string[] = [];
14+const temp = (label: string) => {
15+ const d = mkdtempSync(join(tmpdir(), `abso-local-${label}-`));
16+ dirs.push(d);
17+ return d;
18+};
20+const outside: string[] = [];
21+const realFetch = globalThis.fetch;
22+before(() => {
23+ globalThis.fetch = (async (input: unknown) => {
24+ outside.push(String(input instanceof Request ? input.url : input));
25+ throw new TypeError("network is off in this test");
26+ }) as typeof fetch;
27+});
28+after(() => {
29+ globalThis.fetch = realFetch;
30+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
31+ assert.deepEqual(outside, [], "nothing reached for the network");
32+});
34+let store: string;
35+const env = () => ({ ABSO_STORE: store, ABSO_SERVERS_FILE: "no-servers.json", ABSO_HOOK_FORCE: "1" });
36+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string; err: string }> {
37+ const r = await main(argv, { cwd, env: env(), write: () => {} });
38+ return { exit: r.exit, out: r.stdout, err: r.stderr };
39+}
40+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), "utf8");
42+describe("a local project, with the network off", () => {
43+ let alice: string;
44+ let bob: string;
45+ before(() => {
46+ store = temp("store");
47+ });
49+ it("init --local makes the project in the store, with no sign-in", async () => {
50+ alice = temp("alice");
51+ writeFileSync(join(alice, "a.txt"), "one\ntwo\nthree\n");
52+ const r = await run(alice, "init", "--local", "--project", "demo", "--agent", "alice");
53+ assert.equal(r.exit, 0, r.out + r.err);
54+ assert.match(r.out, /Created project demo at version 0 from 2 text files/, "a.txt and the starting .absoignore");
55+ assert.doesNotMatch(r.out, /CI has nothing to run/);
56+ assert.match(r.out, /It's a local project: its history is in .*demo, on this machine/);
57+ assert.doesNotMatch(r.out + r.err, /Signing in/);
58+ assert.ok(existsSync(join(store, "demo", "project.sqlite")));
59+ const config = JSON.parse(readFileSync(join(stateDir(alice), "config.json"), "utf8"));
60+ assert.equal(config.server, "local");
61+ assert.equal(config.store, undefined, "the store came from ABSO_STORE, so the folder doesn't name it");
62+ });
64+ it("record and push make version 1, and log says so", async () => {
65+ writeFileSync(join(alice, "a.txt"), "one\nTWO\nthree\n");
66+ writeFileSync(join(alice, "b.txt"), "new\n");
67+ assert.equal((await run(alice, "record")).exit, 0);
68+ const pushed = await run(alice, "push", "-m", "Change two, add b");
69+ assert.equal(pushed.exit, 0, pushed.out + pushed.err);
70+ assert.match(pushed.out, /Pushed version 1/);
71+ const log = await run(alice, "log");
72+ assert.equal(log.exit, 0, log.err);
73+ assert.match(log.out, /Change two, add b/);
74+ });
76+ it("a second folder joins, and pulls what the first pushes", async () => {
77+ bob = temp("bob");
78+ const joined = await run(bob, "join", "demo", "--local", "--agent", "bob", "--dir", bob);
79+ assert.equal(joined.exit, 0, joined.out + joined.err);
80+ assert.equal(text(bob, "a.txt"), "one\nTWO\nthree\n");
81+ assert.equal(text(bob, "b.txt"), "new\n");
82+ writeFileSync(join(alice, "b.txt"), "new\nmore\n");
83+ assert.equal((await run(alice, "push", "-m", "More in b")).exit, 0);
84+ const pulled = await run(bob, "pull");
85+ assert.equal(pulled.exit, 0, pulled.out + pulled.err);
86+ assert.equal(text(bob, "b.txt"), "new\nmore\n");
87+ });
89+ it("blame names who wrote each line", async () => {
90+ const r = await run(bob, "blame", "a.txt");
91+ assert.equal(r.exit, 0, r.err);
92+ assert.match(r.out, /alice/);
93+ assert.match(r.out, /TWO/);
94+ });
96+ it("a push that collides with work pushed since is held", async () => {
97+ assert.equal((await run(bob, "pull")).exit, 0);
98+ writeFileSync(join(alice, "a.txt"), "one\nalice's\nthree\n");
99+ assert.equal((await run(alice, "push", "-m", "Alice's two")).exit, 0);
100+ writeFileSync(join(bob, "a.txt"), "one\nbob's\nthree\n");
101+ const held = await run(bob, "push", "-m", "Bob's two");
102+ assert.notEqual(held.exit, 0);
103+ assert.match(held.out + held.err, /collision/);
104+ });
105+});
107+describe("where a local project's store is", () => {
108+ it("--store inside the folder is kept in its settings and left out of its files", async () => {
109+ store = temp("unused");
110+ const dir = temp("venv");
111+ writeFileSync(join(dir, "a.txt"), "x\n");
112+ const r = await run(dir, "init", "--local", "--project", "beside", "--agent", "a", "--store", ".abso-store");
113+ assert.equal(r.exit, 0, r.out + r.err);
114+ assert.ok(existsSync(join(dir, ".abso-store", "beside", "project.sqlite")));
115+ assert.equal(JSON.parse(readFileSync(join(stateDir(dir), "config.json"), "utf8")).store, join(dir, ".abso-store"));
116+ assert.match(text(dir, ".absoignore"), /^\/\.abso-store\/$/m);
117+ assert.match(r.out, /from 2 text files/, "a.txt and .absoignore, not the store");
118+ // Every later command finds the store from the folder's settings, whatever ABSO_STORE says.
119+ writeFileSync(join(dir, "a.txt"), "y\n");
120+ assert.equal((await run(dir, "push", "-m", "y")).exit, 0);
121+ });
123+ it("--local refuses --server, and --store needs --local", async () => {
124+ const dir = temp("refuse");
125+ mkdirSync(join(dir, "x"));
126+ const both = await run(dir, "init", "--local", "--server", "https://abso.test", "--project", "p");
127+ assert.match(both.out + both.err, /--local or --server, not both/);
128+ const alone = await run(dir, "init", "--store", "s", "--project", "p");
129+ assert.match(alone.out + alone.err, /--store goes with --local/);
130+ });
132+ it("joining a project the store doesn't have leaves nothing behind", async () => {
133+ store = temp("empty");
134+ const dir = temp("nojoin");
135+ const r = await run(dir, "join", "nothing", "--local", "--agent", "a", "--dir", dir);
136+ assert.notEqual(r.exit, 0);
137+ assert.match(r.out + r.err, /no local project nothing/);
138+ assert.equal(existsSync(join(dir, ".abso")) || existsSync(join(dir, ".avcs")), false);
139+ });
140+});
MCP
compare on this site's /mcp
CLI
abso diff 286 287 client/test/local.test.ts --json
JSON
/christopher/abso-core/compare/286..287?file=client%2Ftest%2Flocal.test.ts&format=json