{"agent":"review","draft":null,"base":317,"files":[{"path":"server/test/cap56-extra.test.ts","added":116,"removed":0,"diff":"--- /dev/null\n+++ b/server/test/cap56-extra.test.ts\n@@ -0,0 +1,116 @@\n+import assert from \"node:assert/strict\";\n+import { it } from \"node:test\";\n+import git from \"isomorphic-git\";\n+import { MemoryFS } from \"../src/memory-fs.ts\";\n+import { blobOid, commitShared, readTreeFiles, type TreeFile, writeTrees } from \"../src/push.ts\";\n+\n+const MiB = 1024 * 1024;\n+const enc = new TextEncoder();\n+const flat = async (fs: MemoryFS, dir: string, commit: string) => {\n+\tconst tree = (await git.readCommit({ fs, dir, oid: commit })).commit.tree;\n+\tconst r = await readTreeFiles(fs, dir, tree, \"\", new Map(), new Map());\n+\t// every blob in the tree must be readable (valid tree, no dangling entries)\n+\tfor (const [, f] of r.files) await git.readObject({ fs, dir, oid: f.oid });\n+\treturn { tree, files: r.files };\n+};\n+\n+it(\"many large text changes split near 16 MiB, pending files keep old entries, final equals unbatched\", async () => {\n+\tconst fs = new MemoryFS(),\n+\t\tdir = \"/repo\";\n+\tawait git.init({ fs, dir, defaultBranch: \"main\" });\n+\tconst v0: Record<string, string> = { \"keep.txt\": \"same\", \"gone/x.txt\": \"bye\" };\n+\tfor (let i = 0; i < 8; i++) v0[`d${i % 3}/f${i}.txt`] = `old ${i}`;\n+\tconst blobStore: Record<string, Uint8Array> = { s1: new Uint8Array(6 * MiB).fill(7), s0: new Uint8Array([1, 2]) };\n+\tconst first = await commitShared(fs, dir, null, { version: 0, files: v0, blobs: { \"bin/a.bin\": \"s0\" } }, (s) => blobStore[s] ?? null);\n+\tconst v0flat = (await flat(fs, dir, first.commit)).files;\n+\tconst v1: Record<string, string> = { \"keep.txt\": \"same\", \"new/n.txt\": \"x\".repeat(5 * MiB) };\n+\tfor (let i = 0; i < 8; i++) v1[`d${i % 3}/f${i}.txt`] = String(i).repeat(5 * MiB);\n+\tconst blobs = { \"bin/a.bin\": \"s1\" };\n+\tconst parts: string[] = [];\n+\tconst seen = new Set<string>();\n+\tconst next = await commitShared(\n+\t\tfs,\n+\t\tdir,\n+\t\tfirst.commit,\n+\t\t{ version: 1, files: v1, blobs, modes: { \"d0/f0.txt\": { exec: true } } },\n+\t\t(s) => blobStore[s] ?? null,\n+\t\tasync (c) => {\n+\t\t\tparts.push(c);\n+\t\t\tconst { files } = await flat(fs, dir, c);\n+\t\t\tassert.ok(!files.has(\"gone/x.txt\"));\n+\t\t\tlet newBytes = 0;\n+\t\t\tfor (const p of [...Object.keys(v1), ...Object.keys(blobs)]) {\n+\t\t\t\tconst f = files.get(p);\n+\t\t\t\tconst was = v0flat.get(p);\n+\t\t\t\tif (was && f?.oid === was.oid) continue; // still the old version: pending\n+\t\t\t\tif (!was && !f) continue; // new file not reached yet\n+\t\t\t\tassert.ok(f, `${p} vanished in part ${parts.length}`);\n+\t\t\t\tif (!seen.has(p)) {\n+\t\t\t\t\tseen.add(p);\n+\t\t\t\t\tnewBytes += p === \"bin/a.bin\" ? 6 * MiB : v1[p]!.length;\n+\t\t\t\t}\n+\t\t\t}\n+\t\t\tfor (const p of Object.keys(v1)) if (v0flat.has(p)) assert.ok(files.has(p), `${p} missing`);\n+\t\t\tassert.ok(files.has(\"bin/a.bin\"));\n+\t\t\tassert.ok(newBytes <= 16 * MiB, `part ${parts.length} carried ${newBytes}`);\n+\t\t\tassert.ok(newBytes > 10 * MiB, `part ${parts.length} small ${newBytes}`);\n+\t\t},\n+\t);\n+\tassert.ok(parts.length >= 3, `parts ${parts.length}`);\n+\t// chain\n+\tlet c = next.commit;\n+\tfor (let i = parts.length - 1; i >= 0; i--) {\n+\t\tc = (await git.readCommit({ fs, dir, oid: c })).commit.parent[0]!;\n+\t\tassert.equal(c, parts[i]);\n+\t}\n+\tassert.equal((await git.readCommit({ fs, dir, oid: parts[0]! })).commit.parent[0], first.commit);\n+\t// unbatched expectation built independently on a fresh repo\n+\tconst fs2 = new MemoryFS();\n+\tawait git.init({ fs: fs2, dir, defaultBranch: \"main\" });\n+\tconst want = new Map<string, TreeFile>();\n+\tfor (const [p, t] of Object.entries(v1)) {\n+\t\tconst b = enc.encode(t);\n+\t\tawait git.writeBlob({ fs: fs2, dir, blob: b });\n+\t\twant.set(p, { oid: await blobOid(b), mode: p === \"d0/f0.txt\" ? \"100755\" : \"100644\" } as TreeFile);\n+\t}\n+\tawait git.writeBlob({ fs: fs2, dir, blob: blobStore.s1! });\n+\twant.set(\"bin/a.bin\", { oid: await blobOid(blobStore.s1!), mode: \"100644\" } as TreeFile);\n+\tconst wantTree = await writeTrees(fs2, dir, want, new Map(), new Set(want.keys()));\n+\tassert.equal((await flat(fs, dir, next.commit)).tree, wantTree);\n+\tconsole.log(\"parts\", parts.length + 1, \"changed\", next.changed);\n+});\n+\n+it(\"small push stays one commit\", async () => {\n+\tconst fs = new MemoryFS(),\n+\t\tdir = \"/repo\";\n+\tawait git.init({ fs, dir, defaultBranch: \"main\" });\n+\tconst first = await commitShared(fs, dir, null, { version: 0, files: { \"a.txt\": \"a\" } }, () => null);\n+\tlet calls = 0;\n+\tconst next = await commitShared(\n+\t\tfs,\n+\t\tdir,\n+\t\tfirst.commit,\n+\t\t{ version: 1, files: { \"a.txt\": \"b\".repeat(8 * MiB), \"c.txt\": \"c\".repeat(7 * MiB) } },\n+\t\t() => null,\n+\t\tasync () => {\n+\t\t\tcalls++;\n+\t\t},\n+\t);\n+\tassert.equal(calls, 0);\n+\tconst cm = (await git.readCommit({ fs, dir, oid: next.commit })).commit;\n+\tassert.deepEqual(cm.parent, [first.commit]);\n+\tassert.ok(!cm.message.includes(\"part\"));\n+\t// unchanged large text does not count\n+\tconst again = await commitShared(\n+\t\tfs,\n+\t\tdir,\n+\t\tnext.commit,\n+\t\t{ version: 2, files: { \"a.txt\": \"b\".repeat(8 * MiB), \"c.txt\": \"c\".repeat(7 * MiB), \"d.txt\": \"d\".repeat(9 * MiB) } },\n+\t\t() => null,\n+\t\tasync () => {\n+\t\t\tcalls++;\n+\t\t},\n+\t);\n+\tassert.equal(calls, 0);\n+\tassert.deepEqual((await git.readCommit({ fs, dir, oid: again.commit })).commit.parent, [next.commit]);\n+});"}]}