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): drain runtime capture on shell errors [C7,H16]

Corey Olson6e1cbabb17de
diff --git a/src/shell-run.js b/src/shell-run.js
index d8ba5d62..bb835ba3 100644
--- a/src/shell-run.js
+++ b/src/shell-run.js
@@ -41,8 +41,7 @@ import { sandboxBlockedOperation } from './sandbox-denial.js';
*/
export function runShell(root, command, { pipefail = false, env = {}, stages = false, timeoutMs } = {}) {
const started = Date.now();
- const runtimes = captureTestRuntimes({ ...gitChildEnv(root), ...env });
- const options = { cwd: root, env: runtimes.env, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 };
+ const options = { cwd: root, env: { ...gitChildEnv(root), ...env }, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8', maxBuffer: 2 ** 30 };
let prefix = '';
if (pipefail) {
// Probe the same shell as the command, with no load-sensitive deadline or alternate shell.
@@ -52,34 +51,38 @@ export function runShell(root, command, { pipefail = false, env = {}, stages = f
throw new Refused('PIPEFAIL_UNAVAILABLE', 'the repo gate shell cannot enable pipefail; rewrite the gate without a pipe');
}
}
- const split = stages ? gateStages(command) : null;
- const marker = `PULLBOARD_STAGE_${randomUUID().replaceAll('-', '')}`;
- const pipes = split?.some((stage) => stage.pipeline.length > 1) ? mkdtempSync(join(tmpdir(), 'pullboard-pipes-')) : null;
- // Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.
- const script = `${prefix}(\n${split ? stagedScript(split, marker, pipes) : command}\n) 2>&1`;
- const timedDirectory = timeoutMs ? mkdtempSync(join(tmpdir(), 'pullboard-timed-output-')) : null;
- const outputFile = timedDirectory ? join(timedDirectory, 'output.log') : null;
- const timed = timeoutMs ? spawnSync(process.execPath, [fileURLToPath(new URL('./timed-shell-worker.js', import.meta.url))], { ...options, shell: false, stdio: ['pipe', 'pipe', 'pipe'], input: JSON.stringify({ command: script, timeoutMs, outputFile }) }) : null;
- if (timed && (timed.status !== 0 || timed.error)) throw new Refused('LAND_TIMEOUT_CUSTODY', 'the timed gate worker did not prove cleanup; inspect its owned processes before landing again');
- const result = timed ? { ...JSON.parse(timed.stdout || '{}'), stdout: '', stderr: timed.stderr } : spawnSync(script, options);
- if (timed && result.error) throw new Refused('LAND_GATE_OUTPUT', `the timed gate stopped and drained after its output failed (${result.error}); inspect free disk space and ${timedDirectory} before landing again`);
- if (timed) result.stdout = readFileSync(outputFile, 'utf8') + (result.timedOut ? `\n[LAND_GATE_TIMEOUT] landing gate exceeded ${timeoutMs}ms; its owned processes are stopped\n` : '');
- if (timedDirectory) rmSync(timedDirectory, { recursive: true, force: true });
- if (result.timedOut || result.overflow || result.error) result.status = 1;
- invalidateGitFacts();
- const pipeStatuses = pipes ? readPipes(split, pipes) : null;
- if (pipes) rmSync(pipes, { recursive: true, force: true });
- const testRuntimes = runtimes.finish();
- const environment = executionEnvironment();
- const raw = `${result.stdout ?? ''}${result.stderr ?? ''}`;
- const seconds = Math.round((Date.now() - started) / 1000);
- const blocked = (output) => (result.status === 0 ? null : sandboxBlockedOperation(root, output));
- if (!stages) return { isGreen: result.status === 0, exitCode: result.status, output: raw, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), sandboxBlocked: blocked(raw) };
- if (!split) return { isGreen: result.status === 0, exitCode: result.status, output: raw, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), stages: null, sandboxBlocked: blocked(raw) };
- const staged = readStages(raw, marker, split.length);
- // Each pipeline component's own status rides on its stage, so no failing producer hides behind a later one.
- const withPipes = staged.stages.map((stage, index) => (pipeStatuses?.[index] ? { ...stage, pipeline: pipeStatuses[index] } : stage));
- return { isGreen: result.status === 0, exitCode: result.status, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), ...staged, stages: withPipes, sandboxBlocked: blocked(staged.output) };
+ const runtimes = captureTestRuntimes(options.env);
+ options.env = runtimes.env;
+ try {
+ const split = stages ? gateStages(command) : null;
+ const marker = `PULLBOARD_STAGE_${randomUUID().replaceAll('-', '')}`;
+ const pipes = split?.some((stage) => stage.pipeline.length > 1) ? mkdtempSync(join(tmpdir(), 'pullboard-pipes-')) : null;
+ // Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.
+ const script = `${prefix}(\n${split ? stagedScript(split, marker, pipes) : command}\n) 2>&1`;
+ const timedDirectory = timeoutMs ? mkdtempSync(join(tmpdir(), 'pullboard-timed-output-')) : null;
+ const outputFile = timedDirectory ? join(timedDirectory, 'output.log') : null;
+ const timed = timeoutMs ? spawnSync(process.execPath, [fileURLToPath(new URL('./timed-shell-worker.js', import.meta.url))], { ...options, shell: false, stdio: ['pipe', 'pipe', 'pipe'], input: JSON.stringify({ command: script, timeoutMs, outputFile }) }) : null;
+ if (timed && (timed.status !== 0 || timed.error)) throw new Refused('LAND_TIMEOUT_CUSTODY', 'the timed gate worker did not prove cleanup; inspect its owned processes before landing again');
+ const result = timed ? { ...JSON.parse(timed.stdout || '{}'), stdout: '', stderr: timed.stderr } : spawnSync(script, options);
+ if (timed && result.error) throw new Refused('LAND_GATE_OUTPUT', `the timed gate stopped and drained after its output failed (${result.error}); inspect free disk space and ${timedDirectory} before landing again`);
+ if (timed) result.stdout = readFileSync(outputFile, 'utf8') + (result.timedOut ? `\n[LAND_GATE_TIMEOUT] landing gate exceeded ${timeoutMs}ms; its owned processes are stopped\n` : '');
+ if (timedDirectory) rmSync(timedDirectory, { recursive: true, force: true });
+ if (result.timedOut || result.overflow || result.error) result.status = 1;
+ invalidateGitFacts();
+ const pipeStatuses = pipes ? readPipes(split, pipes) : null;
+ if (pipes) rmSync(pipes, { recursive: true, force: true });
+ const testRuntimes = runtimes.finish();
+ const environment = executionEnvironment();
+ const raw = `${result.stdout ?? ''}${result.stderr ?? ''}`;
+ const seconds = Math.round((Date.now() - started) / 1000);
+ const blocked = (output) => (result.status === 0 ? null : sandboxBlockedOperation(root, output));
+ if (!stages) return { isGreen: result.status === 0, exitCode: result.status, output: raw, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), sandboxBlocked: blocked(raw) };
+ if (!split) return { isGreen: result.status === 0, exitCode: result.status, output: raw, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), stages: null, sandboxBlocked: blocked(raw) };
+ const staged = readStages(raw, marker, split.length);
+ // Each pipeline component's own status rides on its stage, so no failing producer hides behind a later one.
+ const withPipes = staged.stages.map((stage, index) => (pipeStatuses?.[index] ? { ...stage, pipeline: pipeStatuses[index] } : stage));
+ return { isGreen: result.status === 0, exitCode: result.status, seconds, environment, testRuntimes, ...(timed ? { timedOut: result.timedOut } : {}), ...staged, stages: withPipes, sandboxBlocked: blocked(staged.output) };
+ } finally { runtimes.finish(); }
}
/** Conservatively detect a pipe when the configured gate shell cannot enforce every stage's status. */
diff --git a/test/proof-provenance.test.js b/test/proof-provenance.test.js
index ef76e7a0..2f8adce0 100644
--- a/test/proof-provenance.test.js
+++ b/test/proof-provenance.test.js
@@ -8,6 +8,9 @@ import * as store from '../src/board.js';
import { prepareEngineMove, applyEngineMove } from '../src/engine.js';
import { boardReceiptStore, receiptBody, receiptFields } from '../src/gate-run-receipt.js';
import { proofCounts } from '../src/proof-provenance.js';
+import { captureTestRuntimes } from '../src/execution-environment.js';
+import { runFixtureChild } from './fixture-child.js';
+import { fileURLToPath } from 'node:url';
import { bindRefs, resolveMove, strayItemRefs } from '../src/relay-outbox.js';
import { recordNativeProof } from '../src/proof-cli.js';
import { createE2eHelpers } from './e2e-helpers.js';
@@ -77,6 +80,27 @@ test('native receipts carry each child reported runtime instead of borrowing the
if (versions.size > 1) assert.equal(receipt.environment, null, 'a mixed actual run has no invented common Node version');
});
+test('runtime capture binds the admitted file to its closed actual worker [C7,H16]', t => {
+ const helpers = createE2eHelpers();
+ t.after(helpers.cleanup);
+ const box = helpers.project('true');
+ mkdirSync(join(box.repo, 'test'), { recursive: true });
+ const file = join(box.repo, 'test/runtime-child.test.js');
+ writeFileSync(file, "require('node:test')('the actual worker executes [G1]',()=>{});\n");
+ box.git(box.repo, 'add', 'test/runtime-child.test.js');
+ box.git(box.repo, 'commit', '-q', '-m', 'test: record the actual admitted test file');
+ const capture = captureTestRuntimes(box.env);
+ t.after(() => capture.finish());
+ const result = runFixtureChild(process.execPath, [fileURLToPath(new URL('../bin/run-tests.js', import.meta.url)), file],
+ { cwd: box.repo, env: capture.env, encoding: 'utf8' });
+ assert.equal(result.status, 0, result.failure || result.stderr || result.stdout);
+ const children = capture.finish();
+ assert.ok(children && children.length === 1, 'the dispatcher identifies exactly one test child rather than its launcher');
+ assert.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);
+});
+
test('proof counters retain explicit totals and do not invent success from missing output [C7,H16]', () => {
const unknown = { passed: null, failed: null, skipped: null };
assert.deepEqual(proofCounts('no test reporter\n'), unknown);