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(runner): carry by-launch browser classification to runners [C7]
Corey Olsonc6d6cf6c0a50
diff --git a/src/gate.js b/src/gate.jsindex ead1127d..1f3dc863 100644--- a/src/gate.js+++ b/src/gate.js@@ -510,7 +510,17 @@ function hasPipeline(command) {* @param {{ landing?: boolean, itemCheck?: boolean, shortEligible?: boolean, diagnostic?: boolean, browser?: boolean, remote?: boolean, agent?: string, item?: string|number, kind?: string, onWait?: (state: object) => void, onReceipt?: (receipt: object) => void, readMemory?: typeof readMachineMemory }} [options] - Queue class, short-slot eligibility, remote eligibility, progress reporter, the run's receipt once its slot is released (#836) and, for tests, the machine memory reader.* @returns {Promise<any>} The action's result after releasing its lease.*/-export async function withGateSlot(root, action, { landing = false, itemCheck = false, shortEligible = false, diagnostic = false, browser = false, remote = true, agent, item = '', kind = '', onWait, onReceipt, readMemory = readMachineMemory } = {}) {+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 });+ }+}++/** One gate admission and its action; withGateSlot may call it again for a local rerun. */+async function withOneGateSlot(root, action, { landing = false, itemCheck = false, shortEligible = false, diagnostic = false, browser = false, remote = true, agent, item = '', kind = '', onWait, onReceipt, readMemory = readMachineMemory } = {}) {const tracker = startReceipt();const receiptKind = kind || (landing ? 'landing' : 'gate');/** Hand the run its receipt tracker and slot, then record its receipt once the slot is released (#836). */diff --git a/src/landing-shards.js b/src/landing-shards.jsindex e5075377..60427be3 100644--- a/src/landing-shards.js+++ b/src/landing-shards.js@@ -282,7 +282,7 @@ export function landingSource(root) {}/** Runner refusals that mean the host could not run the shard right now, so a local rerun is sound. */-const RERUN_REFUSALS = new Set(['RUNNER_SETUP_REFUSED', 'RESOURCE_LEASE_LOST']);+const RERUN_REFUSALS = new Set(['RUNNER_SETUP_REFUSED', 'RESOURCE_LEASE_LOST', 'RUNNER_BROWSER_SLOT_REQUIRED']);/*** How a sharded landing answers a runner that gave no test result. A lost host or transport, or adiff --git a/src/runner-worker.js b/src/runner-worker.jsindex 083898fc..dc93dabf 100644--- a/src/runner-worker.js+++ b/src/runner-worker.js@@ -173,6 +173,7 @@ async function readSpec() {|| typeof value.pipefail !== 'boolean' || !Number.isSafeInteger(value.slots) || value.slots < 1|| !Number.isSafeInteger(value.browser) || value.browser < 0|| typeof value.browserRequired !== 'boolean'+ || (value.browserByLaunch !== undefined && typeof value.browserByLaunch !== 'boolean')|| !value.runtime || typeof value.runtime !== 'object' || !value.runtime.files || typeof value.runtime.files !== 'object'|| typeof value.runtime.sha256 !== 'string') throw new Error('invalid work specification');if (value.stageMarker !== undefined && !/^PULLBOARD_STAGE_[a-f0-9]{32}$/u.test(value.stageMarker)) throw new Error('invalid stage marker');@@ -1316,7 +1317,7 @@ 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', PULLBOARD_LANDING_WAIVERS: JSON.stringify(spec.landing === true ? spec.waivers ?? [] : []) }, sink, tracker)), root };+ 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 };} 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.jsindex a86f6a21..98d8dc60 100644--- a/src/runners.js+++ b/src/runners.js@@ -56,6 +56,7 @@ import {readStages,} from './gate-stages.js';import { remoteFileDenial } from './sandbox-denial.js';+import { 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;@@ -486,6 +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,...(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 } : {}),@@ -541,7 +544,11 @@ function resultFrom(request, result) {? pipes[index] : null } : stage) };}}- return { isGreen: receipt.code === 0 && !receipt.signal, output: staged?.output ?? output.toString('utf8'), sandboxBlocked,+ 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`);+ }+ return { isGreen: receipt.code === 0 && !receipt.signal, output: text, sandboxBlocked,...(request.spec.stageMarker ? { stages: staged?.stages ?? null } : {}),seconds: Math.round(receipt.wallMs / 1000), exitCode: receipt.code,executionRunner: request.runner.host, executionRoot: receipt.root, remoteWallMs: receipt.wallMs,diff --git a/src/settings.js b/src/settings.jsindex 3e54be72..f27c3658 100644--- a/src/settings.js+++ b/src/settings.js@@ -85,6 +85,9 @@ 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;}diff --git a/test/runner-browser-free-fixture.js b/test/runner-browser-free-fixture.jsnew file mode 100644index 00000000..bd77f68a--- /dev/null+++ b/test/runner-browser-free-fixture.js@@ -0,0 +1,119 @@+/** @pullboard-test-input source-tree */+/** A runner registered with no browser slots runs browser-free test files and never browser-bound ones [C7]. */+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 { listResources, takeResource } from '../src/resources.js';+import { runFixtureChild, runFixtureChildAsync } from './fixture-child.js';+import { HOST, installSshStandIn } from './runner-ssh-fixture.js';++const SOURCE = resolve(import.meta.dirname, '..');++// Browser-bound only under the broad classifier: a Node child with no Chrome reference.+const FREE = "import { test } from 'node:test';\nimport { spawnSync } from 'node:child_process';\n"+ + "test('browser-free file ran', () => { if (spawnSync(process.execPath, ['-e', '0']).status !== 0) throw new Error('child failed'); });\n";+// 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.+const REFUSED = "import { test } from 'node:test';\n"+ + "test('refused file ran', () => { if (process.cwd().includes('.pullboard-runner')) throw new Error('[BROWSER_SLOT_REQUIRED] the runner held no browser slot for this file'); });\n";++/** Count the stand-in's dispatched and returned markers. */+function phases(file) {+ const lines = existsSync(file) ? readFileSync(file, 'utf8').split('\n') : [];+ return { dispatched: lines.filter(line => line === 'dispatched').length, returned: lines.filter(line => line === 'returned').length };+}++/** Poll a condition with a named hang ceiling. */+async function until(condition, what) {+ const deadline = Date.now() + 60_000; // budget: one runner round trip with checkout and npm setup.+ while (!condition()) {+ if (Date.now() >= deadline) throw new Error(`fixture wait timed out: ${what}`);+ await new Promise(resolveWait => setTimeout(resolveWait, 50)); // budget: polling interval for fixture state.+ }+}++/** Drive bin/run-tests.js against a stand-in SSH runner registered with --browser 0. */+export async function browserFreeRunnerCheck(t, { cli, git }) {+ 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));+ const machineHome = join(home, '.pullboard');+ const remoteMachineHome = join(remoteHome, '.pullboard');+ const requests = join(dir, 'ssh-requests.jsonl');+ for (const folder of [repo, worker, bin, machineHome, remoteMachineHome, join(repo, 'test')]) mkdirSync(folder, { recursive: true });+ // The controller classifies by launch; the runner machine has no settings file at all, as on a fresh host.+ writeFileSync(join(machineHome, 'settings.json'), JSON.stringify({ gateSlots: 1, gate: { browserByLaunch: true } }));+ const env = { ...process.env, HOME: home, PULLBOARD_HOME: home, PULLBOARD_MACHINE_HOME: machineHome,+ PATH: `${bin}:${process.env.PATH}`, GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'Runner Fixture', GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'Runner Fixture', GIT_COMMITTER_EMAIL: '[email protected]' };+ // This file runs under the suite's own lease and launch guard; the fixture's runs take their own.+ for (const key of Object.keys(env)) if (/^PULLBOARD_(GATE|BROWSER|TEST|LANDING)_/u.test(key) || key === 'NODE_OPTIONS' || key === 'NODE_TEST_CONTEXT') delete env[key];+ const initialized = runFixtureChild('git', ['init', '-q', '-b', 'main'], { cwd: repo, env, encoding: 'utf8' });+ assert.equal(initialized.status, 0, initialized.context);+ writeFileSync(join(repo, 'package.json'), JSON.stringify({ name: 'pullboard', version: '0.0.0-fixture', private: true, type: 'module' }) + '\n');+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ gate: 'true' }));+ cpSync(join(SOURCE, 'src'), join(repo, 'src'), { recursive: true });+ 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'), REFUSED);+ 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 });+ const added = cli(repo, env, 'runner', 'add', HOST, '--slots', '1', '--browser', '0', '--json');+ assert.equal(added.status, 0, added.context);++ const previousHome = process.env.PULLBOARD_HOME;+ 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 {+ // 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();++ 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 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;+ 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');++ // A browser-bound file waits for a local slot rather than going to a runner with no browser slots.+ held = await hold();+ const bound = runTests('test/chrome.test.js');+ const waiting = () => listResources({ scope: 'machine', root: 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;+ 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;+ }+}diff --git a/test/runners.test.js b/test/runners.test.jsindex d09eb06d..ed889b18 100644--- a/test/runners.test.js+++ b/test/runners.test.js@@ -22,6 +22,7 @@ import { SECRET, HOST, shellQuote, installSshStandIn } from './runner-ssh-fixturimport { 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';/** 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.@@ -1847,6 +1848,8 @@ test('review655 a registered runner honors the same live person waiver at landinif (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 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']) {await t.test(mode, child => sourceSetupFailureFixture(child, { cli, git, runThroughGate, gateResult }, mode));