mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 03:44:38 +01:00
Windows: a python3 that won't run no longer deletes skills on update, and long test commands fail clearly (#4793)
On Windows, an update no longer deletes your brain-aware skills when `python3` is the Microsoft Store alias, and a pre-ship test command too long for Git Bash is split to fit or refused clearly instead of running cut off. Why: keeps install and upgrade working on Windows, where gstack promises minimal support (#4752 by @Barack-zero-to-one, #4773 by @targetpark). Nothing to do. Co-authored-by: Barack-zero-to-one <121355791+Barack-zero-to-one@users.noreply.github.com> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com> Review-Finding: bin/gstack-config:1335:completeness reader=core Review-Finding: lib/pregate/checks/lanes.ts:457:completeness reader=core Review-Finding: lib/pregate/checks/lanes.ts:442:completeness reader=core Review-Finding: lib/pregate/checks/lanes.ts:456:completeness reader=core
This commit is contained in:
10 files changed
+207
-40
No files matched your search
@@ -21,6 +21,32 @@ const refresh = () => spawnSync('bash', [path.join(binDir, 'gstack-config'), 'gb
|
||||
encoding: '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');
|
||||
});
|
||||
});
|
||||
@@ -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 o
|
||||
const 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', () => {
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in new issue
Block a user