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

Versions 2 to 318

Compare

+68 −0 in 1 place
new file, 68 lines
1+import assert from "node:assert/strict";
2+import { test } from "node:test";
3+import { StoredText } from "../stored-text.ts";
4+import { SqlState } from "./storage-helper.ts";
5+
6+test("stored text preserves long lines and split surrogate pairs with bounded values", () => {
7+ const state = new SqlState();
8+ try {
9+ const text = new StoredText(state, "text");
10+ const value = "x".repeat(StoredText.chunkCharacters - 1) + "\uD83D\uDE00" + "y".repeat(8100000);
11+ text.write("line", value);
12+ let count = 0;
13+ for (const chunk of text.chunks("line")) {
14+ assert.ok(chunk.length <= StoredText.chunkCharacters);
15+ count += chunk.length;
16+ }
17+ assert.equal(count, value.length);
18+ assert.equal(text.read("line"), value);
19+ assert.throws(() => text.write("line", "overwrite"), /already exists/);
20+ text.write("empty", "");
21+ assert.equal(text.read("empty"), "");
22+ const before = state.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
23+ state.failWrite = state.writes + 2;
24+ assert.throws(() => text.write("failure", value), /injected/);
25+ assert.deepEqual(state.db.prepare("SELECT * FROM state ORDER BY collection,key").all(), before);
26+ state.failWrite = Infinity;
27+ state.remove("text:chunks", JSON.stringify(["line", 1]));
28+ assert.throws(() => text.read("line"), /incomplete/);
29+ } finally {
30+ state.db.close();
31+ }
32+});
34+test("streamed text repacks small chunks and rolls back interrupted input", () => {
35+ const state = new SqlState();
36+ try {
37+ const text = new StoredText(state, "stream");
38+ const value = `${"a".repeat(20000)}\uD83D\uDE00${"b".repeat(20000)}`;
39+ text.writeChunks(
40+ "unicode",
41+ (function* () {
42+ for (const unit of value.split("")) yield unit;
43+ })(),
44+ );
45+ assert.equal(text.read("unicode"), value);
46+ const rows = () => state.db.prepare("SELECT * FROM state ORDER BY collection,key").all();
47+ const before = rows();
48+ assert.throws(
49+ () =>
50+ text.writeChunks(
51+ "interrupted",
52+ (function* () {
53+ yield "x".repeat(StoredText.chunkCharacters);
54+ yield "tail";
55+ throw Error("input interrupted");
56+ })(),
57+ ),
58+ /input interrupted/,
59+ );
60+ assert.deepEqual(rows(), before);
61+ assert.throws(() => text.writeChunks("oversized", ["x".repeat(StoredText.chunkCharacters + 1)]), /exceeds bound/);
62+ assert.deepEqual(rows(), before);
63+ text.writeChunks("interrupted", ["retry"]);
64+ assert.equal(text.read("interrupted"), "retry");
65+ } finally {
66+ state.db.close();
67+ }
68+});
MCP
compare on this site's /mcp
CLI
abso diff 2 318 src/engine/test/stored-text.test.ts --json
JSON
/christopher/abso-core/compare/2..318?file=src%2Fengine%2Ftest%2Fstored-text.test.ts&format=json