Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
test: eight more git shims run the real git under their original PATH
garrytanceb90215a9e3
diff --git a/test/git-listing-memo.serial.test.ts b/test/git-listing-memo.serial.test.tsindex 947b878025..0b4fabaafa 100644--- a/test/git-listing-memo.serial.test.ts+++ b/test/git-listing-memo.serial.test.ts@@ -45,7 +45,7 @@ beforeAll(() => {const real = execFileSync('which', ['git'], { encoding: 'utf8' }).trim();const bin = join(root, 'bin');mkdirSync(bin);- writeFileSync(join(bin, 'git'), `#!/bin/sh\necho "$*" >> '${log}'\nexec '${real}' "$@"\n`);+ writeFileSync(join(bin, 'git'), `#!/bin/sh\necho "$*" >> '${log}'\nPATH='${process.env.PATH}' exec '${real}' "$@"\n`);chmodSync(join(bin, 'git'), 0o755);for (const [k, v] of Object.entries({ ...ENV, PATH: `${bin}:${process.env.PATH}` })) {saved[k] = process.env[k];diff --git a/test/git-target-pending-6665.test.ts b/test/git-target-pending-6665.test.tsindex baaef948d6..5a226aa9a3 100644--- a/test/git-target-pending-6665.test.ts+++ b/test/git-target-pending-6665.test.ts@@ -33,6 +33,7 @@ function fixture() {const bin = join(base, 'bin'); mkdirSync(bin);writeFileSync(join(bin, 'git'), `#!/bin/shREAL='${realGit}'+export PATH='${process.env.PATH}'if [ -n "$SHIM_RM_NOOP" ]; then for arg in "$@"; do [ "$arg" = rm ] && exit 0; done; ficase " $* " in *" core.fscache=false "*) exec "$REAL" "$@" ;; esacfor arg in "$@"; dodiff --git a/test/hardened-git-safe-directory-7584.test.ts b/test/hardened-git-safe-directory-7584.test.tsindex 736223b089..68c8efb14c 100644--- a/test/hardened-git-safe-directory-7584.test.ts+++ b/test/hardened-git-safe-directory-7584.test.ts@@ -29,7 +29,7 @@ async function setup() {const realGit = execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8' }).trim();const shim = join(dir, 'bin');execFileSync('mkdir', ['-p', shim]);- writeFileSync(join(shim, 'git'), `#!/bin/sh\nGIT_TEST_ASSUME_DIFFERENT_OWNER=1 exec "${realGit}" "$@"\n`);+ writeFileSync(join(shim, 'git'), `#!/bin/sh\nGIT_TEST_ASSUME_DIFFERENT_OWNER=1 PATH='${process.env.PATH}' exec "${realGit}" "$@"\n`);chmodSync(join(shim, 'git'), 0o755);const excludes = join(dir, 'excludes');writeFileSync(excludes, '*.md\n');diff --git a/test/managed-sync-pinned-reads.test.ts b/test/managed-sync-pinned-reads.test.tsindex 6e61520931..88628e707d 100644--- a/test/managed-sync-pinned-reads.test.ts+++ b/test/managed-sync-pinned-reads.test.ts@@ -165,7 +165,7 @@ function gitCounter(dir: string): GitCounter {const log = join(dir, 'git.log'), bin = join(dir, 'bin');mkdirSync(bin, { recursive: true });const real = REAL_GIT ??= execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8', timeout: 10_000, env: { ...process.env, PATH: PATH_AT_LOAD } }).trim();- writeFileSync(join(bin, 'git'), `#!/bin/sh\nprintf 'S %s %s %s\\n' "$$" "$(date +%s%N)" "$*" >> '${log}'\n'${real}' "$@"\ncode=$?\n`+ writeFileSync(join(bin, 'git'), `#!/bin/sh\nprintf 'S %s %s %s\\n' "$$" "$(date +%s%N)" "$*" >> '${log}'\nPATH='${PATH_AT_LOAD ?? ''}' '${real}' "$@"\ncode=$?\n`+ `printf 'E %s %s %s\\n' "$$" "$(date +%s%N)" "$code" >> '${log}'\nexit $code\n`);chmodSync(join(bin, 'git'), 0o755);const lines = () => existsSync(log) ? readFileSync(log, 'utf8').split('\n').filter(Boolean) : [];diff --git a/test/pathological/s-classic-byte-paths.test.ts b/test/pathological/s-classic-byte-paths.test.tsindex 01bb0d1419..93d9e00fe7 100644--- a/test/pathological/s-classic-byte-paths.test.ts+++ b/test/pathological/s-classic-byte-paths.test.ts@@ -113,7 +113,7 @@ describe('sync Git reads take no optional lock (GIT_OPTIONAL_LOCKS=0)', () => {const realGit = execFileSync('bash', ['-c', 'command -v git'], { encoding: 'utf8' }).trim();mkdirSync(bin); mkdirSync(repo);writeFileSync(join(bin, 'git'), '#!/bin/sh\nsub=""\nskip=0\nfor a in "$@"; do\n if [ $skip = 1 ]; then skip=0; continue; fi\n case "$a" in -c|-C) skip=1; continue;; esac\n sub="$a"; break\ndone\n'- + 'printf \'%s %s\\n\' "${GIT_OPTIONAL_LOCKS:-unset}" "$sub" >> "$PROBE_GIT_LOG"\nexec ' + realGit + ' "$@"\n');+ + 'printf \'%s %s\\n\' "${GIT_OPTIONAL_LOCKS:-unset}" "$sub" >> "$PROBE_GIT_LOG"\nPATH=\'' + process.env.PATH + '\' exec ' + realGit + ' "$@"\n');chmodSync(join(bin, 'git'), 0o755);gitIn(repo, 'init', '-q', '-b', 'main'); gitIn(repo, 'config', 'user.name', 'Example'); gitIn(repo, 'config', 'user.email', '[email protected]');writeFileSync(join(repo, 'a.md'), md('a')); gitIn(repo, 'add', '-A'); gitIn(repo, 'commit', '-qm', 'a');diff --git a/test/pending-import-async-git-7436.test.ts b/test/pending-import-async-git-7436.test.tsindex 46a2b9b24b..de246d0eae 100644--- a/test/pending-import-async-git-7436.test.ts+++ b/test/pending-import-async-git-7436.test.ts@@ -57,7 +57,7 @@ describe('#7436 pending-import Git check during page preparation', () => {const [binding] = await engine.executeRaw<{ worktree_id: string }>("SELECT worktree_id FROM persistence_source_bindings WHERE source_id='default'");const realGit = Bun.which('git')!;const shims = mkdtempSync(join(tmpdir(), 'gbrain-slow-git-'));- writeFileSync(join(shims, 'git'), `#!/bin/sh\nsleep 0.4\nexec "${realGit}" "$@"\n`);+ writeFileSync(join(shims, 'git'), `#!/bin/sh\nsleep 0.4\nPATH='${process.env.PATH}' exec "${realGit}" "$@"\n`);chmodSync(join(shims, 'git'), 0o755);const clock = startClaimPhase();enterClaimStep(clock, 'link_resolution', undefined, 'db');@@ -81,7 +81,7 @@ describe('#7436 pending-import Git check during page preparation', () => {const { snapshot, row } = await pendingImportPage(engine, ctx, root);const pids = join(mkdtempSync(join(tmpdir(), 'gbrain-git-pids-')), 'pids');// hash-object ignores SIGTERM and leaves a grandchild that does too, both outliving any deadline: only the group SIGKILL ends them.- const shims = gitShim(realGit => `#!/bin/sh\nfor a in "$@"; do if [ "$a" = "hash-object" ]; then trap '' TERM; sleep 120 & echo "$PPID $$ $!" >> ${pids}; wait; fi; done\nexec "${realGit}" "$@"\n`);+ const shims = gitShim(realGit => `#!/bin/sh\nfor a in "$@"; do if [ "$a" = "hash-object" ]; then trap '' TERM; sleep 120 & echo "$PPID $$ $!" >> ${pids}; wait; fi; done\nPATH='${process.env.PATH}' exec "${realGit}" "$@"\n`);const deadline = new AbortController();const clock = startClaimPhase(Date.now(), deadline.signal);enterClaimStep(clock, 'link_resolution', undefined, 'db');diff --git a/test/persistence-effect-git-index-lock.test.ts b/test/persistence-effect-git-index-lock.test.tsindex 6c6d0616a8..34d3560877 100644--- a/test/persistence-effect-git-index-lock.test.ts+++ b/test/persistence-effect-git-index-lock.test.ts@@ -74,7 +74,7 @@ test('an aborted git run that held the lock leaves it in place; the next attemptroot=""; prev=""for a in "$@"; do [ "$prev" = "-C" ] && root="$a"; prev="$a"; donefor a in "$@"; do if [ "$a" = "add" ]; then : > "$root/.git/index.lock"; : > "$root/.git/shim-add-holds-lock"; exec sleep 30; fi; done-exec ${realGit} "$@"+PATH='${process.env.PATH}' exec ${realGit} "$@"`, { mode: 0o755 });const lock = join(root, '.git', 'index.lock');const holding = join(root, '.git', 'shim-add-holds-lock');@@ -101,7 +101,7 @@ function refusingGit(refusal: string): { bin: string; path: string } {root=""; prev=""for a in "$@"; do [ "$prev" = "-C" ] && root="$a"; prev="$a"; donefor a in "$@"; do if [ "$a" = "add" ]; then ${refusal}; exit 128; fi; done-exec ${realGit} "$@"+PATH='${process.env.PATH}' exec ${realGit} "$@"`, { mode: 0o755 });return { bin, path: `${bin}:${process.env.PATH}` };}diff --git a/test/persistence-worktree-refresh.test.ts b/test/persistence-worktree-refresh.test.tsindex 21dd45753b..57c1756e35 100644--- a/test/persistence-worktree-refresh.test.ts+++ b/test/persistence-worktree-refresh.test.ts@@ -149,7 +149,7 @@ async function withFailingGit<T>(token: string, code: number, fn: () => Promise<const realGit = execFileSync('sh', ['-c', 'command -v git'], { encoding: 'utf8' }).trim();writeFileSync(join(bin, 'git'), `#!/bin/shfor a in "$@"; do if [ "$a" = "${token}" ]; then echo "fatal: injected failure of ${token}" >&2; exit ${code}; fi; done-exec ${realGit} "$@"+PATH='${process.env.PATH}' exec ${realGit} "$@"`, { mode: 0o755 });try { return await withEnv({ PATH: `${bin}:${process.env.PATH}` }, fn); } finally { rmSync(bin, { recursive: true, force: true }); }}