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 4 to 318

Compare

+88 −0 in 1 place
new file, 88 lines
1+import assert from "node:assert/strict";
2+import { randomBytes } from "node:crypto";
3+import { test } from "node:test";
4+import git from "isomorphic-git";
5+import { GitFileContents } from "../src/git-file-contents.ts";
6+import { MemoryFS } from "../src/memory-fs.ts";
7+import { memoryStorage } from "./helpers.ts";
8+
9+test("Git writes and reads exact objects while filesystem entries retain no content bytes", async (t) => {
10+ const storage = memoryStorage();
11+ t.after(() => storage.db.close());
12+ using contents = new GitFileContents(storage, 1000000, 10000000);
13+ const fs = new MemoryFS(contents),
14+ dir = "/repo";
15+ await git.init({ fs, dir, defaultBranch: "main" });
16+ const entries = [],
17+ bodies: Uint8Array[] = [];
18+ for (let index = 0; index < 20; index++) {
19+ const body = randomBytes(70000);
20+ bodies.push(body);
21+ entries.push({
22+ mode: "100644",
23+ path: `file-${index}`,
24+ oid: await git.writeBlob({ fs, dir, blob: body }),
25+ type: "blob" as const,
26+ });
27+ }
28+ const tree = await git.writeTree({ fs, dir, tree: entries });
29+ const commit = await git.commit({
30+ fs,
31+ dir,
32+ tree,
33+ parent: [],
34+ message: "Scratch fixture",
35+ author: { name: "Fixture", email: "fixture@example.invalid" },
36+ });
37+ for (let index = 0; index < 20; index++) {
38+ const blob = await git.readBlob({ fs, dir, oid: commit, filepath: `file-${index}` });
39+ assert.deepEqual(new Uint8Array(blob.blob), new Uint8Array(bodies[index]!));
40+ }
41+ for (const entry of fs.entries.values()) if (entry.kind === "file") assert.equal(entry.data.byteLength, 0);
42+ assert.ok(Number(storage.db.prepare("SELECT MAX(length(data)) AS n FROM git_fs_chunks").get()!.n) <= 65536);
43+ const reference = "/repo/.git/refs/heads/main";
44+ assert.equal((await fs.stat(reference)).size, ((await fs.readFile(reference)) as Uint8Array).byteLength);
45+});
47+test("Git scratch replacement failure preserves old contents, metadata and budget", async (t) => {
48+ const storage = memoryStorage();
49+ t.after(() => storage.db.close());
50+ using contents = new GitFileContents(storage, 100000, 150000);
51+ const fs = new MemoryFS(contents);
52+ await fs.writeFile("/file", new Uint8Array([7]));
53+ const exec = storage.sql.exec.bind(storage.sql);
54+ const failure = t.mock.method(storage.sql, "exec", (query: string, ...bindings: unknown[]) => {
55+ if (query.startsWith("INSERT INTO git_fs_chunks") && bindings[2] === 1) throw Error("injected chunk failure");
56+ return exec(query, ...bindings);
57+ });
58+ await assert.rejects(() => fs.writeFile("/file", new Uint8Array(70000)), /injected chunk failure/);
59+ assert.deepEqual(await fs.readFile("/file"), new Uint8Array([7]));
60+ assert.equal((await fs.stat("/file")).size, 1);
61+ assert.equal(storage.db.prepare("SELECT bytes FROM git_fs_budget").get()!.bytes, 1);
62+ failure.mock.restore();
63+ await fs.writeFile("/file", new Uint8Array(70000));
64+ await assert.rejects(() => fs.writeFile("/other", new Uint8Array(90000)), /total byte limit/);
65+ await assert.rejects(() => fs.stat("/other"), /ENOENT/);
66+ await fs.unlink("/file");
67+ assert.equal(storage.db.prepare("SELECT bytes FROM git_fs_budget").get()!.bytes, 0);
68+});
70+test("cold Git file recovery preserves canonical rows and active scopes dispose independently", (t) => {
71+ const storage = memoryStorage();
72+ t.after(() => storage.db.close());
73+ storage.sql.exec("CREATE TABLE canonical_fs_fixture (value TEXT)");
74+ storage.sql.exec("INSERT INTO canonical_fs_fixture VALUES ('preserved')");
75+ const first = new GitFileContents(storage, 10, 20),
76+ second = new GitFileContents(storage, 10, 20);
77+ first.write("/a", new Uint8Array([1]));
78+ second.write("/b", new Uint8Array([2]));
79+ first.dispose();
80+ assert.deepEqual(second.read("/b"), new Uint8Array([2]));
81+ GitFileContents.recover(storage);
82+ GitFileContents.recover(storage);
83+ for (const table of ["git_fs_meta", "git_fs_chunks", "git_fs_budget"])
84+ assert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0);
85+ assert.equal(storage.db.prepare("SELECT value FROM canonical_fs_fixture").get()!.value, "preserved");
86+ assert.throws(() => second.read("/b"), /invalid Git scratch file/);
87+ second.dispose();
88+});
MCP
compare on this site's /mcp
CLI
abso diff 4 318 server/test/git-file-contents.test.ts --json
JSON
/christopher/abso-core/compare/4..318?file=server%2Ftest%2Fgit-file-contents.test.ts&format=json