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(gate): report browser admission fallbacks [C7]
Corey Olsonef7a1c961f7f
diff --git a/src/browser-admission.js b/src/browser-admission.jsindex c7057ed7..b01345bf 100644--- a/src/browser-admission.js+++ b/src/browser-admission.js@@ -1,7 +1,6 @@/** Classify whether selected tests may launch Chrome; uncertainty keeps browser coverage enabled. */-import { createHash } from 'node:crypto';import { accessSync, constants } from 'node:fs';-import { readFile, realpath, stat } from 'node:fs/promises';+import { lstat, readFile, realpath, stat } from 'node:fs/promises';import { posix, relative, resolve, sep } from 'node:path';import { commonJsIn, importsIn } from './module-imports.js';import { cleanGitEnvironment, git } from './git.js';@@ -10,16 +9,14 @@ const MODULE_SUFFIXES = ['.js', '.mjs', '.cjs', '.cts', '.json'];const CHROME_FIXTURE = 'test/chrome-fixture.js';const JOURNEYS_TEST = 'test/journeys.test.js';const TEST_RUNNER = 'bin/run-tests.js';-const TRUSTED_TEST_RUNNER_BLOB = '2166ff4052d4c24835aff3de561948843d4ff30c';-const TRUSTED_TEST_RUNNER_SHA256 = '03df8bbb82585ff10df88ec4ecba9354301f73c091fd7eecddf1d57a84ef47f5';const VALUE_OPTIONS = new Set(['--test-concurrency', '--test-name-pattern', '--test-shard', '--test-skip-pattern', '--test-timeout']);const FLAG_OPTIONS = new Set(['--test-only']);-/** Known read-only or test-runner child-process modules; hash pins prevent path-only exemptions. */+/** Path-scoped child-process exceptions with a short reason for each reviewed non-Chrome helper. */const SAFE_CHILD_PROCESS_MODULES = new Map([- ['test/fixture-child.js', { hash: '77013ed0773d16e439fc1ab235364a612d9a9d19b911dc406050e0e5a512517e', reason: 'shared fixture runner for explicit fixture commands' }],- ['src/git.js', { hash: '35b278a548b95a55e142df2058092e7ea7ab80453d40acc9f22a86bcf68ca5ff', reason: 'runs Git commands for repository inspection' }],- ['src/module-imports.js', { hash: 'a4853eca3cbb4140391a1003dfe145fb8e6ad46dfb06b2c4285c66fbc97fa2de', reason: 'runs the Node parser in an isolated child' }],- ['src/resources.js', { hash: 'cd57aa2ac72315d10f07ae4b15af7ffd399d0c34b14e326651ed281b83553bee', reason: 'reads process identity with /bin/ps' }],+ ['test/fixture-child.js', 'shared fixture runner for explicit fixture commands'],+ ['src/git.js', 'runs Git commands for repository inspection'],+ ['src/module-imports.js', 'runs the Node parser in an isolated child'],+ ['src/resources.js', 'reads process identity with /bin/ps'],]);/** Split a literal shell command into words, refusing expansion, operators, and incomplete quoting. */@@ -165,36 +162,51 @@ function namesChromeLauncher(source) {return /\b(?:spawn|spawnSync|exec|execSync|execFile|execFileSync|fork)\s*\(\s*(['"`])[^'"`\r\n]*\b(?:chrome|chromium|playwright|puppeteer)\b/iu.test(source);}+/** Report a one-line explanation when uncertainty reserves browser capacity.+ * @param {(decision:{file:string,reason:string})=>void|undefined} onFallback+ * @param {string} file+ * @param {string} reason+ * @returns {true}+ */+function browserFallback(onFallback, file, reason) {+ onFallback?.({+ file: String(file).replace(/[\r\n\t]+/gu, ' '),+ reason: String(reason).replace(/[\r\n\t]+/gu, ' '),+ });+ return true;+}+/** Parse the frozen check and classify its explicit test files, failing closed on unknown shell. */-export async function checkNeedsBrowser(root, command, { commit, env = process.env } = {}) {- if (env.NODE_OPTIONS) return true;+export async function checkNeedsBrowser(root, command, { commit, env = process.env, onFallback } = {}) {+ if (env.NODE_OPTIONS) return browserFallback(onFallback, '<frozen check>', 'NODE_OPTIONS may load an unclassified module');let words = literalShellWords(command);if (!words) {const inner = capturedRunner(command);- if (!inner) return true;+ if (!inner) return browserFallback(onFallback, '<frozen check>', 'shell syntax is outside the supported literal capture form');const grep = resolveExecutable('grep', env.PATH);- if (!grep || !['/usr/bin/grep', '/bin/grep'].includes(await realpath(grep).catch(() => ''))) return true;+ if (!grep || !['/usr/bin/grep', '/bin/grep'].includes(await realpath(grep).catch(() => ''))) return browserFallback(onFallback, '<frozen check>', 'capture wrapper does not resolve the system grep');words = literalShellWords(inner);}- if (!words || words.length < 3) return true;+ if (!words || words.length < 3) return browserFallback(onFallback, '<frozen check>', 'command is not an explicit Node test selection');const node = resolveExecutable(words[0], env.PATH);- if (!node || await realpath(node).catch(() => '') !== await realpath(process.execPath).catch(() => '')) return true;+ if (!node || await realpath(node).catch(() => '') !== await realpath(process.execPath).catch(() => '')) return browserFallback(onFallback, '<frozen check>', 'Node executable does not resolve to this runtime');const runner = resolve(root, words[1]);- if (runner !== resolve(root, TEST_RUNNER)) return true;+ if (runner !== resolve(root, TEST_RUNNER)) return browserFallback(onFallback, '<frozen check>', 'runner is not bin/run-tests.js in this repository');const files = explicitRunnerFiles(words.slice(2));- if (!files) return true;+ if (!files) return browserFallback(onFallback, '<frozen check>', 'runner options or test selection are not statically understood');if (files.some(file => file === JOURNEYS_TEST || file === 'test/cockpit' || file.startsWith('test/cockpit/'))) return true;if (commit) {const committed = committedFiles(root, commit);const runnerEntry = committed?.get(TEST_RUNNER);- if (!runnerEntry || runnerEntry.type !== 'blob' || !['100644', '100755'].includes(runnerEntry.mode)- || runnerEntry.object !== TRUSTED_TEST_RUNNER_BLOB) return true;- return testsNeedBrowserInTree(root, files, committed);+ if (!runnerEntry || runnerEntry.type !== 'blob' || !['100644', '100755'].includes(runnerEntry.mode)) return browserFallback(onFallback, TEST_RUNNER, 'committed runner is missing or is not a regular file');+ return testsNeedBrowserInTree(root, files, committed, onFallback);}- if (await realpath(runner).catch(() => '') !== await realpath(resolve(root, TEST_RUNNER)).catch(() => '')) return true;- const runnerSource = await readFile(runner, 'utf8').catch(() => '');- if (createHash('sha256').update(runnerSource).digest('hex') !== TRUSTED_TEST_RUNNER_SHA256) return true;- return testsNeedBrowser(root, files);+ if (await realpath(runner).catch(() => '') !== await realpath(resolve(root, TEST_RUNNER)).catch(() => '')) return browserFallback(onFallback, TEST_RUNNER, 'runner resolves outside the expected repository path');+ const runnerInfo = await lstat(runner).catch(() => null);+ let runnerInside = false;+ try { runnerInside = await staysInside(root, runner); } catch { /* Missing or unresolved runner is uncertain. */ }+ if (!runnerInfo?.isFile() || runnerInfo.isSymbolicLink() || !runnerInside) return browserFallback(onFallback, TEST_RUNNER, 'runner is not a regular in-repository file');+ return testsNeedBrowser(root, files, { onFallback });}/** Convert an in-root absolute or relative selection to a normalized repository-relative path. */@@ -236,10 +248,10 @@ async function localTarget(root, importer, request) {}/** Classify test imports from either the current checkout or one immutable committed tree. */-async function testsNeedBrowserInTree(root, files, committed = null) {- if (!Array.isArray(files) || files.length === 0) return true;+async function testsNeedBrowserInTree(root, files, committed = null, onFallback) {+ if (!Array.isArray(files) || files.length === 0) return browserFallback(onFallback, '<test selection>', 'selection is empty or unavailable');const normalized = files.map((file) => repositoryPath(root, file));- if (normalized.some((file) => file === null)) return true;+ if (normalized.some((file) => file === null)) return browserFallback(onFallback, '<test selection>', 'a selected path is outside the repository');if (normalized.some((file) => file === JOURNEYS_TEST || file === 'test/cockpit' || file.startsWith('test/cockpit/'))) return true;let frontier = [...new Set(normalized)];@@ -253,38 +265,39 @@ async function testsNeedBrowserInTree(root, files, committed = null) {seen.add(path);if (path === CHROME_FIXTURE) return true;if (path.endsWith('.json')) continue;- if (/\.(?:cjs|cts)$/u.test(path)) return true;+ if (/\.(?:cjs|cts)$/u.test(path)) return browserFallback(onFallback, path, 'CommonJS loader behavior is not statically classified');paths.push(path);if (committed) {const source = committedSource(root, committed, path);- if (source === null) return true;+ if (source === null) return browserFallback(onFallback, path, 'committed source is missing or not a regular file');sources.push(source);} else {const absolute = resolve(root, ...path.split('/'));- if (!(await staysInside(root, absolute))) return true;+ if (!(await staysInside(root, absolute))) return browserFallback(onFallback, path, 'live source resolves outside the repository');sources.push(await readFile(absolute, 'utf8'));}}if (!sources.length) break;if (paths.some((path, index) => (path.startsWith('test/') || SAFE_CHILD_PROCESS_MODULES.has(path))&& namesChromeLauncher(sources[index]))) return true;- if (commonJsIn(sources).some(Boolean)) return true;+ const commonJsIndex = commonJsIn(sources).findIndex(Boolean);+ if (commonJsIndex >= 0) return browserFallback(onFallback, paths[commonJsIndex], 'CommonJS loading is not statically classified');const imports = importsIn(sources);const next = new Set();for (let index = 0; index < imports.length; index += 1) {for (const request of imports[index]) {if (request === 'node:child_process') {const policy = SAFE_CHILD_PROCESS_MODULES.get(paths[index]);- if (!policy || createHash('sha256').update(sources[index]).digest('hex') !== policy.hash) return true;+ if (!policy) return browserFallback(onFallback, paths[index], 'child_process use has no reviewed path-and-reason exception');continue;}- if (request === 'node:module') return true;+ if (request === 'node:module') return browserFallback(onFallback, paths[index], 'node:module can create a dynamic loader');if (request.startsWith('node:')) continue;- if (!request.startsWith('.')) return true;+ if (!request.startsWith('.')) return browserFallback(onFallback, paths[index], `non-local import ${request} is not classified`);const target = committed? committedTarget(committed, paths[index], request): await localTarget(root, paths[index], request);- if (!target) return true;+ if (!target) return browserFallback(onFallback, paths[index], `import ${request} is missing or ambiguous`);if (target === CHROME_FIXTURE) return true;if (!target.endsWith('.json') && !seen.has(target)) next.add(target);}@@ -293,11 +306,11 @@ async function testsNeedBrowserInTree(root, files, committed = null) {}return false;} catch {- return true;+ return browserFallback(onFallback, '<test selection>', 'source graph could not be inspected safely');}}/** Return true for full or uncertain selections, cockpit tests, or imports reaching the Chrome fixture. */-export async function testsNeedBrowser(root, files) {- return testsNeedBrowserInTree(root, files);+export async function testsNeedBrowser(root, files, { onFallback } = {}) {+ return testsNeedBrowserInTree(root, files, null, onFallback);}diff --git a/src/cli.js b/src/cli.jsindex ccebfa71..f62de5f4 100644--- a/src/cli.js+++ b/src/cli.js@@ -2111,7 +2111,7 @@ async function submitHere(ctx, id) {withBoard(ctx, (board) => refuseUnverifiedStack(root, board, held, commit, trunk));// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).// A full-gate stamp never substitutes for either proof; only an actual full fallback may stamp.- const gate = await runSubmitGate(root, ctx.config, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: gateWaitReporter(ctx.io) });+ const gate = await runSubmitGate(root, ctx.config, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: gateWaitReporter(ctx.io), onBrowserFallback: browserAdmissionReporter(ctx.io) });if (!gate.isGreen) {const message = `the submission proof is red at ${commit.slice(0, 12)}; fix it, commit, submit again. ${submitGateReport(gate)}`;// No submission can follow this verdict. Read-only main comparisons must not retain the seat's write lease.@@ -2202,7 +2202,7 @@ async function verifyHere(ctx, id, { second, values }) {if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');const trunk = requireTrunkMerge(root, commit);refuseUnverifiedStack(root, board, item, commit, trunk);- const browser = await checkNeedsBrowser(root, frozenCheck(item), { commit });+ const browser = await checkNeedsBrowser(root, frozenCheck(item), { commit, onFallback: browserAdmissionReporter(ctx.io) });check = await withGateSlot(root, (lease) => checkAtCommit(root, item, { waitMs: lease.waitMs, gateLease: lease }), { browser, agent: me.id, item: String(id), kind: 'review', itemCheck: true, onWait: gateWaitReporter(ctx.io) });verificationProfile = check.profile ?? null;const evidence = check.checked@@ -2606,7 +2606,7 @@ function workCommands(io, args) {throw new Refused('CHECK_CONFIRM', `the check set by ${authorName} was not run: ${check}; run pullboard check ${item.item_id} --yes after reading the command, or answer yes at the prompt`);}}- const browser = await checkNeedsBrowser(ctx.info.root, check);+ const browser = await checkNeedsBrowser(ctx.info.root, check, { onFallback: browserAdmissionReporter(io) });const run = await withGateSlot(ctx.info.root, (lease) => runProfiledShell(ctx.info.root, check, { waitMs: lease.waitMs, artifactPrefix: `pullboard-check-${item.item_id}`, persistLog: true, gateLease: lease }), { browser, agent: caller, item: String(item.item_id), kind: 'check', itemCheck: true, onWait: gateWaitReporter(io) });io.result?.({ id: item.item_id, green: run.isGreen, seconds: run.seconds, check, by, report: run.isGreen ? '' : digestOf(run.output) });const timings = timingDigest(run.profile);@@ -2797,6 +2797,14 @@ function resourceAgent(ctx) {return ctx.info.isMain ? COORDINATOR : withBoard(ctx, board => store.agentAt(board, ctx.info.root)?.agent_id);}+/** Print the file and reason when conservative uncertainty reserves browser capacity.+ * @param {any} io+ * @returns {(decision:{file:string,reason:string})=>void}+ */+function browserAdmissionReporter(io) {+ return ({ file, reason }) => io.say(`browser admission fallback: ${file}: ${reason}`);+}+/** Build a de-duplicated queue message for a gate waiting on machine capacity. */function gateWaitReporter(io) {let last = '';diff --git a/src/gate.js b/src/gate.jsindex 1928892a..795650ef 100644--- a/src/gate.js+++ b/src/gate.js@@ -312,15 +312,15 @@ function commandWord(value) {** @param {string} root* @param {any} config- * @param {{base:string|null, trunk?:string, changed?:string[], check:string, agent?:string, item?:string|number, kind?:string, onWait?:(state:object)=>void}} options+ * @param {{base:string|null, trunk?:string, changed?:string[], check:string, agent?:string, item?:string|number, kind?:string, onWait?:(state:object)=>void, onBrowserFallback?:(decision:{file:string,reason:string})=>void}} options* @returns {Promise<any>}*/-export async function runSubmitGate(root, config, { base, trunk, changed, check, agent, item = '', kind = 'submit', onWait }) {+export async function runSubmitGate(root, config, { base, trunk, changed, check, agent, item = '', kind = 'submit', onWait, onBrowserFallback }) {if (!config.gate.trim()) throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json, e.g. "npm test"');const selection = config.affectedTests? selectAffectedTests(root, { base, trunk, changed }): { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };- const browser = (check ? await checkNeedsBrowser(root, check) : false) || selection.full || await testsNeedBrowser(root, selection.files);+ const browser = (check ? await checkNeedsBrowser(root, check, { onFallback: onBrowserFallback }) : false) || selection.full || await testsNeedBrowser(root, selection.files, { onFallback: onBrowserFallback });return await withGateSlot(root, (lease) => {const startedAt = Date.now();const log = gitPath(root, 'pullboard-submit.log');diff --git a/test/test-resources.test.js b/test/test-resources.test.jsindex ddb3d5ef..384fb560 100644--- a/test/test-resources.test.js+++ b/test/test-resources.test.js@@ -1,7 +1,7 @@/** Browser admission follows current test dependencies without executing them [C7]. */import assert from 'node:assert/strict';import { spawnSync } from 'node:child_process';-import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { copyFileSync, cpSync, existsSync, mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { delimiter, dirname, join, resolve } from 'node:path';import { test } from 'node:test';@@ -104,6 +104,20 @@ test('frozen checks classify only explicit source-backed test commands [C7]', asassert.equal(await checkNeedsBrowser(root, command, { env: classifyEnv }), false);assert.equal(await checkNeedsBrowser(root, command, { env: classifyEnv }), false,'the supported captured runner form remains statically classifiable');++ const runnerPath = join(root, 'bin/run-tests.js');+ rmSync(runnerPath);+ symlinkSync('/bin/echo', runnerPath);+ const symlinkFallbacks = [];+ assert.equal(await checkNeedsBrowser(root, command, { env: classifyEnv, onFallback: decision => symlinkFallbacks.push(decision) }), true,+ 'a symlinked runner outside the repository is browser-required');+ assert.equal(symlinkFallbacks[0].file, 'bin/run-tests.js');+ assert.match(symlinkFallbacks[0].reason, /regular in-repository file/u);+ rmSync(runnerPath);+ mkdirSync(runnerPath);+ assert.equal(await checkNeedsBrowser(root, command, { env: classifyEnv }), true, 'a directory runner fails closed');+ rmSync(runnerPath, { recursive: true, force: true });+ copyFileSync(TEST_RUNNER, runnerPath);for (const opaque of ['node bin/run-tests.js test/plain.test.js; touch side-effect','node bin/run-tests.js test/*.test.js',@@ -116,17 +130,26 @@ test('frozen checks classify only explicit source-backed test commands [C7]', ascopyFileSync(resolve(import.meta.dirname, './fixture-child.js'), join(root, 'test/fixture-child.js'));writeFileSync(join(root, 'test/known-fixture.test.js'), "import './fixture-child.js';\n");assert.equal(await testsNeedBrowser(root, ['test/known-fixture.test.js']), false,- 'the hash-pinned shared fixture child helper remains CPU-only');+ 'the path-reviewed shared fixture child helper remains CPU-only');+ writeFileSync(join(root, 'test/fixture-child.js'), "import { spawn } from 'node:child_process'; spawn('git', ['status']);\n");+ assert.equal(await testsNeedBrowser(root, ['test/known-fixture.test.js']), false,+ 'the reviewed path exception does not depend on a content hash');writeFileSync(join(root, 'test/fixture-child.js'), "import { spawn } from 'node:child_process'; spawn('google-chrome', []);\n");assert.equal(await testsNeedBrowser(root, ['test/known-fixture.test.js']), true,- 'changing an allowlisted helper invalidates its source hash and detects the Chrome launcher');+ 'a literal Chrome launcher still overrides the path exception');writeFileSync(join(root, 'test/launcher.test.js'), "import { spawn } from 'node:child_process'; spawn('google-chrome', []);\n");- assert.equal(await testsNeedBrowser(root, ['test/launcher.test.js']), true,+ const chromeFallbacks = [];+ assert.equal(await testsNeedBrowser(root, ['test/launcher.test.js'], { onFallback: decision => chromeFallbacks.push(decision) }), true,'a test source that names a Chrome launcher remains browser-required');+ assert.deepEqual(chromeFallbacks, [], 'known Chrome launchers reserve browser capacity without uncertainty diagnostics');writeFileSync(join(root, 'test/computed-launch.test.js'), "import { spawn } from 'node:child_process'; spawn(process.env.BROWSER, []);\n");- assert.equal(await testsNeedBrowser(root, ['test/computed-launch.test.js']), true,+ const fallbackReasons = [];+ assert.equal(await testsNeedBrowser(root, ['test/computed-launch.test.js'], { onFallback: decision => fallbackReasons.push(decision) }), true,'an unknown computed child-process target remains browser-required');+ assert.equal(fallbackReasons.length, 1);+ assert.equal(fallbackReasons[0].file, 'test/computed-launch.test.js');+ assert.match(fallbackReasons[0].reason, /child_process/u);const commit = commitSourceFixture(root);assert.equal(await checkNeedsBrowser(root, command, { commit, env: classifyEnv }), false,