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(resources): runners ship queue settings; classed follows it [C7,O5]

Corey Olson39663e4005b3
diff --git a/src/queue-settings.js b/src/queue-settings.js
new file mode 100644
index 00000000..17bc7a96
--- /dev/null
+++ b/src/queue-settings.js
@@ -0,0 +1,69 @@
+/** The gate queue's machine settings, read with node: built-ins only so a runner's trusted runtime can ship them [O5]. */
+import { existsSync, readFileSync } from 'node:fs';
+import { join } from 'node:path';
+import { machineHome } from './machine-home.js';
+import { Refused } from './refused.js';
+
+/** A waiting run moves up one class after this many minutes, unless the machine sets agingMinutes. */
+export const DEFAULT_QUEUE_AGING_MINUTES = 30;
+
+/** Resolve the separate machine settings file. */
+export function machineSettingsFile() {
+ return join(machineHome(), 'settings.json');
+}
+
+/**
+ * Read the machine settings file as a plain object, or null when there is none. Why here and not
+ * in settings.js: resources.js runs on remote runners, whose trusted runtime ships only a few
+ * files, and settings.js imports runners.js and resources.js.
+ *
+ * @param {string} [file]
+ * @returns {object|null}
+ */
+export function readMachineSettingsFile(file = machineSettingsFile()) {
+ if (!existsSync(file)) return null;
+ let value;
+ try { value = JSON.parse(readFileSync(file, 'utf8')); }
+ catch { throw new Refused('BAD_MACHINE_SETTINGS', `cannot read ${file}; fix its JSON before running Pullboard`); }
+ if (!value || typeof value !== 'object' || Array.isArray(value)) {
+ throw new Refused('BAD_MACHINE_SETTINGS', `settings in ${file} must be a JSON object; fix it before running Pullboard`);
+ }
+ if (value.gate !== undefined && (!value.gate || typeof value.gate !== 'object' || Array.isArray(value.gate))) {
+ throw new Refused('BAD_MACHINE_SETTINGS', `gate in ${file} must be an object; fix it before running Pullboard`);
+ }
+ return value;
+}
+
+/**
+ * Refuse an unusable gate.queue setting by name, with the fix.
+ *
+ * @param {object} value - The parsed machine settings.
+ * @param {string} file - The settings file, for the message.
+ */
+export function validateGateQueue(value, file) {
+ const queue = value.gate?.queue;
+ if (queue !== undefined && (!queue || typeof queue !== 'object' || Array.isArray(queue))) {
+ throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue in ${file} must be an object; fix it before running Pullboard`);
+ }
+ if (queue?.reviewsFirst !== undefined && typeof queue.reviewsFirst !== 'boolean') {
+ throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue.reviewsFirst in ${file} must be true or false`);
+ }
+ if (queue?.agingMinutes !== undefined && (!Number.isSafeInteger(queue.agingMinutes) || queue.agingMinutes < 1)) {
+ throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue.agingMinutes in ${file} must be a positive whole number of minutes; fix it or remove it for the default ${DEFAULT_QUEUE_AGING_MINUTES}`);
+ }
+}
+
+/**
+ * The gate pool's admission order. Reviews-first class order is opt-in per machine because it
+ * changes who waits for whom on every board sharing the pool; absent or false keeps landings
+ * first, then arrival. agingMinutes only matters while class order is on.
+ *
+ * @returns {{ reviewsFirst: boolean, agingMinutes: number }}
+ */
+export function gateQueueSettings() {
+ const file = machineSettingsFile();
+ const value = readMachineSettingsFile(file) ?? {};
+ validateGateQueue(value, file);
+ const queue = value.gate?.queue;
+ return { reviewsFirst: queue?.reviewsFirst === true, agingMinutes: queue?.agingMinutes ?? DEFAULT_QUEUE_AGING_MINUTES };
+}
diff --git a/src/resources.js b/src/resources.js
index 7e2a0f99..dc6c48d0 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -7,7 +7,7 @@ import { DatabaseSync } from 'node:sqlite';
import { repoInfo } from './git.js';
import { machineHome, withMachineHomeWrite } from './machine-home.js';
import { Refused } from './refused.js';
-import { gateQueueSettings } from './settings.js';
+import { gateQueueSettings } from './queue-settings.js';
const LEASE_MS = 20_000;
const HEARTBEAT_MS = 3_000;
@@ -249,6 +249,20 @@ function classOrderInEffect(waiters, order) {
return order.reviewsFirst && waiters.every((waiter) => waiter.classed === 1);
}
+/**
+ * The classed marker this process writes on its waiter: 1 only while it admits by class order.
+ * Why not always 1: a #651-only process reads classed=1 on every waiter as "everyone admits by
+ * class" and ranks by class, while a process with reviewsFirst off ranks by arrival; the two would
+ * disagree and a free slot could stay empty. Writing 0 with the setting off makes every process,
+ * old or new, fall back to arrival order together.
+ *
+ * @param {{ reviewsFirst: boolean }} order - This process's admission order setting, read this poll.
+ * @returns {0|1}
+ */
+function classedMarker(order) {
+ return order.reviewsFirst ? 1 : 0;
+}
+
/**
* The admission rank every process in this queue agrees on. Class order (with aging) applies only
* while the machine opts in to reviews first and every waiter was queued by a process that admits
@@ -524,7 +538,7 @@ export async function takeResource(options) {
if (!resume) {
// Remote eligibility is metadata on this same ticket; the kind and flags decide the
// admission class, and the ticket keeps arrival order within it.
- const inserted = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote));
+ const inserted = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote), classedMarker(queueOrder(scope)));
initialTicket = Number(inserted.lastInsertRowid);
}
});
@@ -538,15 +552,16 @@ export async function takeResource(options) {
const waiter = db.prepare('SELECT ticket FROM waiter WHERE token = ?').get(token);
if (!waiter) {
if (resume && initialTicket) {
- db.prepare('INSERT OR IGNORE INTO waiter(ticket, token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)').run(initialTicket, token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote));
+ db.prepare('INSERT OR IGNORE INTO waiter(ticket, token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(initialTicket, token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote), classedMarker(order));
return { acquired: false, state: { ...snapshot(db, name, order), position: waiterPosition(db, name, initialTicket, { order }), rejoined: true } };
}
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, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote));
+ const rejoined = db.prepare('INSERT INTO waiter(token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote), classedMarker(order));
initialTicket = Number(rejoined.lastInsertRowid);
return { acquired: false, state: { ...snapshot(db, name, order), position: waiterPosition(db, name, initialTicket, { order }), rejoined: true } };
}
- db.prepare('UPDATE waiter SET heartbeat = ? WHERE token = ?').run(Date.now(), token);
+ // The marker follows this poll's setting, so a change mid-wait reaches every process's ranking.
+ db.prepare('UPDATE waiter SET heartbeat = ?, classed = ? WHERE token = ?').run(Date.now(), classedMarker(order), token);
const spot = snapshot(db, name, order);
const reportPosition = waiterPosition(db, name, waiter.ticket, { order });
const limit = db.prepare('SELECT capacity FROM resource WHERE name = ?').get(name).capacity;
@@ -618,14 +633,16 @@ export async function takeResource(options) {
// served holds within each class (and its queuedAt, so its aging). Under arrival order
// (reviewsFirst off, or an older pullboard waiting in the line) it takes #663's front
// ticket ahead of its landing tier, as on main.
- if (classOrderInEffect(db.prepare("SELECT classed FROM waiter WHERE name = 'gate'").all(), queueOrder(scope))) requeueTicket = acquired.ticket;
+ const requeueOrder = queueOrder(scope);
+ const marker = classedMarker(requeueOrder);
+ if (classOrderInEffect([...db.prepare("SELECT classed FROM waiter WHERE name = 'gate'").all(), { classed: marker }], requeueOrder)) requeueTicket = acquired.ticket;
else {
const minimumTicket = db.prepare("SELECT MIN(ticket) AS ticket FROM waiter WHERE name = 'gate' AND landing = ?").get(Number(landing)).ticket;
requeueTicket = Math.min(0, minimumTicket ?? 0) - 1;
}
db.prepare('DELETE FROM holder WHERE token = ?').run(token);
- db.prepare('INSERT INTO waiter(ticket, token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1)')
- .run(requeueTicket, token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote));
+ db.prepare('INSERT INTO waiter(ticket, token, name, pid, started, agent, repo, since, heartbeat, landing, item_check, diagnostic, browser, item, kind, remote, classed) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')
+ .run(requeueTicket, token, name, pid, started, agent, repo, queuedAt, Date.now(), Number(landing), Number(itemCheck || diagnostic), Number(diagnostic), Number(browser), item, kind, Number(remote), marker);
});
} catch (error) {
transferred = false;
diff --git a/src/runner-worker.js b/src/runner-worker.js
index 7e01c2ef..7a0127ea 100644
--- a/src/runner-worker.js
+++ b/src/runner-worker.js
@@ -130,7 +130,7 @@ async function readSpec() {
tagNames.add(tag.name);
if (tag.chain.length ? tag.chain[0] !== tag.object : tag.object !== tag.peeledCommit) throw new Error('invalid tag manifest');
}
- const runtimeNames = ['resources.js', 'git.js', 'machine-home.js', 'refused.js'];
+ const runtimeNames = ['resources.js', 'git.js', 'machine-home.js', 'refused.js', 'queue-settings.js'];
if (Object.keys(value.runtime.files).length !== runtimeNames.length
|| runtimeNames.some(name => typeof value.runtime.files[name] !== 'string')) throw new Error('invalid work specification');
if (createHash('sha256').update(JSON.stringify(value.runtime.files)).digest('hex') !== value.runtime.sha256) throw new Error('invalid trusted runtime');
diff --git a/src/runners.js b/src/runners.js
index fb169328..d5e6f91e 100644
--- a/src/runners.js
+++ b/src/runners.js
@@ -18,7 +18,7 @@ const MAX_BLOB_BYTES = 8 * 1024 ** 2;
const MAX_HISTORY_TAGS = 1_024;
const MAX_TAG_CHAIN = 8;
const TOOL_ROOT = fileURLToPath(new URL('../', import.meta.url));
-const RUNTIME_NAMES = ['resources.js', 'git.js', 'machine-home.js', 'refused.js'];
+const RUNTIME_NAMES = ['resources.js', 'git.js', 'machine-home.js', 'refused.js', 'queue-settings.js'];
/** Validate an SSH destination as one argument, never a command or an SSH option. */
export function validateRunner(value) {
diff --git a/src/settings.js b/src/settings.js
index 28649f37..b9eead48 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -1,47 +1,27 @@
/** Machine-wide settings shared by every Pullboard checkout on this machine. */
-import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
-import { dirname, join } from 'node:path';
+import { mkdirSync, renameSync, rmSync, writeFileSync } from 'node:fs';
+import { dirname } from 'node:path';
import { randomUUID } from 'node:crypto';
-import { machineHome } from './machine-home.js';
import { setResourceCapacity, updateRunnerSettings } from './resources.js';
import { validateRunner } from './runners.js';
import { Refused } from './refused.js';
+import { gateQueueSettings, machineSettingsFile, readMachineSettingsFile, validateGateQueue } from './queue-settings.js';
+
+// The gate queue's settings live in queue-settings.js so the runner runtime can read them too.
+export { gateQueueSettings, machineSettingsFile };
const DEFAULT_GATE_SLOTS = 2;
const DEFAULT_BROWSER_SLOTS = 1;
-const DEFAULT_QUEUE_AGING_MINUTES = 30;
-
-/** Resolve the separate machine settings file. */
-export function machineSettingsFile() {
- return join(machineHome(), 'settings.json');
-}
/** Read and validate machine settings, preserving any unrelated settings. */
export function loadMachineSettings() {
const file = machineSettingsFile();
- if (!existsSync(file)) return { gateSlots: DEFAULT_GATE_SLOTS, browserSlots: DEFAULT_BROWSER_SLOTS };
- let value;
- try { value = JSON.parse(readFileSync(file, 'utf8')); }
- catch { throw new Refused('BAD_MACHINE_SETTINGS', `cannot read ${file}; fix its JSON before running Pullboard`); }
- if (!value || typeof value !== 'object' || Array.isArray(value)) {
- throw new Refused('BAD_MACHINE_SETTINGS', `settings in ${file} must be a JSON object; fix it before running Pullboard`);
- }
- if (value.gate !== undefined && (!value.gate || typeof value.gate !== 'object' || Array.isArray(value.gate))) {
- throw new Refused('BAD_MACHINE_SETTINGS', `gate in ${file} must be an object; fix it before running Pullboard`);
- }
+ const value = readMachineSettingsFile(file);
+ if (!value) return { gateSlots: DEFAULT_GATE_SLOTS, browserSlots: DEFAULT_BROWSER_SLOTS };
if (value.gate?.browserFreeChecks !== undefined && typeof value.gate.browserFreeChecks !== 'boolean') {
throw new Refused('BAD_MACHINE_SETTINGS', `gate.browserFreeChecks in ${file} must be true or false`);
}
- const queue = value.gate?.queue;
- if (queue !== undefined && (!queue || typeof queue !== 'object' || Array.isArray(queue))) {
- throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue in ${file} must be an object; fix it before running Pullboard`);
- }
- if (queue?.reviewsFirst !== undefined && typeof queue.reviewsFirst !== 'boolean') {
- throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue.reviewsFirst in ${file} must be true or false`);
- }
- if (queue?.agingMinutes !== undefined && (!Number.isSafeInteger(queue.agingMinutes) || queue.agingMinutes < 1)) {
- throw new Refused('BAD_MACHINE_SETTINGS', `gate.queue.agingMinutes in ${file} must be a positive whole number of minutes; fix it or remove it for the default ${DEFAULT_QUEUE_AGING_MINUTES}`);
- }
+ validateGateQueue(value, file);
const gateSlots = value.gateSlots ?? DEFAULT_GATE_SLOTS;
if (!Number.isSafeInteger(gateSlots) || gateSlots < 1) {
throw new Refused('BAD_GATE_SLOTS', `gateSlots in ${file} must be a positive integer; run pullboard settings gateSlots <n>`);
@@ -66,18 +46,6 @@ export function browserFreeChecksEnabled() {
return loadMachineSettings().gate?.browserFreeChecks === true;
}
-/**
- * The gate pool's admission order. Reviews-first class order is opt-in per machine because it
- * changes who waits for whom on every board sharing the pool; absent or false keeps landings
- * first, then arrival. agingMinutes only matters while class order is on.
- *
- * @returns {{ reviewsFirst: boolean, agingMinutes: number }}
- */
-export function gateQueueSettings() {
- const queue = loadMachineSettings().gate?.queue;
- return { reviewsFirst: queue?.reviewsFirst === true, agingMinutes: queue?.agingMinutes ?? DEFAULT_QUEUE_AGING_MINUTES };
-}
-
/** Atomically replace machine settings without exposing a partial JSON file. */
function writeMachineSettings(settings) {
const file = machineSettingsFile();
diff --git a/test/resources.test.js b/test/resources.test.js
index 7a047572..716cae37 100644
--- a/test/resources.test.js
+++ b/test/resources.test.js
@@ -17,6 +17,7 @@ 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 PRE_RUNNER_MODULE = pathToFileURL(resolve(import.meta.dirname, './fixtures/resources-pre-runners.js')).href;
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');
@@ -235,8 +236,9 @@ function worker(box, { name = 'gate', capacity = 1, scope = 'machine', root = bo
}
/** 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)];
+function poolWorker(box, { agent, browser = false, item = '', kind = '', landing = false, module = MODULE }) {
+ // module swaps in another resources implementation, such as an older pullboard's, for mixed-version tests.
+ const workerArgs = ['--input-type=module', '-e', POOL_MODULE_WORKER.replace(JSON.stringify(MODULE), JSON.stringify(module)), 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'],
@@ -918,12 +920,9 @@ test('a line holding an older pullboard waiter keeps arrival order, so mixed ver
setQueueOrder(box, { reviewsFirst: true }); // #697: class order is a machine opt-in.
const holders = [poolWorker(box, { agent: 'mixed-holder-one' }), poolWorker(box, { agent: 'mixed-holder-two' })];
for (const holder of holders) await acquired(holder);
- const older = poolWorker(box, { agent: 'older-focused', kind: 'focused' });
+ // A real older pullboard (before #651) writes no class marker; it admits landings first and then by ticket.
+ const older = poolWorker(box, { agent: 'older-focused', kind: 'focused', module: PRE_RUNNER_MODULE });
await event(older);
- // An older pullboard writes no class marker; it admits landings first and then by ticket.
- const db = new DatabaseSync(join(box.home, 'resources.sqlite'));
- try { db.prepare("UPDATE waiter SET classed = 0 WHERE agent = 'older-focused'").run(); }
- finally { db.close(); }
const review = poolWorker(box, { agent: 'newer-review', kind: 'review', item: '651' });
assert.equal((await event(review)).queued.position, 2, 'the review waits behind the older waiter\'s earlier ticket');
const gate = () => privateList(box).find(({ name }) => name === 'gate');
@@ -1047,6 +1046,47 @@ test('queue order follows the machine settings [C7,O5]', async () => {
assert.equal(requeuedOn.tickets['remote-focused'], requeuedOn.lastIssued, 'with reviewsFirst true the requeued run keeps its original ticket');
assert.deepEqual(requeuedOn.admitted, ['review-later', 'submit-later', 'focused-early', 'remote-focused']);
+ // Mixed versions agree on the next waiter. A #651-only process ranks by class only when every
+ // waiter is marked classed=1, and otherwise landings first, then ticket; a #697 process follows
+ // its setting and marks its waiters to match, so both rankers pick the same waiter off and on.
+ const { queueClass: classOf } = await import('../src/resources.js');
+ const agree = fixture();
+ const agreeHolders = [poolWorker(agree, { agent: 'agree-holder-one' }), poolWorker(agree, { agent: 'agree-holder-two' })];
+ for (const holder of agreeHolders) await acquired(holder);
+ const agreeFocused = poolWorker(agree, { agent: 'agree-focused', kind: 'focused' });
+ await event(agreeFocused);
+ const agreeReview = poolWorker(agree, { agent: 'agree-review', kind: 'review', item: '697' });
+ await event(agreeReview);
+ /** The raw waiter rows every process reads. */
+ const rows = () => {
+ const db = new DatabaseSync(join(agree.home, 'resources.sqlite'));
+ try { return db.prepare("SELECT ticket, agent, since, landing, item_check AS itemCheck, diagnostic, kind, classed FROM waiter WHERE name = 'gate'").all(); }
+ finally { db.close(); }
+ };
+ /** The next waiter as a #651-only process ranks the same rows. */
+ const next651 = (waiters) => {
+ const byClass = waiters.every((waiter) => waiter.classed === 1);
+ const rank = (waiter) => (byClass ? classOf(waiter).effective : waiter.landing === 1 ? 0 : 1);
+ return [...waiters].sort((left, right) => rank(left) - rank(right) || left.ticket - right.ticket)[0].agent;
+ };
+ assert.deepEqual(rows().map(({ classed }) => classed), [0, 0], 'with reviewsFirst off a waiter is marked as not admitting by class');
+ assert.equal(next651(rows()), gate(agree).line[0].agent, 'off: a #651-only process and this one pick the same next waiter');
+ assert.equal(gate(agree).line[0].agent, 'agree-focused', 'off: both pick by arrival');
+ setQueueOrder(agree, { reviewsFirst: true });
+ // Each waiter re-marks itself on its next poll, so a setting change reaches every ranking.
+ for (let tries = 0; rows().some(({ classed }) => classed !== 1); tries += 1) {
+ assert.ok(tries < 250, 'waiters re-mark themselves after the setting turns on');
+ await new Promise((resolveTick) => setTimeout(resolveTick, 20));
+ }
+ assert.equal(next651(rows()), gate(agree).line[0].agent, 'on: a #651-only process and this one pick the same next waiter');
+ assert.equal(gate(agree).line[0].agent, 'agree-review', 'on: both pick by class');
+ await release(agreeHolders[0]);
+ assert.equal((await acquired(agreeReview)).acquired, 'agree-review');
+ await release(agreeHolders[1]);
+ assert.equal((await acquired(agreeFocused)).acquired, 'agree-focused');
+ await release(agreeReview);
+ await release(agreeFocused);
+
// An unusable value is refused by name, with the fix.
setQueueOrder(aging, { reviewsFirst: 'yes' });
const badFlag = settingsCli(aging, '--json');
diff --git a/test/runners.test.js b/test/runners.test.js
index f3bfcb89..7ab7c8ed 100644
--- a/test/runners.test.js
+++ b/test/runners.test.js
@@ -457,6 +457,27 @@ function observe(child) {
return { child, closed };
}
+test("the runner's trusted runtime list is closed under its relative imports [C7,O5]", () => {
+ const src = resolve(import.meta.dirname, '../src');
+ /** Read a runtime list literal from its source file, so the test sees exactly what ships. */
+ const listIn = (file, pattern) => {
+ const found = pattern.exec(readFileSync(join(src, file), 'utf8'));
+ assert.ok(found, `${file} declares the runner runtime list`);
+ return JSON.parse(found[1].replaceAll("'", '"'));
+ };
+ const controller = listIn('runners.js', /const RUNTIME_NAMES = (\[[^\]]*\]);/u);
+ const worker = listIn('runner-worker.js', /const runtimeNames = (\[[^\]]*\]);/u);
+ assert.deepEqual([...worker].sort(), [...controller].sort(), 'the controller ships the files the worker expects');
+ // Every relative import of a shipped file (and of the worker itself) must ship too, or it fails on the runner.
+ for (const file of [...controller, 'runner-worker.js']) {
+ const text = readFileSync(join(src, file), 'utf8');
+ const imports = [...text.matchAll(/(?:\bfrom\s+|\bimport\s*\(\s*|^import\s+)'(\.\/[^']+)'/gmu)].map(([, path]) => basename(path));
+ for (const name of imports) {
+ assert.ok(controller.includes(name), `${file} imports ./${name}, which the runner runtime list does not ship`);
+ }
+ }
+});
+
test('a queued run executes on a registered runner and its result comes back (host checkout isolation) [C7]', async (t) => {
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-tooling-isolation-')));
let completedCleanly = false;