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(proof): restore caller options after child runtime capture [C7,H16]

Corey Olson819af0b026df
diff --git a/src/execution-environment.js b/src/execution-environment.js
index 37ba869b..700c8061 100644
--- a/src/execution-environment.js
+++ b/src/execution-environment.js
@@ -54,9 +54,26 @@ import { randomUUID } from 'node:crypto';
const directory=${JSON.stringify(directory)};
const file=directory+'/runtime-'+process.pid+'-'+randomUUID()+'.json';
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='--import='+import.meta.url;
+ const options=process.env.NODE_OPTIONS;
+ if (options===token) delete process.env.NODE_OPTIONS;
+ else if (options?.endsWith(' '+token)) process.env.NODE_OPTIONS=options.slice(0,-token.length-1);
+}
`;
}
+/** 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');
+ try {
+ return readFileSync(file, 'utf8') === runtimeCaptureSource(directory) ? pathToFileURL(file).href : null;
+ } catch { return null; /* An absent or foreign recorder never becomes an import. */ }
+}
+
/** 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;
diff --git a/src/gate.js b/src/gate.js
index ffe986bf..7e7dfe20 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -250,7 +250,7 @@ export function runProfiledShell(root, command, { waitMs = 0, artifactDirectory,
gateLease?.tracker?.mark('runAt');
const run = gateLease?.runner ? { ...runOnRunner(root, command, { runner: gateLease.runner, source: gateLease.source,
browser: gateLease.browser, pipefail, stages, waivers: landing ? waivers : [], metadata: { ...(gateLease.runMetadata ?? {}), landing, ...(timeoutMs ? { timeoutMs } : {}) } }) }
- : runShell(root, command, { pipefail, env: inherited, stages, timeoutMs, captureRuntimes: Boolean(gateLease?.proof) });
+ : runShell(root, command, { pipefail, env: inherited, stages, timeoutMs, captureRuntimes: Boolean(gateLease) });
gateLease?.tracker?.mark('ranAt');
if (gateLease) {
gateLease.environment = run.environment ?? null;
diff --git a/src/test-file-dispatch.js b/src/test-file-dispatch.js
index e4e60d25..50799677 100644
--- a/src/test-file-dispatch.js
+++ b/src/test-file-dispatch.js
@@ -19,7 +19,7 @@ import { testsNeedBrowser } from './browser-admission.js';
import { takeResource } from './resources.js';
import { reserveTestFileToken } from './test-file-pool.js';
import { TEST_FILE_POOL_ENV } from './test-file-pool.js';
-import { bindTestRuntime } from './execution-environment.js';
+import { bindTestRuntime, testRuntimeImport } from './execution-environment.js';
/** Counter trailers are identified by their structured root-plan boundary, never by parsing test stdout/TAP. */
function trailer(event, afterPlan) {
@@ -46,7 +46,8 @@ function notify(stream, event) {
/** Set only this actual worker's legitimately reserved admission before its ordinary runner preload. */
function admissionImport(value, browser, runner) {
- const source = `process.env[${JSON.stringify(TEST_FILE_POOL_ENV)}]=${JSON.stringify(value)};`
+ const recorder = testRuntimeImport();
+ const source = (recorder ? `await import(${JSON.stringify(recorder)});` : '') + `process.env[${JSON.stringify(TEST_FILE_POOL_ENV)}]=${JSON.stringify(value)};`
+ (browser ? `process.env.PULLBOARD_TEST_BROWSER_OWNER_PID=${JSON.stringify(String(process.pid))};`
+ "if(process.env.PULLBOARD_TEST_BROWSER_BY_LAUNCH==='1')process.env.PULLBOARD_TEST_BROWSER_SLOT='held';"
+ 'delete process.env.PULLBOARD_TEST_BROWSER_BY_LAUNCH;' : '')