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.

chore(core): integrate queued leases with current main [C7,V4]

Corey Olson36b1a190a17c
diff --cc src/cli.js
index 0c5a4492,9ccc8f9c..8328c414
--- a/src/cli.js
+++ b/src/cli.js
@@@ -2146,7 -2136,8 +2148,8 @@@ async function submitHere(ctx, id)
withBoard(ctx, (board) => refuseUnverifiedStack(root, board, held, commit, trunk));
// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).
// A full-gate stamp never substitutes for either proof; only an actual full fallback may stamp.
- const gate = await runSubmitGate(root, ctx.config, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: queuedItemLease(ctx, held, me.id, 'build'), onBrowserFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
+ const submitConfig = { ...ctx.config, submitGate: acceptedMain.config.submitGate };
- const gate = await runSubmitGate(root, submitConfig, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: gateWaitReporter(ctx.io), onBrowserFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
++ const gate = await runSubmitGate(root, submitConfig, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: queuedItemLease(ctx, held, me.id, 'build'), onBrowserFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
if (!gate.isGreen) {
const message = `the submission proof is red at ${commit.slice(0, 12)}; fix it, commit, submit again. ${submitGateReport(gate)}`;
// No submission can follow this verdict. Read-only main comparisons must not retain the seat's write lease.
@@@ -2237,8 -2229,8 +2241,8 @@@ async function verifyHere(ctx, id, { se
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);
- const browser = await checkNeedsBrowser(root, frozenCheck(item), { commit, onFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
+ const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(root, frozenCheck(item), { commit, onFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
- check = await withGateSlot(root, (lease) => checkAtCommit(root, item, { waitMs: lease.waitMs, gateLease: lease }), { browser, agent: me.id, item: String(id), kind: 'review', itemCheck: true, onWait: gateWaitReporter(ctx.io) });
+ check = await withGateSlot(root, (lease) => checkAtCommit(root, item, { waitMs: lease.waitMs, gateLease: lease }), { browser, agent: me.id, item: String(id), kind: 'review', itemCheck: true, onWait: queuedItemLease(ctx, item, me.id, 'review') });
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}` : ''})`}`
@@@ -2641,8 -2633,8 +2645,8 @@@ function workCommands(io, args)
throw new Refused('CHECK_CONFIRM', `the check set by ${authorName} was not run: ${check}; run pullboard check ${item.item_id} --yes after reading the command, or answer yes at the prompt`);
}
}
- const browser = await checkNeedsBrowser(ctx.info.root, check, { onFallback: browserAdmissionReporter(io, values.json) });
+ const browser = !browserFreeChecksEnabled() || await checkNeedsBrowser(ctx.info.root, check, { onFallback: browserAdmissionReporter(io, values.json) });
- const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true, gateLease: lease }), { browser, agent: caller, item: String(item.item_id), kind: 'check', 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, gateLease: lease }), { browser, agent: caller, item: String(item.item_id), kind: 'check', itemCheck: true, onWait: queuedItemLease(ctx, item, caller, 'build') });
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 --cc src/resources.js
index a2ffcc0c,7f505336..b1237de6
--- a/src/resources.js
+++ b/src/resources.js
@@@ -218,7 -217,7 +219,7 @@@ function pause(ms) { return new Promise
/**
* Join the landing-first queue; every other kind keeps its original FIFO ticket.
*
- * @param {{ name: string, capacity: number, capacityProvider?: () => number, scope?: 'machine'|'repo'|'board', root?: string, agent?: string, repo?: string, landing?: boolean, itemCheck?: boolean, diagnostic?: boolean, browser?: boolean, item?: string, kind?: string, onWait?: (state: object) => any | Promise<any>, allowIdleCapacityUpdate?: boolean }} options - An awaited wait callback may return {leaseUntil}; it then receives one final {admitted:true} callback before work starts.
- * @param {{ name: string, capacity: number, capacityProvider?: () => number, browserCapacityProvider?: () => number, scope?: 'machine'|'repo'|'board', root?: string, agent?: string, repo?: string, landing?: boolean, itemCheck?: boolean, diagnostic?: boolean, browser?: boolean, item?: string, kind?: string, onWait?: (state: object) => void, allowIdleCapacityUpdate?: boolean }} options - Resource identity and queue class.
++ * @param {{ name: string, capacity: number, capacityProvider?: () => number, browserCapacityProvider?: () => number, scope?: 'machine'|'repo'|'board', root?: string, agent?: string, repo?: string, landing?: boolean, itemCheck?: boolean, diagnostic?: boolean, browser?: boolean, item?: string, kind?: string, onWait?: (state: object) => any | Promise<any>, allowIdleCapacityUpdate?: boolean }} options - An awaited wait callback may return {leaseUntil}; it then receives one final {admitted:true} callback before work starts.
* @returns {Promise<{ name: string, scope: string, token: string, pool: string, browser: boolean, waitMs: number, release: () => void, renew: () => void }>}
*/
export async function takeResource(options) {
diff --cc test/resources.test.js
index a864a215,a1aafa5e..6d49cbaf
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@@ -19,16 -17,7 +19,17 @@@ const TEMP = []
const CHILDREN = new Set();
const MODULE = pathToFileURL(resolve(import.meta.dirname, '../src/resources.js')).href;
const GATE_MODULE = pathToFileURL(resolve(import.meta.dirname, '../src/gate.js')).href;
+const LEASE_HELPERS = createE2eHelpers();
+const CLOCKED_CLI = `
+import { readFileSync } from 'node:fs';
+import { main } from ${JSON.stringify(pathToFileURL(resolve(import.meta.dirname, '../src/cli.js')).href)};
+/** The private test alone controls the board clock; resource liveness still uses real OS time. */
+const clock = { now: () => new Date(Number(readFileSync(process.env.PULLBOARD_FIXTURE_CLOCK, 'utf8'))) };
+process.exitCode = await main(process.argv.slice(1), {
+ cwd: process.cwd(), clock, stdin: process.stdin, stdout: process.stdout, stderr: process.stderr,
+});
+`;
+ const SETTINGS_MODULE = pathToFileURL(resolve(import.meta.dirname, '../src/settings.js')).href;
const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
const TEST_RUNNER = resolve(import.meta.dirname, '../bin/run-tests.js');
const POOL_MODULE_WORKER = `
@@@ -436,243 -510,57 +533,292 @@@ after(async () =>
await Promise.all(running.map((child) => child.finished));
for (const child of running) child.lines.close();
TEMP.forEach((dir) => rmSync(dir, { recursive: true, force: true }));
+ LEASE_HELPERS.cleanup();
+});
+
+/** Run the real CLI with a private file-backed board clock and the fixture's ordinary identity. */
+function clockedCli(box, cwd, ...args) {
+ const result = runFixtureChild(process.execPath, ['--input-type=module', '-e', CLOCKED_CLI, ...args],
+ { cwd, env: box.env, encoding: 'utf8' });
+ assert.equal(result.status, 0, `${result.stdout}\n${result.failure ?? result.stderr}`);
+ return args.includes('--json') ? JSON.parse(result.stdout) : result.stdout;
+}
+
+/** Track a waiting real CLI process in the same cleanup registry as the resource workers. */
+function leaseCommand(box, cwd, ...args) {
+ const child = LEASE_HELPERS.launch(box, cwd, process.execPath, ['--input-type=module', '-e', CLOCKED_CLI, ...args]);
+ child.lines = createInterface({ input: child.stdout });
+ child.exitResult = null;
+ child.finished = child.closed.then((result) => {
+ child.exitResult = result;
+ CHILDREN.delete(child);
+ return result;
+ });
+ CHILDREN.add(child);
+ return child;
+}
+
+/** Create genuine submitted/claimed items and independent reviewers before advancing any clock. */
+function itemLeaseFixture(t) {
+ const box = LEASE_HELPERS.project('true');
+ const configFile = join(box.repo, 'pullboard.json');
+ const config = JSON.parse(readFileSync(configFile, 'utf8'));
+ writeFileSync(configFile, JSON.stringify({ ...config, lease: '1m', reviewLease: '1m' }));
+ box.git(box.repo, 'add', 'pullboard.json');
+ box.git(box.repo, 'commit', '-q', '-m', 'chore: configure queue lease fixture');
+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');
+ box.first = box.repo;
+ box.home = box.env.PULLBOARD_MACHINE_HOME;
+ box.clockFile = join(box.dir, 'board-clock');
+ writeFileSync(box.clockFile, String(Date.now()));
+ box.env.PULLBOARD_FIXTURE_CLOCK = box.clockFile;
+ box.clock = { now: () => new Date(Number(readFileSync(box.clockFile, 'utf8'))) };
+ box.advance = (ms) => writeFileSync(box.clockFile, String(box.clock.now().getTime() + ms));
+ box.board = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'), box.clock);
+ t.after(() => store.closeBoard(box.board));
+ box.gates = [];
+ box.ids = [];
+ box.reviewCommits = [];
+ for (const number of [1, 2, 3, 4]) {
+ const folder = join(box.dir, `item-gate-${number}`);
+ mkdirSync(folder);
+ const gate = LEASE_HELPERS.holdingGate({ dir: folder });
+ const added = clockedCli(box, box.repo, 'add', 'web', `Queued lease ${number}`, '--specs', 'G1',
+ '--criterion', 'The queued command retains only its own live item lease.', '--check', gate.command, '--json');
+ const id = added.item.item_id;
+ box.ids.push(id); box.gates.push(gate);
+ if (number < 4) {
+ // Each item has independent ancestry: a pending review cannot be another submit's base.
+ box.git(box.web, 'switch', '-q', '--detach', 'main');
+ clockedCli(box, box.web, 'claim', String(id), '--json');
+ mkdirSync(join(box.web, 'web'), { recursive: true });
+ writeFileSync(join(box.web, 'web', `queued-${number}.txt`), 'fixture\n');
+ box.git(box.web, 'add', 'web');
+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): queue lease fixture [G1]');
+ if (number < 3) {
+ clockedCli(box, box.web, 'submit', String(id), '--json');
+ box.reviewCommits.push(box.git(box.web, 'rev-parse', 'HEAD'));
+ }
+ }
+ }
+ box.reviewers = [];
+ const commit = box.git(box.web, 'rev-parse', 'HEAD');
+ for (const number of [1, 2]) {
+ const root = join(box.dir, `queue-review-${number}`);
+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', root, box.reviewCommits[number - 1]);
+ clockedCli(box, root, 'join', 'api', '--json');
+ box.reviewers.push(root);
+ }
+ box.checker = join(box.dir, 'queue-build-check');
+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', box.checker, commit);
+ clockedCli(box, box.checker, 'join', 'web', '--json');
+ clockedCli(box, box.checker, 'claim', String(box.ids[3]), '--json');
+ clockedCli(box, box.repo, 'settings', 'gateSlots', '2', '--json');
+ return box;
+}
+
+test('a review waiting in the pool keeps its lease [C7,V4]', {
+ timeout: 120_000, // budget: real private Git/CLI setup and causally controlled queue/run/death phases, never a production lease extension.
+}, async (t) => {
+ const box = itemLeaseFixture(t);
+ const [reviewId, deadId, buildId, checkId] = box.ids;
+ const [reviewGate, deadGate, buildGate, checkGate] = box.gates;
+ const [reviewer, deadReviewer] = box.reviewers;
+ // Readers project expired claims as open with no lease. Observe the retained raw deadline
+ // here so admission's normal expiry remains distinguishable from an unwanted renewal.
+ const item = (id) => store.itemById(box.board, id);
+ const end = (id, kind) => item(id)[kind === 'review' ? 'item_review_until' : 'item_lease_until'];
+ const waiting = (id) => privateList(box).find((resource) => resource.name === 'gate')?.line.find((entry) => entry.item === String(id));
+ let holder;
+ const commands = [];
+ try {
+ clockedCli(box, reviewer, 'next', '--verify', String(reviewId), '--json');
+ const originalReviewEnd = end(reviewId, 'review');
+ const originalBuildEnd = end(buildId, 'check');
+ const originalCheckEnd = end(checkId, 'check');
+ holder = poolWorker(box, { agent: 'lease-test-holder', browser: true });
+ await acquired(holder);
+ writeFileSync(reviewGate.mode, 'hold'); writeFileSync(buildGate.mode, 'hold'); writeFileSync(checkGate.mode, 'hold');
+ const review = leaseCommand(box, reviewer, 'verify', String(reviewId), 'accept',
+ '--note', 'Private fixture: waited behind held capacity and ran the frozen check.', '--json');
+ commands.push(review);
+ await waitUntil(() => waiting(reviewId)?.leaseUntil, 'the real verify waiter and its item lease end');
+ const build = leaseCommand(box, box.web, 'submit', String(buildId), '--json');
+ commands.push(build);
+ await waitUntil(() => waiting(buildId)?.leaseUntil, 'the real submit waiter and its item lease end');
+ const check = leaseCommand(box, box.checker, 'check', String(checkId), '--yes', '--json');
+ commands.push(check);
+ await waitUntil(() => waiting(checkId)?.leaseUntil, 'the independent owned check and its item lease end');
+ const listed = clockedCli(box, box.repo, 'resources', '--json').resources.find((resource) => resource.name === 'gate');
+ for (const [id, kind] of [[reviewId, 'review'], [buildId, 'submit'], [checkId, 'check']]) {
+ const entry = listed.line.find((row) => row.item === String(id));
+ assert.equal(entry.kind, kind);
+ assert.equal(entry.leaseUntil, end(id, kind), 'resources reports this exact board item lease, not the pool heartbeat');
+ }
+ assert.match(clockedCli(box, box.repo, 'resources'), /lease until \d{4}-\d{2}-\d{2}T/u);
+
+ box.advance(30_000);
+ await waitUntil(() => end(reviewId, 'review') > originalReviewEnd && end(buildId, 'check') > originalBuildEnd
+ && end(checkId, 'check') > originalCheckEnd, 'all live queued commands renew before their original expiry');
+ const previousReviewEnd = end(reviewId, 'review');
+ const previousBuildEnd = end(buildId, 'check');
+ const previousCheckEnd = end(checkId, 'check');
+ box.advance(31_000);
+ await waitUntil(() => end(reviewId, 'review') > previousReviewEnd && end(buildId, 'check') > previousBuildEnd
+ && end(checkId, 'check') > previousCheckEnd, 'all leases remain held past their original deadlines');
+ assert.ok(box.clock.now().toISOString() > originalReviewEnd);
+ assert.ok(end(reviewId, 'review') > box.clock.now().toISOString());
+ assert.ok(end(buildId, 'check') > box.clock.now().toISOString());
+ assert.ok(end(checkId, 'check') > box.clock.now().toISOString());
+
+ await release(holder); holder = null;
+ await waitUntil(() => existsSync(reviewGate.events), 'the admitted verification starts its actual frozen check');
+ const runningReviewEnd = end(reviewId, 'review');
+ for (const advance of [30_000, 31_000, 1_000]) {
+ const beforeBuildEnd = end(buildId, 'check');
+ const beforeCheckEnd = end(checkId, 'check');
+ box.advance(advance);
+ if (advance >= 30_000) await waitUntil(() => end(buildId, 'check') > beforeBuildEnd
+ && end(checkId, 'check') > beforeCheckEnd, 'both build waiters renew while the admitted review runs');
+ }
+ assert.equal(end(reviewId, 'review'), runningReviewEnd, 'admission ends review item renewals');
+ assert.ok(runningReviewEnd < box.clock.now().toISOString(), 'the running review resumes ordinary lease expiry');
+ assert.ok(waiting(buildId) && waiting(checkId), 'submit and check remain queued behind the review');
+ writeFileSync(reviewGate.release, 'release');
+ assert.equal((await review.finished).code, 0, `${review.stdoutText}\n${review.stderrText}`);
+ await waitUntil(() => existsSync(buildGate.events), 'the admitted real submit starts its frozen check');
+ const runningBuildEnd = end(buildId, 'check');
+ for (const advance of [30_000, 31_000, 1_000]) {
+ const beforeCheckEnd = end(checkId, 'check');
+ box.advance(advance);
+ if (advance >= 30_000) await waitUntil(() => end(checkId, 'check') > beforeCheckEnd,
+ 'the standalone check keeps renewing while submit runs');
+ }
+ clockedCli(box, box.repo, 'resources', '--json');
+ assert.equal(end(buildId, 'check'), runningBuildEnd, 'admission ends build item renewals');
+ assert.ok(runningBuildEnd < box.clock.now().toISOString(), 'the running build resumes ordinary lease expiry');
+ writeFileSync(buildGate.release, 'release');
+ assert.equal((await build.finished).code, 0, `${build.stdoutText}\n${build.stderrText}`);
+ assert.equal(item(buildId).item_status, 'submitted', 'the actual queued submit completes its ordinary board move');
+ await waitUntil(() => existsSync(checkGate.events), 'the independent owned check starts');
+ const runningCheckEnd = end(checkId, 'check');
+ box.advance(Date.parse(runningCheckEnd) - box.clock.now().getTime() + 1);
+ clockedCli(box, box.repo, 'resources', '--json');
+ assert.equal(end(checkId, 'check'), runningCheckEnd, 'admission ends standalone check renewals');
+ assert.ok(runningCheckEnd < box.clock.now().toISOString(), 'the standalone check resumes normal expiry');
+ writeFileSync(checkGate.release, 'release');
+ assert.equal((await check.finished).code, 0, `${check.stdoutText}\n${check.stderrText}`);
+
+ clockedCli(box, deadReviewer, 'next', '--verify', String(deadId), '--json');
+ holder = poolWorker(box, { agent: 'dead-waiter-holder', browser: true });
+ await acquired(holder);
+ const dead = leaseCommand(box, deadReviewer, 'verify', String(deadId), 'accept',
+ '--note', 'Private fixture: the queued waiter must not start before its holder releases.', '--json');
+ commands.push(dead);
+ await waitUntil(() => waiting(deadId)?.leaseUntil, 'the doomed real reviewer is queued with its item lease');
+ const beforeDeadEnd = end(deadId, 'review');
+ box.advance(30_000);
+ await waitUntil(() => end(deadId, 'review') > beforeDeadEnd, 'the reviewer renews while alive');
+ assert.equal(existsSync(deadGate.events), false, 'the killed waiter never started its frozen check');
+ dead.kill('SIGKILL');
+ assert.equal((await dead.finished).signal, 'SIGKILL');
+ await waitUntil(() => !waiting(deadId), 'the real dead waiter is pruned');
+ const lastDeadEnd = end(deadId, 'review');
+ box.advance(Date.parse(lastDeadEnd) - box.clock.now().getTime() + 1);
+ assert.equal(end(deadId, 'review'), lastDeadEnd, 'a dead process cannot continue renewing');
+ clockedCli(box, reviewer, 'next', '--verify', String(deadId), '--json');
+ assert.equal(item(deadId).item_review_by, store.agentAt(box.board, reviewer).agent_id,
+ 'another actual reviewer can reserve after the dead waiter lease lapses');
+
+ await t.test('asynchronous renewal finishes outside the queue transaction before admission', async () => {
+ const callbackBox = fixture();
+ const callbackHolder = await privateTake(callbackBox, { name: 'awaited-renewal', capacity: 1 });
+ let enter;
+ let finish;
+ const entered = new Promise((resolve) => { enter = resolve; });
+ const barrier = new Promise((resolve) => { finish = resolve; });
+ const refused = new Error('fixture item lease was lost while waiting');
+ let completed = false;
+ const queued = privateTake(callbackBox, { name: 'awaited-renewal', capacity: 1, onWait: async () => {
+ const connection = new DatabaseSync(join(callbackBox.home, 'resources.sqlite'));
+ try { connection.exec('BEGIN IMMEDIATE'); connection.exec('ROLLBACK'); }
+ finally { connection.close(); }
+ enter();
+ await barrier;
+ completed = true;
+ throw refused;
+ } }).then((lease) => ({ lease }), (error) => ({ error }));
+ await entered;
+ callbackHolder.release();
+ finish();
+ const result = await queued;
+ try {
+ assert.equal(completed, true);
+ assert.equal(result.error, refused, 'a failed awaited renewal refuses admission instead of running stale work');
+ const pool = privateList(callbackBox).find((entry) => entry.name === 'awaited-renewal');
+ assert.deepEqual(pool.line, [], 'failed renewal removes its waiter');
+ assert.deepEqual(pool.holders, [], 'failed renewal never leaves a held resource');
+ } finally { result.lease?.release(); }
+ });
+ } finally {
+ for (const gate of box.gates) writeFileSync(gate.release, 'release');
+ if (holder && !holder.exitResult) await release(holder);
+ // Released gates let each CLI reap its own check workers and private clone before the
+ // shared fixture directory is removed. Killing a parent here would strand those workers.
+ await Promise.all(commands.map((child) => child.finished));
+ for (const child of commands) child.lines.close();
+ }
});
+ /** Prove the machine setting changes real browser admission while retaining the single-slot default [C7]. */
+ test('browserSlots admits that many browser runs and no more [C7]', async () => {
+ const defaults = fixture();
+ const defaultSettings = runFixtureChild(process.execPath, [BIN, 'settings', '--json'], {
+ cwd: defaults.first, env: defaults.env, encoding: 'utf8',
+ });
+ assert.equal(defaultSettings.status, 0, defaultSettings.stderr);
+ assert.equal(JSON.parse(defaultSettings.stdout).settings.browserSlots, 1, 'an unset machine keeps the existing single browser slot');
+
+ const box = fixture();
+ const configured = configureBrowserSlots(box, 2);
+ assert.equal(configured.status, 0, configured.stderr);
+ assert.equal(JSON.parse(configured.stdout).settings.browserSlots, 2);
+ const readBack = runFixtureChild(process.execPath, [BIN, 'settings', '--json'], {
+ cwd: box.first, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(readBack.status, 0, readBack.stderr);
+ assert.equal(JSON.parse(readBack.stdout).settings.browserSlots, 2, 'the machine setting persists for other processes');
+ assert.equal(privateList(box).find(({ name }) => name === 'browser').capacity, 2,
+ 'the shared browser resource row has the configured capacity before workers start');
+ const invalid = configureBrowserSlots(box, 3);
+ assert.equal(invalid.status, 1);
+ assert.equal(JSON.parse(invalid.stdout).error.code, 'BAD_BROWSER_SLOTS');
+ assert.match(JSON.parse(invalid.stdout).error.message, /pullboard settings gateSlots/u);
+
+ const first = poolWorker(box, { agent: 'browser-one', browser: true });
+ assert.equal((await acquired(first)).acquired, 'browser-one');
+ const second = poolWorker(box, { agent: 'browser-two', browser: true });
+ const secondStart = await event(second);
+ if (!secondStart.acquired) {
+ const gate = privateList(box).find(({ name }) => name === 'gate');
+ const browser = privateList(box).find(({ name }) => name === 'browser');
+ assert.fail(`the configured second browser lease queued: ${JSON.stringify({ state: secondStart.queued, gate, browser })}`);
+ }
+ assert.equal(secondStart.acquired, 'browser-two', 'the configured second browser lease starts while the first is held');
+ const third = poolWorker(box, { agent: 'browser-three', browser: true });
+ assert.equal((await event(third)).queued.position, 1, 'the next browser run waits for a configured slot');
+ const browser = privateList(box).find(({ name }) => name === 'browser');
+ assert.equal(browser.capacity, 2, 'resource listing reflects the machine browserSlots setting');
+ assert.equal(browser.holders.length, 2);
+ assert.deepEqual(browser.holders.map(({ agent }) => agent).sort(), ['browser-one', 'browser-two']);
+ assert.deepEqual(browser.line.map(({ agent }) => agent), ['browser-three']);
+
+ await release(first);
+ assert.equal((await acquired(third)).acquired, 'browser-three', 'a released browser lease admits the oldest waiting browser run');
+ await release(second);
+ await release(third);
+ });
+
test('[Q1,Q2] capacity-one takers acquire in strict FIFO arrival order', async () => {
const box = fixture();
const holder = worker(box, { agent: 'holder' });