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(gate): classify nested child denials [C7,B26]

Corey Olson3aec36c88fed
diff --git a/src/gate.js b/src/gate.js
index cf33501f..d1539775 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -218,6 +218,37 @@ function tapScalar(value) {
return /^[A-Z_]+$/u.test(value) ? value : null;
}
+/** Recognize a bounded child fatal denial carried inside one failed TAP error block. */
+function nestedChildPermission(root, lines, { includeFilePaths = true } = {}) {
+ const detail = lines.join('\n');
+ const childExit = /\b(?:child|app|server|process)\b[^\n]{0,120}\bexited\b[^\n]{0,100}\bcode\s*[(:=]?\s*([1-9]\d*)/iu.exec(detail);
+ if (!childExit || !Number.isSafeInteger(Number(childExit[1]))) return null;
+
+ const errorLine = /^\s*Error: (.+)$/mu.exec(detail);
+ if (!errorLine) return null;
+ const operation = permissionOperation(root, errorLine[1], { includeFilePaths });
+ if (!operation?.syscall) return null;
+
+ const objectStart = detail.indexOf('{', errorLine.index + errorLine[0].length);
+ if (objectStart < 0) return null;
+ const objectEnd = detail.indexOf('}', objectStart + 1);
+ if (objectEnd < 0 || objectEnd - objectStart > 2048) return null;
+ const fields = detail.slice(objectStart, objectEnd + 1);
+ /** Read one exact structured field, removing only TAP's optional delimiter comma. */
+ const fieldValue = (name) => {
+ const match = new RegExp(`(?:^|\\n)\\s*${name}:\\s*(.*?)\\s*(?=\\n|$)`, 'u').exec(fields);
+ return match ? tapScalar(match[1].replace(/,$/u, '')) : null;
+ };
+ const code = fieldValue('code');
+ const syscall = fieldValue('syscall');
+ if (code !== operation.code || syscall !== operation.syscall) return null;
+ if (operation.path) {
+ const childPath = fieldValue('path');
+ if (typeof childPath !== 'string' || diagnosticPath(resolve(root, childPath)) !== operation.path) return null;
+ }
+ return operation;
+}
+
/** Scan complete lines with bounded TAP state so assertion messages cannot impersonate OS codes. */
export function sandboxBlockedScanner(root, { includeFilePaths = true } = {}) {
let failureIndent = null;
@@ -229,6 +260,12 @@ export function sandboxBlockedScanner(root, { includeFilePaths = true } = {}) {
let failureMessage = null;
let failureType = false;
let exitCode = null;
+ let nestedError = null;
+ let nestedErrorBytes = 0;
+ let nestedErrorLines = 0;
+ let nestedErrorOverflow = false;
+ const maxNestedErrorBytes = 16 * 1024;
+ const maxNestedErrorLines = 64;
/** Retain one pending fatal diagnostic and the current failed TAP record. */
return (raw) => {
const line = raw.trim().replace(/^#\s*/u, '');
@@ -244,6 +281,7 @@ export function sandboxBlockedScanner(root, { includeFilePaths = true } = {}) {
comment = null; startup = null;
failureIndent = null; fieldIndent = null; permission = null; code = null;
failureMessage = null; failureType = false; exitCode = null;
+ nestedError = null; nestedErrorBytes = 0; nestedErrorLines = 0; nestedErrorOverflow = false;
}
// Uncaught module-load errors are comments too. Keep their complete Node fatal
// diagnostic pending; it is evidence only if the following file record failed
@@ -271,24 +309,38 @@ export function sandboxBlockedScanner(root, { includeFilePaths = true } = {}) {
comment = null;
fieldIndent = null; permission = null; code = null;
failureMessage = null; failureType = false; exitCode = null;
+ nestedError = null; nestedErrorBytes = 0; nestedErrorLines = 0; nestedErrorOverflow = false;
} else if (line === '---' && failureIndent !== null && indent === failureIndent + 2) {
fieldIndent = indent;
} else if (line === '...' && indent === fieldIndent) {
failureIndent = null; fieldIndent = null; permission = null; code = null;
startup = null; comment = null;
failureMessage = null; failureType = false; exitCode = null;
+ nestedError = null; nestedErrorBytes = 0; nestedErrorLines = 0; nestedErrorOverflow = false;
+ } else if (nestedError !== null && (indent > fieldIndent || line === '')) {
+ const nestedLine = line;
+ nestedErrorBytes += Buffer.byteLength(nestedLine, 'utf8') + 1;
+ nestedErrorLines += 1;
+ if (nestedErrorBytes > maxNestedErrorBytes || nestedErrorLines > maxNestedErrorLines) nestedErrorOverflow = true;
+ else nestedError.push(nestedLine);
} else if (fieldIndent !== null && indent === fieldIndent) {
const field = /^(error|code|failureType|exitCode): (.*)$/u.exec(line);
if (field) {
const value = tapScalar(field[2]);
if (field[1] === 'error') {
failureMessage = value;
+ nestedError = field[2] === '|-' || field[2] === '|' ? [] : null;
+ nestedErrorBytes = 0; nestedErrorLines = 0; nestedErrorOverflow = false;
permission = typeof value === 'string' ? permissionOperation(root, value, { includeFilePaths }) : null;
} else if (field[1] === 'code') {
code = value;
if (code !== 'ERR_TEST_FAILURE') startup = null;
} else if (field[1] === 'failureType') failureType = value === 'testCodeFailure' || field[2] === 'testCodeFailure';
else exitCode = /^[1-9]\d*$/u.test(field[2]) && Number.isSafeInteger(Number(field[2])) ? Number(field[2]) : null;
+ const nestedPermission = field[1] === 'code'
+ && failureType && nestedError && !nestedErrorOverflow
+ ? nestedChildPermission(root, nestedError, { includeFilePaths }) : null;
+ if (nestedPermission) return nestedPermission.operation;
if (permission && permission.code === code) return permission.operation;
if (startup && code === 'ERR_TEST_FAILURE' && failureMessage === 'test failed'
&& failureType && exitCode !== null) return startup.operation;
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index 40d4b1a4..a528703b 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -13,7 +13,7 @@ import { after, test } from 'node:test';
import { selectAffectedTests } from '../src/affected-tests.js';
import { configFromSource } from '../src/config.js';
import { checkAtCommit } from '../src/trusted-policy.js';
-import { refuseSandboxBlocked } from '../src/gate.js';
+import { refuseSandboxBlocked, sandboxBlockedOperation } from '../src/gate.js';
const BIN = resolveBin();
const dirs = [];
@@ -98,6 +98,71 @@ function commitAll(box, message = 'chore: fixture state') {
return box.git('rev-parse', 'HEAD');
}
+/** Build a claimed submit fixture whose changed source selects a nested child-process test. */
+function childFailureSubmitBox(t, testSource) {
+ let box = privateRepo(t);
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test', spec: 'SPEC.md' }));
+ put(box.root, 'SPEC.md', SPEC);
+ put(box.root, 'src/listener-probe.js', 'export const listenerProbe = 1;\n');
+ put(box.root, 'test/listen-denial.js', [
+ "import net from 'node:net';",
+ "net.Server.prototype.listen = function deniedListen() {",
+ " const error = new Error('listen EPERM: operation not permitted 127.0.0.1:0');",
+ " Object.assign(error, { code: 'EPERM', syscall: 'listen', address: '127.0.0.1', port: 0 });",
+ ' throw error;',
+ '};',
+ ].join('\n'));
+ box.env.LISTEN_DENIAL_SHIM = join(box.root, 'test/listen-denial.js');
+ put(box.root, 'test/child-listener.test.js', testSource);
+ commitAll(box);
+ box = builderRepo(box);
+ const added = box.coordinator('add', 'build', 'Child-process gate fixture', '--check', 'true');
+ assert.equal(added.code, 0, added.err);
+ assert.equal(box.run('claim', '1').code, 0);
+ put(box.root, 'src/listener-probe.js', 'export const listenerProbe = 2;\n');
+ commitAll(box, 'feat(core): change listener probe [G1]');
+ return box;
+}
+
+/** Produce a real TAP failure containing a nested child's EPERM without relying on host sandbox support. */
+function childListenerTestSource() {
+ return [
+ "import { test } from 'node:test';",
+ "import assert from 'node:assert/strict';",
+ "import { spawnSync } from 'node:child_process';",
+ "import '../src/listener-probe.js';",
+ "test('the server child binds', () => {",
+ " const child = spawnSync(process.execPath, ['--import', process.env.LISTEN_DENIAL_SHIM, '--input-type=module', '-e', \"import { createServer } from 'node:net'; createServer().listen(0, '127.0.0.1');\"], { encoding: 'utf8' });",
+ " assert.equal(child.status, 0, `App exited before listening (code ${child.status}, signal ${child.signal}):\\n${child.stderr}`);",
+ '});',
+ ].join('\n');
+}
+
+test('a child process listen denial reads as sandbox blocked [C7,B26]', (t) => {
+ const box = childFailureSubmitBox(t, childListenerTestSource());
+ const result = box.run('submit', '1');
+ const output = `${result.out}\n${result.err}`;
+ assert.equal(result.code, 1, output);
+ assert.match(output, /SANDBOX_BLOCKED/u, 'submit names the denied child-process listen');
+ assert.match(output, /listen \(EPERM\)/u);
+ assert.doesNotMatch(output, /GATE_RED/u);
+});
+
+test('an ordinary failure stays gate red [C7,B26]', (t) => {
+ const source = [
+ "import { test } from 'node:test';",
+ "import assert from 'node:assert/strict';",
+ "import '../src/listener-probe.js';",
+ "test('ordinary failure', () => assert.fail('ordinary assertion failure'));",
+ ].join('\n');
+ const box = childFailureSubmitBox(t, source);
+ const result = box.run('submit', '1');
+ const output = `${result.out}\n${result.err}`;
+ assert.equal(result.code, 1, output);
+ assert.match(output, /GATE_RED/u);
+ assert.doesNotMatch(output, /SANDBOX_BLOCKED/u);
+});
+
/** Seed a small import graph with three independently discoverable test files. */
function seedGraph(box) {
put(box.root, 'src/a.js', 'export const value = 1;\n');
@@ -1060,3 +1125,39 @@ test('a sandbox-blocked gate asks the person [I1,C7]', async (t) => {
assert.equal(JSON.parse(box.coordinator('show', '1', '--json').out).item_status, 'submitted', 'checks alone record no verdict');
});
});
+
+test('nested TAP child denials require bounded matching fatal details [C7,B26]', (t) => {
+ const box = privateRepo(t);
+ const outside = join(box.dir, 'outside-denied.txt');
+ /** Build a failed child TAP record with configurable structured error fields. */
+ function tapChildError({ code = 'EACCES', messageCode = 'EACCES', syscall = 'open', path = outside, extra = '' } = {}) {
+ return [
+ 'TAP version 13',
+ 'not ok 1 - child opens a denied file',
+ ' ---',
+ " failureType: 'testCodeFailure'",
+ ' error: |-',
+ ' App exited before opening the file (code 1, signal null):',
+ ` Error: ${messageCode}: permission denied, ${syscall} '${outside}'`,
+ ' {',
+ ` code: '${code}',`,
+ ` syscall: '${syscall}',`,
+ ` path: '${path}'`,
+ ' }',
+ ...extra.split('\n').filter(Boolean).map((line) => ` ${line}`),
+ " code: 'ERR_ASSERTION'",
+ ' ...',
+ ].join('\n');
+ }
+ const blocked = sandboxBlockedOperation(box.root, tapChildError());
+ assert.equal(blocked, `open "${outside}" (EACCES)`);
+
+ assert.equal(sandboxBlockedOperation(box.root, tapChildError({ code: 'EPERM_FAKE', messageCode: 'EACCES' })), null,
+ 'the structured code must exactly match the child error');
+ assert.equal(sandboxBlockedOperation(box.root, tapChildError({ path: join(box.root, 'inside.txt') })), null,
+ 'the structured child path must match the resolved denied target');
+ assert.equal(sandboxBlockedOperation(box.root, tapChildError({ extra: Array(65).fill('bounded continuation').join('\n') })), null,
+ 'an oversized error block is not classified');
+ assert.equal(sandboxBlockedOperation(box.root, tapChildError(), { includeFilePaths: false }), null,
+ 'file-path classification remains disabled when requested');
+});