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 40 to 318

Compare

+88 −0 in 1 place
new file, 88 lines
1+// A pull whose answer never arrives (abso-core 26): the server has moved the agent's base, so later pulls
2+// send only what changed since then. The folder notes the pull it started and, until one is written, the
3+// next pull asks for every file and writes the ones that differ. Status says so in the meantime.
4+
5+import assert from "node:assert/strict";
6+import { existsSync, 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 { type Fake, startFake } from "./fake-server.ts";
13+const TOKEN = "test-token-not-secret";
14+const ENV = { AVCS_TOKEN: TOKEN, AVCS_HOOK_FORCE: "1", AVCS_SERVERS_FILE: "no-servers.json" };
16+let fake: Fake;
17+const dirs: string[] = [];
18+before(async () => {
19+ fake = await startFake(0, TOKEN);
20+});
21+after(async () => {
22+ await fake.close();
23+ for (const d of dirs) rmSync(d, { recursive: true, force: true, maxRetries: 5 });
24+});
26+function temp(): string {
27+ const d = mkdtempSync(join(tmpdir(), "abso-lost-pull-"));
28+ dirs.push(d);
29+ return d;
30+}
32+async function run(cwd: string, ...argv: string[]): Promise<{ exit: number; out: string }> {
33+ const r = await main(argv, { cwd, env: ENV, write: () => {} });
34+ return { exit: r.exit, out: r.stdout + r.stderr };
35+}
37+let projects = 0;
38+/** alice and bob on one project; alice pushes a change and a new file, and bob's pull of them is lost. */
39+async function lost(): Promise<{ alice: string; bob: string }> {
40+ const name = `lost${++projects}`;
41+ const alice = temp();
42+ writeFileSync(join(alice, "a.txt"), "one\n");
43+ assert.equal(
44+ (await run(alice, "init", "--server", fake.url, "--project", name, "--agent", "alice", "--as-is")).exit,
45+ 0,
46+ );
47+ const bob = temp();
48+ assert.equal((await run(bob, "join", name, "--agent", "bob", "--server", fake.url)).exit, 0);
49+ writeFileSync(join(alice, "a.txt"), "two\n");
50+ writeFileSync(join(alice, "b.txt"), "new\n");
51+ const pushed = await run(alice, "push", "-m", "Change a.txt and add b.txt");
52+ assert.equal(pushed.exit, 0, pushed.out);
53+ fake.loseSyncAnswers = 1;
54+ assert.notEqual((await run(bob, "pull")).exit, 0, "the pull whose answer was lost fails");
55+ return { alice, bob };
56+}
58+const text = (dir: string, rel: string) => readFileSync(join(dir, rel), "utf8");
60+describe("a pull whose answer never arrives", () => {
61+ it("leaves the folder as it was, and status says a pull didn't finish", async () => {
62+ const { bob } = await lost();
63+ assert.equal(text(bob, "a.txt"), "one\n");
64+ assert.equal(existsSync(join(bob, "b.txt")), false);
65+ const status = await run(bob, "status");
66+ assert.match(status.out, /A pull here didn't finish/);
67+ });
69+ it("the next pull asks for every file and writes what the lost one would have", async () => {
70+ const { bob } = await lost();
71+ const pulled = await run(bob, "pull");
72+ assert.equal(pulled.exit, 0, pulled.out);
73+ assert.match(pulled.out, /The last pull here didn't finish, so this one asked for every file/);
74+ assert.equal(text(bob, "a.txt"), "two\n");
75+ assert.equal(text(bob, "b.txt"), "new\n");
76+ assert.doesNotMatch((await run(bob, "status")).out, /A pull here didn't finish/);
77+ const again = await run(bob, "pull");
78+ assert.doesNotMatch(again.out, /didn't finish/, "once caught up, pulls are plain again");
79+ });
81+ it("keeps work done in the folder meanwhile", async () => {
82+ const { bob } = await lost();
83+ writeFileSync(join(bob, "a.txt"), "bob's own\n");
84+ const pulled = await run(bob, "pull");
85+ assert.equal(text(bob, "a.txt"), "bob's own\n", pulled.out);
86+ assert.equal(text(bob, "b.txt"), "new\n");
87+ });
88+});
MCP
compare on this site's /mcp
CLI
abso diff 40 318 client/test/lost-pull.test.ts --json
JSON
/christopher/abso-core/compare/40..318?file=client%2Ftest%2Flost-pull.test.ts&format=json