{"draft":null,"from":177,"to":178,"files":[{"path":"server/test/project-object-disk-first.test.ts","added":46,"removed":3,"diff":"--- a/server/test/project-object-disk-first.test.ts\n+++ b/server/test/project-object-disk-first.test.ts\n@@ -1,9 +1,10 @@\n import assert from \"node:assert/strict\";\n-import { registerHooks } from \"node:module\";\n+import { createRequire, registerHooks } from \"node:module\";\n import { test } from \"node:test\";\n import git from \"isomorphic-git\";\n import { Project } from \"../../worker/project/project.ts\";\n import { EngineProject } from \"../src/engine-project.ts\";\n+import { GitDiskIntake } from \"../src/git-disk-intake.ts\";\n import { MemoryFS } from \"../src/memory-fs.ts\";\n import { memoryStorage } from \"./helpers.ts\";\n \n@@ -20,6 +21,40 @@\n const { ProjectObject } = await import(\"../src/project-object.ts\");\n hooks.deregister();\n \n+function assertGitScratchEmpty(storage: ReturnType<typeof memoryStorage>) {\n+\tfor (const table of [\n+\t\t\"git_pack_spool\",\n+\t\t\"git_pack_resolve\",\n+\t\t\"git_object_meta\",\n+\t\t\"git_object_bytes\",\n+\t\t\"git_object_budget\",\n+\t])\n+\t\tassert.equal(storage.db.prepare(`SELECT COUNT(*) AS n FROM ${table}`).get()!.n, 0, table);\n+}\n+\n+/** Keep transport synthetic while exercising the real disk pack decoder and cache. */\n+async function cloneFixture(remote: MemoryFS, options: Parameters<typeof git.clone>[0]) {\n+\tconst intake = (options.cache as Record<symbol, GitDiskIntake> | undefined)?.[Symbol.for(\"abso.git.disk-pack\")];\n+\tif (!intake) {\n+\t\t(options.fs as MemoryFS).entries = structuredClone(remote.entries);\n+\t\treturn;\n+\t}\n+\tconst oids = [...remote.entries.keys()].flatMap((path) => {\n+\t\tconst match = /\\/objects\\/([0-9a-f]{2})\\/([0-9a-f]{38})$/.exec(path);\n+\t\treturn match ? [match[1]! + match[2]!] : [];\n+\t});\n+\tconst pack = (await git.packObjects({ fs: remote, dir: \"/repo\", oids, write: false })).packfile!;\n+\tconst { Inflate } = createRequire(import.meta.url)(\"pako\");\n+\tawait intake.ingest([pack], () => new Inflate({ chunkSize: 16384 }));\n+\tawait git.init({ fs: options.fs, dir: options.dir, defaultBranch: \"main\" });\n+\tawait git.writeRef({\n+\t\tfs: options.fs,\n+\t\tdir: options.dir,\n+\t\tref: \"main\",\n+\t\tvalue: await git.resolveRef({ fs: remote, dir: \"/repo\", ref: \"main\" }),\n+\t});\n+}\n+\n test(\"empty disk projects and unloadable legacy projects preserve lookup fallbacks\", async (t) => {\n \tconst storage = memoryStorage();\n \tt.after(() => storage.db.close());\n@@ -344,9 +379,14 @@\n \tawait git.writeRef({ fs: remote, dir: \"/repo\", ref: \"main\", value: incoming, force: true });\n \tt.mock.method(git, \"listServerRefs\", async () => [{ ref: \"refs/heads/main\", oid: incoming }]);\n \tt.mock.method(git, \"clone\", async (options: Parameters<typeof git.clone>[0]) => {\n-\t\t(options.fs as MemoryFS).entries = structuredClone(remote.entries);\n+\t\tawait cloneFixture(remote, options);\n \t});\n \tconst beforeIntake = rows();\n+\tconst originalRead = GitDiskIntake.prototype.read;\n+\tt.mock.method(GitDiskIntake.prototype, \"read\", function (this: GitDiskIntake, oid: string) {\n+\t\tif (oid === blob) throw Error(\"whole intake text blob forbidden\");\n+\t\treturn originalRead.call(this, oid);\n+\t});\n \tconst originalIngest = EngineProject.prototype.ingest;\n \tconst failedIngest = t.mock.method(\n \t\tEngineProject.prototype,\n@@ -357,15 +397,18 @@\n \t\t},\n \t);\n \tawait assert.rejects(() => bound().gitSync(), /injected after Git intake/);\n+\tassertGitScratchEmpty(storage);\n \tassert.deepEqual(rows(), beforeIntake);\n \tassert.equal((await bound().out()).git.head, parent, \"failed intake must not acknowledge the remote head\");\n \tfailedIngest.mock.restore();\n \tfailGitAcknowledgement = true;\n \tawait assert.rejects(() => bound().gitSync(), /Git cursor persistence failure/);\n+\tassertGitScratchEmpty(storage);\n \tconst committedIntake = rows();\n \tassert.equal((await bound().out()).version, 3);\n \tassert.equal((await bound().out()).git.head, parent);\n \tconst intake = await bound().gitSync();\n+\tassertGitScratchEmpty(storage);\n \tassert.deepEqual(rows(), committedIntake, \"retry after cursor failure returns the atomic intake receipt\");\n \tassert.ok(intake);\n \tassert.equal(intake?.head, incoming);\n@@ -443,7 +486,7 @@\n \t\tlet head = await commit({ \"A.TXT\": \"clash\\n\", \"a.txt\": \"original\\n\" }, \"Refused\", [base]);\n \t\tt.mock.method(git, \"listServerRefs\", async () => [{ ref: \"refs/heads/main\", oid: head }]);\n \t\tt.mock.method(git, \"clone\", async (options: Parameters<typeof git.clone>[0]) => {\n-\t\t\t(options.fs as MemoryFS).entries = structuredClone(remote.entries);\n+\t\t\tawait cloneFixture(remote, options);\n \t\t});\n \t\tconst refused = await object().gitSync();\n \t\tassert.ok(refused);"}],"unmatched":[]}