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(browser): inspect executable launch arguments [C7,O5]
Corey Olsone3778b3657e9
diff --git a/src/browser-admission.js b/src/browser-admission.jsindex b278c392..377a8a44 100644--- a/src/browser-admission.js+++ b/src/browser-admission.js@@ -25,6 +25,7 @@ import {} from './git.js';import { literalShellWords } from './literal-shell-words.js';import { foreignNodeOptions } from './test-isolation.js';+import { sourceLaunchesBrowser } from './browser-launch-source.js';const MODULE_SUFFIXES = ['.js', '.mjs', '.cjs', '.cts', '.json'];const CHROME_FIXTURE = 'test/chrome-fixture.js';@@ -52,8 +53,6 @@ const LAUNCH_FREE_CHROME_EXPORTS = new Set(['requireBrowserSlot', 'waitForTarget'createEvaluator', 'createPageStepEvaluator']);/** Imports that let a module start another process or module, which by launch counts only with a Chrome reference. */const PROCESS_STARTERS = new Set(['node:child_process', 'node:worker_threads', 'node:cluster', 'node:module', 'node:vm']);-/** A Chrome executable named in source: the paths and variable a direct launcher uses outside the guarded fixture. */-const CHROME_EXECUTABLE = /PULLBOARD_CHROME|google-chrome|Google Chrome|chromium|puppeteer|playwright/iu;const VALUE_OPTIONS = new Set(['--test-concurrency', '--test-name-pattern', '--test-shard', '--test-skip-pattern', '--test-timeout']);/** What module-imports reports for a dynamic import whose target is not one plain string. */const COMPUTED_IMPORT = '(computed)';@@ -248,7 +247,7 @@ function launchFreeChromeImport(source, request) {/** Detect direct literal Chrome launchers without treating help text or refusal messages as launches. */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);+ return sourceLaunchesBrowser(source);}/** Detect dynamic process builtin access, which can load launch-capable modules.@@ -542,8 +541,9 @@ async function testsNeedBrowserInTree(root, files, committed = null, onFallback,}}if (!sources.length) break;+ const browserCalls = sources.map(namesChromeLauncher);if (paths.some((path, index) => (path.startsWith('test/') || SAFE_CHILD_PROCESS_MODULES.has(path))- && namesChromeLauncher(sources[index]))) return true;+ && browserCalls[index])) return true;// By launch, a process or module starter launches a browser only beside a Chrome executable reference.const starts = sources.map(source => byLaunch && usesDynamicBuiltinLoader(source));const dynamicLoaderIndex = byLaunch ? -1 : sources.findIndex(usesDynamicBuiltinLoader);@@ -587,7 +587,7 @@ async function testsNeedBrowserInTree(root, files, committed = null, onFallback,}if (!target.endsWith('.json') && !seen.has(target)) next.add(target);}- if (starts[index] && CHROME_EXECUTABLE.test(sources[index])) return true;+ if (starts[index] && browserCalls[index]) return true;}frontier = [...next];}diff --git a/src/browser-launch-source.js b/src/browser-launch-source.jsnew file mode 100644index 00000000..15c2c9f1--- /dev/null+++ b/src/browser-launch-source.js@@ -0,0 +1,102 @@+/** Recognize Chrome-bearing process arguments in executable code, not generated fixture programs [C7,O5]. */+import { lex } from './js-lex.js';++const PROCESS_CALLS = new Set(['spawn', 'spawnSync', 'exec', 'execSync', 'execFile', 'execFileSync', 'fork',+ 'runFixtureChild', 'runFixtureChildAsync', 'startFixtureChild', 'Worker', 'SharedWorker',+ 'runInContext', 'runInNewContext', 'runInThisContext', 'compileFunction', 'SourceTextModule', 'Script']);+const CHROME = /PULLBOARD_CHROME|google-chrome|Google Chrome|chromium|puppeteer|playwright/iu;+const WORD = /[$A-Z_a-z][$\w]*/gu;++/** Decode only character escapes for a conservative executable-name comparison; never evaluate source. */+function browserText(text) {+ const plain = text.replace(/\\u\{([\da-f]+)\}|\\u([\da-f]{4})|\\x([\da-f]{2})/giu,+ (whole, point, unicode, byte) => {+ const value = parseInt(point ?? unicode ?? byte, 16);+ return value <= 0x10ffff ? String.fromCodePoint(value) : whole;+ });+ return CHROME.test(plain);+}++/** Find the end of a balanced argument/expression span in lexer's offset-preserving executable code. */+function closing(code, start) {+ const pairs = new Map([['(', ')'], ['[', ']'], ['{', '}']]);+ const stack = [];+ for (let at = start; at < code.length; at += 1) {+ const char = code[at];+ if (pairs.has(char)) stack.push(pairs.get(char));+ else if (')]}'.includes(char)) {+ if (stack.pop() !== char) return null;+ if (!stack.length) return at;+ }+ }+ return null;+}++/** Static aliases remain process calls; unknown imports are still handled by admission's existing graph walk. */+function callNames(source, code) {+ const names = new Set(PROCESS_CALLS);+ // A quoted generated import can add a name here, but cannot create an executable call in `code`.+ for (const match of source.matchAll(/\bimport\s*\{([^}]+)\}\s*from\s*(['"])(?:node:(?:child_process|worker_threads|cluster|vm|module)|[^'"\n]*fixture-child\.js)\2/gu)) {+ for (const binding of match[1].split(',')) {+ const [original, alias] = binding.trim().split(/\s+as\s+/u);+ if (names.has(original) && alias) names.add(alias);+ }+ }+ for (const match of code.matchAll(/\b(?:const|let|var)\s+([$\w]+)\s*=\s*(?:[$\w]+\s*\.\s*)?([$\w]+)\s*[;,]/gu)) {+ if (names.has(match[2])) names.add(match[1]);+ }+ return names;+}++/**+ * Determine whether executable process calls can reach a Chrome argument. Local literal bindings are+ * followed conservatively, without scope-sensitive elimination. A program supplied to a real process+ * (including node -e or a shell) remains an argument, unlike a program merely written to a fixture file.+ * Template interpolations remain executable in lex.code. This is not an arbitrary JavaScript evaluator.+ *+ * @param {string} source+ * @returns {boolean}+ */+export function sourceLaunchesBrowser(source) {+ const { code, strings } = lex(source);+ const names = callNames(source, code);+ const bindings = new Map();+ /** A span's literals or executable environment references can name a browser. */+ const browserIn = (start, end) => CHROME.test(code.slice(start, end))+ || strings.some(string => string.start >= start && string.start < end && browserText(string.text));+ // Record initializer dependencies without assigning authority to a variable name or executing a getter.+ for (const match of code.matchAll(/\b(?:const|let|var)\s+([$\w]+)\s*=/gu)) {+ const start = match.index + match[0].length;+ let end = start;+ while (end < code.length && !';\n'.includes(code[end])) {+ if ('([{'.includes(code[end])) {+ const close = closing(code, end);+ if (close === null) return CHROME.test(source);+ end = close + 1;+ } else end += 1;+ }+ const prior = bindings.get(match[1]) ?? { browser: false, dependencies: new Set() };+ prior.browser ||= browserIn(start, end);+ for (const word of code.slice(start, end).matchAll(WORD)) prior.dependencies.add(word[0]);+ bindings.set(match[1], prior);+ }+ /** Follow only the finite local binding graph, retaining a possible browser through aliases. */+ function namedBrowser(name, seen = new Set()) {+ if (seen.has(name)) return false;+ seen.add(name);+ const binding = bindings.get(name);+ return Boolean(binding && (binding.browser || [...binding.dependencies].some(next => namedBrowser(next, seen))));+ }+ for (const match of code.matchAll(/(?<![\w$])([$A-Z_a-z][$\w]*)\s*(?:\?\.)?\s*\(/gu)) {+ if (!names.has(match[1])) continue;+ const start = match.index + match[0].length - 1;+ const end = closing(code, start);+ if (end === null) return CHROME.test(source);+ if (browserIn(start + 1, end)) return true;+ if ([...code.slice(start + 1, end).matchAll(WORD)].some(word => namedBrowser(word[0]))) return true;+ }+ // Computed/dynamic process access has no complete static call binding: keep Chrome-capable sources bound.+ if (/\b(?:getBuiltinModule|eval|Function)\s*\(|\b(?:process|require)\s*\[|\]\s*(?:\?\.)?\s*\(|\.\s*(?:call|apply|bind)\s*\(|\\u(?:[\da-f]{4}|\{[\da-f]+\})/iu.test(code)+ && CHROME.test(source)) return true;+ return false;+}diff --git a/test/test-resources.test.js b/test/test-resources.test.jsindex 905fadec..2a15e461 100644--- a/test/test-resources.test.js+++ b/test/test-resources.test.js@@ -483,6 +483,7 @@ test('generated Chrome programs stay launch-free while executable launcher argum'test/variable-call.test.js': "import { spawnSync } from 'node:child_process';\nconst executable = '/opt/browser/google-chrome';\nspawnSync(executable, []);",'test/environment-call.test.js': "import { spawnSync } from 'node:child_process';\nspawnSync(process.env.PULLBOARD_CHROME, []);",'test/interpolation-call.test.js': "import { spawnSync } from 'node:child_process';\nexport const output = `${spawnSync('google-chrome', [])}`;",+ 'test/worker-call.test.js': "import { Worker as Thread } from 'node:worker_threads';\nnew Thread(\"require('child_process').execSync('google-chrome')\", { eval: true });",'test/computed-loader.test.js': "const source = process['getBuiltinModule']('child_process');\nsource.spawnSync(process.env.PULLBOARD_CHROME, []);",});for (const name of ['quoted-program', 'template-program', 'comment-program']) {@@ -490,7 +491,7 @@ test('generated Chrome programs stay launch-free while executable launcher argumassert.equal(await testsNeedBrowser(root, [file], { byLaunch: true }), false, `${name}: generated source is not a browser launch in this module`);assert.equal(await testsNeedBrowser(root, [file], { byLaunch: false }), true, `${name}: the default classification remains conservative`);}- for (const name of ['direct-call', 'alias-call', 'shell-call', 'variable-call', 'environment-call', 'interpolation-call', 'computed-loader']) {+ for (const name of ['direct-call', 'alias-call', 'shell-call', 'variable-call', 'environment-call', 'interpolation-call', 'worker-call', 'computed-loader']) {assert.equal(await testsNeedBrowser(root, [`test/${name}.test.js`], { byLaunch: true }), true, `${name}: executable or uncertain Chrome launch remains browser-bound`);}});