mirror of
https://github.com/garrytan/gstack.git
synced 2026-11-30 11:53:55 +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
@@ -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']; signal
|
||||
const 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 } : {}) };
|
||||
}
|
||||
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -213,9 +213,18 @@ export function scriptInvocation(script: string, args: readonly string[], o: Inv
|
||||
return 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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user