{"draft":null,"from":54,"to":318,"files":[{"path":"server/scripts/capacity-install-git-runtime.mjs","added":61,"removed":0,"diff":"--- /dev/null\n+++ b/server/scripts/capacity-install-git-runtime.mjs\n@@ -0,0 +1,61 @@\n+import { execFileSync } from \"node:child_process\";\n+import { createHash } from \"node:crypto\";\n+import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\n+import { tmpdir } from \"node:os\";\n+import { basename, dirname, join, resolve } from \"node:path\";\n+import { fileURLToPath } from \"node:url\";\n+\n+const scripts = dirname(fileURLToPath(import.meta.url));\n+const rootIndex = process.argv.indexOf(\"--root\");\n+if (rootIndex < 0 || !process.argv[rootIndex + 1])\n+\tthrow Error(\"Pass --root with the exact isomorphic-git package directory\");\n+const root = resolve(process.argv[rootIndex + 1]);\n+const hash = (bytes) => createHash(\"sha256\").update(bytes).digest(\"hex\");\n+const original = {\n+\t\"index.js\": \"66c20b7d890a6d48819f0be5f7bb1c5aab69937e6318ec912295c501028a5084\",\n+\t\"index.cjs\": \"b2142bba9e651fce83d6c1d266d32fc5eefa748544c452f9f22fada4e33dc367\",\n+};\n+const expected = {\n+\t\"index.js\": \"50ada141b506bff7cced797098f5ea70a6e40cda859884cc25b0dea985b10592\",\n+\t\"index.cjs\": \"3b8a78b7145330038cf56e057f7726004a78d0af9a55845b685cf1f65443bae0\",\n+};\n+if (JSON.parse(readFileSync(join(root, \"package.json\"), \"utf8\")).version !== \"1.44.2\")\n+\tthrow Error(\"Unsupported Git version\");\n+const installed = Object.fromEntries(Object.keys(original).map((file) => [file, readFileSync(join(root, file))]));\n+if (Object.entries(expected).every(([file, digest]) => hash(installed[file]) === digest)) {\n+\tconsole.log(\"Verified the complete Git capacity runtime patch.\");\n+\tprocess.exit(0);\n+}\n+if (process.argv.includes(\"--check\")) throw Error(\"Complete Git capacity runtime patch is absent or modified\");\n+for (const [file, digest] of Object.entries(original)) {\n+\tif (hash(installed[file]) !== digest) throw Error(`Unrecognized or partially patched Git bundle: ${file}`);\n+}\n+const temporary = mkdtempSync(join(tmpdir(), \"abso-git-patch-\"));\n+if (dirname(resolve(temporary)) !== resolve(tmpdir()) || !basename(temporary).startsWith(\"abso-git-patch-\"))\n+\tthrow Error(\"Unexpected temporary cleanup path\");\n+try {\n+\tconst staged = join(temporary, \"capacity-git-dependency-sandbox/node_modules/isomorphic-git\");\n+\tmkdirSync(staged, { recursive: true });\n+\tcopyFileSync(join(root, \"package.json\"), join(staged, \"package.json\"));\n+\tfor (const [file, bytes] of Object.entries(installed)) writeFileSync(join(staged, file), bytes);\n+\tcopyFileSync(join(scripts, \"capacity-git-bounded-fifo.mjs\"), join(temporary, \"capacity-git-bounded-fifo.mjs\"));\n+\tfor (const stage of [\"push\", \"fetch\", \"sideband\", \"progress\", \"pump\"]) {\n+\t\texecFileSync(process.execPath, [join(scripts, `capacity-patch-git-${stage}.mjs`)], {\n+\t\t\tcwd: temporary,\n+\t\t\tstdio: \"pipe\",\n+\t\t});\n+\t}\n+\tconst outputs = Object.fromEntries(Object.keys(expected).map((file) => [file, readFileSync(join(staged, file))]));\n+\tfor (const [file, digest] of Object.entries(expected)) {\n+\t\tif (hash(outputs[file]) !== digest) throw Error(`Unexpected complete Git patch: ${file}`);\n+\t}\n+\t// All stages and both final hashes pass before touching the installed package.\n+\tfor (const [file, bytes] of Object.entries(outputs)) writeFileSync(join(root, file), bytes);\n+\tconsole.log(\"Installed and verified the complete Git capacity runtime patch.\");\n+} finally {\n+\ttry {\n+\t\trmSync(temporary, { recursive: true, force: true });\n+\t} catch {\n+\t\tconsole.warn(\"Could not remove the Git patch staging directory.\");\n+\t}\n+}"}],"unmatched":[]}