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(proof): bind external workers and unknown descendants [C7,H16]
Corey Olson201092d56ddc
diff --git a/src/execution-environment.js b/src/execution-environment.jsindex 40448add..d182e503 100644--- a/src/execution-environment.js+++ b/src/execution-environment.js@@ -50,17 +50,31 @@ export function carriesLandingEnvironment(batch) {/** The exact trusted preload reports from inside each Node process, independently of its launcher. */export function runtimeCaptureSource(directory) {return `import { writeFileSync } from 'node:fs';+import { channel } from 'node:diagnostics_channel';import { randomUUID } from 'node:crypto';const directory=${JSON.stringify(directory)};const file=directory+'/runtime-'+process.pid+'-'+randomUUID()+'.json';+// Observe child identities without replacing spawn or changing any caller arguments/environment.+channel('child_process').subscribe(({process:child})=>{+ if (!child || typeof child.once!=='function') return;+ const record=()=>{+ if (!Number.isSafeInteger(child.pid) || child.pid<1) return;+ try { writeFileSync(directory+'/child-'+process.pid+'-'+child.pid+'.json',JSON.stringify({parent:process.pid,pid:child.pid}),{flag:'wx',mode:0o400}); } catch {}+ };+ if (Number.isSafeInteger(child.pid)) record(); else child.once('spawn',record);+});writeFileSync(file,JSON.stringify({pid:process.pid,environment:{platform:process.platform,arch:process.arch,node:process.version.slice(1)},file:null}),{flag:'wx',mode:0o400});// Node's --test parent only starts workers; retain capture until the actual test process boots.// User code sees its original NODE_OPTIONS, not this recorder's injected option.if (!process.execArgv.includes('--test')) {const token=${JSON.stringify('--import=' + pathToFileURL(join(directory, 'test-runtime-preload.mjs')).href)};const options=process.env.NODE_OPTIONS;- if (options===token) delete process.env.NODE_OPTIONS;+ if (options===token) {+ if (process.env.PULLBOARD_RUNTIME_EMPTY_OPTIONS==='1') process.env.NODE_OPTIONS='';+ else delete process.env.NODE_OPTIONS;+ }else if (options?.endsWith(' '+token)) process.env.NODE_OPTIONS=options.slice(0,-token.length-1);+ delete process.env.PULLBOARD_RUNTIME_EMPTY_OPTIONS;}`;}@@ -86,7 +100,9 @@ export function bindTestRuntime(pid, file) {if (!stat.isFile() || stat.mode & 0o222) return false;const own = JSON.parse(readFileSync(path, 'utf8'));if (own.pid !== pid || own.file !== null || environmentProblem(own.environment)) return false;- const bound = { pid, environment: own.environment, file: relative(process.cwd(), file).replaceAll('\\', '/') };+ const selected = relative(process.cwd(), file).replaceAll('\\', '/');+ // Accepted callers may select a real test outside the checkout; never invent an in-repo path for it.+ const bound = { pid, environment: own.environment, file: selected.split('/').includes('..') ? null : selected };if (!testRuntimeRows([bound])) return false;writeFileSync(join(directory, 'binding-' + pid + '.json'), JSON.stringify({ pid, file: bound.file }), { flag: 'wx', mode: 0o600 });return true;@@ -128,15 +144,18 @@ export function captureTestRuntimes(env) {let finished = false;return {env: { ...env, NODE_OPTIONS: [env.NODE_OPTIONS, '--import=' + pathToFileURL(preload).href].filter(Boolean).join(' '),- PULLBOARD_RUNTIME_CAPTURE_DIR: directory },+ PULLBOARD_RUNTIME_CAPTURE_DIR: directory, PULLBOARD_RUNTIME_EMPTY_OPTIONS: env.NODE_OPTIONS === '' ? '1' : '0' },/** Read bounded child reports only after command close, then remove the private capture directory. */finish() {if (finished) return null;finished = true;try {- const names = readdirSync(directory).filter(name => /^runtime-[0-9]+-[a-f0-9-]+\.json$/u.test(name));+ const entries = readdirSync(directory);+ if (entries.length > 200_001) return null;+ const names = entries.filter(name => /^runtime-[0-9]+-[a-f0-9-]+\.json$/u.test(name));if (names.length > 100_000) return null;const rows = [];+ const boundPids = new Set();let bytes = 0;for (const name of names.sort()) {const file = join(directory, name);@@ -152,13 +171,29 @@ export function captureTestRuntimes(env) {const bound = JSON.parse(readFileSync(binding, 'utf8'));if (Object.keys(bound).sort().join(',') !== 'file,pid' || bound.pid !== row.pid) return null;row.file = bound.file;+ boundPids.add(row.pid);} catch (error) { if (error.code !== 'ENOENT') return null; }rows.push(row);}const checked = testRuntimeRows(rows);if (!checked) return null;- const files = checked.filter(row => row.file !== null);- return files.length ? files : checked;+ const files = checked.filter(row => boundPids.has(row.pid));+ if (files.length) return files;+ const reported = new Set(checked.map(row => row.pid));+ const launchers = new Set();+ for (const name of entries.filter(name => /^child-[0-9]+-[0-9]+\.json$/u.test(name))) {+ const path = join(directory, name);+ const stat = lstatSync(path);+ bytes += stat.size;+ if (!stat.isFile() || stat.mode & 0o222 || stat.size > 8192 || bytes > 8 * 1024 * 1024) return null;+ const child = JSON.parse(readFileSync(path, 'utf8'));+ if (Object.keys(child).sort().join(',') !== 'parent,pid' || !Number.isSafeInteger(child.parent) || child.parent < 1+ || !Number.isSafeInteger(child.pid) || child.pid < 1 || name !== 'child-' + child.parent + '-' + child.pid + '.json') return null;+ // An unbound launcher's own runtime cannot stand in for an unobserved custom descendant.+ if (reported.has(child.parent) && !reported.has(child.pid)) return null;+ launchers.add(child.parent);+ }+ return testRuntimeRows(checked.filter(row => !launchers.has(row.pid)));} catch { return null; /* Missing or incomplete self-reports stay unknown, never become the launcher runtime. */ }finally { rmSync(directory, { recursive: true, force: true }); }},diff --git a/test/proof-provenance.test.js b/test/proof-provenance.test.jsindex bb32729b..04bfaad8 100644--- a/test/proof-provenance.test.js+++ b/test/proof-provenance.test.js@@ -47,8 +47,9 @@ test('native receipts carry each child reported runtime instead of borrowing theconst helpers = createE2eHelpers();t.after(helpers.cleanup);const box = helpers.project('true');+ box.env.NODE_OPTIONS = '';const paths = [join(box.dir, 'first-runtime.json'), join(box.dir, 'second-runtime.json')];- const programs = paths.map(path => `require('node:fs').writeFileSync(${JSON.stringify(path)},JSON.stringify({pid:process.pid,node:process.versions.node,platform:process.platform,arch:process.arch,argv:process.argv,execArgv:process.execArgv,nodeOptions:process.env.NODE_OPTIONS??''}));`);+ const programs = paths.map(path => `require('node:fs').writeFileSync(${JSON.stringify(path)},JSON.stringify({pid:process.pid,node:process.versions.node,platform:process.platform,arch:process.arch,argv:process.argv,execArgv:process.execArgv,nodeOptions:process.env.NODE_OPTIONS??'',hasNodeOptions:Object.hasOwn(process.env,'NODE_OPTIONS')}));`);// Separate actual processes must remain distinct even when they happen to run the same Node version.// Approved MIN/current runner images have both versions; a single-runtime install still exercises two real children.const alternate = ['24.21.0', '22.13.1'].map(version => join(dirname(process.execPath), '..', '..', 'v' + version, 'bin', 'node'))@@ -75,7 +76,7 @@ test('native receipts carry each child reported runtime instead of borrowing theconst actualChildren = [];for (const [index, path] of paths.entries()) {const actual = JSON.parse(readFileSync(path, 'utf8'));- for (const field of ['argv', 'execArgv', 'nodeOptions']) {+ for (const field of ['argv', 'execArgv', 'nodeOptions', 'hasNodeOptions']) {assert.deepEqual(actual[field], bare[index][field], 'a receipted native child retains its caller ' + field);}actualChildren.push(actual);@@ -89,6 +90,23 @@ test('native receipts carry each child reported runtime instead of borrowing theif (versions.size > 1) assert.equal(receipt.environment, null, 'a mixed actual run has no invented common Node version');});+test('an unobserved custom nested Node child never borrows its launcher runtime [C7,H16]', t => {+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-nested-runtime-'));+ t.after(() => rmSync(directory, { recursive: true, force: true }));+ const actualPath = join(directory, 'child.json');+ const alternate = ['24.21.0', '22.13.1'].map(version => join(dirname(process.execPath), '..', '..', 'v' + version, 'bin', 'node'))+ .find(path => path !== process.execPath && existsSync(path)) ?? process.execPath;+ const childProgram = `require('node:fs').writeFileSync(${JSON.stringify(actualPath)},JSON.stringify({pid:process.pid,node:process.versions.node}));`;+ const launcher = `require('node:child_process').execFileSync(${JSON.stringify(alternate)},['-e',${JSON.stringify(childProgram)}]);`;+ const capture = captureTestRuntimes(process.env);+ t.after(() => capture.finish());+ const result = runFixtureChild(process.execPath, ['-e', launcher], { env: capture.env, encoding: 'utf8' });+ assert.equal(result.status, 0, result.failure || result.stderr);+ const actual = JSON.parse(readFileSync(actualPath, 'utf8'));+ assert.equal(actual.node, alternate === process.execPath ? process.versions.node : alternate.split('/v').at(-1).split('/')[0]);+ assert.equal(capture.finish(), null, 'unknown custom execution cannot inherit the launcher runtime');+});+test('runtime capture binds the admitted file to its closed actual worker [C7,H16]', t => {const helpers = createE2eHelpers();t.after(helpers.cleanup);@@ -108,6 +126,17 @@ test('runtime capture binds the admitted file to its closed actual worker [C7,H1assert.equal(children[0].file, 'test/runtime-child.test.js');assert.deepEqual(children[0].environment, { platform: process.platform, arch: process.arch, node: process.versions.node });assert.notEqual(children[0].pid, process.pid);+ const outside = join(box.dir, 'external-runtime.test.js');+ writeFileSync(outside, "require('node:test')('external selected worker [G1]',()=>{});\n");+ const externalCapture = captureTestRuntimes(box.env);+ t.after(() => externalCapture.finish());+ const externalRun = runFixtureChild(process.execPath, [fileURLToPath(new URL('../bin/run-tests.js', import.meta.url)), outside],+ { cwd: box.repo, env: externalCapture.env, encoding: 'utf8' });+ assert.equal(externalRun.status, 0, externalRun.failure || externalRun.stderr || externalRun.stdout);+ const external = externalCapture.finish();+ assert.equal(external.length, 1, 'one closed admitted external worker excludes its launcher');+ assert.equal(external[0].file, null, 'a selected external file has no invented relative checkout path');+ assert.deepEqual(external[0].environment, { platform: process.platform, arch: process.arch, node: process.versions.node });});test('timed shell proof records the actual command child rather than the timeout worker [C7,H16]', t => {