Skip to content

Autonomous development for real products. Governed agents build from specs you approve, follow the rules you set, and nothing merges until another agent proves it. Your decisions, judgement and taste are the bar that work must clear. Declare your vision and let agents build it.

fix(gate): every full test run holds a machine slot [Q4]

Corey Olsona4c0bc3de7a3
diff --git a/bin/run-tests.js b/bin/run-tests.js
index 173874d6..9e66aca4 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -10,6 +10,9 @@ import { tmpdir } from 'node:os';
import { after, afterEach, beforeEach } from 'node:test';
import { Worker } from 'node:worker_threads';
import { AGENT_SHELL_MARKERS, SSH_SHELL_MARKERS } from '../src/person.js';
+import { withGateSlot } from '../src/gate.js';
+import { GATE_SLOT_HELD_ENV } from '../src/resources.js';
+import { loadMachineSettings } from '../src/settings.js';
const runner = fileURLToPath(import.meta.url);
export const DEFAULT_TEST_TIMEOUT_MS = 660_000;
@@ -156,13 +159,47 @@ function runTests(args, env) {
return spawnSync(process.execPath, nodeArgs, { env, stdio: 'inherit' });
}
+const NODE_TEST_OPTIONS_WITH_VALUES = new Set([
+ '--test-name-pattern', '--test-skip-pattern', '--test-reporter', '--test-reporter-destination',
+ '--test-timeout', '--test-concurrency', '--import', '--require', '--conditions', '--loader',
+ '--experimental-loader', '--inspect-port', '-r', '-C',
+ '--test-shard', '--test-coverage-branches', '--test-coverage-exclude',
+ '--test-coverage-functions', '--test-coverage-include', '--test-coverage-lines',
+ '--test-global-setup', '--test-random-seed', '--test-rerun-failures',
+]);
+
+/** Distinguish file selection from option values so filtered discovery still takes a full-suite slot. */
+function hasTestFiles(args) {
+ let takesValue = false;
+ for (let index = 0; index < args.length; index += 1) {
+ const argument = args[index];
+ if (takesValue) { takesValue = false; continue; }
+ if (argument === '--') return index < args.length - 1;
+ if (argument.startsWith('-')) {
+ if (!argument.includes('=')) takesValue = NODE_TEST_OPTIONS_WITH_VALUES.has(argument);
+ continue;
+ }
+ return true;
+ }
+ return false;
+}
+
+/** Run tests in the disposable environment, preserving a marker only when a parent holds the slot. */
+function executeTests(args, sandbox, gateSlotHeld) {
+ const env = testEnvironment(sandbox);
+ if (gateSlotHeld) env[GATE_SLOT_HELD_ENV] = '1';
+ const result = runTests(args, env);
+ if (result.error) throw result.error;
+ return result;
+}
+
/**
* Launch Node's test runner in a disposable environment and remove it after the run ends.
*
* @param {string[]} args
- * @returns {void}
+ * @returns {Promise<void>}
*/
-function main(args) {
+async function main(args) {
try {
testTimeoutMs();
} catch (error) {
@@ -170,21 +207,35 @@ function main(args) {
process.exitCode = 1;
return;
}
- const sandbox = mkdtempSync(join(tmpdir(), 'pullboard-test-run-'));
+ const fullSuite = !hasTestFiles(args);
+ const inheritedSlot = process.env[GATE_SLOT_HELD_ENV] === '1';
let signal = null;
- try {
- const result = runTests(args, testEnvironment(sandbox));
- if (result.error) throw result.error;
- signal = result.signal;
- process.exitCode = result.status ?? 1;
- } finally {
- rmSync(sandbox, { recursive: true, force: true });
+ /** Keep sandbox lifetime inside the held lease, including the complete child process. */
+ const run = (gateSlotHeld) => {
+ const sandbox = mkdtempSync(join(tmpdir(), 'pullboard-test-run-'));
+ try {
+ const result = executeTests(args, sandbox, gateSlotHeld);
+ signal = result.signal;
+ process.exitCode = result.status ?? 1;
+ } finally { rmSync(sandbox, { recursive: true, force: true }); }
+ };
+ if (!fullSuite || inheritedSlot) run(inheritedSlot);
+ else {
+ const capacity = loadMachineSettings().gateSlots;
+ let announced = false;
+ await withGateSlot(process.cwd(), () => run(true), {
+ onWait: ({ holders }) => {
+ if (announced) return;
+ announced = true;
+ process.stderr.write(`waiting for a gate slot: ${holders.length} of ${capacity} in use\n`);
+ },
+ });
}
if (signal) process.kill(process.pid, signal);
}
if (process.argv[1] && resolve(process.argv[1]) === runner) {
- main(process.argv.slice(2));
+ await main(process.argv.slice(2));
} else if (process.argv[1]) {
process.env.PULLBOARD_TEST_FILE = process.argv[1];
installTestWatchdog();
diff --git a/src/cli.js b/src/cli.js
index 5448d2e7..cac43d3d 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1602,7 +1602,7 @@ async function verifyHere(ctx, id, { second, values }) {
if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');
const trunk = requireTrunkMerge(root, commit);
refuseUnverifiedStack(root, board, item, commit, trunk);
- check = await withGateSlot(root, (lease) => checkAtCommit(root, item, { waitMs: lease.waitMs }), { itemCheck: true, onWait: gateWaitReporter(ctx.io) });
+ check = await withGateSlot(root, (lease) => checkAtCommit(root, item, { waitMs: lease.waitMs, gateSlotHeld: true }), { itemCheck: true, onWait: gateWaitReporter(ctx.io) });
verificationProfile = check.profile ?? null;
const evidence = check.checked
? `\nlast output lines (up to 40):\n${(check.outputTail ?? '(no output)').split('\n').map((line) => ` ${line}`).join('\n')}\nfull output file: ${check.outputPath ?? `(unavailable${check.outputError ? `: ${check.outputError}` : ''})`}`
@@ -1991,7 +1991,7 @@ function workCommands(io, args) {
throw new Refused('CHECK_CONFIRM', `the check set by ${by} was not run: ${check}; run pullboard check ${item.item_id} --yes after reading the command, or answer yes at the prompt`);
}
}
- const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true }), { itemCheck: true, onWait: gateWaitReporter(io) });
+ const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true, gateSlotHeld: true }), { itemCheck: true, onWait: gateWaitReporter(io) });
io.result?.({ id: item.item_id, green: run.isGreen, seconds: run.seconds, check, by, report: run.isGreen ? '' : digestOf(run.output) });
const timings = timingDigest(run.profile);
const compact = timings && !run.profile.files.length
diff --git a/src/gate.js b/src/gate.js
index 70cefbeb..ac6eaf6f 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -11,7 +11,7 @@ import { dirname, join } from 'node:path';
import { gitChildEnv, gitPath, headTree, invalidateGitFacts, isClean, untracked } from './git.js';
import { secretsIn } from './hooks.js';
import { Refused } from './refused.js';
-import { takeResource } from './resources.js';
+import { GATE_SLOT_HELD_ENV, takeResource } from './resources.js';
import { loadMachineSettings } from './settings.js';
import { selectAffectedTests } from './affected-tests.js';
import { timingFromOutput, timingRunner } from './timing.js';
@@ -129,16 +129,16 @@ function safeLog(output) {
/** Run the unchanged caller command and profile only timings already present in its output.
* @param {string} root
* @param {string} command
- * @param {{ waitMs?: number, artifactDirectory?: string, artifactPrefix?: string, persistLog?: boolean, profileFile?: string, pipefail?: boolean }} [options]
+ * @param {{ waitMs?: number, artifactDirectory?: string, artifactPrefix?: string, persistLog?: boolean, profileFile?: string, pipefail?: boolean, gateSlotHeld?: boolean }} [options]
*/
-export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory, artifactPrefix = 'pullboard-gate', persistLog = false, profileFile, pipefail = false } = {}) {
+export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory, artifactPrefix = 'pullboard-gate', persistLog = false, profileFile, pipefail = false, gateSlotHeld = false } = {}) {
const directory = artifactDirectory ?? dirname(gitPath(root, LOG));
mkdirSync(directory, { recursive: true, mode: 0o700 });
const id = randomUUID();
const profilePath = profileFile ?? join(directory, `${artifactPrefix}-${id}.profile.json`);
const logPath = persistLog ? join(directory, `${artifactPrefix}-${id}.log`) : null;
const started = Date.now();
- const run = runShell(root, command, { pipefail });
+ const run = runShell(root, command, { pipefail, env: gateSlotHeld ? { [GATE_SLOT_HELD_ENV]: '1' } : {} });
const profile = writeTimingProfile(profilePath, {
...timingFromOutput(run.output, timingRunner(command)),
waitMs: Math.max(0, Math.round(waitMs)), wallMs: Math.max(0, Date.now() - started),
@@ -246,7 +246,7 @@ export async function runGate(root, config, { trustStamp = true, onWait, landing
function fullGateRun(root, config, trustStamp = false, { waitMs = 0, log = gitPath(root, LOG) } = {}) {
if (trustStamp && isStampedGreen(root)) return { isGreen: true, isCached: true, output: '', seconds: 0, log: '' };
const before = committedTree(root);
- const { isGreen, output, seconds, profile, profilePath } = runProfiledShell(root, config.gate, { waitMs, pipefail: true, profileFile: `${log}.profile.json` });
+ const { isGreen, output, seconds, profile, profilePath } = runProfiledShell(root, config.gate, { waitMs, pipefail: true, profileFile: `${log}.profile.json`, gateSlotHeld: true });
writeFileSync(log, output);
if (isGreen && before !== null && committedTree(root) === before) writeFileSync(gitPath(root, STAMP), `${before}\n`);
return { isGreen, isCached: false, output, seconds, log, profile, profilePath };
@@ -277,7 +277,7 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
const checkLog = `${log}.check.log`;
const proofLog = `${log}.proof.log`;
const criterion = check ? runProfiledShell(root, check, {
- waitMs: lease.waitMs, profileFile: `${checkLog}.profile.json`,
+ waitMs: lease.waitMs, profileFile: `${checkLog}.profile.json`, gateSlotHeld: true,
}) : { isGreen: true, output: '', seconds: 0 };
if (check) writeFileSync(checkLog, safeLog(criterion.output), { mode: 0o600 });
const receipt = { command: check, green: criterion.isGreen, seconds: criterion.seconds, checked: Boolean(check),
@@ -307,7 +307,7 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
else if (!selection.files.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log: '' };
else {
const command = `${config.affectedTests.trimEnd()} ${selection.files.map(path => commandWord('./' + path)).join(' ')}`;
- proof = { ...runProfiledShell(root, command, { waitMs: proofWait, profileFile: `${proofLog}.profile.json` }), isCached: false, log: proofLog };
+ proof = { ...runProfiledShell(root, command, { waitMs: proofWait, profileFile: `${proofLog}.profile.json`, gateSlotHeld: true }), isCached: false, log: proofLog };
writeFileSync(proofLog, proof.output);
}
writeFileSync(log, `item check:\n${criterion.output}\n${selection.full ? 'full gate' : 'affected tests'}:\n${proof.output}`);
diff --git a/src/resources.js b/src/resources.js
index 35683f3c..30bc370a 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -14,6 +14,9 @@ const POLL_MS = 40;
const PROCESS_IDENTITY_CACHE_MS = 3_000;
const processIdentities = new Map();
+/** Mark child commands whose parent already owns a machine gate slot. */
+export const GATE_SLOT_HELD_ENV = 'PULLBOARD_GATE_SLOT_HELD';
+
/** Resolve the local database for the requested scope. */
function databaseFile(scope, root) {
if (scope === 'board') throw new Refused('BOARD_SCOPE_UNAVAILABLE', 'board-scoped resources need the relay; run pullboard relay on');
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index bc707e1a..a11ef88f 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -8,6 +8,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { StringDecoder } from 'node:string_decoder';
import { fileURLToPath } from 'node:url';
+import { GATE_SLOT_HELD_ENV } from './resources.js';
import { configFromSource } from './config.js';
import { cleanGitEnvironment, gitConfig, invalidateGitFacts, mainCheckout, refuseGrafts } from './git.js';
import { secretsIn } from './hooks.js';
@@ -138,9 +139,9 @@ export function frozenCheck(item) {
/** Run the frozen check at the exact submitted commit in a private clone, leaving live worktrees untouched.
* @param {string} root
* @param {object} item
- * @param {{ waitMs?: number }} [options] - Queue wait before the private check started.
+ * @param {{ waitMs?: number, gateSlotHeld?: boolean }} [options] - Queue wait before the private check started.
*/
-export function checkAtCommit(root, item, { waitMs = 0 } = {}) {
+export function checkAtCommit(root, item, { waitMs = 0, gateSlotHeld = false } = {}) {
const command = frozenCheck(item);
if (!command) return { state: 'pass', green: true, checked: false, report: '' };
let config;
@@ -155,6 +156,7 @@ export function checkAtCommit(root, item, { waitMs = 0 } = {}) {
const verifierHome = process.env.HOME ?? process.env.USERPROFILE;
const npmCache = process.env.npm_config_cache ?? join(verifierHome ?? home, '.npm');
const env = { ...cleanGitEnvironment(), HOME: home, PULLBOARD_HOME: join(home, '.pullboard'), PULLBOARD_MACHINE_HOME: join(home, 'machine'), GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1', npm_config_cache: npmCache };
+ if (gateSlotHeld) env[GATE_SLOT_HELD_ENV] = '1';
delete env.PULLBOARD_RELAY_TOKEN;
let installOutput = '';
let checkOutput = '';
diff --git a/test/gate-resource.test.js b/test/gate-resource.test.js
index 5e4de8fc..e4fedd46 100644
--- a/test/gate-resource.test.js
+++ b/test/gate-resource.test.js
@@ -5,8 +5,14 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSy
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { after, test } from 'node:test';
+import { GATE_SLOT_HELD_ENV } from '../src/resources.js';
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+const RUNNER = resolve(import.meta.dirname, '../bin/run-tests.js');
+const PROBE_NAME = 'machine gate slot runner probe [Q4]';
+const PROBE_PATTERN = '^machine gate slot runner probe \\[Q4\\]$';
+const PROBE_PATH_ENV = 'PULLBOARD_GATE_RESOURCE_PROBE_PATH';
+const PROBE_RELEASE_ENV = 'PULLBOARD_GATE_RESOURCE_PROBE_RELEASE';
const TEMP = [];
const CHILDREN = new Set();
@@ -29,9 +35,38 @@ function fixture() {
PULLBOARD_HOME: join(dir, 'home'),
PULLBOARD_MACHINE_HOME: join(dir, 'home'),
};
+ delete env[GATE_SLOT_HELD_ENV];
return { dir, events, env };
}
+/** Create a tiny test-project with one discoverable probe instead of recursively loading this repository's suite. */
+function probeSuite(box, name) {
+ const root = join(box.dir, name);
+ const tests = join(root, 'test');
+ mkdirSync(tests, { recursive: true });
+ writeFileSync(join(tests, 'probe.test.js'), `import { existsSync, writeFileSync } from 'node:fs';\nimport { test } from 'node:test';\ntest(${JSON.stringify(PROBE_NAME)}, async () => {\n const marker = process.env.${PROBE_PATH_ENV};\n if (marker) writeFileSync(marker, process.env.${GATE_SLOT_HELD_ENV} ?? 'none');\n const release = process.env.${PROBE_RELEASE_ENV};\n while (release && !existsSync(release)) await new Promise(done => setTimeout(done, 10));\n});\n`);
+ return root;
+}
+
+/** Launch a run-tests invocation with its own process group and captured output. */
+function launchTestRunner(box, root, args, marker, release) {
+ const env = { ...box.env, [PROBE_PATH_ENV]: marker, ...(release ? { [PROBE_RELEASE_ENV]: release } : {}) };
+ delete env[GATE_SLOT_HELD_ENV];
+ const child = spawn(process.execPath, [RUNNER, ...args], { cwd: root, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
+ child.stdoutText = '';
+ child.stderrText = '';
+ child.stdout.setEncoding('utf8');
+ child.stderr.setEncoding('utf8');
+ child.stdout.on('data', chunk => { child.stdoutText += chunk; });
+ child.stderr.on('data', chunk => { child.stderrText += chunk; });
+ CHILDREN.add(child);
+ child.closed = new Promise(resolveClose => child.once('close', (code, signal) => {
+ CHILDREN.delete(child);
+ resolveClose({ code, signal });
+ }));
+ return child;
+}
+
/** Create a clean gate repo whose start and end record observable execution, optionally waiting for a release file. */
function gateRepo(box, name, delay = 0.25, releaseFile = null) {
const root = join(box.dir, name);
@@ -96,6 +131,12 @@ function checkProject(box) {
return { root, runner };
}
+/** Set the fixture machine pool to one gate slot before starting holders. */
+function setOneGateSlot(box, root) {
+ const configured = spawnSync(process.execPath, [BIN, 'settings', 'gateSlots', '1'], { cwd: root, env: box.env, encoding: 'utf8' });
+ assert.equal(configured.status, 0, configured.failure ?? configured.stderr);
+}
+
/** Wait until an observable fixture state is reached, or fail with a useful timeout. */
async function waitFor(predicate, description, timeoutMs = 30_000) {
const until = Date.now() + timeoutMs;
@@ -325,3 +366,120 @@ test('[Q1,Q2,V18] item checks wait for a gate slot and ordinary gates precede th
assert.equal(verifyResult.code, 0, `${verify.stderrText}${verify.stdoutText}`);
assert.deepEqual(events(box), ['verify-holder start', 'verify-holder end', 'verify-next-gate start', 'verify-next-gate end', 'item check']);
});
+
+test('a raw full-suite run takes a machine gate slot [Q4]', async () => {
+ const modes = [[], ['--test-name-pattern', PROBE_PATTERN, '--test-reporter', 'tap', '--test-concurrency', '1', '--test-shard', '1/1']];
+ for (const args of modes) {
+ const box = fixture();
+ const release = join(box.dir, 'release-full-suite-holder');
+ const releaseProbe = join(box.dir, 'release-running-probe');
+ const holderRoot = gateRepo(box, 'full-suite-holder', 0.1, release);
+ const nextRoot = gateRepo(box, 'after-full-suite');
+ const suiteRoot = probeSuite(box, 'raw-full-suite');
+ const marker = join(box.dir, 'raw-full-suite.started');
+ setOneGateSlot(box, holderRoot);
+ const holder = launch(box, holderRoot);
+ let fullRun;
+ let focusedRun;
+ let followingGate;
+ try {
+ await waitFor(() => events(box).includes('full-suite-holder start'), 'the fixture gate to hold its only machine slot');
+ fullRun = launchTestRunner(box, suiteRoot, args, marker, releaseProbe);
+ const outcome = await waitFor(() => {
+ if (fullRun.stderrText.includes('waiting for a gate slot:')) return 'waiting';
+ if (existsSync(marker)) return 'ran';
+ return false;
+ }, 'the raw full runner to announce its queued slot', 15_000);
+ assert.equal(outcome, 'waiting', 'both bare and option-only discovery must queue without a test file');
+ assert.match(fullRun.stderrText, /waiting for a gate slot: 1 of 1 in use/u);
+ assert.equal(existsSync(marker), false, 'the probe has not run while the other process owns the slot');
+ // Real focused work keeps the full run queued across resource polls without a synthetic delay.
+ focusedRun = launchTestRunner(box, suiteRoot, ['test/probe.test.js'], join(box.dir, 'focused.started'));
+ assert.equal((await focusedRun.closed).code, 0, `${focusedRun.stderrText}${focusedRun.stdoutText}`);
+ writeFileSync(release, 'release\n');
+ assert.equal((await holder.closed).code, 0, holder.stderrText);
+ await waitFor(() => existsSync(marker), 'the admitted full-suite probe to start');
+ assert.equal(readFileSync(marker, 'utf8'), '1', 'the runner marks its child only after acquiring its machine slot');
+ followingGate = launch(box, nextRoot);
+ const holding = await waitFor(() => {
+ if (followingGate.stdoutText.includes('gate waiting:')) return 'waiting';
+ if (events(box).includes('after-full-suite start')) return 'ran';
+ return false;
+ }, 'the following gate to wait for the full test process');
+ assert.equal(holding, 'waiting', 'the full runner holds its slot until its test process exits');
+ assert.equal(events(box).includes('after-full-suite start'), false);
+ writeFileSync(releaseProbe, 'release\n');
+ const [fullResult, followingResult] = await Promise.all([fullRun.closed, followingGate.closed]);
+ assert.equal(fullResult.code, 0, `${fullRun.stderrText}${fullRun.stdoutText}`);
+ assert.equal(followingResult.code, 0, `${followingGate.stderrText}${followingGate.stdoutText}`);
+ assert.equal((fullRun.stderrText.match(/waiting for a gate slot:/g) ?? []).length, 1, 'one wait line per full run');
+ } finally {
+ writeFileSync(release, 'release\n');
+ writeFileSync(releaseProbe, 'release\n');
+ await Promise.all([holder, fullRun, focusedRun, followingGate].filter(Boolean).map(child => child.closed));
+ }
+ }
+});
+
+test('a focused run takes no slot [Q4]', async () => {
+ const box = fixture();
+ const release = join(box.dir, 'release-focused-holder');
+ const holderRoot = gateRepo(box, 'focused-holder', 0.1, release);
+ const suiteRoot = probeSuite(box, 'focused-suite');
+ const marker = join(box.dir, 'focused-suite.started');
+ setOneGateSlot(box, holderRoot);
+ const holder = launch(box, holderRoot);
+ let focusedRun;
+ try {
+ await waitFor(() => events(box).includes('focused-holder start'), 'the fixture gate to hold its only machine slot');
+ focusedRun = launchTestRunner(box, suiteRoot, [
+ '--test-name-pattern', PROBE_PATTERN,
+ 'test/probe.test.js',
+ ], marker);
+ const outcome = await waitFor(() => {
+ if (existsSync(marker)) return 'ran';
+ if (focusedRun.stderrText.includes('waiting for a gate slot:')) return 'waiting';
+ return false;
+ }, 'the focused test to run without joining the machine gate queue', 15_000);
+ assert.equal(outcome, 'ran', 'a named test file is focused even when test options have separate values');
+ const focusedResult = await focusedRun.closed;
+ assert.equal(focusedResult.code, 0, `${focusedRun.stderrText}${focusedRun.stdoutText}`);
+ assert.equal(readFileSync(marker, 'utf8'), 'none', 'the focused run does not claim or propagate a full-suite slot');
+ assert.deepEqual(events(box), ['focused-holder start'], 'the original gate still owns its slot while the focused run completes');
+ } finally {
+ writeFileSync(release, 'release\n');
+ await Promise.all([holder, focusedRun].filter(Boolean).map(child => child.closed));
+ }
+});
+
+test('a full run nested under a held gate does not take a second slot [Q4]', async () => {
+ const box = fixture();
+ const gateRoot = gateRepo(box, 'nested-full-suite');
+ probeSuite(box, 'nested-full-suite');
+ const marker = join(box.dir, 'nested-full-suite.started');
+ const output = join(box.dir, 'nested-full-suite-runner.log');
+ const command = `${quote(process.execPath)} ${quote(RUNNER)} --test-name-pattern ${quote(PROBE_PATTERN)} > ${quote(output)} 2>&1`;
+ writeFileSync(join(gateRoot, 'pullboard.json'), JSON.stringify({ gate: command }));
+ assert.equal(spawnSync('git', ['add', '-A'], { cwd: gateRoot, env: box.env }).status, 0);
+ const policyCommit = spawnSync('git', ['commit', '-q', '-m', 'chore: add nested runner probe'], { cwd: gateRoot, env: box.env, encoding: 'utf8' });
+ assert.equal(policyCommit.status, 0, policyCommit.failure ?? policyCommit.stderr);
+ setOneGateSlot(box, gateRoot);
+ const nestedGate = launch({ ...box, env: { ...box.env, [PROBE_PATH_ENV]: marker } }, gateRoot);
+ try {
+ const outcome = await waitFor(() => {
+ if (existsSync(marker)) return 'completed';
+ if (existsSync(output) && readFileSync(output, 'utf8').includes('waiting for a gate slot:')) return 'queued';
+ return false;
+ }, 'the nested runner to complete or expose a second-slot wait', 15_000);
+ const runnerOutput = existsSync(output) ? readFileSync(output, 'utf8') : '';
+ assert.equal(outcome, 'completed', `the child must inherit the held parent slot, not wait on its own slot; output=${runnerOutput}`);
+ assert.equal(readFileSync(marker, 'utf8'), '1', 'the nested test child inherited the actual parent-held-slot marker');
+ const result = await nestedGate.closed;
+ assert.equal(result.code, 0, `${nestedGate.stderrText}${nestedGate.stdoutText}`);
+ } finally {
+ if (nestedGate.exitCode === null && nestedGate.signalCode === null) {
+ try { process.kill(-nestedGate.pid, 'SIGKILL'); } catch { /* The gate already exited. */ }
+ }
+ await nestedGate.closed;
+ }
+});