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

review's draft

RV review on version 317. 1 file, 116 lines added, 0 removed.

server/test/cap56-extra.test.ts +116 −0
--- /dev/null
+++ b/server/test/cap56-extra.test.ts
@@ -0,0 +1,116 @@
1+import assert from "node:assert/strict";
2+import { it } from "node:test";
3+import git from "isomorphic-git";
4+import { MemoryFS } from "../src/memory-fs.ts";
5+import { blobOid, commitShared, readTreeFiles, type TreeFile, writeTrees } from "../src/push.ts";
6+
7+const MiB = 1024 * 1024;
8+const enc = new TextEncoder();
9+const flat = async (fs: MemoryFS, dir: string, commit: string) => {
10+ const tree = (await git.readCommit({ fs, dir, oid: commit })).commit.tree;
11+ const r = await readTreeFiles(fs, dir, tree, "", new Map(), new Map());
12+ // every blob in the tree must be readable (valid tree, no dangling entries)
13+ for (const [, f] of r.files) await git.readObject({ fs, dir, oid: f.oid });
14+ return { tree, files: r.files };
15+};
16+
17+it("many large text changes split near 16 MiB, pending files keep old entries, final equals unbatched", async () => {
18+ const fs = new MemoryFS(),
19+ dir = "/repo";
20+ await git.init({ fs, dir, defaultBranch: "main" });
21+ const v0: Record<string, string> = { "keep.txt": "same", "gone/x.txt": "bye" };
22+ for (let i = 0; i < 8; i++) v0[`d${i % 3}/f${i}.txt`] = `old ${i}`;
23+ const blobStore: Record<string, Uint8Array> = { s1: new Uint8Array(6 * MiB).fill(7), s0: new Uint8Array([1, 2]) };
24+ const first = await commitShared(fs, dir, null, { version: 0, files: v0, blobs: { "bin/a.bin": "s0" } }, (s) => blobStore[s] ?? null);
25+ const v0flat = (await flat(fs, dir, first.commit)).files;
26+ const v1: Record<string, string> = { "keep.txt": "same", "new/n.txt": "x".repeat(5 * MiB) };
27+ for (let i = 0; i < 8; i++) v1[`d${i % 3}/f${i}.txt`] = String(i).repeat(5 * MiB);
28+ const blobs = { "bin/a.bin": "s1" };
29+ const parts: string[] = [];
30+ const seen = new Set<string>();
31+ const next = await commitShared(
32+ fs,
33+ dir,
34+ first.commit,
35+ { version: 1, files: v1, blobs, modes: { "d0/f0.txt": { exec: true } } },
36+ (s) => blobStore[s] ?? null,
37+ async (c) => {
38+ parts.push(c);
39+ const { files } = await flat(fs, dir, c);
40+ assert.ok(!files.has("gone/x.txt"));
41+ let newBytes = 0;
42+ for (const p of [...Object.keys(v1), ...Object.keys(blobs)]) {
43+ const f = files.get(p);
44+ const was = v0flat.get(p);
45+ if (was && f?.oid === was.oid) continue; // still the old version: pending
46+ if (!was && !f) continue; // new file not reached yet
47+ assert.ok(f, `${p} vanished in part ${parts.length}`);
48+ if (!seen.has(p)) {
49+ seen.add(p);
50+ newBytes += p === "bin/a.bin" ? 6 * MiB : v1[p]!.length;
51+ }
52+ }
53+ for (const p of Object.keys(v1)) if (v0flat.has(p)) assert.ok(files.has(p), `${p} missing`);
54+ assert.ok(files.has("bin/a.bin"));
55+ assert.ok(newBytes <= 16 * MiB, `part ${parts.length} carried ${newBytes}`);
56+ assert.ok(newBytes > 10 * MiB, `part ${parts.length} small ${newBytes}`);
57+ },
58+ );
59+ assert.ok(parts.length >= 3, `parts ${parts.length}`);
60+ // chain
61+ let c = next.commit;
62+ for (let i = parts.length - 1; i >= 0; i--) {
63+ c = (await git.readCommit({ fs, dir, oid: c })).commit.parent[0]!;
64+ assert.equal(c, parts[i]);
65+ }
66+ assert.equal((await git.readCommit({ fs, dir, oid: parts[0]! })).commit.parent[0], first.commit);
67+ // unbatched expectation built independently on a fresh repo
68+ const fs2 = new MemoryFS();
69+ await git.init({ fs: fs2, dir, defaultBranch: "main" });
70+ const want = new Map<string, TreeFile>();
71+ for (const [p, t] of Object.entries(v1)) {
72+ const b = enc.encode(t);
73+ await git.writeBlob({ fs: fs2, dir, blob: b });
74+ want.set(p, { oid: await blobOid(b), mode: p === "d0/f0.txt" ? "100755" : "100644" } as TreeFile);
75+ }
76+ await git.writeBlob({ fs: fs2, dir, blob: blobStore.s1! });
77+ want.set("bin/a.bin", { oid: await blobOid(blobStore.s1!), mode: "100644" } as TreeFile);
78+ const wantTree = await writeTrees(fs2, dir, want, new Map(), new Set(want.keys()));
79+ assert.equal((await flat(fs, dir, next.commit)).tree, wantTree);
80+ console.log("parts", parts.length + 1, "changed", next.changed);
81+});
82+
83+it("small push stays one commit", async () => {
84+ const fs = new MemoryFS(),
85+ dir = "/repo";
86+ await git.init({ fs, dir, defaultBranch: "main" });
87+ const first = await commitShared(fs, dir, null, { version: 0, files: { "a.txt": "a" } }, () => null);
88+ let calls = 0;
89+ const next = await commitShared(
90+ fs,
91+ dir,
92+ first.commit,
93+ { version: 1, files: { "a.txt": "b".repeat(8 * MiB), "c.txt": "c".repeat(7 * MiB) } },
94+ () => null,
95+ async () => {
96+ calls++;
97+ },
98+ );
99+ assert.equal(calls, 0);
100+ const cm = (await git.readCommit({ fs, dir, oid: next.commit })).commit;
101+ assert.deepEqual(cm.parent, [first.commit]);
102+ assert.ok(!cm.message.includes("part"));
103+ // unchanged large text does not count
104+ const again = await commitShared(
105+ fs,
106+ dir,
107+ next.commit,
108+ { version: 2, files: { "a.txt": "b".repeat(8 * MiB), "c.txt": "c".repeat(7 * MiB), "d.txt": "d".repeat(9 * MiB) } },
109+ () => null,
110+ async () => {
111+ calls++;
112+ },
113+ );
114+ assert.equal(calls, 0);
115+ assert.deepEqual((await git.readCommit({ fs, dir, oid: again.commit })).commit.parent, [next.commit]);
116+});

Back to Now · Every draft · Where, line by line

MCP
draft on this site's /mcp
CLI
none: the JSON below is the answer
JSON
/christopher/abso-core/drafts/by/review?format=json