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(test): put focused runs in the gate pool [C7,Q4]

Corey Olsonaf35e6ae9671
diff --git a/bin/run-tests.js b/bin/run-tests.js
index a5a430ac..9e56b68a 100644
--- a/bin/run-tests.js
+++ b/bin/run-tests.js
@@ -418,9 +418,9 @@ async function main(args) {
process.exitCode = result.status ?? 1;
} finally { rmSync(sandbox, { recursive: true, force: true }); }
};
- if (!fullSuite || inheritedSlot) run(inheritedSlot);
+ if (inheritedSlot) run(true);
else {
- // Focused and preload-only copies do not need the queue's repository dependencies.
+ // Direct runs, focused or full, use the public queue; preload-only imports never call main.
const [{ withGateSlot }, { loadMachineSettings }] = await Promise.all([
import('../src/gate.js'), import('../src/settings.js'),
]);
diff --git a/test/gate-resource.test.js b/test/gate-resource.test.js
index 5a8e01d8..3a8cefc9 100644
--- a/test/gate-resource.test.js
+++ b/test/gate-resource.test.js
@@ -483,7 +483,7 @@ syncBuiltinESMExports();
assert.equal(readFileSync(marker, 'utf8'), '1', 'the final marker contains the complete slot value');
});
-test('a focused run takes no slot [Q4]', async () => {
+test('a focused run queues behind a held gate slot [Q4,C7]', async () => {
const box = fixture();
const release = join(box.dir, 'release-focused-holder');
const holderRoot = gateRepo(box, 'focused-holder', 0.1, release);
@@ -500,15 +500,18 @@ test('a focused run takes no slot [Q4]', async () => {
'test/probe.test.js',
], marker);
const outcome = await waitFor(() => { // budget: hang ceiling for the focused runner to announce its actual start state; no throughput claim.
- if (existsSync(marker)) return 'ran';
if (focusedRun.stderrText.includes('waiting for a gate slot:')) return 'waiting';
+ if (existsSync(marker)) return 'ran';
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');
+ }, 'the focused test to queue behind the held machine gate slot', 15_000);
+ assert.equal(outcome, 'waiting', 'a named test file is queued even when test options have separate values');
+ assert.equal(existsSync(marker), false, 'the focused test does not execute while the original holder owns the only slot');
+ assert.deepEqual(events(box), ['focused-holder start'], 'the original gate still owns its slot while the focused run waits');
+ writeFileSync(release, 'release\n');
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');
+ assert.equal(readFileSync(marker, 'utf8'), '1', 'the focused run propagates its public held-slot marker to the test process');
+ assert.deepEqual(events(box), ['focused-holder start', 'focused-holder end'], 'the original holder releases before the focused run proceeds');
} finally {
writeFileSync(release, 'release\n');
await Promise.all([holder, focusedRun].filter(Boolean).map(child => child.closed));
diff --git a/test/run-tests.test.js b/test/run-tests.test.js
index d7a72ad6..0c8260aa 100644
--- a/test/run-tests.test.js
+++ b/test/run-tests.test.js
@@ -1,12 +1,13 @@
/** Exercise native test-file sharding through the production test runner [C7]. */
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
-import { copyFileSync, cpSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
import { test } from 'node:test';
-import { runFixtureChild } from './fixture-child.js';
+import { startFixtureChild, runFixtureChild } from './fixture-child.js';
+import { listResources } from '../src/resources.js';
const runner = fileURLToPath(new URL('../bin/run-tests.js', import.meta.url));
const shardFileCount = 9;
@@ -373,6 +374,7 @@ describe('clean suite [C7]', () => {
writeFileSync(process.env.PULLBOARD_FILE_EXIT_CLEANUP, 'done');
});
});
+
test('later active body uses its per-test ceiling [C7]', async () => {
await new Promise((ready) => setTimeout(ready, 650)); // budget: exceed the 500ms file-exit ceiling while a real test body is active.
});
@@ -386,3 +388,190 @@ test('later active body uses its per-test ceiling [C7]', async () => {
assert.match(output, /ok [0-9]+ - later active body uses its per-test ceiling \[C7\]/u);
assert.doesNotMatch(output, /file-exit timeout/u);
});
+
+/** Wait for an observable fixture state; the bound is a hang ceiling, not a timing claim. */
+async function waitForFocusedPoolState(predicate, description, timeoutMs = 30_000) {
+ const deadline = Date.now() + timeoutMs;
+ while (Date.now() < deadline) {
+ const value = predicate();
+ if (value) return value;
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ }
+ assert.fail(`timed out waiting for ${description} [C7 hang ceiling ${timeoutMs}ms]`);
+}
+
+/** Create fixture files that exercise direct and nested focused runner processes. */
+function makeFocusedPoolFixture(t) {
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-focused-pool-')));
+ const bin = join(root, 'bin');
+ const tests = join(root, 'test');
+ const machine = join(root, 'machine');
+ mkdirSync(bin);
+ mkdirSync(tests);
+ mkdirSync(machine);
+ writeFileSync(join(machine, 'settings.json'), JSON.stringify({ gateSlots: 1 }));
+ writeFileSync(join(root, 'package.json'), JSON.stringify({ type: 'module' }));
+ copyFileSync(runner, join(bin, 'run-tests.js'));
+ cpSync(fileURLToPath(new URL('../src', import.meta.url)), join(root, 'src'), { recursive: true });
+ const ready = join(root, 'first-ready');
+ const nestedDone = join(root, 'nested-done');
+ const release = join(root, 'release-first');
+ const firstDone = join(root, 'first-done');
+ const secondStarted = join(root, 'second-started');
+ writeFileSync(join(tests, 'nested.test.js'), `import { writeFileSync } from 'node:fs';
+import { test } from 'node:test';
+test('nested focused run inherits the held slot [C7]', () => {
+ if (process.env.PULLBOARD_GATE_SLOT_HELD !== '1') throw new Error('nested run lost its held-slot marker');
+ writeFileSync(process.env.PULLBOARD_C7_NESTED_DONE, 'nested completed');
+});
+`);
+ writeFileSync(join(tests, 'hold.test.js'), `import { spawnSync } from 'node:child_process';
+import { existsSync, writeFileSync } from 'node:fs';
+import { test } from 'node:test';
+test('focused holder remains live through nested run [C7]', async () => {
+ writeFileSync(process.env.PULLBOARD_C7_FIRST_READY, 'ready');
+ const env = { ...process.env, PULLBOARD_MACHINE_HOME: process.env.PULLBOARD_C7_POOL };
+ const nested = spawnSync(process.execPath, [process.env.PULLBOARD_C7_RUNNER, 'test/nested.test.js'], {
+ cwd: process.env.PULLBOARD_C7_ROOT, env, encoding: 'utf8', timeout: 10000,
+ });
+ if (nested.error || nested.status !== 0) throw new Error('nested focused runner failed: ' + (nested.error?.message ?? nested.stderr));
+ if (!existsSync(process.env.PULLBOARD_C7_NESTED_DONE)) throw new Error('nested run produced no completion marker');
+ while (!existsSync(process.env.PULLBOARD_C7_RELEASE)) await new Promise(resolve => setTimeout(resolve, 10));
+ writeFileSync(process.env.PULLBOARD_C7_FIRST_DONE, 'first completed');
+});
+`);
+ writeFileSync(join(tests, 'second.test.js'), `import { writeFileSync } from 'node:fs';
+import { test } from 'node:test';
+test('second focused run starts after the slot is released [C7]', () => {
+ writeFileSync(process.env.PULLBOARD_C7_SECOND_STARTED, 'second started');
+});
+`);
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ return { root, runner: join(bin, 'run-tests.js'), machine, ready, nestedDone, release, firstDone, secondStarted };
+}
+
+/** Launch one direct fixture runner with an explicit, cleared inherited-slot marker. */
+function launchFocusedPoolRunner(fixture, testFile, extraEnv = {}) {
+ const env = { ...process.env, ...extraEnv, PULLBOARD_MACHINE_HOME: fixture.machine };
+ delete env.PULLBOARD_GATE_SLOT_HELD;
+ delete env.PULLBOARD_AGENT;
+ const child = startFixtureChild(process.execPath, [fixture.runner, testFile], {
+ cwd: fixture.root, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'],
+ });
+ child.stdoutText = '';
+ child.stderrText = '';
+ child.stdout?.setEncoding('utf8').on('data', (part) => { child.stdoutText += part; });
+ child.stderr?.setEncoding('utf8').on('data', (part) => { child.stderrText += part; });
+ child.closed = new Promise((resolve) => child.once('close', (code, signal) => resolve({ code, signal })));
+ return child;
+}
+
+/** Read the real machine queue from the fixture pool while preserving this test process's environment. */
+function focusedPoolSnapshot(machine) {
+ const previous = process.env.PULLBOARD_MACHINE_HOME;
+ process.env.PULLBOARD_MACHINE_HOME = machine;
+ try { return listResources({ scope: 'machine' }).find((resource) => resource.name === 'gate'); }
+ finally {
+ if (previous === undefined) delete process.env.PULLBOARD_MACHINE_HOME;
+ else process.env.PULLBOARD_MACHINE_HOME = previous;
+ }
+}
+
+/** Stop only children owned by this test, releasing the held test before signaling its process group. */
+async function stopFocusedPoolChild(child, fixture) {
+ if (!child) return;
+ if (child.exitCode === null && child.signalCode === null) {
+ try { writeFileSync(fixture.release, 'release'); } catch { /* The fixture may already be removed during teardown. */ }
+ try { process.kill(-child.pid, 'SIGTERM'); }
+ catch {
+ try { child.kill('SIGTERM'); } catch { /* The owned process already exited. */ }
+ }
+ const deadline = Date.now() + 1000; // [C7] cleanup ceiling for an owned fixture process group.
+ while (child.exitCode === null && child.signalCode === null && Date.now() < deadline) {
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ }
+ if (child.exitCode === null && child.signalCode === null) {
+ try { process.kill(-child.pid, 'SIGKILL'); }
+ catch {
+ try { child.kill('SIGKILL'); } catch { /* The owned process already exited. */ }
+ }
+ }
+ }
+ await focusedPoolCloseWithin(child, 'owned fixture process cleanup', 2000);
+}
+
+/** Bound completion waits and always clear the watchdog timer. */
+async function focusedPoolCloseWithin(child, label, timeoutMs = 30_000) {
+ let timer;
+ try {
+ return await Promise.race([
+ child.closed,
+ new Promise((_, reject) => {
+ timer = setTimeout(() => reject(new Error(`${label} did not close [C7 hang ceiling ${timeoutMs}ms]`)), timeoutMs);
+ }),
+ ]);
+ } finally { clearTimeout(timer); }
+}
+
+test('a focused test run holds a gate slot [C7]', async (t) => {
+ const fixture = makeFocusedPoolFixture(t);
+ const commonEnv = {
+ PULLBOARD_C7_POOL: fixture.machine,
+ PULLBOARD_C7_ROOT: fixture.root,
+ PULLBOARD_C7_RUNNER: fixture.runner,
+ PULLBOARD_C7_FIRST_READY: fixture.ready,
+ PULLBOARD_C7_NESTED_DONE: fixture.nestedDone,
+ PULLBOARD_C7_RELEASE: fixture.release,
+ PULLBOARD_C7_FIRST_DONE: fixture.firstDone,
+ PULLBOARD_C7_SECOND_STARTED: fixture.secondStarted,
+ };
+ let first;
+ let second;
+ let testFailure;
+ try {
+ first = launchFocusedPoolRunner(fixture, 'test/hold.test.js', commonEnv);
+ await waitForFocusedPoolState(() => existsSync(fixture.ready), 'the first focused test readiness marker');
+ const firstPool = focusedPoolSnapshot(fixture.machine);
+ assert.ok(firstPool, 'the focused run creates the machine gate resource');
+ assert.equal(firstPool.capacity, 1);
+ assert.deepEqual(firstPool.holders.map(({ agent }) => agent), [`pid-${first.pid}`],
+ 'the direct focused-runner process is the actual gate holder');
+ await waitForFocusedPoolState(() => existsSync(fixture.nestedDone), 'the nested held-slot focused run');
+ assert.equal(first.exitCode, null, 'the first focused run still owns its slot after nested completion');
+ assert.deepEqual(focusedPoolSnapshot(fixture.machine).holders.map(({ agent }) => agent), [`pid-${first.pid}`],
+ 'the nested run did not acquire a second lease or displace its parent');
+
+ second = launchFocusedPoolRunner(fixture, 'test/second.test.js', commonEnv);
+ const observed = await waitForFocusedPoolState(() => {
+ const pool = focusedPoolSnapshot(fixture.machine);
+ const waiter = pool?.line.find(({ agent }) => agent === `pid-${second.pid}`);
+ return waiter || existsSync(fixture.secondStarted);
+ }, 'the second runner to enter the queue or expose an unexpected execution marker');
+ assert.equal(typeof observed, 'object', 'a second direct focused run must become an actual queue waiter');
+ assert.equal(existsSync(fixture.secondStarted), false, 'the queued second test has not executed while the first holds the slot');
+ await waitForFocusedPoolState(() => second.stderrText.includes('waiting for a gate slot: 1 of 1 in use'),
+ 'the second runner wait announcement');
+ assert.match(second.stderrText, /waiting for a gate slot: 1 of 1 in use/u,
+ 'the focused runner reports its actual slot wait');
+ assert.deepEqual(focusedPoolSnapshot(fixture.machine).holders.map(({ agent }) => agent), [`pid-${first.pid}`]);
+
+ writeFileSync(fixture.release, 'release');
+ const firstResult = await focusedPoolCloseWithin(first, 'first focused run');
+ const secondResult = await focusedPoolCloseWithin(second, 'second focused run');
+ assert.equal(firstResult.code, 0, `${first.stderrText}${first.stdoutText}`);
+ assert.equal(firstResult.signal, null);
+ assert.equal(secondResult.code, 0, `${second.stderrText}${second.stdoutText}`);
+ assert.equal(secondResult.signal, null);
+ assert.equal(readFileSync(fixture.firstDone, 'utf8'), 'first completed');
+ assert.equal(readFileSync(fixture.secondStarted, 'utf8'), 'second started');
+ } catch (error) {
+ testFailure = error;
+ }
+ let cleanupFailure;
+ for (const child of [first, second]) {
+ try { await stopFocusedPoolChild(child, fixture); }
+ catch (error) { cleanupFailure ??= error; }
+ }
+ if (testFailure) throw testFailure;
+ if (cleanupFailure) throw cleanupFailure;
+});