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): preload native test parents before worker launch [C7,H16]
Corey Olsone8de90ac52c7
diff --git a/src/execution-environment.js b/src/execution-environment.jsindex 6dffe8e4..09fbbb66 100644--- a/src/execution-environment.js+++ b/src/execution-environment.js@@ -14,7 +14,7 @@ import {join,relative,} from 'node:path';-import { pathToFileURL } from 'node:url';+import { fileURLToPath, pathToFileURL } from 'node:url';/** Exact executor identity for gate receipts and landing policy [E27,E28]. */@@ -52,10 +52,10 @@ export function carriesLandingEnvironment(batch) {/** The exact trusted preload reports from inside each Node process, independently of its launcher. */export function runtimeCaptureSource(directory) {- return `import { lstatSync, readFileSync, readdirSync, realpathSync, writeFileSync } from 'node:fs';-import { basename, dirname, join, relative, resolve } from 'node:path';-import { channel } from 'node:diagnostics_channel';-import { randomUUID } from 'node:crypto';+ return `const { lstatSync, readFileSync, readdirSync, realpathSync, writeFileSync } = require('node:fs');+const { basename, dirname, join, relative, resolve } = require('node:path');+const { channel } = require('node:diagnostics_channel');+const { randomUUID } = require('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.@@ -96,7 +96,7 @@ process.once('exit',()=>{// 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 token=${JSON.stringify('--require=' + JSON.stringify(join(directory, 'test-runtime-preload.cjs')))};const options=process.env.NODE_OPTIONS;if (options===token) {if (process.env.PULLBOARD_RUNTIME_EMPTY_OPTIONS==='1') process.env.NODE_OPTIONS='';@@ -111,12 +111,18 @@ if (!process.execArgv.includes('--test')) {/** Reuse only the exact native recorder for an admitted worker after its parent restores caller options. */export function testRuntimeImport(directory = process.env.PULLBOARD_RUNTIME_CAPTURE_DIR) {if (!directory) return null;- const file = join(directory, 'test-runtime-preload.mjs');+ const file = join(directory, 'test-runtime-preload.cjs');try {return readFileSync(file, 'utf8') === runtimeCaptureSource(directory) ? pathToFileURL(file).href : null;} catch { return null; /* An absent or foreign recorder never becomes an import. */ }}+/** Use the validated recorder before Node's native test parent starts workers, without adding execArgv. */+export function testRuntimeOption(directory = process.env.PULLBOARD_RUNTIME_CAPTURE_DIR) {+ const imported = testRuntimeImport(directory);+ return imported ? '--require=' + JSON.stringify(fileURLToPath(imported)) : null;+}+/** Bind a closed admitted worker's self-report to the file selected by its parent, never by test stdout. */export function bindTestRuntime(pid, file) {const directory = process.env.PULLBOARD_RUNTIME_CAPTURE_DIR;@@ -166,11 +172,11 @@ export function testRuntimeEnvironment(rows) {/** Capture actual Node children in a private run directory without changing test output or the machine pool. */export function captureTestRuntimes(env) {const directory = mkdtempSync(join(tmpdir(), 'pullboard-test-runtimes-'));- const preload = join(directory, 'test-runtime-preload.mjs');+ const preload = join(directory, 'test-runtime-preload.cjs');writeFileSync(preload, runtimeCaptureSource(directory), { flag: 'wx', mode: 0o600 });let finished = false;return {- env: { ...env, NODE_OPTIONS: [env.NODE_OPTIONS, '--import=' + pathToFileURL(preload).href].filter(Boolean).join(' '),+ env: { ...env, NODE_OPTIONS: [env.NODE_OPTIONS, '--require=' + JSON.stringify(preload)].filter(Boolean).join(' '),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() {diff --git a/src/test-isolation.js b/src/test-isolation.jsindex 25d9ffef..745d1632 100644--- a/src/test-isolation.js+++ b/src/test-isolation.js@@ -50,11 +50,12 @@ function runnerPreload(declared) {/** Recognize only the exact child-runtime recorder, without trusting a caller's preload declaration. */function runtimePreload(token) {- const url = /^--import=(file:\/\/\S+\/test-runtime-preload\.mjs)$/u.exec(token ?? '')?.[1];- if (!url) return false;+ const declared = /^--require=(.+)$/u.exec(token ?? '')?.[1];+ if (!declared) return false;try {- const file = fileURLToPath(url);- return readFileSync(file, 'utf8') === runtimeCaptureSource(dirname(file));+ const file = declared.startsWith('"') ? JSON.parse(declared) : declared;+ return typeof file === 'string' && file.endsWith('/test-runtime-preload.cjs')+ && readFileSync(file, 'utf8') === runtimeCaptureSource(dirname(file));} catch { return false; /* A missing or different recorder remains foreign and retains conservative admission. */ }}diff --git a/src/timed-shell-worker.js b/src/timed-shell-worker.jsindex f479211a..ac1aed3d 100644--- a/src/timed-shell-worker.js+++ b/src/timed-shell-worker.js@@ -13,7 +13,7 @@ import {join,} from 'node:path';import { createDescendantTracker } from './runner-custody.js';-import { testRuntimeImport } from './execution-environment.js';+import { testRuntimeOption } from './execution-environment.js';const request = JSON.parse(readFileSync(0, 'utf8'));if (!Number.isSafeInteger(request.timeoutMs) || request.timeoutMs < 1 || request.timeoutMs > 2_147_483_647) throw new Error('invalid shell timeout');@@ -32,8 +32,8 @@ function reportState(force = false) {catch { process.stderr.write('timed gate: cleanup state could not be written; retain the worker and inspect its private output directory\n'); }}tracker = createDescendantTracker(directory, { tick: () => reportState(), warn: () => reportState(true) });-const recorder = testRuntimeImport();-const env = { ...process.env, NODE_OPTIONS: [process.env.NODE_OPTIONS, tracker.nodeOptions, recorder ? '--import=' + recorder : null].filter(Boolean).join(' '), PULLBOARD_RUNNER_PRELOAD: tracker.nodeOptions };+const recorder = testRuntimeOption();+const env = { ...process.env, NODE_OPTIONS: [process.env.NODE_OPTIONS, tracker.nodeOptions, recorder].filter(Boolean).join(' '), PULLBOARD_RUNNER_PRELOAD: tracker.nodeOptions };const child = spawn('/bin/sh', ['-c', request.command], { env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });tracker.registerRoot(child.pid);tracker.observe();