Files
gstack/test/sandbox-doctor-shell.test.ts
T
Garry TanandClaude Fable 5 3e674e4c01 fix: sweep — every sync spawn in the test trees carries a timeout (436 sites, 157 files)
spawnSync/execSync/Bun.spawnSync BLOCK the main thread, so bun's in-process
per-test timeout can never fire while one waits — a hung child (stdin read,
network probe, dead daemon) wedges the whole shard until the runner's
external wall-clock SIGKILL. This exact class reached main: free-tests run
33262077256, test/gstack-memory-ingest.test.ts (normally 2.3s) held shard 2
at the 360s wall while its five siblings finished in ~65s.

Mechanical sweep in two waves (12 + 4 fan-out agents, every edit verified
against its call site): default timeout: 30_000 (matches the free runner's
per-test budget), 120_000 for genuinely slow ops (installs, builds,
playwright, provider CLIs), helper wrappers fixed ONCE where call sites
route through them. Sites that only LOOK like calls (string fixtures, grep
needles, comments) were skipped with reasons — the enforcement commit that
follows marks them exempt.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-31 04:49:57 +00:00

35 lines
1.7 KiB
TypeScript

/**
* scripts/sandbox-doctor.sh — static shell sanity (free).
*
* The script mutates a live sandbox (sudo mounts, dnf, bashrc), so its
* behavior can't run under the suite; this pins what CAN be checked for
* free: it parses as POSIX sh, fails fast, and every mutation is guarded so
* a re-run is a no-op (its documented contract is "idempotent — run once per
* sandbox boot").
*/
import { describe, test, expect } from 'bun:test';
import { spawnSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
const SCRIPT = path.join(import.meta.dir, '..', 'scripts', 'sandbox-doctor.sh');
describe('sandbox-doctor.sh', () => {
test('parses as POSIX sh, fails fast, and guards every mutation for idempotency', () => {
// Syntax: `sh -n` parses without executing.
const parse = spawnSync('sh', ['-n', SCRIPT], { encoding: 'utf8', timeout: 30_000 });
expect(parse.status, parse.stderr).toBe(0);
const src = fs.readFileSync(SCRIPT, 'utf-8');
expect(src.startsWith('#!/bin/sh')).toBe(true);
expect(src).toContain('set -eu');
// Idempotency guards: each mutation is conditioned on current state.
expect(src).toContain('[ ! -e /dev/fd ]'); // /dev/fd restore
expect(src).toContain('git config --global user.name >/dev/null 2>&1 ||'); // never clobber identity
expect(src).toContain("grep -q 'GSTACK sandbox test env'"); // bashrc seeded once
expect(src).toContain('if ! command -v Xvfb >/dev/null 2>&1'); // install only if absent, dnf-gated
expect(src).toContain('[ ! -e /tmp/.X11-unix/X99 ]'); // :99 socket check, not any-display pgrep
expect(src).toContain('[ "${shm_kb:-0}" -gt 0 ]'); // missing /dev/shm: skip, not a set -eu abort
});
});