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.
JavaScript agentic-codingai-agentsai-governanceautonomous-agentsclaude-codeclicode-reviewcodexcoding-agentsdeveloper-toolsgit-hooksllmlocal-firstmulti-agentsoftware-factoryspec-driven-developmentverificationvibe-coding
fix(queue): keep every nonlanding kind in FIFO order [C7,Q1,Q2]
Corey Olsondb9e2f3a9e94
diff --git a/src/gate.js b/src/gate.jsindex c7136c7e..765f004b 100644--- a/src/gate.js+++ b/src/gate.js@@ -230,7 +230,7 @@ function hasPipeline(command) {return false;}-/** Run work under the machine queue: landing gates, ordinary gates, item checks, then diagnostics.+/** Run work under the machine queue: landings first, then every other eligible waiter in arrival order.** @param {string} root - Checkout used to locate the machine resource database.* @param {(lease: { waitMs: number, token?: string, pool?: string, browser?: boolean, release: () => void }) => any | Promise<any>} action - Work to perform while holding a slot.diff --git a/src/resources.js b/src/resources.jsindex 13629938..635f9dde 100644--- a/src/resources.js+++ b/src/resources.js@@ -1,4 +1,4 @@-/** Machine and repository queues persist leases; diagnostics yield to landings, gates and item checks [Q1,Q2,Q3,V18]. */+/** Machine and repository queues persist leases; landings go first, then eligible waiters in arrival order [Q1,Q2,Q3]. */import { mkdirSync, realpathSync } from 'node:fs';import { execFileSync } from 'node:child_process';import { basename, dirname, join, resolve } from 'node:path';@@ -171,7 +171,7 @@ function update(db, action) {}}-/** Current holders and the landing-first line, then gates, item checks and diagnostics. */+/** Current holders and the landing-first line, then every other kind in arrival order. */function snapshot(db, name) {/** Preserve older public entries while naming diagnostics as a distinct queue class. */const project = ({ diagnostic, browser, item, kind, ...entry }) => ({ ...entry, landing: entry.landing === 1,@@ -181,7 +181,7 @@ function snapshot(db, name) {const where = name === 'browser' ? 'name = ? AND browser = 1' : 'name = ?';const sourceName = name === 'browser' ? 'gate' : name;const holders = db.prepare(`SELECT agent, repo, since, landing, item_check AS itemCheck, diagnostic, browser, item, kind FROM holder WHERE ${where} ORDER BY since, token`).all(sourceName).map(project);- const line = db.prepare(`SELECT agent, repo, since, landing, item_check AS itemCheck, diagnostic, browser, item, kind FROM waiter WHERE ${where} ORDER BY landing DESC, diagnostic, item_check, ticket`).all(sourceName).map(project);+ const line = db.prepare(`SELECT agent, repo, since, landing, item_check AS itemCheck, diagnostic, browser, item, kind FROM waiter WHERE ${where} ORDER BY landing DESC, ticket`).all(sourceName).map(project);return { holders, line };}@@ -197,8 +197,7 @@ function waiterPosition(db, name, ticket, { eligibleOnly = false } = {}) {const blockedByLanding = (waiter) => holdsSlot(waiter)&& waiters.some((other) => other.landing === 1 && other.pid !== waiter.pid);/** Map queue entries to their declared precedence class. */- // Keep the older client's ranking: diagnostic takers yield their FIFO ticket to later checks.- const rank = (waiter) => waiter.landing === 1 ? 0 : waiter.itemCheck === 1 ? 2 : 1;+ const rank = (waiter) => waiter.landing === 1 ? 0 : 1;const line = name === 'browser' ? waiters.filter((waiter) => waiter.browser === 1) : waiters;const considered = line.filter((waiter) => !blockedByLanding(waiter)// Browser availability affects admission only; reported positions retain every browser waiter.@@ -215,7 +214,7 @@ function waiterPosition(db, name, ticket, { eligibleOnly = false } = {}) {function pause(ms) { return new Promise((resolvePromise) => setTimeout(resolvePromise, ms)); }/**- * Join the existing queue; diagnostics rejoin behind later item checks so older clients agree on priority.+ * 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) => void, allowIdleCapacityUpdate?: boolean }} options - Resource identity and queue class.* @returns {Promise<{ name: string, scope: string, token: string, pool: string, browser: boolean, waitMs: number, release: () => void, renew: () => void }>}@@ -265,24 +264,17 @@ export async function takeResource(options) {if (browserResource && browserResource.capacity !== 1) throw new Refused('RESOURCE_CAPACITY_MISMATCH', 'resource "browser" has fixed capacity 1');db.prepare("INSERT INTO resource(name, capacity) VALUES ('browser', 1) ON CONFLICT(name) DO NOTHING").run();}- // Older queue clients see diagnostics as item checks, never as ordinary gates.+ // Retain queue metadata for older readers; admission uses landing priority and arrival only.db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind);});while (true) {const acquired = update(db, () => {- let waiter = db.prepare('SELECT ticket, landing, item_check AS itemCheck, diagnostic FROM waiter WHERE token = ?').get(token);+ const waiter = db.prepare('SELECT ticket FROM waiter WHERE token = ?').get(token);if (!waiter) {queuedAt = new Date().toISOString();const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind);return { acquired: false, state: { ...snapshot(db, name), position: waiterPosition(db, name, Number(rejoined.lastInsertRowid)), rejoined: true } };}- if (diagnostic && db.prepare('SELECT 1 FROM waiter WHERE name=? AND diagnostic=0 AND item_check=1 AND ticket>? LIMIT 1').get(name, waiter.ticket)) {- // An older item-check client only knows FIFO within its class. Move behind it so both- // old and new callers agree who goes first instead of waiting on one another forever.- db.prepare('DELETE FROM waiter WHERE token=?').run(token);- const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), 0, 1, 1, Number(browser), item, kind);- waiter = { ticket: Number(rejoined.lastInsertRowid) };- }db.prepare('UPDATE waiter SET heartbeat = ? WHERE token = ?').run(Date.now(), token);const spot = snapshot(db, name);const reportPosition = waiterPosition(db, name, waiter.ticket);diff --git a/test/gate-resource.test.js b/test/gate-resource.test.jsindex f5a3b961..1f701ce6 100644--- a/test/gate-resource.test.js+++ b/test/gate-resource.test.js@@ -5,10 +5,12 @@ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSyimport { tmpdir } from 'node:os';import { join, resolve } from 'node:path';import { after, test } from 'node:test';+import { pathToFileURL } from 'node:url';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 GATE_MODULE = pathToFileURL(resolve(import.meta.dirname, '../src/gate.js')).href;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';@@ -70,6 +72,33 @@ function launchTestRunner(box, root, args, marker, release, extraEnv = {}) {return child;}+/** Launch a real process that holds the production diagnostic resource class until released. */+function launchDiagnostic(box, root, name, started, release, waiting) {+ const script = join(box.dir, `${name}.mjs`);+ writeFileSync(script, `import { existsSync, renameSync, writeFileSync } from 'node:fs';+import { withGateSlot } from ${JSON.stringify(GATE_MODULE)};+/** Publish a complete handshake so its visible file always contains its value. */+function publish(file, value) { writeFileSync(file + '.tmp', value); renameSync(file + '.tmp', file); }+await withGateSlot(process.cwd(), async () => {+ publish(${JSON.stringify(started)}, 'started');+ while (!existsSync(${JSON.stringify(release)})) await new Promise(done => setTimeout(done, 10));+}, { diagnostic: true, kind: 'main-red', agent: ${JSON.stringify(name)}, onWait: state => publish(${JSON.stringify(waiting)}, String(state.position)) });+`);+ const child = spawn(process.execPath, [script], { cwd: root, env: box.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);@@ -102,8 +131,8 @@ function launch(box, root, args = ['gate']) {return child;}-/** Create a real claimed item with a failing-at-baseline check that leaves an execution marker. */-function checkProject(box) {+/** Create a real claimed item whose check can pause after admission and leave an execution marker. */+function checkProject(box, { releaseCheck = null } = {}) {const root = join(box.dir, 'check-project');const runner = join(box.dir, 'check-runner');const script = join(box.dir, 'item-check.cjs');@@ -126,10 +155,14 @@ function checkProject(box) {assert.equal(spawnSync('git', ['worktree', 'add', '-q', runner, '-b', 'web/runner'], { cwd: root, env: box.env }).status, 0);const joined = spawnSync(process.execPath, [BIN, 'join', 'web'], { cwd: runner, env: box.env, encoding: 'utf8' });assert.equal(joined.status, 0, joined.stderr);- writeFileSync(script, `const fs = require('node:fs'); fs.appendFileSync(${JSON.stringify(box.events)}, 'item check\\n'); process.exitCode = fs.existsSync('web/result.txt') ? 0 : 1;\n`);+ writeFileSync(script, releaseCheck+ ? `const fs = require('node:fs');\n(async () => {\n fs.appendFileSync(${JSON.stringify(box.events)}, 'item check start\\n');\n while (!fs.existsSync(${JSON.stringify(releaseCheck)})) await new Promise(done => setTimeout(done, 10));\n fs.appendFileSync(${JSON.stringify(box.events)}, 'item check\\n');\n process.exitCode = fs.existsSync('web/result.txt') ? 0 : 1;\n})();\n`+ : `const fs = require('node:fs'); fs.appendFileSync(${JSON.stringify(box.events)}, 'item check\\n'); process.exitCode = fs.existsSync('web/result.txt') ? 0 : 1;\n`);+ if (releaseCheck) writeFileSync(releaseCheck, 'baseline runs without a hold\n');const added = spawnSync(process.execPath, [BIN, 'add', 'web', 'Check item', '--specs', 'G1', '--route', 'light', '--criterion', 'the item check runs', '--check', `node '${script}'`, '--wait', '--brief', 'Files: web/result.txt\nTest: run the item check and observe its result.'], { cwd: root, env: box.env, encoding: 'utf8' });assert.equal(added.status, 0, added.stderr);assert.equal(spawnSync(process.execPath, [BIN, 'claim', '1'], { cwd: runner, env: box.env }).status, 0);+ if (releaseCheck) rmSync(releaseCheck, { force: true });writeFileSync(box.events, '');return { root, runner };}@@ -302,12 +335,13 @@ test('[Q4] SIGKILL during a gate releases its machine slot for the next process'assert.ok(events(box).includes('next start'));});-test('[Q1,Q2,V18] item checks wait for a gate slot and ordinary gates precede them', async () => {+test('[Q1,Q2,V18] an older item check keeps its place ahead of a later ordinary gate', async () => {const box = fixture();const release = join(box.dir, 'release-holder');+ const checkRelease = join(box.dir, 'release-item-check');const firstRoot = gateRepo(box, 'slot-holder', 0.1, release);const nextRoot = gateRepo(box, 'ordinary-gate', 0.15);- const { root, runner } = checkProject(box);+ const { root, runner } = checkProject(box, { releaseCheck: checkRelease });assert.equal(spawnSync(process.execPath, [BIN, 'settings', 'gateSlots', '1'], { cwd: firstRoot, env: box.env }).status, 0);const first = launch(box, firstRoot);@@ -319,18 +353,21 @@ test('[Q1,Q2,V18] item checks wait for a gate slot and ordinary gates precede thassert.deepEqual(events(box), ['slot-holder start'], 'the item check command has not started while the gate holds the slot');const ordinary = launch(box, nextRoot);await waitFor(() => /place [12]/u.test(ordinary.stdoutText), 'the later ordinary gate to enter the queue');- assert.ok(ordinary.stdoutText.includes('place 1'), 'the ordinary gate is granted priority over the queued item check');+ assert.ok(ordinary.stdoutText.includes('place 2'), 'the later ordinary gate stays second behind the item check');assert.deepEqual(events(box), ['slot-holder start'], 'neither queued command runs before the holder releases');writeFileSync(release, 'release\n');- await waitFor(() => events(box).includes('ordinary-gate start'), 'the waiting ordinary gate to acquire the released slot');- assert.equal(events(box).includes('item check'), false, 'the ordinary gate starts before the lower-priority item check');+ await waitFor(() => events(box).includes('item check start'), 'the older item check to acquire the released slot');+ assert.equal(events(box).includes('ordinary-gate start'), false, 'the later ordinary gate stays behind the older item check');+ writeFileSync(checkRelease, 'release\n');+ await waitFor(() => events(box).includes('item check'), 'the older item check to release its slot');+ await waitFor(() => events(box).includes('ordinary-gate start'), 'the later ordinary gate to acquire after the item check');await waitFor(() => events(box).includes('ordinary-gate end'), 'the ordinary gate to finish');const [firstResult, ordinaryResult, checkResult] = await Promise.all([first.closed, ordinary.closed, check.closed]);assert.equal(firstResult.code, 0);assert.equal(ordinaryResult.code, 0, ordinary.stderrText);assert.equal(checkResult.code, 1, check.stderrText);- assert.deepEqual(events(box), ['slot-holder start', 'slot-holder end', 'ordinary-gate start', 'ordinary-gate end', 'item check']);+ assert.deepEqual(events(box), ['slot-holder start', 'slot-holder end', 'item check start', 'item check', 'ordinary-gate start', 'ordinary-gate end']);mkdirSync(join(runner, 'web'));writeFileSync(join(runner, 'web', 'result.txt'), 'ready\n');@@ -339,6 +376,7 @@ test('[Q1,Q2,V18] item checks wait for a gate slot and ordinary gates precede thassert.equal(commit.status, 0, commit.stderr);const submitted = spawnSync(process.execPath, [BIN, 'submit', '1'], { cwd: runner, env: box.env, encoding: 'utf8' });assert.equal(submitted.status, 0, submitted.stderr);+ rmSync(checkRelease, { force: true });const review = join(box.dir, 'check-review');const itemCommit = spawnSync('git', ['rev-parse', 'HEAD'], { cwd: runner, env: box.env, encoding: 'utf8' }).stdout.trim();assert.equal(spawnSync('git', ['worktree', 'add', '-q', '--detach', review, itemCommit], { cwd: root, env: box.env }).status, 0);@@ -348,26 +386,69 @@ test('[Q1,Q2,V18] item checks wait for a gate slot and ordinary gates precede thwriteFileSync(box.events, '');const verifyRelease = join(box.dir, 'release-verify-holder');const verifyHolderRoot = gateRepo(box, 'verify-holder', 0.1, verifyRelease);- const verifyNextRoot = gateRepo(box, 'verify-next-gate', 0.15);+ const verifyFocusedRoot = probeSuite(box, 'verify-focused-suite');+ const verifyFocusedMarker = join(box.dir, 'verify-focused.started');+ const verifyFocusedRelease = join(box.dir, 'release-verify-focused');const verifyHolder = launch(box, verifyHolderRoot);await waitFor(() => events(box).includes('verify-holder start') && !events(box).includes('verify-holder end'), 'a gate to hold the slot before accepting an item');const verify = launch(box, review, ['verify', '1', 'accept', '--note', 'queue fixture']);await waitFor(() => verify.stdoutText.includes('place 1') || verify.exitCode !== null, 'verify accept to queue for the gate slot');assert.ok(verify.stdoutText.includes('place 1'), 'verify accept prints its queued gate-slot position');assert.match(verify.stdoutText, /gate waiting:/);- const verifyNext = launch(box, verifyNextRoot);- await waitFor(() => /place [12]/u.test(verifyNext.stdoutText), 'the ordinary gate to enter the queue ahead of accept');- assert.ok(verifyNext.stdoutText.includes('place 1'), 'the ordinary gate is granted priority over the queued accept check');+ const verifyNext = launchTestRunner(box, verifyFocusedRoot, ['--test-name-pattern', PROBE_PATTERN, 'test/probe.test.js'], verifyFocusedMarker, verifyFocusedRelease);+ await waitFor(() => /waiting for a gate slot:/u.test(verifyNext.stderrText) || verifyNext.exitCode !== null, 'the later focused run to enter the queue');+ assert.equal(existsSync(verifyFocusedMarker), false, 'the focused run has not started while the holder owns the slot');assert.equal(events(box).includes('item check'), false);writeFileSync(verifyRelease, 'release\n');- await waitFor(() => events(box).includes('verify-next-gate start'), 'the waiting ordinary gate to acquire before accept');- assert.equal(events(box).includes('item check'), false);- await waitFor(() => events(box).includes('verify-next-gate end'), 'the ordinary gate before accept to finish');- const [verifyHolderResult, verifyNextResult, verifyResult] = await Promise.all([verifyHolder.closed, verifyNext.closed, verify.closed]);+ await waitFor(() => events(box).includes('item check start'), 'the older verify check to acquire the released slot');+ assert.equal(existsSync(verifyFocusedMarker), false, 'the later focused run stays behind review');+ writeFileSync(checkRelease, 'release\n');+ await waitFor(() => events(box).includes('item check'), 'the verify check to release its slot');+ await waitFor(() => existsSync(verifyFocusedMarker), 'the focused run to start after review releases');+ const verifyRun = await verify.closed;+ assert.equal(verifyRun.code, 0, `${verify.stderrText}${verify.stdoutText}`);+ writeFileSync(verifyFocusedRelease, 'release\n');+ const [verifyHolderResult, verifyNextResult] = await Promise.all([verifyHolder.closed, verifyNext.closed]);assert.equal(verifyHolderResult.code, 0);- assert.equal(verifyNextResult.code, 0, verifyNext.stderrText);- 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']);+ assert.equal(verifyNextResult.code, 0, verifyNext.stderrText + verifyNext.stdoutText);+ assert.deepEqual(events(box), ['verify-holder start', 'verify-holder end', 'item check start', 'item check']);+});++test('[Q1,Q2] an older diagnostic stays ahead of a later ordinary gate', async () => {+ const box = fixture();+ const holderRelease = join(box.dir, 'release-diagnostic-holder');+ const diagnosticRelease = join(box.dir, 'release-diagnostic');+ const diagnosticStarted = join(box.dir, 'older-diagnostic.started');+ const diagnosticWaiting = join(box.dir, 'older-diagnostic.waiting');+ const holderRoot = gateRepo(box, 'diagnostic-holder', 0.1, holderRelease);+ const ordinaryRoot = gateRepo(box, 'later-ordinary-gate', 0.1);+ setOneGateSlot(box, holderRoot);+ const holder = launch(box, holderRoot);+ let diagnostic;+ let ordinary;+ try {+ await waitFor(() => events(box).includes('diagnostic-holder start'), 'the holder to acquire the only gate slot');+ diagnostic = launchDiagnostic(box, holderRoot, 'older-diagnostic', diagnosticStarted, diagnosticRelease, diagnosticWaiting);+ await waitFor(() => existsSync(diagnosticWaiting) || diagnostic.exitCode !== null, 'the older diagnostic to enter the queue');+ assert.equal(readFileSync(diagnosticWaiting, 'utf8'), '1', 'diagnostic is first in the waiting line');+ ordinary = launch(box, ordinaryRoot);+ await waitFor(() => ordinary.stdoutText.includes('place 2') || ordinary.exitCode !== null, 'the later ordinary gate to join behind the diagnostic');+ assert.ok(ordinary.stdoutText.includes('place 2'), 'the ordinary gate is physically second in the queue');+ writeFileSync(holderRelease, 'release\n');+ await waitFor(() => existsSync(diagnosticStarted), 'the older diagnostic to acquire the released slot');+ assert.equal(events(box).includes('later-ordinary-gate start'), false, 'the later ordinary gate stays queued while diagnostics hold the slot');+ writeFileSync(diagnosticRelease, 'release\n');+ await waitFor(() => events(box).includes('later-ordinary-gate start'), 'the ordinary gate to start after diagnostics release');+ const [holderResult, diagnosticResult, ordinaryResult] = await Promise.all([holder.closed, diagnostic.closed, ordinary.closed]);+ assert.equal(holderResult.code, 0, holder.stderrText);+ assert.equal(diagnosticResult.code, 0, diagnostic.stderrText + diagnostic.stdoutText);+ assert.equal(ordinaryResult.code, 0, ordinary.stderrText);+ assert.deepEqual(events(box), ['diagnostic-holder start', 'diagnostic-holder end', 'later-ordinary-gate start', 'later-ordinary-gate end']);+ } finally {+ writeFileSync(holderRelease, 'release\n');+ writeFileSync(diagnosticRelease, 'release\n');+ await Promise.all([holder, diagnostic, ordinary].filter(Boolean).map(child => child.closed));+ }});test('a raw full-suite run takes a machine gate slot [Q4]', async () => {diff --git a/test/resources.test.js b/test/resources.test.jsindex 4a1cd3fa..08f065b9 100644--- a/test/resources.test.js+++ b/test/resources.test.js@@ -19,10 +19,11 @@ const GATE_MODULE = pathToFileURL(resolve(import.meta.dirname, '../src/gate.js')const POOL_MODULE_WORKER = `import { takeResource } from ${JSON.stringify(MODULE)};let announced = false;-const [root, agent, browserText, item, kind] = process.argv.slice(1);+const [root, agent, browserText, item, kind, landingText] = process.argv.slice(1);const lease = await takeResource({name: 'gate', capacity: 2, scope: 'machine', root, agent,browser: browserText === 'true', item, kind, itemCheck: kind === 'review',+ diagnostic: kind === 'diagnostic', landing: landingText === 'true',onWait: (state) => {if (!announced) { announced = true; console.log(JSON.stringify({ queued: state })); }},@@ -175,9 +176,9 @@ function worker(box, { name = 'gate', capacity = 1, scope = 'machine', root = boreturn child;}-/** Launch a dedicated gate-pool worker carrying browser and review metadata. */-function poolWorker(box, { agent, browser = false, item = '', kind = '' }) {- const workerArgs = ['--input-type=module', '-e', POOL_MODULE_WORKER, box.first, agent, String(browser), item, kind];+/** Launch a dedicated gate-pool worker carrying browser and queue-priority metadata. */+function poolWorker(box, { agent, browser = false, item = '', kind = '', landing = false }) {+ const workerArgs = ['--input-type=module', '-e', POOL_MODULE_WORKER, box.first, agent, String(browser), item, kind, String(landing)];const startedAt = performance.now();const child = spawn(process.execPath, workerArgs, {env: box.env, stdio: ['pipe', 'pipe', 'pipe'],@@ -367,6 +368,72 @@ test('[Q1,Q2] landing waiters jump ordinary gates but keep FIFO within each clas});test('the pool alone orders submits, reviews and browser runs [C7]', async () => {+ const orderBox = fixture();+ const orderHolder = poolWorker(orderBox, { agent: 'order-holder' });+ const otherHolder = poolWorker(orderBox, { agent: 'other-holder' });+ assert.equal((await acquired(orderHolder)).acquired, 'order-holder');+ assert.equal((await acquired(otherHolder)).acquired, 'other-holder');++ const olderReview = poolWorker(orderBox, { agent: 'older-review', browser: true, item: '620', kind: 'review' });+ assert.equal((await event(olderReview)).queued.position, 1);+ const laterFocused = poolWorker(orderBox, { agent: 'later-focused', kind: 'focused' });+ assert.ok((await event(laterFocused)).queued, 'later focused work has joined behind the review');++ await release(orderHolder);+ await waitUntil(() => privateList(orderBox).find(({ name }) => name === 'gate').holders+ .some(({ agent }) => agent === 'older-review' || agent === 'later-focused'), 'the first eligible waiter to acquire');+ let orderedGate = privateList(orderBox).find(({ name }) => name === 'gate');+ assert.ok(orderedGate.holders.some(({ agent, itemCheck, item }) =>+ agent === 'older-review' && itemCheck && item === '620'),+ 'an older eligible review stays ahead of later focused work');+ assert.ok(!orderedGate.holders.some(({ agent }) => agent === 'later-focused'),+ 'later focused work cannot jump the older review');+ assert.equal((await acquired(olderReview)).acquired, 'older-review');++ const diagnosticOne = poolWorker(orderBox, { agent: 'diagnostic-one', kind: 'diagnostic' });+ assert.equal((await event(diagnosticOne)).queued.position, 2);+ const laterReview = poolWorker(orderBox, { agent: 'later-review', item: '621', kind: 'review' });+ assert.equal((await event(laterReview)).queued.position, 3);+ const diagnosticTwo = poolWorker(orderBox, { agent: 'diagnostic-two', kind: 'diagnostic' });+ assert.equal((await event(diagnosticTwo)).queued.position, 4);+ const laterGate = poolWorker(orderBox, { agent: 'later-gate', kind: 'focused' });+ assert.equal((await event(laterGate)).queued.position, 5);+ const laterLanding = poolWorker(orderBox, { agent: 'later-landing', landing: true });+ await event(laterLanding);+ orderedGate = privateList(orderBox).find(({ name }) => name === 'gate');+ assert.deepEqual(orderedGate.line.map(({ agent, landing, diagnostic, itemCheck, kind }) =>+ [agent, landing, diagnostic === true, itemCheck, kind ?? '']), [+ ['later-landing', true, false, false, ''],+ ['later-focused', false, false, false, 'focused'],+ ['diagnostic-one', false, true, false, 'diagnostic'],+ ['later-review', false, false, true, 'review'],+ ['diagnostic-two', false, true, false, 'diagnostic'],+ ['later-gate', false, false, false, 'focused'],+ ], 'landing moves ahead while all other kinds retain their arrival order');++ await release(otherHolder);+ assert.equal((await acquired(laterLanding)).acquired, 'later-landing',+ 'a later landing jumps the older focused and diagnostic waiters');+ orderedGate = privateList(orderBox).find(({ name }) => name === 'gate');+ assert.ok(orderedGate.holders.some(({ agent, landing }) => agent === 'later-landing' && landing));++ await release(laterLanding);+ assert.equal((await acquired(laterFocused)).acquired, 'later-focused',+ 'the oldest eligible non-landing waiter acquires next');+ await release(laterFocused);+ assert.equal((await acquired(diagnosticOne)).acquired, 'diagnostic-one');+ await release(diagnosticOne);+ assert.equal((await acquired(laterReview)).acquired, 'later-review',+ 'a diagnostic does not yield its older ticket to a later item check');+ await release(laterReview);+ assert.equal((await acquired(diagnosticTwo)).acquired, 'diagnostic-two',+ 'diagnostics keep their FIFO place around a later item check');+ await release(diagnosticTwo);+ assert.equal((await acquired(laterGate)).acquired, 'later-gate',+ 'a diagnostic does not yield its older ticket to later ordinary gate work');+ await release(laterGate);+ await release(olderReview);+const box = fixture();const firstHolder = poolWorker(box, { agent: 'submit-one' });const secondHolder = poolWorker(box, { agent: 'submit-two' });@@ -394,8 +461,8 @@ test('the pool alone orders submits, reviews and browser runs [C7]', async () =>assert.equal(secondQueued.queued.position, 1, 'the browser waiter reports its actual queue position');const thirdSubmit = poolWorker(box, { agent: 'submit-three' });const submitQueued = await event(thirdSubmit);- assert.equal(submitQueued.queued.position, 1,- 'a browser waiter does not head-of-line block ordinary gate work');+ assert.equal(submitQueued.queued.position, 2,+ 'the visible queue preserves FIFO position behind its earlier browser waiter');browser = privateList(box).find(({ name }) => name === 'browser');assert.deepEqual(browser.line.map(({ agent, itemCheck, item, kind }) => [agent, itemCheck, item, kind]), [['review-two', true, '619', 'review'],