Use Garry Tan's exact Claude Code setup: 23 opinionated tools that serve as CEO, Designer, Eng Manager, Release Manager, Doc Engineer, and QA
TypeScript
Windows: a python3 that won't run no longer deletes skills on update, and long test commands fail clearly (#4793)
Garry Tan3b9d9757fdcf
diff --git a/bin/gstack-config b/bin/gstack-configindex cfb902f3b..c7f005595 100755--- a/bin/gstack-config+++ b/bin/gstack-config@@ -1225,25 +1225,33 @@ $_gstack_legacy_root"echo "gstack-gbrain-detect not found at $DETECT_BIN" >&2exit 1fi+ _GBRAIN_PROBE=absentif ! "$DETECT_BIN" > "$DETECTION_FILE.tmp.$$" 2>/dev/null; thenprintf '{"gbrain_on_path":false,"gbrain_local_status":"no-cli"}\n' > "$DETECTION_FILE.tmp.$$"+ _GBRAIN_PROBE=unknownfimv "$DETECTION_FILE.tmp.$$" "$DETECTION_FILE"- # Summarize for the user. Use python (already required elsewhere) to- # parse the JSON portably; fall back to grep if python is unavailable.+ # Summarize for the user with the first Python that runs, else grep. A+ # python3 on PATH may not run: on Windows it is often the Microsoft Store+ # alias, which exits 49 (#4752), so it counts as absent.# The file goes in on stdin (E6, #1967): bash opens the path, so a native# Windows Python under Git Bash never has to resolve an MSYS /c/... path.- PYTHON_CMD=$(command -v python3 || command -v python || true)- if [ -n "$PYTHON_CMD" ]; then- STATUS=$("$PYTHON_CMD" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_local_status','unknown'))" < "$DETECTION_FILE" 2>/dev/null || echo unknown)- VERSION=$("$PYTHON_CMD" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_version') or 'unknown')" < "$DETECTION_FILE" 2>/dev/null || echo unknown)- else- STATUS=$(grep -o '"gbrain_local_status":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/')- VERSION=$(grep -o '"gbrain_version":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/')- [ -z "$STATUS" ] && STATUS=unknown- [ -z "$VERSION" ] && VERSION=unknown+ STATUS=""; VERSION=""+ for _py in python3 python; do+ command -v "$_py" >/dev/null 2>&1 || continue+ STATUS=$("$_py" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_local_status','unknown'))" < "$DETECTION_FILE" 2>/dev/null) \+ && VERSION=$("$_py" -c "import json,sys; d=json.load(sys.stdin); print(d.get('gbrain_version') or 'unknown')" < "$DETECTION_FILE" 2>/dev/null) \+ && break+ STATUS=""; VERSION=""+ done+ if [ -z "$STATUS" ]; then+ STATUS=$(grep -o '"gbrain_local_status":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/' || true)+ VERSION=$(grep -o '"gbrain_version":[[:space:]]*"[^"]*"' "$DETECTION_FILE" | sed 's/.*"\([^"]*\)"$/\1/' || true)fi+ [ -n "$STATUS" ] || STATUS=unknown+ [ -n "$VERSION" ] || VERSION=unknown+ [ "$STATUS" != unknown ] || _GBRAIN_PROBE=unknowncase "$STATUS" inok|timeout|db-unreachable|thin-client|engine-locked)@@ -1308,8 +1316,12 @@ $_gstack_legacy_root"fi;;*)- echo "gbrain not detected (local-status: $STATUS) → brain-aware blocks will be suppressed in planning-skill SKILL.md files."- echo "Install gbrain (see /setup-gbrain) and re-run 'gstack-config gbrain-refresh' once it's configured."+ if [ "$_GBRAIN_PROBE" = unknown ]; then+ echo "Could not read gbrain's state (local-status: $STATUS); an existing Claude render is left in place. Re-run 'gstack-config gbrain-refresh' to retry."+ else+ echo "gbrain not detected (local-status: $STATUS) → brain-aware blocks will be suppressed in planning-skill SKILL.md files."+ echo "Install gbrain (see /setup-gbrain) and re-run 'gstack-config gbrain-refresh' once it's configured."+ fi# Drop a brain-aware render, or re-render a pinned overlay without# brain blocks, so removing gbrain keeps the chosen overlay.INSTALL_DIR="$HOME/.claude/skills/gstack"@@ -1320,19 +1332,25 @@ $_gstack_legacy_root"echo "Skip: bun not on PATH — the Claude render at $RENDER_DIR was not refreshed. Install bun, then re-run 'gstack-config gbrain-refresh'."elsegstack_claude_overlay "$INSTALL_DIR" "$0"- gstack_claude_render_action "$RENDER_DIR" absent- if [ "$_GSTACK_RENDER_ACTION" = plain ]; then+ if [ "$_GBRAIN_PROBE" = unknown ] && [ -d "$RENDER_DIR" ]; then+ _GSTACK_RENDER_ACTION=keep+ else+ gstack_claude_render_action "$RENDER_DIR" "$_GBRAIN_PROBE"+ fi+ if [ "$_GSTACK_RENDER_ACTION" = keep ]; then+ :+ elif [ "$_GSTACK_RENDER_ACTION" = plain ]; thenif gstack_claude_render_plain "$INSTALL_DIR" "$RENDER_DIR"; then- gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent rendered+ gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" renderedelse- gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent failed+ gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" failedfielseif [ -d "$RENDER_DIR" ]; thenrm -rf "$RENDER_DIR"echo "Removed the brain-aware render at $RENDER_DIR; Claude skills serve the committed files."fi- gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" absent removed+ gstack_claude_render_settle "$INSTALL_DIR" "$RENDER_DIR" "$_GBRAIN_PROBE" removedfi"$INSTALL_DIR/bin/gstack-relink" >/dev/null 2>&1 || truefidiff --git a/changelog.d/windows-python3-stub-and-long-test-commands.md b/changelog.d/windows-python3-stub-and-long-test-commands.mdnew file mode 100644index 000000000..635cd09e8--- /dev/null+++ b/changelog.d/windows-python3-stub-and-long-test-commands.md@@ -0,0 +1,4 @@+---+important: data-loss+---+**On Windows, an update no longer deletes your brain-aware skills when `python3` is the Microsoft Store alias.** That alias stays on PATH next to a real Python and exits 49 without running anything, so `gstack-config gbrain-refresh`, which runs after every team-mode update, read a healthy gbrain as "not detected" and removed the brain-aware render. A Python that does not run now counts as absent (the next Python, then a plain-text read, is used instead), and when gbrain's state cannot be read at all the existing render is left in place. Thanks to @Barack-zero-to-one for the diagnosis and tests (#4752). A pre-ship test command longer than the 8,186 characters Git Bash keeps is now split to fit, or refused with a clear "argument list too long" message, instead of starting cut off and failing with an empty log (#4773).diff --git a/docs/pregate.md b/docs/pregate.mdindex 32eadb8d4..1dd5cc8c5 100644--- a/docs/pregate.md+++ b/docs/pregate.md@@ -490,7 +490,8 @@ Two stages with separate clocks, both printed:`**/*.serial.test.*`) run one process per file after the unit files. A unitgroup whose quoted file list would pass the system's argument limits (Linuxcaps one argument at 128 KiB) runs as several runner processes in sequence,- each under about 96 KB of file arguments (24 KB on Windows), read back as one run: counts add up,+ each under about 96 KB of file arguments (on Windows, under the 8,186 characters+ Git Bash keeps of one argument, #4773), read back as one run: counts add up,any failing chunk fails the lane, and they share the group's one `--timeout`. Therunner and every guard run with the verified launch Bun first on PATH: thefirst of `$BUN_INSTALL/bin` and `~/.bun/bin` whose Bun satisfies gstack's anddiff --git a/docs/troubleshooting.md b/docs/troubleshooting.mdindex 42bcdc890..3559f6d8f 100644--- a/docs/troubleshooting.md+++ b/docs/troubleshooting.md@@ -4894,11 +4894,14 @@ line really pins the old value, so update the golden.the system's limit, so it never ran and no test was counted. Linux caps oneargument at 128 KiB and a whole command line plus environment at about 2 MiB,macOS caps the total at 1 MiB, and Windows caps a command line at 32,767-characters. The usual trigger is a long file list: thousands of selected test+characters. Git Bash on Windows keeps only the first 8,186 characters of a+`bash -c` command, so gstack refuses a longer one with `argument list too long+for Git Bash` instead of running it cut off (#4773). The usual trigger is a long file list: thousands of selected testfiles put into one argument.**Fix.** gstack keeps file lists out of single arguments: a local lane splits-its files into runner processes of about 96 KB each (24 KB on Windows), and+its files into runner processes of about 96 KB each (under 8,186 characters on+Windows), andthe `test_backend` command for the remote gate passes them in a setup script(docs/pregate.md#remote-gate). So this cause is a gstack bug: report it withthe `environment:` line and the lane or command it names. Until it is fixed,diff --git a/lib/pregate/checks/lanes.ts b/lib/pregate/checks/lanes.tsindex 91c7e2e90..cc4fe4b75 100644--- a/lib/pregate/checks/lanes.ts+++ b/lib/pregate/checks/lanes.ts@@ -40,8 +40,9 @@ import { docsOnlyLane } from '../docs-only-lane';import { selectLanes, type Selection } from '../lane-selection';import { launchRuntime } from '../runtime';import { cargoModel, type CargoModel } from '../rust';-import { adapterFor, readRange, STALL_IDLE, supervise, type Counter, type Supervised } from '../supervise';+import { adapterFor, PIPEFAIL, readRange, STALL_IDLE, supervise, type Counter, type Supervised } from '../supervise';import { ranFiles, runChanged, runReceiptFields, verifyFromRun, type RunProfile } from '../../run-evidence';+import { WINDOWS_BASH_ARG_MAX } from '../../script-invocation';import { matchesAny } from '../../ship-policy';import { testFileArgs } from '../../test-paths';import type { CheckDef, CheckResult, PregateContext, RemoteObligation } from '../types';@@ -406,15 +407,14 @@ interface LocalRun { exit: number | null; outcome: Supervised['outcome']; signalconst quote = (f: string) => `'${f.replace(/'/g, `'\\''`)}'`;/**- * Bytes of quoted file arguments one runner process may take. supervise passes the whole command as one `bash -c`- * argument: Linux caps a single execve argument at 128 KiB (MAX_ARG_STRLEN), every POSIX system caps argv plus the- * environment (ARG_MAX: 1 MiB on macOS, 2 MiB by default on Linux), and Windows caps a whole command line at 32,767- * characters. The runner text itself and a margin come off the top.+ * Bytes of quoted file arguments one runner process may take (unlimited without a {files} placeholder: `cargo test -p`).+ * supervise passes PIPEFAIL plus the command as one `bash -c` argument: Linux caps one execve argument at 128 KiB, POSIX+ * caps argv plus environment (ARG_MAX), and Git Bash on Windows keeps its first 8,186 characters only (#4773).*/export function argBudget(runner: string, env: NodeJS.ProcessEnv, platform = process.platform): number {const envBytes = Object.entries(env).reduce((n, [k, v]) => n + Buffer.byteLength(`${k}=${v ?? ''}`) + 9, 0);- const cap = platform === 'win32' ? 24 * 1024 : Math.min(96 * 1024, 1024 * 1024 - 64 * 1024 - envBytes);- return cap - Buffer.byteLength(runner) - 512;+ const cap = platform === 'win32' ? WINDOWS_BASH_ARG_MAX : Math.min(96 * 1024, 1024 * 1024 - 64 * 1024 - envBytes);+ return runner.includes('{files}') ? cap - Buffer.byteLength(PIPEFAIL) - Buffer.byteLength(runner) - 512 : Infinity;}/** `args` split in order into chunks whose quoted, space-joined text fits `budget` bytes; an argument over it runs alone. */@@ -452,8 +452,8 @@ async function runOnce(ctx: PregateContext, env: NodeJS.ProcessEnv, g: RunGroup,if (r.exit === null) break;}if (parts.length === 1) return parts[0]!;- const bad = parts.find(p => p.exit === null) ?? parts.find(p => p.exit !== 0) ?? parts.at(-1)!;- const sum = (k: 'ran' | 'failed') => (parts.some(p => p[k] === null) ? null : parts.reduce((n, p) => n + (p[k] as number), 0));+ const bad = parts.find(p => p.exit === null) ?? parts.find(p => p.exit !== 0) ?? parts.find(p => p.ran === 0) ?? parts.at(-1)!;+ const sum = (k: 'ran' | 'failed') => (k === 'ran' && parts.some(p => p.ran === 0) ? 0 : parts.some(p => p[k] === null) ? null : parts.reduce((n, p) => n + (p[k] as number), 0));return { ...(parts.every(p => p.noBrowsers) ? { noBrowsers: parts[0]!.noBrowsers } : {}), exit: bad.exit, outcome: bad.outcome, signal: bad.signal, observedStart: parts.some(p => p.observedStart), ran: sum('ran'), failed: sum('failed'), tail: bad.tail, runner: g.runner, command: parts.map(p => p.command).join(' && '), files: parts.flatMap(p => p.files), lastFile: bad.lastFile, ms: parts.reduce((n, p) => n + p.ms, 0), ...(bad.error ? { error: bad.error } : {}) };}diff --git a/lib/pregate/supervise.ts b/lib/pregate/supervise.tsindex ce8618595..84594cd5a 100644--- a/lib/pregate/supervise.ts+++ b/lib/pregate/supervise.ts@@ -30,6 +30,8 @@ import { BUN_TEST } from '../test-paths';export type ProgressAdapter = 'bun';export const PROGRESS_ADAPTERS: Record<ProgressAdapter, RegExp> = { bun: BUN_TEST };+/** Prefixed to every supervised command, so it counts against the argument limits too. */+export const PIPEFAIL = 'set -o pipefail; ';export interface Counter { done: number; total: number }@@ -216,7 +218,7 @@ export function supervise(o: SuperviseOptions): Promise<Supervised> {let fd: number;try { fd = fs.openSync(o.log, 'a'); }catch (e: any) { resolve({ outcome: 'spawn-failed', exit: null, signal: null, start, end: start, lastFile: null, observedStart: false, error: e.message, ms: 0 }); return; }- const inv = bashCommandInvocation(`set -o pipefail; ${o.command}`);+ const inv = bashCommandInvocation(`${PIPEFAIL}${o.command}`);if (!inv.ok) {fs.closeSync(fd);resolve({ outcome: 'spawn-failed', exit: null, signal: null, start, end: start, lastFile: null, observedStart: false, error: inv.error, ms: Date.now() - started });diff --git a/lib/script-invocation.ts b/lib/script-invocation.tsindex df5d19b3c..1e8f27602 100644--- a/lib/script-invocation.ts+++ b/lib/script-invocation.ts@@ -213,9 +213,18 @@ export function scriptInvocation(script: string, args: readonly string[], o: Invreturn bash.ok ? { ok: true, cmd: bash.bash, argv: [slash(script), ...args] } : bash;}-/** How to run `bash -c <command>` on this platform. */+/**+ * Characters of one argument that Git Bash keeps when a Windows program starts it: the Cygwin/MSYS runtime silently drops+ * the rest of an argument with spaces (#4773; reported on Git for Windows 2.53, bash 5.2.37).+ */+export const WINDOWS_BASH_ARG_MAX = 8186;++/** How to run `bash -c <command>` on this platform. On Windows a command Git Bash would cut off is refused, never run. */export function bashCommandInvocation(command: string, o: InvocationOptions = {}): Invocation {if ((o.platform ?? process.platform) !== 'win32') return { ok: true, cmd: 'bash', argv: ['-c', command] };+ if (command.length > WINDOWS_BASH_ARG_MAX) {+ return { ok: false, error: `argument list too long for Git Bash: the bash -c command is ${command.length.toLocaleString('en-US')} characters and Git Bash on Windows keeps only the first ${WINDOWS_BASH_ARG_MAX.toLocaleString('en-US')}, so it was not started rather than run cut off (#4773)` };+ }const bash = windowsBash(o);return bash.ok ? { ok: true, cmd: bash.bash, argv: ['-c', command] } : bash;}diff --git a/test/gstack-config-gbrain-refresh.test.ts b/test/gstack-config-gbrain-refresh.test.tsindex 979504579..4fa4dc613 100644--- a/test/gstack-config-gbrain-refresh.test.ts+++ b/test/gstack-config-gbrain-refresh.test.ts@@ -21,6 +21,32 @@ const refresh = () => spawnSync('bash', [path.join(binDir, 'gstack-config'), 'gbencoding: 'utf8', timeout: 30_000,env: { PATH: `${binDir}:${process.env.PATH ?? '/usr/bin:/bin'}`, HOME: home, GSTACK_HOME: home, GSTACK_STATE_ROOT: home },});+// A Python that cannot open() the state path but reads stdin, like native+// Windows Python handed an MSYS path. Bun stands in for its JSON parse, and+// each call appends the name it ran under to $HOME/python-calls.+const parsingPython = (name: string) => fs.writeFileSync(path.join(binDir, name), `#!/usr/bin/env bash+echo ${name} >> "$HOME/python-calls"+case "$2" in *"open("*) echo "FileNotFoundError: [Errno 2] No such file or directory" >&2; exit 1 ;; esac+exec ${JSON.stringify(process.execPath)} -e 'const d = JSON.parse(require("fs").readFileSync(0, "utf8")); console.log(process.argv[1].includes("gbrain_version") ? (d.gbrain_version || "unknown") : (d.gbrain_local_status || "unknown"))' "$2"+`, { mode: 0o755 });+// The Microsoft Store alias Windows keeps on PATH as python3 (often python+// too), even next to a python.org install: it runs no Python, prints a hint+// on stderr and exits 49.+const storeAlias = (name: string) => fs.writeFileSync(path.join(binDir, name), `#!/usr/bin/env bash+echo "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Apps > Advanced app settings > App execution aliases." >&2+exit 49+`, { mode: 0o755 });+// A global install with an existing brain-aware render; returns the render file.+const installWithRender = () => {+ const install = path.join(home, '.claude', 'skills', 'gstack');+ fs.mkdirSync(install, { recursive: true });+ fs.writeFileSync(path.join(install, 'VERSION'), '1.0.0.0\n');+ fs.writeFileSync(path.join(install, 'package.json'), '{}\n');+ const rendered = path.join(home, 'render', 'claude', 'review', 'SKILL.md');+ fs.mkdirSync(path.dirname(rendered), { recursive: true });+ fs.writeFileSync(rendered, 'brain-aware render\n');+ return rendered;+};beforeEach(() => {tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gbrain-refresh-'));@@ -28,17 +54,12 @@ beforeEach(() => {home = path.join(tmp, 'home');fs.mkdirSync(binDir, { recursive: true });fs.mkdirSync(home, { recursive: true });- for (const f of ['gstack-config', 'gstack-state-root.sh', 'gstack-render-claude.sh']) {+ for (const f of ['gstack-config', 'gstack-state-root.sh', 'gstack-render-claude.sh', 'gstack-lock.sh']) {fs.copyFileSync(path.join(ROOT, 'bin', f), path.join(binDir, f));fs.chmodSync(path.join(binDir, f), 0o755);}writeDetect('no-config');- // A Python that cannot open() the state path but reads stdin, like native- // Windows Python handed an MSYS path. Bun stands in for its JSON parse.- fs.writeFileSync(path.join(binDir, 'python3'), `#!/usr/bin/env bash-case "$2" in *"open("*) echo "FileNotFoundError: [Errno 2] No such file or directory" >&2; exit 1 ;; esac-exec ${JSON.stringify(process.execPath)} -e 'const d = JSON.parse(require("fs").readFileSync(0, "utf8")); console.log(process.argv[1].includes("gbrain_version") ? (d.gbrain_version || "unknown") : (d.gbrain_local_status || "unknown"))' "$2"-`, { mode: 0o755 });+ parsingPython('python3');});afterEach(() => { fs.rmSync(tmp, { recursive: true, force: true }); });@@ -62,3 +83,71 @@ describe('gstack-config gbrain-refresh (E6)', () => {}});});++describe('gstack-config gbrain-refresh when python3 is the Windows Store alias (#4752)', () => {+ test('a python3 that does not run counts as absent: python parses the file, else grep does', () => {+ storeAlias('python3');+ parsingPython('python');+ writeDetect('ok');+ let r = refresh();+ expect(r.status, r.stderr).toBe(0);+ expect(r.stdout).toContain('Detected gbrain v0.35.8.0 (local-status: ok).');+ expect(fs.readFileSync(path.join(home, 'python-calls'), 'utf8').trim().split('\n')).toEqual(['python', 'python']);++ storeAlias('python');+ r = refresh();+ expect(r.status, r.stderr).toBe(0);+ expect(r.stdout).toContain('Detected gbrain v0.35.8.0 (local-status: ok).');+ expect(r.stderr).not.toContain('Python was not found');+ });++ test('a healthy gbrain keeps its brain-aware render when no Python runs', () => {+ storeAlias('python3');+ storeAlias('python');+ writeDetect('ok');+ const rendered = installWithRender();+ // Only the render step fails, so the healthy path ends on "previous render left in place".+ fs.writeFileSync(path.join(binDir, 'bun'), `#!/usr/bin/env bash+case "$*" in *gen:skill-docs*) echo 'render failed (fixture)' >&2; exit 7 ;; esac+exec ${JSON.stringify(process.execPath)} "$@"+`, { mode: 0o755 });+ const r = refresh();+ expect(r.status, r.stderr).toBe(0);+ expect(r.stdout).toContain('previous render (if any) left in place');+ expect(r.stdout).not.toContain('Removed the brain-aware render');+ expect(fs.readFileSync(rendered, 'utf8')).toBe('brain-aware render\n');+ });++ test('a failed probe never removes an installed render', () => {+ storeAlias('python3');+ storeAlias('python');+ const rendered = installWithRender();+ for (const detect of ['exit 1', "echo 'not json'"]) {+ fs.writeFileSync(path.join(binDir, 'gstack-gbrain-detect'), `#!/usr/bin/env bash\n${detect}\n`, { mode: 0o755 });+ const r = refresh();+ expect(r.status, r.stderr).toBe(0);+ expect(r.stdout).toContain("Could not read gbrain's state");+ expect(r.stdout).not.toContain('Removed the brain-aware render');+ expect(fs.readFileSync(rendered, 'utf8')).toBe('brain-aware render\n');+ }+ });++ test('a failed probe leaves a customized render in place instead of re-rendering it without brain blocks', () => {+ const rendered = installWithRender();+ const set = spawnSync('bash', [path.join(binDir, 'gstack-config'), 'set', 'claude_loadout', 'lite'], { encoding: 'utf8', timeout: 30_000, env: { PATH: `${binDir}:${process.env.PATH ?? '/usr/bin:/bin'}`, HOME: home, GSTACK_HOME: home, GSTACK_STATE_ROOT: home } });+ expect(set.status, set.stderr).toBe(0);+ // A plain render that would succeed, so only the refresh's own choice keeps the brain-aware one.+ fs.writeFileSync(path.join(binDir, 'bun'), `#!/usr/bin/env bash+case "$*" in *gen:skill-docs*)+ while [ $# -gt 0 ]; do [ "$1" = --out-dir ] && { mkdir -p "$2/review"; echo 'plain render' > "$2/review/SKILL.md"; exit 0; }; shift; done; exit 1 ;;+esac+exec ${JSON.stringify(process.execPath)} "$@"+`, { mode: 0o755 });+ fs.writeFileSync(path.join(binDir, 'gstack-patch-names'), '#!/usr/bin/env bash\nexit 0\n', { mode: 0o755 });+ fs.writeFileSync(path.join(binDir, 'gstack-gbrain-detect'), '#!/usr/bin/env bash\nexit 1\n', { mode: 0o755 });+ const r = refresh();+ expect(r.status, r.stderr).toBe(0);+ expect(r.stdout).toContain("Could not read gbrain's state");+ expect(fs.readFileSync(rendered, 'utf8')).toBe('brain-aware render\n');+ });+});diff --git a/test/pregate-lanes-arg-limit.test.ts b/test/pregate-lanes-arg-limit.test.tsindex b9a63d474..fdf3076f5 100644--- a/test/pregate-lanes-arg-limit.test.ts+++ b/test/pregate-lanes-arg-limit.test.ts@@ -21,7 +21,8 @@ afterEach(() => { while (repos.length) cleanup(repos.pop()!); });const FILES = 700;const name = (i: number, tag = 'x') => `test/big/${tag.padEnd(186, 'x')}${String(i).padStart(4, '0')}.test.js`;const RUNNER = [- 'const files = process.argv.slice(2);',+ "if (process.argv.slice(2).some(f => f.includes('yodd'))) { console.log('done'); process.exit(0); }",+ "const files = process.argv.slice(2).filter(f => !f.includes('zskip'));","const failed = files.filter(f => f.includes('fail')).length;","console.log(`ℹ tests ${files.length}\\nℹ pass ${files.length - failed}\\nℹ fail ${failed}`);",'process.exit(failed ? 1 : 0);',@@ -55,6 +56,20 @@ describe.skipIf(process.platform === 'win32')('a local lane whose file list is oconst red = await lanesOver([...tests.slice(0, -1), name(FILES - 1, 'zfail')]);expect(red).toMatchObject({ status: 'fail', code: 'PREGATE_LANE_FAILED', detail: `local lane exited 1 (1 failed of ${FILES} ran; ${FILES} files; pipefail)` });}, 120_000);++ // Value: protects=a chunk that exits 0 having run no tests fails the lane as ZERO-RUN, as the same files alone would;+ // fails_when=the chunks' counts are summed, so another chunk's tests hide it; why_new=#4773 sends ordinary Windows+ // selections through chunks; seam=runPregate --only lanes with a runner that runs nothing for zskip files+ test('a chunk that ran no tests makes the lane zero-run, even when another chunk ran tests', async () => {+ const tests = Array.from({ length: FILES }, (_, i) => name(i, i < FILES / 2 ? 'x' : 'zskip'));+ const lane = await lanesOver(tests);+ expect(lane).toMatchObject({ status: 'fail', code: 'PREGATE_LANE_FAILED' });+ expect(lane.detail).toStartWith('ZERO-RUN: the runner reported 0 tests');++ const odd = await lanesOver(Array.from({ length: FILES }, (_, i) => name(i, i < FILES / 2 ? 'yodd' : 'zskip')));+ expect(odd).toMatchObject({ status: 'fail', code: 'PREGATE_LANE_FAILED' });+ expect(odd.detail).toStartWith('ZERO-RUN: the runner reported 0 tests');+ }, 120_000);});describe.skipIf(process.platform === 'win32')('the test backend command for a file list over the per-argument limit', () => {@@ -101,6 +116,18 @@ describe('argChunks and argBudget', () => {expect(argBudget('bun test {files}', { BIG: 'x'.repeat(900 * 1024) }, 'linux')).toBeLessThan(1024 * 1024 - 64 * 1024 - 900 * 1024);expect(argBudget('bun test {files}', {}, 'win32')).toBeLessThan(32 * 1024);});++ // Value: protects=on Windows a lane's whole `bash -c` string, supervise's `set -o pipefail; ` prefix included, fits the+ // 8,186 characters Git Bash keeps of one argument, so a long file list runs as chunks instead of arriving cut;+ // fails_when=the Windows cap is the 32,767-character CreateProcess limit or the prefix is not counted; why_new=#4773, a+ // 172-file vitest lane of 8,244 characters exited 2 with an empty log; seam=none+ test('the budget counts the pipefail prefix, and on Windows the whole command fits Git Bash\'s 8,186 characters', () => {+ const runner = 'npx vitest run {files}';+ const command = (platform: NodeJS.Platform) => 'set -o pipefail; ' + runner.replace('{files}', 'x'.repeat(argBudget(runner, {}, platform)));+ expect(command('win32').length).toBeLessThanOrEqual(8186);+ expect(Buffer.byteLength(command('linux'))).toBeLessThanOrEqual(96 * 1024 - 512);+ expect(argBudget('cargo test -p core', {}, 'win32')).toBe(Infinity);+ });});describe('E2BIG is its own cause', () => {diff --git a/test/script-invocation.test.ts b/test/script-invocation.test.tsindex 515909eae..b6e694c57 100644--- a/test/script-invocation.test.ts+++ b/test/script-invocation.test.ts@@ -10,6 +10,7 @@ import * as fs from 'node:fs';import * as os from 'node:os';import * as path from 'node:path';import { bunIsolationArgs } from '../lib/bun-isolation';+import { classifyEnvironment } from '../lib/pregate/environment';import {bashCommandInvocation, resolveWindowsBash, resolveWindowsBashCached, runBashSync, runScriptSync, scriptInvocation, wtreeFingerprint,type BashProbe,@@ -94,6 +95,19 @@ describe('scriptInvocation', () => {expect(bashCommandInvocation('echo hi', noBash).ok).toBe(false);});+ test('a bash -c command over the 8,186 characters Git Bash keeps is refused on Windows, never run cut off (#4773)', () => {+ const fits = `echo ${'x'.repeat(8186 - 5)}`;+ expect(bashCommandInvocation(fits, win)).toEqual({ ok: true, cmd: WIN_GIT_BASH, argv: ['-c', fits] });+ const long = `${fits}y`;+ const inv = bashCommandInvocation(long, win);+ expect(inv.ok).toBe(false);+ if (inv.ok) return;+ expect(inv.error).toContain('8,187 characters');+ expect(inv.error).toContain('8,186');+ expect(classifyEnvironment(inv.error, null)?.kind).toBe('arg-limit');+ expect(bashCommandInvocation(long, { platform: 'linux' })).toEqual({ ok: true, cmd: 'bash', argv: ['-c', long] });+ });+test('runScriptSync and runBashSync return a spawnSync-shaped failure the callers already handle', () => {const r = runScriptSync(path.join(BIN, 'gstack-wtree'), [], { encoding: 'utf8', timeout: 5_000 }, noBash);expect(r.status).toBeNull();