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 linescodex-capacity-chair 100%Last change codex-capacity-chair in version 162, 1 version changed it

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

1import assert from "node:assert/strict";
2import { test } from "node:test";
3import { buildBase, Graph } from "../index.ts";
4import { lineKey } from "../keys.ts";
5import type { Atom, LineId } from "../types.ts";
6import { SqlState } from "./storage-helper.ts";
7
8test("deletion page failure rolls back acceptance and missing pages fail after reopen", () => {
9 const storage = new SqlState();
10 try {
11 const graph = new Graph({ storage });
12 graph.add(
13 buildBase(
14 { "a.txt": Array.from({ length: 300 }, (_, i) => `line ${i}`).join("\n") },
15 { author: "fixture", message: "base", time: 0 },
16 ),
17 );
18 const deletes = Array.from({ length: 300 }, (_, i) => `a0.${i}` as LineId);
19 const atom: Atom = {
20 id: "a1",
21 seq: 1,
22 author: "fixture",
23 message: "delete",
24 time: 1,
25 inserts: [],
26 deletes,
27 writes: deletes.map(lineKey),
28 reads: [],
29 holds: [],
30 needs: [],
31 resolves: [],
32 reasons: [],
33 deps: ["a0"],
34 };
35 const before = storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
36 const write = storage.write.bind(storage);
37 storage.write = (collection, key, value) => {
38 write(collection, key, value);
39 if (collection === "atom-deletes:pages" && key === JSON.stringify(["1", 1]))
40 throw Error("injected deletion page failure");
41 };
42 assert.throws(() => graph.add(atom), /injected deletion page failure/);
43 assert.deepEqual(storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
44 assert.equal(graph.size, 1);
45 storage.write = write;
46 graph.add(atom);
47 assert.equal(new Graph({ storage }).deleteCount("a1"), 300);
48 assert.deepEqual(new Graph({ storage }).deletedLines("a1"), deletes);
49 storage.remove("atom-deletes:pages", JSON.stringify(["1", 1]));
50 assert.throws(() => new Graph({ storage }).deletedLines("a1"), /missing or invalid writer list page/);
51 } finally {
52 storage.db.close();
53 }
54});