{"draft":null,"from":179,"to":318,"files":[{"path":"server/test/git-disk-clone.test.ts","added":43,"removed":7,"diff":"--- a/server/test/git-disk-clone.test.ts\n+++ b/server/test/git-disk-clone.test.ts\n@@ -3,9 +3,11 @@\n import { test } from \"node:test\";\n import git, { type HttpClient } from \"isomorphic-git\";\n import { GitDiskIntake } from \"../src/git-disk-intake.ts\";\n+import { GitFileContents } from \"../src/git-file-contents.ts\";\n import { GitIntakeTrees } from \"../src/git-intake-trees.ts\";\n import { pushedSince } from \"../src/ingest.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n+import { commitShared } from \"../src/push.ts\";\n import { memoryStorage } from \"./helpers.ts\";\n \n const packet = (text: string | Uint8Array) => {\n@@ -13,13 +15,14 @@\n \treturn Buffer.concat([Buffer.from((body.length + 4).toString(16).padStart(4, \"0\")), body]);\n };\n \n-for (const mode of [\"success\", \"limit\", \"fatal\", \"server-intake\", \"text-intake\"])\n+for (const mode of [\"success\", \"limit\", \"fatal\", \"server-intake\", \"text-intake\", \"binary-limit\"])\n \ttest(`actual disk clone handles ${mode}`, async (t) => {\n \t\tconst rejectPack = mode === \"limit\";\n \t\tconst source = new MemoryFS(),\n \t\t\tdir = \"/repo\";\n \t\tawait git.init({ fs: source, dir, defaultBranch: \"main\" });\n \t\tconst blob = mode === \"text-intake\" ? Buffer.from(\"x\".repeat(16383) + \"🚀é中\".repeat(20000)) : randomBytes(400000);\n+\t\tif (mode === \"binary-limit\") blob[0] = 255;\n \t\tconst blobOid = await git.writeBlob({ fs: source, dir, blob });\n \t\tconst tree = await git.writeTree({\n \t\t\tfs: source,\n@@ -117,19 +120,20 @@\n \t\t};\n \t\tconst cache = {};\n \t\tintake.attach(cache);\n-\t\tconst fs = new MemoryFS();\n+\t\tconst contents = new GitFileContents(storage, 1000000, 2000000);\n+\t\tconst fs = new MemoryFS(contents);\n \t\tconst write = fs.promises.writeFile;\n \t\tfs.promises.writeFile = async (path, ...args) => {\n \t\t\tassert.ok(!/\\.(pack|idx)$/.test(path), \"clone must not persist a collected pack or index\");\n \t\t\treturn write(path, ...args);\n \t\t};\n \t\ttry {\n-\t\t\tif (mode === \"server-intake\" || mode === \"text-intake\") {\n+\t\t\tif (mode === \"server-intake\" || mode === \"text-intake\" || mode === \"binary-limit\") {\n \t\t\t\tconst trees = new GitIntakeTrees(storage);\n-\t\t\t\tif (mode === \"text-intake\") {\n+\t\t\t\tif (mode === \"text-intake\" || mode === \"binary-limit\") {\n \t\t\t\t\tconst original = GitDiskIntake.prototype.read;\n \t\t\t\t\tt.mock.method(GitDiskIntake.prototype, \"read\", function (this: GitDiskIntake, oid: string) {\n-\t\t\t\t\t\tif (oid === blobOid) throw Error(\"whole text blob read forbidden\");\n+\t\t\t\t\t\tif (oid === blobOid) throw Error(\"whole blob read forbidden\");\n \t\t\t\t\t\treturn original.call(this, oid);\n \t\t\t\t\t});\n \t\t\t\t}\n@@ -145,15 +149,17 @@\n \t\t\t\t\t\"fixture\",\n \t\t\t\t\tundefined,\n \t\t\t\t\tasync (bytes) => {\n+\t\t\t\t\t\tassert.notEqual(mode, \"binary-limit\", \"oversized binary must not reach the store\");\n \t\t\t\t\t\tassert.deepEqual(Buffer.from(bytes), blob);\n \t\t\t\t\t\treturn \"fixture-blob\";\n \t\t\t\t\t},\n+\t\t\t\t\tmode === \"binary-limit\" ? () => \"previous-blob\" : undefined,\n \t\t\t\t\tundefined,\n-\t\t\t\t\tundefined,\n \t\t\t\t\t{\n \t\t\t\t\t\tstorage,\n \t\t\t\t\t\tmaxPackBytes: 2000000,\n \t\t\t\t\t\tmaxObjectBytes: 1000000,\n+\t\t\t\t\t\tmaxBinaryBytes: mode === \"binary-limit\" ? 100000 : undefined,\n \t\t\t\t\t\thttp,\n \t\t\t\t\t\tretainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid),\n \t\t\t\t\t},\n@@ -161,7 +167,10 @@\n \t\t\t\tassert.equal(found!.base, 0);\n \t\t\t\tassert.equal(found!.commits.length, 1);\n \t\t\t\tif (mode === \"text-intake\") assert.equal(found!.commits[0]!.files[\"large.bin\"], blob.toString(\"utf8\"));\n-\t\t\t\telse assert.equal(found!.commits[0]!.blobs[\"large.bin\"], \"fixture-blob\");\n+\t\t\t\telse if (mode === \"binary-limit\") {\n+\t\t\t\t\tassert.equal(found!.commits[0]!.blobs[\"large.bin\"], \"previous-blob\");\n+\t\t\t\t\tassert.deepEqual(found!.tooBig, [\"large.bin\"]);\n+\t\t\t\t} else assert.equal(found!.commits[0]!.blobs[\"large.bin\"], \"fixture-blob\");\n \t\t\t\ttrees.dispose();\n \t\t\t\tfor (const table of [\"git_pack_spool\", \"git_pack_resolve\", \"git_object_meta\", \"git_object_bytes\"])\n \t\t\t\t\tassert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0);\n@@ -206,7 +215,34 @@\n \t\t\tassert.equal(await git.resolveRef({ fs, dir, ref: \"main\" }), head);\n \t\t\tassert.equal((await git.readCommit({ fs, dir, cache, oid: head })).commit.tree, tree);\n \t\t\tassert.deepEqual(Buffer.from((await git.readBlob({ fs, dir, cache, oid: blobOid })).blob), blob);\n+\t\t\tconst exported = await commitShared(\n+\t\t\t\tfs,\n+\t\t\t\tdir,\n+\t\t\t\thead,\n+\t\t\t\t{\n+\t\t\t\t\tversion: 1,\n+\t\t\t\t\tfiles: { \"new.txt\": \"Disk export fixture\" },\n+\t\t\t\t\tblobs: { \"large.bin\": \"fixture-blob\" },\n+\t\t\t\t},\n+\t\t\t\t() => blob,\n+\t\t\t\tundefined,\n+\t\t\t\tcache,\n+\t\t\t);\n+\t\t\tconst next = await git.readCommit({ fs, dir, cache, oid: exported.commit });\n+\t\t\tassert.deepEqual(next.commit.parent, [head]);\n+\t\t\tassert.deepEqual(\n+\t\t\t\tBuffer.from((await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: \"large.bin\" })).blob),\n+\t\t\t\tblob,\n+\t\t\t);\n+\t\t\tassert.equal(\n+\t\t\t\tBuffer.from(\n+\t\t\t\t\t(await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: \"new.txt\" })).blob,\n+\t\t\t\t).toString(),\n+\t\t\t\t\"Disk export fixture\",\n+\t\t\t);\n+\t\t\tfor (const entry of fs.entries.values()) if (entry.kind === \"file\") assert.equal(entry.data.byteLength, 0);\n \t\t} finally {\n+\t\t\tcontents.dispose();\n \t\t\tintake.dispose();\n \t\t\tstorage.db.close();\n \t\t}"}],"unmatched":[]}