Lines 3–13 at 318 (were 3–11 at 178)
33import { test } from "node:test"; 44import git, { type HttpClient } from "isomorphic-git"; 55import { GitDiskIntake } from "../src/git-disk-intake.ts"; 6+import { GitFileContents } from "../src/git-file-contents.ts"; 67import { GitIntakeTrees } from "../src/git-intake-trees.ts"; 78import { pushedSince } from "../src/ingest.ts"; 89import { MemoryFS } from "../src/memory-fs.ts"; 10+import { commitShared } from "../src/push.ts"; 911import { memoryStorage } from "./helpers.ts"; 1113const packet = (text: string | Uint8Array) => { Lines 15–28 at 318 (were 13–25 at 178)
1315 return Buffer.concat([Buffer.from((body.length + 4).toString(16).padStart(4, "0")), body]); 16−for (const mode of ["success", "limit", "fatal", "server-intake", "text-intake"])
18+for (const mode of ["success", "limit", "fatal", "server-intake", "text-intake", "binary-limit"]) 1719 test(`actual disk clone handles ${mode}`, async (t) => { 1820 const rejectPack = mode === "limit"; 1921 const source = new MemoryFS(), 2123 await git.init({ fs: source, dir, defaultBranch: "main" }); 2224 const blob = mode === "text-intake" ? Buffer.from("x".repeat(16383) + "🚀é中".repeat(20000)) : randomBytes(400000); 25+ if (mode === "binary-limit") blob[0] = 255; 2326 const blobOid = await git.writeBlob({ fs: source, dir, blob }); 2427 const tree = await git.writeTree({ Lines 120–139 at 318 (were 117–135 at 178)
119122 intake.attach(cache); 120− const fs = new MemoryFS();
123+ const contents = new GitFileContents(storage, 1000000, 2000000); 124+ const fs = new MemoryFS(contents); 121125 const write = fs.promises.writeFile; 122126 fs.promises.writeFile = async (path, ...args) => { 123127 assert.ok(!/\.(pack|idx)$/.test(path), "clone must not persist a collected pack or index"); 124128 return write(path, ...args); 127− if (mode === "server-intake" || mode === "text-intake") {
131+ if (mode === "server-intake" || mode === "text-intake" || mode === "binary-limit") { 128132 const trees = new GitIntakeTrees(storage); 129− if (mode === "text-intake") {
133+ if (mode === "text-intake" || mode === "binary-limit") { 130134 const original = GitDiskIntake.prototype.read; 131135 t.mock.method(GitDiskIntake.prototype, "read", function (this: GitDiskIntake, oid: string) { 132− if (oid === blobOid) throw Error("whole text blob read forbidden");
136+ if (oid === blobOid) throw Error("whole blob read forbidden"); 133137 return original.call(this, oid); Lines 149–165 at 318 (were 145–159 at 178)
147151 async (bytes) => { 152+ assert.notEqual(mode, "binary-limit", "oversized binary must not reach the store"); 148153 assert.deepEqual(Buffer.from(bytes), blob); 149154 return "fixture-blob"; 156+ mode === "binary-limit" ? () => "previous-blob" : undefined, 152− undefined,
155160 maxPackBytes: 2000000, 156161 maxObjectBytes: 1000000, 162+ maxBinaryBytes: mode === "binary-limit" ? 100000 : undefined, 158164 retainFileChunks: (files, path, chunks, oid) => trees.retainChunks(files, path, chunks, oid), Lines 167–176 at 318 (were 161–167 at 178)
161167 assert.equal(found!.base, 0); 162168 assert.equal(found!.commits.length, 1); 163169 if (mode === "text-intake") assert.equal(found!.commits[0]!.files["large.bin"], blob.toString("utf8")); 164− else assert.equal(found!.commits[0]!.blobs["large.bin"], "fixture-blob");
170+ else if (mode === "binary-limit") { 171+ assert.equal(found!.commits[0]!.blobs["large.bin"], "previous-blob"); 172+ assert.deepEqual(found!.tooBig, ["large.bin"]); 173+ } else assert.equal(found!.commits[0]!.blobs["large.bin"], "fixture-blob"); 166175 for (const table of ["git_pack_spool", "git_pack_resolve", "git_object_meta", "git_object_bytes"]) 167176 assert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0); Lines 215–248 at 318 (were 206–212 at 178)
206215 assert.equal(await git.resolveRef({ fs, dir, ref: "main" }), head); 207216 assert.equal((await git.readCommit({ fs, dir, cache, oid: head })).commit.tree, tree); 208217 assert.deepEqual(Buffer.from((await git.readBlob({ fs, dir, cache, oid: blobOid })).blob), blob); 218+ const exported = await commitShared( 224+ files: { "new.txt": "Disk export fixture" }, 225+ blobs: { "large.bin": "fixture-blob" }, 231+ const next = await git.readCommit({ fs, dir, cache, oid: exported.commit }); 232+ assert.deepEqual(next.commit.parent, [head]); 234+ Buffer.from((await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: "large.bin" })).blob), 239+ (await git.readBlob({ fs, dir, cache, oid: exported.commit, filepath: "new.txt" })).blob, 241+ "Disk export fixture", 243+ for (const entry of fs.entries.values()) if (entry.kind === "file") assert.equal(entry.data.byteLength, 0); 211247 storage.db.close();