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

@@ -30,7 +30,7 @@ const { OUTCOME } = processSeam;
const runGitSpy = mock.method(processSeam, 'runGit');
after(() => mock.restoreAll());
const { gitOrThrow, DEFAULT_GIT_TIMEOUT_MS } = require('./helpers/git-fixture.cjs');
const { gitOrThrow, throwIfFailed, DEFAULT_GIT_TIMEOUT_MS } = require('./helpers/git-fixture.cjs');
const { createTempDir, cleanup } = require('./helpers.cjs');
/**
@@ -211,3 +211,75 @@ describe('git-fixture: E — gitOrThrow', () => {
assert.equal(author, 'Env Author');
});
});
/**
* `throwIfFailed` is exercised only indirectly above (via `gitOrThrow`) and by
* six other per-suite wrappers elsewhere in the tree. It takes a plain
* process-seam result object, so it is tested directly here with literal
* result objects — no subprocess needed.
*/
describe('throwIfFailed', () => {
/** A minimal clean-exit result, spread over in each test below. */
const BASE = { stdout: '', stderr: '', signal: null, timedOut: false };
test('does not throw for outcome=EXITED, exitCode=0', () => {
assert.doesNotThrow(() => throwIfFailed({ ...BASE, outcome: OUTCOME.EXITED, exitCode: 0 }, 'ok'));
});
test('throws when outcome=EXITED but exitCode=1', () => {
assert.throws(() => throwIfFailed({ ...BASE, outcome: OUTCOME.EXITED, exitCode: 1 }, 'bad'));
});
test('throws when outcome=EXITED but exitCode=128', () => {
assert.throws(() => throwIfFailed({ ...BASE, outcome: OUTCOME.EXITED, exitCode: 128 }, 'bad'));
});
for (const outcome of [OUTCOME.TIMED_OUT, OUTCOME.KILLED, OUTCOME.BUFFER_OVERFLOW, OUTCOME.SPAWN_FAILED]) {
test(`throws for non-EXITED outcome: ${outcome}`, () => {
assert.throws(() => throwIfFailed({ ...BASE, outcome, exitCode: null }, 'bad'));
});
}
test('boundary: exitCode=0 with a non-EXITED outcome still throws (0 alone is not success)', () => {
assert.throws(() => throwIfFailed({ ...BASE, outcome: OUTCOME.KILLED, exitCode: 0 }, 'bad'));
});
test('thrown error carries .status and .exitCode as equal aliases of the same value', () => {
const caught = captureThrown(() => throwIfFailed({ ...BASE, outcome: OUTCOME.EXITED, exitCode: 42 }, 'bad'));
assert.equal(caught.status, 42);
assert.equal(caught.exitCode, 42);
assert.equal(caught.status, caught.exitCode);
});
test('thrown error carries stdout, stderr, signal, timedOut, outcome from the input result', () => {
const input = {
outcome: OUTCOME.KILLED,
exitCode: null,
stdout: 'input stdout',
stderr: 'input stderr',
signal: 'SIGTERM',
timedOut: false,
};
const caught = captureThrown(() => throwIfFailed(input, 'bad'));
assert.equal(caught.stdout, input.stdout);
assert.equal(caught.stderr, input.stderr);
assert.equal(caught.signal, input.signal);
assert.equal(caught.timedOut, input.timedOut);
assert.equal(caught.outcome, input.outcome);
});
test('exitCode: null propagates to .status as null, not coerced', () => {
const caught = captureThrown(() =>
throwIfFailed({ ...BASE, outcome: OUTCOME.TIMED_OUT, exitCode: null, timedOut: true }, 'bad')
);
assert.equal(caught.status, null);
assert.notEqual(caught.status, undefined);
});
test('displayName appears in the thrown error message', () => {
const caught = captureThrown(() =>
throwIfFailed({ ...BASE, outcome: OUTCOME.EXITED, exitCode: 1 }, 'my distinctive display name')
);
assert.ok(caught.message.includes('my distinctive display name'));
});
});