test(#3144): bound the git/worktree cluster onto the process seam (#3152)

* test(#3144): bound the git/worktree cluster onto the process seam

Migrates 180 unbounded sync spawn sites across 19 files. Every previously
unbounded call now carries an explicit timeout with a comment giving the
number and why.

The migration is not a callee swap. execSync and execFileSync throw on a
non-zero exit and the seam never does, so each site was classified first:
sites that rely on the throw route to gitOrThrow, and sites that already read
.status to detect an EXPECTED non-zero -- an intended cherry-pick conflict, a
rev-parse outside a repo driving a skip -- route to the never-throwing runGit
instead, which would otherwise throw on exactly the exit being probed for.

Two same-named git() helpers in worktree-cleanup.test.cjs have different
return contracts, one trimmed and one raw; both are preserved rather than
unified.

Collapses five hand-rolled throw wrappers onto one throwIfFailed in
git-fixture.cjs, which gitOrThrow now also uses so the shape cannot drift.

Allowlist drops 139 to 120; BASELINE lowered to match.

* test(#3144): fix pre-PR review findings

Documents throwIfFailed in the CONTEXT.md glossary and CONTRIBUTING.md --
it became the shared throw mechanism without either doc naming it.

Routes the sixth and seventh hand-rolled copies of the throw shape through
throwIfFailed (worktree-baseref-install, worktree-safety-reap); the first
consolidation missed both.

Converts ci-rebase-check's 8 fixture-setup calls from unchecked runGit to
gitOrThrow so a failed setup step aborts where it fails rather than
surfacing later as a confusing failure against the wrong subject.

Adds 12 direct unit tests for throwIfFailed, which until now was only
exercised transitively.

Splits verify.test.cjs's non-git grep/sed bound off GIT_TIMEOUT_MS.

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-08-07 10:58:34 -04:00
committed by GitHub
parent cfb37ccdfc
commit 1d208e5af6
26 changed files with 598 additions and 362 deletions

View File

@@ -1309,11 +1309,18 @@ const assert = require('node:assert/strict');
const fs = require('node:fs');
const os = require('node:os');
const path = require('node:path');
const { execFileSync } = require('node:child_process');
const { cleanup } = require('./helpers.cjs');
const { runNode } = require('./helpers/process-seam.cjs');
const { gitOrThrow, throwIfFailed } = require('./helpers/git-fixture.cjs');
const EXECUTE_PHASE_MD = path.join(__dirname, '..', 'gsd-core', 'workflows', 'execute-phase.md');
// 30000ms: git plumbing (init/config/add/commit/worktree/rev-parse) against a
// small mkdtemp fixture repo, and a `node -e <manifest-reader>` one-liner
// extracted from the shipped workflow — well over any observed duration for
// either class of call in this bug-630 block.
const BUG_630_TIMEOUT_MS = 30_000;
function readMd() {
return fs.readFileSync(EXECUTE_PHASE_MD, 'utf8');
}
@@ -1330,11 +1337,17 @@ function extractManifestReaderScript() {
}
function git(cwd, args) {
return execFileSync('git', args, {
cwd,
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
}).trim();
return gitOrThrow(args, { cwd, timeoutMs: BUG_630_TIMEOUT_MS }).trim();
}
// runNode never throws; the shipped manifest-reader one-liner is expected to
// exit cleanly (it emits either a resolved path or nothing — never an
// error), so a non-clean exit here is a genuine defect and must still abort
// the test loudly, matching the pre-migration execFileSync throw.
function runManifestReaderOrThrow(args, opts) {
const r = runNode(args, opts);
throwIfFailed(r, `node ${args.join(' ')}`);
return r.stdout;
}
// Canonicalize a path the way the OS does. On Windows, os.tmpdir() can yield an 8.3
@@ -1418,10 +1431,10 @@ describe('bug #630 — wave-cleanup pins to the orchestrator root, not git-workt
// Run the EXACT shipped reader one-liner.
const script = extractManifestReaderScript();
const resolved = execFileSync('node', ['-e', script], {
const resolved = runManifestReaderOrThrow(['-e', script], {
cwd: laneDir,
env: { ...process.env, MANIFEST: manifest },
encoding: 'utf8',
timeoutMs: BUG_630_TIMEOUT_MS,
}).trim();
// The buggy first-entry resolution (run from the lane) yields the MAIN checkout.
@@ -1453,9 +1466,9 @@ describe('bug #630 — wave-cleanup pins to the orchestrator root, not git-workt
// Pre-#630 manifest shape: no orchestrator_root.
fs.writeFileSync(manifest, JSON.stringify({ worktrees: [] }) + '\n');
const script = extractManifestReaderScript();
const out = execFileSync('node', ['-e', script], {
const out = runManifestReaderOrThrow(['-e', script], {
env: { ...process.env, MANIFEST: manifest },
encoding: 'utf8',
timeoutMs: BUG_630_TIMEOUT_MS,
});
assert.equal(out, '', 'reader must emit nothing for a manifest without orchestrator_root so the first-entry fallback engages');
} finally {
@@ -1480,16 +1493,21 @@ describe('bug #630 — wave-cleanup pins to the orchestrator root, not git-workt
const { describe, test, before, after } = require('node:test');
const assert = require('node:assert/strict');
const { execSync, spawnSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const os = require('node:os');
const { cleanup, readFileNormalized } = require('./helpers.cjs');
const { runHook } = require('./helpers/process-seam.cjs');
const { runHook, runGit } = require('./helpers/process-seam.cjs');
const { gitOrThrow } = require('./helpers/git-fixture.cjs');
const REPO_ROOT = path.join(__dirname, '..');
const EXECUTE_PHASE_PATH = path.join(REPO_ROOT, 'gsd-core', 'workflows', 'execute-phase.md');
// 15000ms: git plumbing (init/config/add/commit/worktree) against a small
// mkdtemp fixture repo — gitOrThrow's own documented default; the guard
// itself keeps its separately-justified 30000ms (see runGuard below).
const GIT_TIMEOUT_MS = 15000;
// ---------------------------------------------------------------------------
// Extract the cwd-drift guard bash block from execute-phase.md
// ---------------------------------------------------------------------------
@@ -1593,12 +1611,15 @@ let agentSubdir; // subdirectory inside agentWtDir
let legitUnderClaude; // non-agent worktree whose PATH is under .claude/worktrees/
const dirsToCleanup = [];
// Migrated off a hand-rolled shell string (naive per-arg double-quoting,
// run through execSync) onto gitOrThrow's argv form directly — every call
// site below passes a plain args array with no shell metacharacters, so
// running it as direct argv is behaviorally identical and drops the
// quoting hazard. Return value stays the RAW, un-trimmed stdout string
// (gitOrThrow does not trim), matching what execSync returned and what
// this block's ~10 callers expect.
function git(cwd, args) {
return execSync(`git ${args.map(a => `"${a}"`).join(' ')}`, {
cwd,
encoding: 'utf-8',
stdio: ['ignore', 'pipe', 'pipe'],
});
return gitOrThrow(args, { cwd, timeoutMs: GIT_TIMEOUT_MS });
}
before(() => {
@@ -1705,11 +1726,11 @@ describe('bug #48: orchestrator cwd-drift guard — executable e2e', () => {
// Verify that git rev-parse --show-toplevel actually fails here.
// On some systems /tmp itself might be inside a git repo (e.g. if the
// user's HOME is a git repo). If it resolves, we must skip this test.
const check = spawnSync('git', ['rev-parse', '--show-toplevel'], {
const check = runGit(['rev-parse', '--show-toplevel'], {
cwd: nonRepoDir,
encoding: 'utf-8',
timeoutMs: GIT_TIMEOUT_MS,
});
if (check.status === 0) {
if (check.exitCode === 0) {
t.skip('nonRepoDir unexpectedly resolved to a git repo — skipping');
return;
}