From 08e1c43e4e04689b959225833edffd70f24b7850 Mon Sep 17 00:00:00 2001 From: Mattias Petersson Date: Sun, 12 Jul 2026 16:46:49 +0200 Subject: [PATCH] fix(test): resolve gbrain detect install paths and session import xargs crash --- bin/gstack-codex-session-import | 2 +- test/gbrain-detect-install.test.ts | 6 ++++-- test/gbrain-refresh-install-render.test.ts | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bin/gstack-codex-session-import b/bin/gstack-codex-session-import index 91368cac9..f6c091d00 100755 --- a/bin/gstack-codex-session-import +++ b/bin/gstack-codex-session-import @@ -65,7 +65,7 @@ case "$MODE" in exit 0 fi LATEST=$(find "$CODEX_SESSIONS_ROOT" -type f -name "rollout-*.jsonl" -print 2>/dev/null \ - | xargs ls -t 2>/dev/null | head -1 || true) + | xargs -r ls -t 2>/dev/null | head -1 || true) if [ -z "$LATEST" ]; then echo "NO_SESSIONS: no rollout-*.jsonl files under $CODEX_SESSIONS_ROOT" exit 0 diff --git a/test/gbrain-detect-install.test.ts b/test/gbrain-detect-install.test.ts index b9c82c155..376e7b6c2 100644 --- a/test/gbrain-detect-install.test.ts +++ b/test/gbrain-detect-install.test.ts @@ -24,8 +24,10 @@ const INSTALL = path.join(ROOT, 'bin', 'gstack-gbrain-install'); // Minimal PATH with POSIX tools + homebrew (for jq/git/curl) but no user-bin // dirs — this keeps `gbrain` out of PATH deterministically across dev machines // while still finding jq, git, curl, sed, cat, etc. Each test can prepend a -// fake-gbrain dir when it wants to simulate presence. -const SAFE_PATH = '/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/usr/local/bin'; +// fake-gbrain dir when it wants to simulate presence. We append the active Bun +// directory so the script shebang can find bun. +const BUN_DIR = path.dirname(process.execPath); +const SAFE_PATH = `/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin:/usr/local/bin:${BUN_DIR}`; let tmpHome: string; let tmpHomeReal: string; diff --git a/test/gbrain-refresh-install-render.test.ts b/test/gbrain-refresh-install-render.test.ts index f1494d47d..95e75bde5 100644 --- a/test/gbrain-refresh-install-render.test.ts +++ b/test/gbrain-refresh-install-render.test.ts @@ -13,7 +13,7 @@ const SRC = fs.readFileSync(path.join(ROOT, 'bin', 'gstack-config'), 'utf-8'); // satisfied by unrelated text elsewhere in the file. function okBranch(): string { const start = SRC.indexOf('gbrain-refresh)'); - const ok = SRC.indexOf('ok)', start); + const ok = SRC.indexOf('ok|timeout)', start); const end = SRC.indexOf(';;', ok); if (start < 0 || ok < 0 || end < 0) throw new Error('Could not locate gbrain-refresh ok) branch'); return SRC.slice(ok, end);