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(browser-admission): keep dynamic loaders browser-gated [C7]

Corey Olson7f6dc89e16e6
diff --git a/src/browser-admission.js b/src/browser-admission.js
index 48eaffa5..023a26f7 100644
--- a/src/browser-admission.js
+++ b/src/browser-admission.js
@@ -158,7 +158,11 @@ function committedTarget(files, importer, request) {
return found.length === 1 && ['100644', '100755'].includes(files.get(found[0]).mode) ? found[0] : null;
}
-/** Allow only a side-effect fixture import or the fixed-Git helper; generic command helpers keep browser admission. */
+/** Allow only a side-effect fixture import or the fixed-Git helper; generic command helpers keep browser admission.
+ * @param {string} source
+ * @param {string} request
+ * @returns {boolean}
+ */
function safeFixtureChildImport(source, request) {
const escaped = request.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
const sideEffect = new RegExp(`^[ \\t]*import[ \\t]*(['"])${escaped}\\1[ \\t]*;?[ \\t]*$`, 'u');
@@ -179,6 +183,22 @@ 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);
}
+/** Detect dynamic process builtin access, which can load launch-capable modules.
+ * @param {string} source
+ * @returns {boolean}
+ */
+function usesDynamicBuiltinLoader(source) {
+ const loaderName = ['getBuiltin', 'Module'].join('');
+ if (source.includes(loaderName) || /getBuiltin\\u(?:004d|\{4d\})odule/iu.test(source)) return true;
+ if (/\bprocess\s*(?:\?\.)?\s*\[\s*(?!(['"])env\1\s*\])/u.test(source)) return true;
+ const aliases = [...source.matchAll(/\b(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*process\b/gu)].map(match => match[1]);
+ return aliases.some(alias => {
+ const escapedAlias = alias.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
+ const computedAlias = new RegExp(`\\b${escapedAlias}\\s*(?:\\?\\.)?\\[\\s*(?!(['"])env\\1\\s*\\])`, 'u');
+ return computedAlias.test(source);
+ });
+}
+
/** Report a one-line explanation when uncertainty reserves browser capacity.
* @param {(decision:{file:string,reason:string})=>void|undefined} onFallback
* @param {string} file
@@ -297,6 +317,8 @@ async function testsNeedBrowserInTree(root, files, committed = null, onFallback)
if (!sources.length) break;
if (paths.some((path, index) => (path.startsWith('test/') || SAFE_CHILD_PROCESS_MODULES.has(path))
&& namesChromeLauncher(sources[index]))) return true;
+ const dynamicLoaderIndex = sources.findIndex(usesDynamicBuiltinLoader);
+ if (dynamicLoaderIndex >= 0) return browserFallback(onFallback, paths[dynamicLoaderIndex], 'dynamic process builtin loading can load an unclassified module');
const commonJsIndex = commonJsIn(sources).findIndex(Boolean);
if (commonJsIndex >= 0) return browserFallback(onFallback, paths[commonJsIndex], 'CommonJS loading is not statically classified');
const imports = importsIn(sources);
@@ -309,6 +331,12 @@ async function testsNeedBrowserInTree(root, files, committed = null, onFallback)
continue;
}
if (request === 'node:module') return browserFallback(onFallback, paths[index], 'node:module can create a dynamic loader');
+ if (request === 'node:worker_threads' || request === 'node:cluster') {
+ return browserFallback(onFallback, paths[index], `${request} can launch an unclassified module`);
+ }
+ if (request === 'node:vm' && paths[index] !== 'src/module-imports.js') {
+ return browserFallback(onFallback, paths[index], 'node:vm can evaluate an unclassified module');
+ }
if (request.startsWith('node:')) continue;
if (!request.startsWith('.')) return browserFallback(onFallback, paths[index], `non-local import ${request} is not classified`);
const target = committed
diff --git a/src/cli.js b/src/cli.js
index 419f882b..12a75ec7 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), onBrowserFallback: browserAdmissionReporter(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, ctx.io.relayJson) });
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, onFallback: browserAdmissionReporter(ctx.io) });
+ const browser = await checkNeedsBrowser(root, frozenCheck(item), { commit, onFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
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, { onFallback: browserAdmissionReporter(io) });
+ const browser = await checkNeedsBrowser(ctx.info.root, check, { onFallback: browserAdmissionReporter(io, values.json) });
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);
@@ -2799,10 +2799,13 @@ function resourceAgent(ctx) {
/** Print the file and reason when conservative uncertainty reserves browser capacity.
* @param {any} io
+ * @param {boolean} jsonMode
* @returns {(decision:{file:string,reason:string})=>void}
*/
-function browserAdmissionReporter(io) {
- return ({ file, reason }) => io.stderr.write(`browser admission fallback: ${file}: ${reason}\n`);
+function browserAdmissionReporter(io, jsonMode = false) {
+ return ({ file, reason }) => {
+ if (!jsonMode) io.stderr.write(`browser admission fallback: ${file}: ${reason}\n`);
+ };
}
/** Build a de-duplicated queue message for a gate waiting on machine capacity. */
diff --git a/test/test-resources.test.js b/test/test-resources.test.js
index 004cf40a..50cc31a9 100644
--- a/test/test-resources.test.js
+++ b/test/test-resources.test.js
@@ -64,6 +64,31 @@ test('full, cockpit and uncertain test selections reserve browser capacity [C7]'
}
});
+test('module launchers and dynamic builtins keep browser admission conservative [C7]', async t => {
+ const root = sourceFixture(t, {
+ 'test/workers.test.js': "import { Worker } from 'node:worker_threads'; void Worker;",
+ 'test/cluster.test.js': "import cluster from 'node:cluster'; void cluster;",
+ 'test/vm.test.js': "import vm from 'node:vm'; void vm;",
+ 'test/builtin.test.js': "const builtin = process.getBuiltinModule('node:worker_threads'); void builtin;",
+ 'test/computed-builtin.test.js': "const builtin = process['getBuiltinModule']('node:cluster'); void builtin;",
+ 'test/computed-expression.test.js': "const builtin = process['get' + 'BuiltinModule']('node:worker_threads'); void builtin;",
+ 'test/escaped-builtin.test.js': "const builtin = process['getBuiltin\\u004dodule']('node:cluster'); void builtin;",
+ 'test/optional-builtin.test.js': "const builtin = process?.['getBuiltinModule']('node:cluster'); void builtin;",
+ 'test/destructured-builtin.test.js': "const { getBuiltinModule: load } = process; void load;",
+ 'test/computed-process-alias.test.js': "const proc = process; const builtin = proc[property]; void builtin;",
+ });
+ for (const file of ['workers', 'cluster', 'vm', 'builtin', 'computed-builtin', 'computed-expression',
+ 'escaped-builtin', 'optional-builtin', 'destructured-builtin', 'computed-process-alias']) {
+ assert.equal(await testsNeedBrowser(root, [`test/${file}.test.js`]), true, file);
+ }
+
+ mkdirSync(join(root, 'src'), { recursive: true });
+ copyFileSync(resolve(import.meta.dirname, '../src/module-imports.js'), join(root, 'src/module-imports.js'));
+ writeFileSync(join(root, 'test/parser.test.js'), "import '../src/module-imports.js';\n");
+ assert.equal(await testsNeedBrowser(root, ['test/parser.test.js']), false,
+ 'the reviewed V8 compile-only import parser may use node:vm without evaluating the test graph');
+});
+
test('only actual CommonJS loader words trigger browser admission in JavaScript source [C7]', async t => {
const root = sourceFixture(t, {
'test/mentions.test.js': "// require('./chrome-fixture.js') and createRequire are only comments\nconst note = 'require createRequire';\nconst pattern = /require|createRequire/;",