{"draft":null,"from":30,"to":318,"files":[{"path":"server/scripts/capacity-patch-git-fetch.mjs","added":91,"removed":0,"diff":"--- /dev/null\n+++ b/server/scripts/capacity-patch-git-fetch.mjs\n@@ -0,0 +1,91 @@\n+import { createHash } from \"node:crypto\";\n+import { readFileSync, writeFileSync } from \"node:fs\";\n+import { join } from \"node:path\";\n+\n+// Extends only the reviewed-version push prototype in this isolated dependency tree.\n+const root = \"capacity-git-dependency-sandbox/node_modules/isomorphic-git\";\n+const inputs = {\n+\t\"index.js\": \"0bd051b1a38bf8d593bf37b5acf9ee453ddab33d48950c84e2c2c3f3ec449fc8\",\n+\t\"index.cjs\": \"6c9f6eab37a10c9311f2b7aa8d24b0772d4ba2703d848525a0519e1454d016e7\",\n+};\n+const hash = (source) => createHash(\"sha256\").update(source).digest(\"hex\");\n+const expectedOutputs = {\n+\t\"index.js\": \"eebe6911fa660d4b95857768ea2308be74435dd5f9a796bb7b2491a31bdd109d\",\n+\t\"index.cjs\": \"33364e3ed7f3a1a6cf17a1ecabbfc5d6de6a8494f31a524d8ac293402ad4e447\",\n+};\n+function once(source, before, after) {\n+\tif (source.split(before).length !== 2) throw Error(\"Fetch patch anchor mismatch\");\n+\treturn source.replace(before, after);\n+}\n+if (JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")).version !== \"1.44.2\") {\n+\tthrow Error(\"Unsupported Git version\");\n+}\n+const outputs = [];\n+const installed = Object.fromEntries(Object.keys(inputs).map((file) => [file, readFileSync(join(root, file), \"utf8\")]));\n+if (Object.entries(expectedOutputs).every(([file, expected]) => hash(installed[file]) === expected)) {\n+\tconsole.log(\n+\t\tJSON.stringify({\n+\t\t\tverified: true,\n+\t\t\tscope: \"Isolated fetch prototype\",\n+\t\t\tbundles: expectedOutputs,\n+\t\t}),\n+\t);\n+\tprocess.exit(0);\n+}\n+for (const [file, expected] of Object.entries(inputs)) {\n+\tconst source = installed[file];\n+\tif (hash(source) !== expected) throw Error(`Unrecognized input: ${file}`);\n+\tlet result = once(\n+\t\tsource,\n+\t\t\"  const packfile = Buffer.from(await collect(response.packfile));\",\n+\t\t`  const diskPack = cache && cache[Symbol.for('abso.git.disk-pack')];\n+  if (diskPack) {\n+    await diskPack.ingest(response.packfile, () => new pako.Inflate({ chunkSize: 16384 }));\n+    if (raw.body.error) throw raw.body.error\n+    const result = {\n+      defaultBranch: response.HEAD,\n+      fetchHead: response.FETCH_HEAD.oid,\n+      fetchHeadDescription: response.FETCH_HEAD.description,\n+    };\n+    if (response.headers) result.headers = response.headers;\n+    if (prune) result.pruned = response.pruned;\n+    return result\n+  }\n+  const packfile = Buffer.from(await collect(response.packfile));`,\n+\t);\n+\tconst readStart = result.indexOf(\"async function _readObject({\");\n+\tconst readEnd = result.indexOf(\"\\nclass AlreadyExistsError\", readStart);\n+\tif (readStart < 0 || readEnd < 0) throw Error(\"Missing object reader boundary\");\n+\tconst readFunction = once(\n+\t\tresult.slice(readStart, readEnd),\n+\t\t\"  // Curry the current read method so that the packfile un-deltification\",\n+\t\t`  const diskPack = cache && cache[Symbol.for('abso.git.disk-pack')];\n+  if (diskPack && format === 'content') {\n+    const stored = await diskPack.read(oid);\n+    if (stored) return stored\n+  }\n+\n+  // Curry the current read method so that the packfile un-deltification`,\n+\t);\n+\tresult = result.slice(0, readStart) + readFunction + result.slice(readEnd);\n+\tif (hash(result) !== expectedOutputs[file]) throw Error(`Unexpected fetch patch output: ${file}`);\n+\toutputs.push({ file, result, sha256: hash(result) });\n+}\n+// Validate both installed bundles and every anchor before either write.\n+if (!process.argv.includes(\"--check\")) {\n+\tfor (const { file, result } of outputs) writeFileSync(join(root, file), result);\n+\twriteFileSync(\n+\t\t\"capacity-git-fetch-patch-manifest.json\",\n+\t\tJSON.stringify(\n+\t\t\toutputs.map(({ file, sha256 }) => ({ file, sha256 })),\n+\t\t\tnull,\n+\t\t\t2,\n+\t\t),\n+\t);\n+}\n+console.log(\n+\tJSON.stringify({\n+\t\tscope: \"Isolated fetch prototype; runtime adapter and transport acceptance still required\",\n+\t\toutputs: outputs.map(({ file, sha256 }) => ({ file, sha256 })),\n+\t}),\n+);"}],"unmatched":[]}