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
54 linescapacity 100%Last change capacity in version 212, 1 version changed it

You're reading version 308. The newest is 318, and no version since then changed this file. Go to the newestCompare with 318

1// Reads of agents' drafts on a writer-backed project (abso Capacity): where and draft collisions find files and
2// lines by line number, take moves from the draft's base, and gather each draft's claimants once among all the
3// drafts. They must answer as the in-memory project does: drafts that edit, delete a whole file, collide on a line,
4// define the same name, and sit on bases before and after a move.
5
6import assert from "node:assert/strict";
7import { test } from "node:test";
8import { storedArray } from "../../../src/engine/state-source.ts";
9import { SqlState } from "../../../src/engine/test/storage-helper.ts";
10import { MemoryStore, Project } from "../project.ts";
11import type { Entry, ProjectStore } from "../project-types.ts";
12import { where } from "../where.ts";
14function writer() {
15 const storage = new SqlState();
16 const entries = storedArray<Entry>(storage, "canonical-log");
17 const store: ProjectStore = {
18 append(batch) {
19 for (const entry of batch) entries.push(entry);
20 },
21 };
22 return new Project(store, { writerStorage: storage });
25const big = Array.from({ length: 300 }, (_, i) => `generated ${i}\n`).join("");
27function history(project: Project) {
28 let t = 0;
29 project.init({ "a.ts": "one\ntwo\nthree\nfour\n", "big.txt": big, "c.ts": "const x = 1;\n" }, t);
30 // One agent's base is before a move, the others' after it.
31 project.sync("old");
32 project.record("old", { "a.ts": "one\ntwo\nthree\nfour\nfive\n" }, ++t);
33 project.move("mover", "c.ts", "d.ts", ++t);
34 assert.equal(project.publish("mover", "Move c to d", ++t).ok, true);
35 project.record("ann", { "a.ts": "one\nTWO\nthree\nfour\n", "d.ts": "const x = 2;\n" }, ++t);
36 project.record("bob", { "a.ts": "one\nTwo\nthree\nfour\n", "big.txt": null }, ++t);
37 project.record("cy", { "e.ts": "export function f() {}\n" }, ++t);
38 project.record("dee", { "e.ts": "export function f() { return 1; }\n" }, ++t);
39 project.sync("idle");
42test("where and draft collisions on a stored writer match the in-memory project's", () => {
43 const oracle = new Project(new MemoryStore());
44 const project = writer();
45 history(oracle);
46 history(project);
47 const expected = where(oracle);
48 assert.ok(expected.files["big.txt"], "bob's deleted file is listed");
49 assert.deepEqual(where(project), expected);
50 const collisions = oracle.collisions();
51 assert.ok(collisions.collisions.length > 0, "ann and bob collide on a.ts");
52 assert.deepEqual(project.collisions(), collisions);
53 assert.deepEqual(project.collisions({ file: "a.ts" }), oracle.collisions({ file: "a.ts" }));
54});