- MCP
- blame on this site's /mcp
- CLI
- abso blame worker/project/test/shared-additions.test.ts --version 307 --json
- JSON
- /christopher/abso-core/blame/worker/project/test/shared-additions.test.ts?version=307&format=json
87 linescapacity 56% · codex-capacity-chair 44%Last change capacity in version 307,
87 lines from 2 changes in 2 versions.
codex-capacity-chair141Avoid full shared-history scans when checking draft newsCompare1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { SqlState } from "../../../src/engine/test/storage-helper.ts";
4import { addVersion, Membership, SharedAdditions } from "../spaces.ts";
6test("shared additions preserve drop/re-add semantics and retained snapshot identity", (t) => {
7 const storage = new SqlState();
8 try {
9 const membership = new Membership(storage),
10 space = membership.shared;
11 const add = (atoms: string[], dropped: string[] = []) =>
12 addVersion(space, { version: space.versions.length, agent: "test", message: "version", time: 0, atoms, dropped });
13 add(["a"]);
14 add(["b"]);
15 add([], ["b"]);
16 add(["b", "c"]);
17 add(["c"]);
18 const base = membership.at(space, 0),
19 current = membership.at(space, 4);
20 const additions = new SharedAdditions(space, 0, base, current);
21 assert.deepEqual([...additions], ["b", "c"]);
22 add([], ["b"]);
23 add(["d"]);
24 add(["b"]);
25 assert.deepEqual([...additions], ["b", "c"]);
26 assert.equal(additions.has("d"), false);
27 assert.deepEqual([...new SharedAdditions(space, 4, current, membership.at(space, 7))], ["d"]);
28 const read = storage.read.bind(storage);
29 t.mock.method(storage, "read", (collection: string, key: string) => {
30 if (collection === 'membership:"":events') throw Error("full event enumeration forbidden");
31 return read(collection, key);
32 });
33 assert.equal(additions.size, 2);
34 assert.deepEqual([...additions], ["b", "c"]);
35 } finally {
36 storage.db.close();
37 }
38});
capacity307Shared additions read each atom's version from the membership pages (abso 714; abso - Performance's draft perf-membership-pages, Capacity ships it)
- After a definition-changing publish, the owed-news read walks SharedAdditions for each agent behind the publish, and membershipVersion read every atom's events each time (a length row, then an event row), never asking the membership pages. On abso's tables that was 47,832 of the read's 57,403 statements. On prod abso at 6:31 PM CT (abso 1470), that read ran in one storage transaction and reset the object.
- Space.membershipVersions() reads each page once (PageReader, as StoredVersionSet does): the page answers when an atom has one event, and its events are read as before only when the page says MIXED or there are no pages. PageReader's presentAt and the new versionAt share #code. SharedAdditions.values() uses it when the space has it.
- Performance's numbers on abso's tables, owed read for shared version 1224: 57,403 statements and 2.9 s before, 6,407 and 1.2 s after; with three used names, 60,240 to 10,241. A check build ran old and new lookups side by side over the owed reads, 20 agents' status, 9 syncs and collisions: 115,973 lookups, none different.
Checks: core tsc clean; Biome clean; node --test worker/project/test/shared-additions (new: three pages with drops and a return, every pair of versions walks the same with pages and with events only, under a tenth of the event reads), membership, owed-definition-news, changed-definition, known-paths, news-lazy, news-cap, writer-adoption, project-writer-storage, project: 50 of 50 pass.Compare39
40test("shared additions read each atom's version from the membership pages, and answer as its events do (abso - Performance, 714)", (t) => {
41 const storage = new SqlState();
42 try {
43 const membership = new Membership(storage),
44 space = membership.shared;
45 const ids = (from: number, to: number) => Array.from({ length: to - from }, (_, i) => `a${from + i}`);
46 const add = (atoms: string[], dropped: string[] = []) =>
47 addVersion(space, { version: space.versions.length, agent: "test", message: "version", time: 0, atoms, dropped });
48 // Three pages of atoms; a5 and a400 dropped and a5 back, a601 added and dropped: their events are read.
49 add(ids(0, 300));
50 add(ids(300, 600));
51 add([], ["a5", "a400"]);
52 add(["a5", "a600"]);
53 add(["a601"]);
54 add([], ["a601"]);
55 const last = space.versions.length - 1;
56 const { membershipVersions: _pages, ...eventsOnly } = space;
57 const read = storage.read.bind(storage);
58 let eventReads = 0;
59 t.mock.method(storage, "read", (collection: string, key: string) => {
60 if (collection.startsWith('membership:"":events:')) eventReads++;
61 return read(collection, key);
62 });
63 const walk = (s: typeof space) => {
64 eventReads = 0;
65 const out: string[][] = [];
66 for (let from = 0; from < last; from++)
67 for (let to = from + 1; to <= last; to++)
68 out.push([...new SharedAdditions(s, from, membership.at(s, from), membership.at(s, to), to)]);
69 return { out, eventReads };
70 };
71 const paged = walk(space);
72 const events = walk(eventsOnly);
73 assert.deepEqual(paged.out, events.out);
74 assert.ok(
75 paged.eventReads < events.eventReads / 10,
76 `${paged.eventReads} event reads against ${events.eventReads}`,
77 );
78 assert.deepEqual([...new SharedAdditions(space, 1, membership.at(space, 1), membership.at(space, 3), 3)], ["a600"]);
79 assert.deepEqual(
80 [...new SharedAdditions(space, 2, membership.at(space, 2), membership.at(space, 3), 3)],
81 ["a5", "a600"],
82 );
83 assert.deepEqual([...new SharedAdditions(space, 3, membership.at(space, 3), membership.at(space, 5), 5)], []);
84 } finally {
85 storage.db.close();
86 }
87});