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(runner): rerun only on the lease guard receipt [C7]

Corey Olsonb827529fea14
diff --git a/src/gate.js b/src/gate.js
index 1f3dc863..61d1db87 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -514,8 +514,12 @@ export async function withGateSlot(root, action, options = {}) {
try { return await withOneGateSlot(root, action, options); }
catch (error) {
if (error?.code !== 'RUNNER_BROWSER_SLOT_REQUIRED' || options.remote === false) throw error;
- process.stderr.write(`${error.message}; rerunning it locally\n`);
- return withOneGateSlot(root, action, { ...options, remote: false });
+ // The runner's red attempt stays on record beside the local rerun.
+ const attempt = error.runnerAttempt ?? { host: '', exitCode: null, output: '' };
+ process.stderr.write(`${error.message}; its attempt (exit ${attempt.exitCode}):\n${attempt.output}${attempt.output.endsWith('\n') || !attempt.output ? '' : '\n'}rerunning it locally with a browser slot\n`);
+ const result = await withOneGateSlot(root, action, { ...options, remote: false, browser: true });
+ if (result && typeof result === 'object') result.runnerAttempt = attempt;
+ return result;
}
}
diff --git a/src/landing-shards.js b/src/landing-shards.js
index 60427be3..0a0ef0ce 100644
--- a/src/landing-shards.js
+++ b/src/landing-shards.js
@@ -394,7 +394,7 @@ export async function runLandingShards({ root, runner, files, count, inherited =
}
// Infrastructure, not a test result: the runner could not give this shard a complete answer.
return { attempt: number, host, outcome: failure.action === 'fail' ? 'refused' : 'infrastructure', reason: failure.reason,
- output: '', wallMs: Date.now() - started };
+ output: error.runnerAttempt?.output ?? '', wallMs: Date.now() - started };
}
};
diff --git a/src/queue-settings.js b/src/queue-settings.js
index 5891b522..94a2227f 100644
--- a/src/queue-settings.js
+++ b/src/queue-settings.js
@@ -10,6 +10,18 @@ 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;
+/**
+ * The test classifier override this process inherited, or null when it inherited none. A run started
+ * on a runner carries the classification its controller used, so the runner never reclassifies from its
+ * own machine settings (#1043).
+ *
+ * @returns {boolean|null}
+ */
+export function carriedBrowserByLaunch() {
+ const carried = process.env.PULLBOARD_TEST_BROWSER_BY_LAUNCH;
+ return carried === '1' ? true : carried === '0' ? false : null;
+}
+
/** Resolve the separate machine settings file. */
export function machineSettingsFile() {
return join(machineHome(), 'settings.json');
diff --git a/src/resources.js b/src/resources.js
index 75f54ac2..fbc25bbc 100644
--- a/src/resources.js
+++ b/src/resources.js
@@ -2,6 +2,7 @@
import {
mkdirSync,
realpathSync,
+ writeFileSync,
} from 'node:fs';
import {
execFile,
@@ -47,6 +48,8 @@ export const GATE_SLOT_HELD_ENV = 'PULLBOARD_GATE_SLOT_HELD';
export const GATE_SLOT_POOL_ENV = 'PULLBOARD_GATE_SLOT_POOL';
export const GATE_SLOT_TOKEN_ENV = 'PULLBOARD_GATE_SLOT_TOKEN';
export const BROWSER_SLOT_HELD_ENV = 'PULLBOARD_BROWSER_SLOT_HELD';
+/** Where a runner asks the lease guard to record its own browser-slot refusal (#1043). */
+export const BROWSER_REFUSAL_FILE_ENV = 'PULLBOARD_BROWSER_REFUSAL_FILE';
/** Reserve a distinct resource row for each configured remote host. */
function runnerResourceName(host) { return `runner:${host}`; }
@@ -850,6 +853,9 @@ export async function takeResource(options) {
* (namedFiles) may reuse one, so a whole suite started under a short check queues for a real slot.
*/
export function inheritedGateSlot({ root = process.cwd(), browser = false, namedFiles = false } = {}) {
+ // Taken by the first guard in this process, so nothing it starts (a test body) can write the receipt.
+ const refusalFile = process.env[BROWSER_REFUSAL_FILE_ENV] ?? '';
+ delete process.env[BROWSER_REFUSAL_FILE_ENV];
const markedPool = process.env[GATE_SLOT_POOL_ENV] ?? '';
const token = process.env[GATE_SLOT_TOKEN_ENV] ?? '';
if (!markedPool && !token) return null;
@@ -869,6 +875,7 @@ export function inheritedGateSlot({ root = process.cwd(), browser = false, named
if (slotClass === 'short' && !namedFiles) throw new Refused('SHORT_SLOT_FULL_SUITE', 'a run that does not name its test files cannot reuse a short gate slot; start it outside the short check so it queues for an ordinary slot');
const expectedBrowserMarker = holder.browser === 1 ? '1' : '';
if (process.env[BROWSER_SLOT_HELD_ENV] !== expectedBrowserMarker) throw new Refused('GATE_SLOT_MARKER_INVALID', 'the inherited browser marker does not match its live gate lease; restart the child with gateSlotEnvironment(lease)');
+ if (browser && holder.browser !== 1 && refusalFile) writeFileSync(refusalFile, '{"code":"BROWSER_SLOT_REQUIRED"}\n', { mode: 0o600 });
if (browser && holder.browser !== 1) throw new Refused('BROWSER_SLOT_REQUIRED', 'the inherited gate lease does not hold the browser slot; release it and reacquire gate with browser: true before launching Chrome');
return {
name: 'gate', scope: 'machine', token, pool, browser: holder.browser === 1, slotClass, waitMs: 0,
diff --git a/src/runner-worker.js b/src/runner-worker.js
index dc93dabf..0f5b95b8 100644
--- a/src/runner-worker.js
+++ b/src/runner-worker.js
@@ -1209,7 +1209,7 @@ async function receipt(spec, fields, sink) {
runtimeSha256: spec.runtime.sha256, toolingSha256: spec.tooling.sha256, root: fields.root ?? '', outputSha256: sink.hash.digest('hex'), wallMs: Math.max(0, Date.now() - sink.wallStart),
// The execution host's load and the pinned main this run used, so a paired rerun here can be judged (#925).
main: typeof spec.main === 'string' ? spec.main : null, load: { average: loadavg(), cpus: availableParallelism(), freeMB: Math.floor(freemem() / 1048576) },
- ...(spec.stageMarker ? { pipeStatuses: fields.pipeStatuses ?? null } : {}), ...(fields.refused ? { refused: fields.refused } : {}), ...(fields.denial ? { denial: fields.denial } : {}) };
+ ...(spec.stageMarker ? { pipeStatuses: fields.pipeStatuses ?? null } : {}), ...(fields.refused ? { refused: fields.refused } : {}), ...(fields.browserRefused ? { browserRefused: true } : {}), ...(fields.denial ? { denial: fields.denial } : {}) };
const encoded = Buffer.from(JSON.stringify(body)).toString('base64');
await new Promise((resolveWrite, rejectWrite) => process.stderr.write(`${RECEIPT} ${spec.id} ${encoded}\n`, error => error ? rejectWrite(error) : resolveWrite()));
}
@@ -1317,7 +1317,9 @@ async function main() {
setupStep = 'committed dependencies';
await installDependencies(root, runnerRoot, env, tracker);
setupStep = 'command start';
- final = { ...(await runCommand(spec, root, { ...env, PULLBOARD_LANDING_RUN: spec.landing === true ? '1' : '0', ...(typeof spec.browserByLaunch === 'boolean' ? { PULLBOARD_TEST_BROWSER_BY_LAUNCH: spec.browserByLaunch ? '1' : '0' } : {}), PULLBOARD_LANDING_WAIVERS: JSON.stringify(spec.landing === true ? spec.waivers ?? [] : []) }, sink, tracker)), root };
+ const browserRefusal = join(runDirectory, 'browser-refusal.json');
+ final = { ...(await runCommand(spec, root, { ...env, PULLBOARD_LANDING_RUN: spec.landing === true ? '1' : '0', [api.BROWSER_REFUSAL_FILE_ENV]: browserRefusal, ...(typeof spec.browserByLaunch === 'boolean' ? { PULLBOARD_TEST_BROWSER_BY_LAUNCH: spec.browserByLaunch ? '1' : '0' } : {}), PULLBOARD_LANDING_WAIVERS: JSON.stringify(spec.landing === true ? spec.waivers ?? [] : []) }, sink, tracker)), root };
+ if (final.code !== 0 && existsSync(browserRefusal)) final.browserRefused = true;
} catch (error) {
const refused = setupRefusalCode(error);
const message = refused ? `${safeSetupMessage(error, setupStep)} [${refused}]` : safeSetupMessage(error, setupStep);
diff --git a/src/runners.js b/src/runners.js
index 98d8dc60..d764a8fb 100644
--- a/src/runners.js
+++ b/src/runners.js
@@ -56,7 +56,7 @@ import {
readStages,
} from './gate-stages.js';
import { remoteFileDenial } from './sandbox-denial.js';
-import { readMachineSettingsFile } from './queue-settings.js';
+import { carriedBrowserByLaunch, readMachineSettingsFile } from './queue-settings.js';
// Budget: 64 MiB bounds worst-case JSON bridge escaping below Node string limits.
const MAX_OUTPUT_BYTES = 64 * 1024 ** 2;
@@ -465,7 +465,7 @@ function anonymousOrigin(root) {
}
/** Prepare the pinned request before negotiating history; cleanup owns only its scratch directory. */
-function requestFor(root, command, { runner, source, browser = false, pipefail = false, stages = false, waivers = [], metadata = {} }) {
+function requestFor(root, command, { runner, source, browser = false, byLaunch, pipefail = false, stages = false, waivers = [], metadata = {} }) {
runner = validateRunner(runner);
const current = runnerSource(root);
if (!current || (source && (current.commit !== source.commit || current.tree !== source.tree))) {
@@ -487,8 +487,8 @@ function requestFor(root, command, { runner, source, browser = false, pipefail =
if (secretsIn([{ path: 'runner continuation', line: 1, text: JSON.stringify(projection) }]).length) throw new Refused('RUNNER_SECRET', 'the continuation projection contains a possible secret; keep this run local');
const spec = { version: 1, id: randomUUID(), repoId, ...(originBase ? { origin, originBase } : {}), runtime, tooling, tags, ...current, command, pipefail, slots: runner.slots,
browser: runner.browser, browserRequired: browser, landing: metadata.landing === true,
- // The runner classifies test files as this controller did, not by its own settings (#1043).
- browserByLaunch: readMachineSettingsFile()?.gate?.browserByLaunch === true,
+ // The classification this controller used, so the runner never reclassifies by its own settings (#1043).
+ browserByLaunch: byLaunch ?? carriedBrowserByLaunch() ?? readMachineSettingsFile()?.gate?.browserByLaunch === true,
...(stages ? { stageMarker: `PULLBOARD_STAGE_${randomUUID().replaceAll('-', '')}` } : {}), waivers: projection,
itemCheck: metadata.itemCheck === true, diagnostic: metadata.diagnostic === true,
item: String(metadata.item ?? ''), kind: String(metadata.kind ?? ''), ...(runner.root ? { root: runner.root } : {}),
@@ -545,8 +545,12 @@ function resultFrom(request, result) {
}
}
const text = staged?.output ?? output.toString('utf8');
- if (!request.spec.browserRequired && receipt.code !== 0 && text.includes('[BROWSER_SLOT_REQUIRED]')) {
- throw new Refused('RUNNER_BROWSER_SLOT_REQUIRED', `runner ${request.runner.host} ran this without a browser slot and answered BROWSER_SLOT_REQUIRED`);
+ if (receipt.browserRefused !== undefined && (receipt.browserRefused !== true || receipt.code === 0 || request.spec.browserRequired)) throw new RunnerDropped(request.runner.host);
+ // Only the lease guard's own receipt counts; text a test prints is never a refusal (#1043).
+ if (receipt.browserRefused === true) {
+ const refused = new Refused('RUNNER_BROWSER_SLOT_REQUIRED', `runner ${request.runner.host} refused this run's lease for want of a browser slot (BROWSER_SLOT_REQUIRED)`);
+ refused.runnerAttempt = { host: request.runner.host, exitCode: receipt.code, output: text };
+ throw refused;
}
return { isGreen: receipt.code === 0 && !receipt.signal, output: text, sandboxBlocked,
...(request.spec.stageMarker ? { stages: staged?.stages ?? null } : {}),
@@ -575,7 +579,7 @@ process.on('SIGTERM',abort); process.on('SIGHUP',abort); process.stdout.on('erro
const parentWatch=setInterval(()=>{if(process.ppid!==request.parentPid)abort();},1000);
if(process.ppid!==request.parentPid)abort();
try { process.stdout.write(JSON.stringify({result:await runOnRunnerAsync(request.root,request.command,{...request.options,signal:canceled.signal})})); }
-catch(error) { process.stdout.write(JSON.stringify({error:{name:error.name,code:error.code,message:error.message,host:error.host}})); process.exitCode=1; }
+catch(error) { process.stdout.write(JSON.stringify({error:{name:error.name,code:error.code,message:error.message,host:error.host,runnerAttempt:error.runnerAttempt}})); process.exitCode=1; }
finally {clearInterval(parentWatch);}`;
const child = spawnSync(process.execPath, ['--input-type=module', '-e', script], {
cwd: root, input: JSON.stringify({ root, command, options, parentPid: process.pid }), encoding: 'utf8', maxBuffer: MAX_OUTPUT_BYTES * 6 + 1024 ** 2,
@@ -585,7 +589,9 @@ finally {clearInterval(parentWatch);}`;
try { reply = JSON.parse(child.stdout); } catch { throw new RunnerDropped(options.runner.host); }
if (reply.error?.name === 'Refused') {
const prefix = `[${reply.error.code}] `;
- throw new Refused(reply.error.code, reply.error.message.startsWith(prefix) ? reply.error.message.slice(prefix.length) : reply.error.message);
+ const refused = new Refused(reply.error.code, reply.error.message.startsWith(prefix) ? reply.error.message.slice(prefix.length) : reply.error.message);
+ if (reply.error.runnerAttempt) refused.runnerAttempt = reply.error.runnerAttempt;
+ throw refused;
}
if (reply.error || child.error || child.status !== 0) throw new RunnerDropped(options.runner.host);
return reply.result;
diff --git a/src/settings.js b/src/settings.js
index f27c3658..8e72d632 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -14,6 +14,7 @@ import {
import { validateRunner } from './runners.js';
import { Refused } from './refused.js';
import {
+ carriedBrowserByLaunch,
gateQueueSettings,
machineSettingsFile,
readMachineSettingsFile,
@@ -85,10 +86,7 @@ export function browserFreeChecksEnabled() {
* machine; off, any path to the Chrome fixture or an unfollowed process starter takes a browser slot.
*/
export function browserByLaunchEnabled() {
- // A runner's command carries its controller's setting, since the runner machine's own may differ (#1043).
- const carried = process.env.PULLBOARD_TEST_BROWSER_BY_LAUNCH;
- if (carried === '1' || carried === '0') return carried === '1';
- return loadMachineSettings().gate?.browserByLaunch === true;
+ return carriedBrowserByLaunch() ?? loadMachineSettings().gate?.browserByLaunch === true;
}
/**
diff --git a/test/runner-browser-free-fixture.js b/test/runner-browser-free-fixture.js
index e7e518af..7db3b40e 100644
--- a/test/runner-browser-free-fixture.js
+++ b/test/runner-browser-free-fixture.js
@@ -4,9 +4,10 @@ import assert from 'node:assert/strict';
import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { tmpdir } from 'node:os';
+import { pathToFileURL } from 'node:url';
import { listResources, takeResource } from '../src/resources.js';
import { runFixtureChild, runFixtureChildAsync } from './fixture-child.js';
-import { HOST, installSshStandIn } from './runner-ssh-fixture.js';
+import { HOST, installSshStandIn, shellQuote } from './runner-ssh-fixture.js';
const SOURCE = resolve(import.meta.dirname, '..');
@@ -16,9 +17,9 @@ const FREE = "import { test } from 'node:test';\nimport { spawnSync } from 'node
// Browser-bound under either classifier: a process starter beside a Chrome executable name.
const CHROME = "import { test } from 'node:test';\nimport { spawnSync } from 'node:child_process';\nconst chrome = 'google-chrome';\n"
+ "test('browser-bound file ran', () => { if (process.env.PULLBOARD_FIXTURE_NEVER_SET) spawnSync(chrome, ['--version']); });\n";
-// A stand-in for a runner whose own run refuses the file for want of a browser slot; it fails only under the stand-in's home.
-const refusedSource = remoteHome => "import { test } from 'node:test';\n"
- + `test('refused file ran', () => { if (process.cwd().startsWith(${JSON.stringify(remoteHome)})) throw new Error('[BROWSER_SLOT_REQUIRED] the runner held no browser slot for this file'); });\n`;
+// A test body that prints and throws the refusal text: an ordinary red, never a lease refusal.
+const MARKER = "import { test } from 'node:test';\n"
+ + "test('marker file ran', () => { console.log('[BROWSER_SLOT_REQUIRED] printed by a test'); throw new Error('[BROWSER_SLOT_REQUIRED] thrown by a test'); });\n";
/** Count the stand-in's dispatched and returned markers. */
function phases(file) {
@@ -35,8 +36,8 @@ async function until(condition, what) {
}
}
-/** Drive bin/run-tests.js against a stand-in SSH runner registered with --browser 0. */
-export async function browserFreeRunnerCheck(t, { cli, git }) {
+/** Build a committed repo, a stand-in runner registered with --browser 0, and a held local slot; run body, then restore. */
+async function withNoBrowserRunner(t, { cli, git }, body) {
const dir = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-runner-browser-free-')));
t.after(() => rmSync(dir, { recursive: true, force: true }));
const [home, repo, worker, bin, remoteHome] = ['home', 'repo', 'second-machine', 'bin', 'worker-home'].map(name => join(dir, name));
@@ -60,7 +61,7 @@ export async function browserFreeRunnerCheck(t, { cli, git }) {
cpSync(join(SOURCE, 'bin'), join(repo, 'bin'), { recursive: true });
writeFileSync(join(repo, 'test', 'free.test.js'), FREE);
writeFileSync(join(repo, 'test', 'chrome.test.js'), CHROME);
- writeFileSync(join(repo, 'test', 'refused.test.js'), refusedSource(remoteHome));
+ writeFileSync(join(repo, 'test', 'marker.test.js'), MARKER);
git(repo, env, 'add', 'package.json', 'pullboard.json', 'src', 'bin', 'test');
git(repo, env, 'commit', '-q', '-m', 'test: commit a browser-free runner fixture');
installSshStandIn({ bin, worker, home: remoteHome, machineHome: remoteMachineHome, requests });
@@ -71,49 +72,90 @@ export async function browserFreeRunnerCheck(t, { cli, git }) {
const previousMachineHome = process.env.PULLBOARD_MACHINE_HOME;
process.env.PULLBOARD_HOME = home;
process.env.PULLBOARD_MACHINE_HOME = machineHome;
- const marks = `${requests}.phases`;
- const runTests = file => runFixtureChildAsync(process.execPath, ['bin/run-tests.js', file], { cwd: repo, env });
- const show = result => `${result.context}\nstdout:\n${result.stdout}`;
- let held;
- try {
+ const slot = { lease: null };
+ const fixture = {
+ repo, env, slot, marks: `${requests}.phases`,
+ phases: () => phases(`${requests}.phases`),
+ runTests: file => runFixtureChildAsync(process.execPath, ['bin/run-tests.js', file], { cwd: repo, env }),
+ show: result => `${result.context}\nstdout:\n${result.stdout}`,
// Fill the controller's only gate slot so a remote-capable run goes to the runner.
- const hold = () => takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: repo,
- agent: 'browser-free-local-holder', item: 'local-holder', kind: 'force-registered-runner' });
- held = await hold();
+ hold: async () => { slot.lease = await takeResource({ name: 'gate', capacity: 1, scope: 'machine', root: repo,
+ agent: 'browser-free-local-holder', item: 'local-holder', kind: 'force-registered-runner' }); },
+ free: () => { slot.lease?.release(); slot.lease = null; },
+ };
+ try { await body(fixture); }
+ finally {
+ fixture.free();
+ if (previousHome === undefined) delete process.env.PULLBOARD_HOME; else process.env.PULLBOARD_HOME = previousHome;
+ if (previousMachineHome === undefined) delete process.env.PULLBOARD_MACHINE_HOME; else process.env.PULLBOARD_MACHINE_HOME = previousMachineHome;
+ }
+}
+
+/** Run one command through the repo's own gate API, as an item check does, with no browser slot asked. */
+function gateRun({ repo, env }, command) {
+ const gateUrl = pathToFileURL(join(repo, 'src', 'gate.js')).href;
+ const script = `const { runProfiledShell, withGateSlot } = await import(${JSON.stringify(gateUrl)});
+const result = await withGateSlot(${JSON.stringify(repo)}, lease => runProfiledShell(${JSON.stringify(repo)}, ${JSON.stringify(command)}, { gateLease: lease }),
+ { browser: false, item: '1043', kind: 'check', itemCheck: true, agent: 'browser-free-fixture' });
+process.stdout.write(result.output);
+process.stdout.write('PULLBOARD_RUN_RESULT ' + JSON.stringify({ isGreen: result.isGreen, runner: result.profile.executionRunner ?? null, runnerAttempt: result.runnerAttempt ?? null }) + '\\n');
+process.exitCode = result.isGreen ? 0 : 1;
+`;
+ return runFixtureChildAsync(process.execPath, ['--input-type=module', '-e', script], { cwd: repo, env });
+}
- const free = await runTests('test/free.test.js');
- assert.doesNotMatch(free.stdout + free.stderr, /BROWSER_SLOT_REQUIRED/u, show(free));
- assert.equal(free.status, 0, show(free));
- assert.match(free.stdout, /^ok 1 - browser-free file ran/mu, show(free));
- assert.deepEqual(phases(marks), { dispatched: 1, returned: 1 }, 'the browser-free file ran on the no-browser runner');
+/** A browser-free file runs green on the no-browser runner; a lease refusal reruns locally; a browser-bound file stays local. */
+export async function browserFreeRunnerCheck(t, helpers) {
+ await withNoBrowserRunner(t, helpers, async (fixture) => {
+ const { runTests, show, hold, free } = fixture;
+ await hold();
+ const ran = await runTests('test/free.test.js');
+ assert.doesNotMatch(ran.stdout + ran.stderr, /BROWSER_SLOT_REQUIRED/u, show(ran));
+ assert.equal(ran.status, 0, show(ran));
+ assert.match(ran.stdout, /^ok 1 - browser-free file ran/mu, show(ran));
+ assert.deepEqual(fixture.phases(), { dispatched: 1, returned: 1 }, 'the browser-free file ran on the no-browser runner');
- // A runner's BROWSER_SLOT_REQUIRED answer reruns the file here once a local slot frees.
- const refused = runTests('test/refused.test.js');
- await until(() => phases(marks).returned === 2, 'the runner answers the refused file');
- held.release();
- held = undefined;
- const rerun = await refused;
+ // A runner whose own run classifies more broadly than this controller (here the command forces the
+ // broad classifier) has its lease guard refuse; the guard's receipt, not any text, reruns it locally.
+ const command = `PULLBOARD_TEST_BROWSER_BY_LAUNCH=0 node bin/run-tests.js ${shellQuote('test/free.test.js')}`;
+ const pending = gateRun(fixture, command);
+ await until(() => fixture.phases().returned === 2, 'the runner answers the refused run');
+ free();
+ const rerun = await pending;
assert.equal(rerun.status, 0, show(rerun));
- assert.match(rerun.stderr, /BROWSER_SLOT_REQUIRED.*rerunning it locally/u, show(rerun));
- assert.match(rerun.stdout, /^ok 1 - refused file ran/mu, show(rerun));
- assert.deepEqual(phases(marks), { dispatched: 2, returned: 2 }, 'the local rerun never went back to the runner');
+ assert.match(rerun.stderr, /RUNNER_BROWSER_SLOT_REQUIRED[^\n]*its attempt \(exit 1\):\n[^]*run-tests: \[BROWSER_SLOT_REQUIRED\][^]*rerunning it locally with a browser slot/u, show(rerun));
+ const record = JSON.parse(rerun.stdout.split('\n').findLast(line => line.startsWith('PULLBOARD_RUN_RESULT ')).slice('PULLBOARD_RUN_RESULT '.length));
+ assert.equal(record.runner, null, 'the green result is the local rerun');
+ assert.equal(record.runnerAttempt.host, HOST, 'the runner attempt is kept beside it');
+ assert.match(record.runnerAttempt.output, /\[BROWSER_SLOT_REQUIRED\] the inherited gate lease does not hold the browser slot/u);
+ assert.match(rerun.stdout, /^ok 1 - browser-free file ran/mu, show(rerun));
+ assert.deepEqual(fixture.phases(), { dispatched: 2, returned: 2 }, 'the local rerun never went back to the runner');
// A browser-bound file waits for a local slot rather than going to a runner with no browser slots.
- held = await hold();
+ await hold();
const bound = runTests('test/chrome.test.js');
- const waiting = () => listResources({ scope: 'machine', root: repo }).find(resource => resource.name === 'gate')?.line.length === 1;
+ const waiting = () => listResources({ scope: 'machine', root: fixture.repo }).find(resource => resource.name === 'gate')?.line.length === 1;
await until(waiting, 'the browser-bound run queues');
await new Promise(resolveWait => setTimeout(resolveWait, 1_000)); // budget: several admission polls in which a runner could take it.
assert.equal(waiting(), true, 'the browser-bound run still waits for a local slot');
- held.release();
- held = undefined;
+ free();
const local = await bound;
assert.equal(local.status, 0, show(local));
assert.match(local.stdout, /^ok 1 - browser-bound file ran/mu, show(local));
- assert.deepEqual(phases(marks), { dispatched: 2, returned: 2 }, 'the browser-bound file never reached the runner');
- } finally {
- held?.release();
- if (previousHome === undefined) delete process.env.PULLBOARD_HOME; else process.env.PULLBOARD_HOME = previousHome;
- if (previousMachineHome === undefined) delete process.env.PULLBOARD_MACHINE_HOME; else process.env.PULLBOARD_MACHINE_HOME = previousMachineHome;
- }
+ assert.deepEqual(fixture.phases(), { dispatched: 2, returned: 2 }, 'the browser-bound file never reached the runner');
+ });
+}
+
+/** Control: a test that prints or throws the refusal text on a runner stays red and is never rerun. */
+export async function browserRefusalTextStaysRed(t, helpers) {
+ await withNoBrowserRunner(t, helpers, async (fixture) => {
+ const { runTests, show, hold } = fixture;
+ await hold();
+ const red = await runTests('test/marker.test.js');
+ assert.equal(red.status, 1, show(red));
+ assert.match(red.stdout, /^not ok 1 - marker file ran/mu, show(red));
+ assert.match(red.stdout, /\[BROWSER_SLOT_REQUIRED\] thrown by a test/u, show(red));
+ assert.doesNotMatch(red.stderr, /RUNNER_BROWSER_SLOT_REQUIRED|rerunning it locally/u, show(red));
+ assert.deepEqual(fixture.phases(), { dispatched: 1, returned: 1 }, 'the red came from the runner, once');
+ });
}
diff --git a/test/runners.test.js b/test/runners.test.js
index ed889b18..f54344a9 100644
--- a/test/runners.test.js
+++ b/test/runners.test.js
@@ -22,7 +22,7 @@ import { SECRET, HOST, shellQuote, installSshStandIn } from './runner-ssh-fixtur
import { sourceSetupFailureFixture } from './runner-source-setup-fixture.js';
import { runnerSourceRefusalCases } from './runner-source-refusal-fixture.js';
import { writeCacheProbe, writeProbe } from './runner-probe-fixture.js';
-import { browserFreeRunnerCheck } from './runner-browser-free-fixture.js';
+import { browserFreeRunnerCheck, browserRefusalTextStaysRed } from './runner-browser-free-fixture.js';
/** Per-phase deadlines for one runner round trip; together they stay near the 60-second hang ceiling. */
const ROUND_TRIP_DEADLINES = { dispatch: 20_000, 'remote run': 30_000, 'result return': 10_000 }; // budget: a stuck runner fails by name in about a minute, far under the 660-second per-test limit.
@@ -1848,7 +1848,8 @@ test('review655 a registered runner honors the same live person waiver at landin
if (priorMachine === undefined) delete process.env.PULLBOARD_MACHINE_HOME; else process.env.PULLBOARD_MACHINE_HOME = priorMachine;
}
});
-test('a browser-free check on a runner with no browser slots passes [C7]', { timeout: 180_000 }, t => browserFreeRunnerCheck(t, { cli, git })); // budget: three runner round trips and two local runs.
+test('a browser-free check on a runner with no browser slots passes [C7]', { timeout: 180_000 }, t => browserFreeRunnerCheck(t, { cli, git })); // budget: two runner round trips and two local runs.
+test('a test that prints the browser refusal text on a runner stays red and is not rerun [C7]', { timeout: 120_000 }, t => browserRefusalTextStaysRed(t, { cli, git })); // budget: one runner round trip.
test('a refused runner checkout names its failed Git step and stderr [C6,C7]', async t => {
for (const mode of ['lock', 'missing', 'large', 'filesystem', 'index', 'custom-filesystem']) {