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

You're reading version 261. The newest is 318, and 2 versions 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, View } from "../../../src/engine/index.ts";
4import { SqlState } from "../../../src/engine/test/storage-helper.ts";
5import { withDefinitionCode } from "../definition-code.ts";
6import { definedTwice, definitionsIn } from "../definitions.ts";
7import { codeOfLines } from "../names.ts";
8
9test("small parsed code stays in memory without scratch writes", (t) => {
10 const storage = new SqlState();
11 t.after(() => storage.db.close());
12 const graph = new Graph({ storage });
13 graph.add(buildBase({ "f.ts": "export const answer = 42;\n" }, { author: "writer", message: "init" }));
14 const view = new View(graph, ["a0"]);
15 const writes = storage.writes;
16 withDefinitionCode(view, view.buildLines("f.ts"), (code) => {
17 assert.deepEqual(code, codeOfLines(["export const answer = 42;"]));
18 });
19 assert.equal(storage.writes, writes);
20});
22test("disk definition code preserves random reads and always rolls scratch back", (t) => {
23 const storage = new SqlState();
24 t.after(() => storage.db.close());
25 const lines = [
26 "/* comment",
27 "end */ export function parseOne(",
28 "arg: string",
29 ") { return 1; }",
30 ...Array.from({ length: 4000 }, (_, i) => `const value${i} = ${i}; // trailing`),
31 ];
32 const atom = buildBase({ "f.ts": `${lines.join("\n")}\n` }, { author: "writer", message: "init" });
33 const memory = new Graph();
34 memory.add(atom);
35 const graph = new Graph({ storage });
36 graph.add(atom);
37 const view = new View(graph, ["a0"]);
38 const expected = codeOfLines(lines);
39 const rows = () => storage.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
40 const before = rows();
41 let escaped: readonly string[] = [];
42 withDefinitionCode(view, view.buildLines("f.ts"), (code) => {
43 escaped = code;
44 assert.deepEqual(code.slice(0, 4), expected.slice(0, 4));
45 for (let i = code.length - 1; i >= 0; i--) assert.equal(code[i], expected[i]);
46 for (let i = 0; i < code.length; i++) assert.equal(code[i], expected[i]);
47 });
48 assert.throws(() => escaped[0], /scope has ended/);
49 assert.deepEqual(rows(), before);
50 assert.deepEqual(definitionsIn(view), definitionsIn(new View(memory, ["a0"])));
51 assert.deepEqual(definedTwice(view, "f.ts"), definedTwice(new View(memory, ["a0"]), "f.ts"));
52 assert.deepEqual(rows(), before);
53 storage.failWrite = storage.writes + 2;
54 assert.throws(() => withDefinitionCode(view, view.buildLines("f.ts"), () => []), /injected storage failure/);
55 assert.deepEqual(rows(), before);
56});