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
MCP
code on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/files/worker/project/test/membership-cache.test.ts?format=json
56 linescapacity 100%Last change capacity in version 200, 1 version changed it
1// The in-memory membership cache is bounded across every space (abso Capacity): 106 drafts on prod project abso
2// each kept whole copies of shared's set, 37 MB in all. One least-recently-used cache now holds MEMBERSHIP_SETS_KEPT.
3
4import assert from "node:assert/strict";
5import { test } from "node:test";
6import { addVersion, MEMBERSHIP_SETS_KEPT, Membership, newSpace } from "../spaces.ts";
7
8const SHARED = "";
9
10/** Shared with `versions` versions, version v adding atom s<v>; then `drafts` drafts, each on shared's version 3. */
11function membership(versions: number, drafts: number): Membership {
12 const m = new Membership();
13 for (let v = 0; v < versions; v++)
14 addVersion(m.shared, { version: v, agent: "a", message: `v${v}`, time: 0, atoms: [`s${v}`] });
15 for (let d = 0; d < drafts; d++) {
16 const space = newSpace(`d${d}`);
17 m.spaces.set(space.name, space);
18 addVersion(space, { version: 0, agent: "a", message: "start", time: 0, atoms: [], sharedBase: 3 });
19 addVersion(space, { version: 1, agent: "a", message: "work", time: 0, atoms: [`d${d}-x`], sharedBase: 3 });
20 }
21 return m;
24test("the cache never holds more than MEMBERSHIP_SETS_KEPT sets, however many drafts are read", () => {
25 const m = membership(10, MEMBERSHIP_SETS_KEPT * 3);
26 for (let d = 0; d < MEMBERSHIP_SETS_KEPT * 3; d++) m.at(m.spaces.get(`d${d}`)!, 1);
27 assert.ok(m.setsKept <= MEMBERSHIP_SETS_KEPT, `kept ${m.setsKept}`);
28});
30test("a set that fell out of the cache is built again the same, and a kept one is the same object", () => {
31 const m = membership(10, MEMBERSHIP_SETS_KEPT * 2);
32 const first = m.spaces.get("d0")!;
33 const before = [...m.at(first, 1)].sort();
34 assert.deepEqual(before, ["d0-x", "s0", "s1", "s2", "s3"], "shared at its base, plus its own");
35 for (let d = 1; d < MEMBERSHIP_SETS_KEPT * 2; d++) m.at(m.spaces.get(`d${d}`)!, 1);
36 assert.deepEqual([...m.at(first, 1)].sort(), before, "rebuilt after eviction, same contents");
37 const again = m.at(first, 1);
38 assert.equal(m.at(first, 1), again, "while kept, the same set");
39 // Shared's history and its newest version answer as before.
40 assert.deepEqual([...m.at(m.shared, 2)].sort(), ["s0", "s1", "s2"]);
41 assert.equal(m.at(m.shared, 9), m.shared.own, "shared's newest version is its live set, never cached");
42});
44test("a draft replaced under the same name never gets the old one's set", () => {
45 const m = membership(10, 1);
46 const old = m.spaces.get("d0")!;
47 assert.ok(m.at(old, 1).has("d0-x"));
48 const replaced = newSpace("d0");
49 m.spaces.set("d0", replaced);
50 addVersion(replaced, { version: 0, agent: "a", message: "start", time: 0, atoms: [], sharedBase: 5 });
51 addVersion(replaced, { version: 1, agent: "a", message: "work", time: 0, atoms: ["new"], sharedBase: 5 });
52 const now = m.at(replaced, 1);
53 assert.equal(now.has("d0-x"), false);
54 assert.deepEqual([...now].sort(), ["new", "s0", "s1", "s2", "s3", "s4", "s5"]);
55 assert.equal(SHARED, m.shared.name);
56});