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): recognize nested Python permission denials [C7,B26]

Corey Olson72a45ad716a3
diff --git a/src/gate.js b/src/gate.js
index efa447db..d490a918 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -225,28 +225,39 @@ function nestedChildPermission(root, lines, { includeFilePaths = true } = {}) {
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;
+ if (errorLine) {
+ const operation = permissionOperation(root, errorLine[1], { includeFilePaths });
+ if (operation?.syscall) {
+ 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;
+ }
}
- return operation;
+
+ // Python child failures have a standard traceback frame and terminal PermissionError,
+ // rather than Node's structured `Error` code/syscall/path object.
+ const tracebackMarker = /(?:^|\n)Traceback \(most recent call last\):\n/u.exec(detail);
+ const tracebackError = /(?:^|\n)(PermissionError: \[Errno (?:1|13)\] [^\n]+)\s*$/u.exec(detail);
+ if (!tracebackMarker || !tracebackError || tracebackError.index <= tracebackMarker.index) return null;
+ const tracebackBody = detail.slice(tracebackMarker.index + tracebackMarker[0].length, tracebackError.index);
+ if (!/(?:^|\n)File (?:'[^'\n]+'|"[^"\n]+"), line \d+(?:, in [^\n]+)?(?:\n|$)/u.test(tracebackBody)) return null;
+ const operation = permissionOperation(root, tracebackError[1], { includeFilePaths });
+ return operation && operation.syscall === null ? operation : null;
}
/** Scan complete lines with bounded TAP state so assertion messages cannot impersonate OS codes. */
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index a528703b..d30d6f5a 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -138,6 +138,50 @@ function childListenerTestSource() {
].join('\n');
}
+/** Produce a child-process test whose stderr models a Python traceback without requiring Python. */
+function childPythonTestSource() {
+ const childProgram = [
+ 'console.error("Traceback (most recent call last):")',
+ 'console.error(" File " + JSON.stringify("child.py") + ", line 1, in <module>")',
+ 'console.error("PermissionError: [Errno 13] Permission denied: " + JSON.stringify(process.env.CHILD_PERMISSION_PATH))',
+ 'process.exit(1)',
+ ].join('\n');
+ 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 child reports a Python-style denial', () => {",
+ ` const child = spawnSync(process.execPath, ['-e', ${JSON.stringify(childProgram)}], { encoding: 'utf8' });`,
+ " assert.equal(child.status, 0, `Child process exited with code ${child.status}:\\n${child.stderr}`);",
+ '});',
+ ].join('\n');
+}
+
+/** Format a standalone Python denial already recognized by the gate scanner. */
+function pythonPermissionError(path, errno = 13) {
+ return `PermissionError: [Errno ${errno}] Permission denied: '${path}'`;
+}
+
+/** Wrap scanner input in a failed child TAP record with or without a fatal traceback. */
+function pythonChildTap(path, { traceback = true, frame = true, prefixMarker = false, errno = 13, wrapper = true, exitCode = 1, trailingError = false } = {}) {
+ const diagnostic = pythonPermissionError(path, errno);
+ const marker = prefixMarker ? 'not a traceback marker: Traceback (most recent call last):' : 'Traceback (most recent call last):';
+ const tracebackDetail = `${marker}\n${frame ? ' File "child.py", line 1, in <module>\n' : ''}${diagnostic}${trailingError ? '\nValueError: later unrelated failure' : ''}`;
+ const detail = traceback ? tracebackDetail : `AssertionError: expected ordinary output\n${diagnostic}`;
+ return [
+ 'TAP version 13',
+ 'not ok 1 - child reads a file',
+ ' ---',
+ " failureType: 'testCodeFailure'",
+ ' error: |-',
+ ...(wrapper ? [` Child process exited with code ${exitCode}:`] : []),
+ ...detail.split('\n').map((line) => ` ${line}`),
+ " code: 'ERR_ASSERTION'",
+ ' ...',
+ ].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');
@@ -146,6 +190,16 @@ test('a child process listen denial reads as sandbox blocked [C7,B26]', (t) => {
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);
+
+ const pythonBox = childFailureSubmitBox(t, childPythonTestSource());
+ pythonBox.env.CHILD_PERMISSION_PATH = join(pythonBox.dir, 'outside-python-denial.txt');
+ const python = pythonBox.run('submit', '1');
+ const pythonOutput = `${python.out}\n${python.err}`;
+ assert.equal(python.code, 1, pythonOutput);
+ assert.match(python.err, /SANDBOX_BLOCKED/u, 'submit names a scanner-known denial from a child traceback');
+ assert.match(python.err, /file access .*\(EACCES\)/u);
+ assert.match(python.err, /Ask the person to allow this operation/u);
+ assert.doesNotMatch(python.err, /GATE_RED/u);
});
test('an ordinary failure stays gate red [C7,B26]', (t) => {
@@ -156,6 +210,29 @@ test('an ordinary failure stays gate red [C7,B26]', (t) => {
"test('ordinary failure', () => assert.fail('ordinary assertion failure'));",
].join('\n');
const box = childFailureSubmitBox(t, source);
+ const outside = join(box.dir, 'outside-python-denial.txt');
+ const direct = sandboxBlockedOperation(box.root, pythonPermissionError(outside));
+ assert.equal(direct, `file access "${outside}" (EACCES)`, 'the standalone known denial remains recognized');
+ assert.equal(sandboxBlockedOperation(box.root, pythonPermissionError(outside, 1)), `file access "${outside}" (EACCES)`,
+ 'the standalone EPERM-style Python errno remains recognized');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { traceback: false })), null,
+ 'permission-looking text without a fatal traceback stays ordinary');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(join(box.root, 'inside.txt'))), null,
+ 'an inside-root path stays ordinary');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside), { includeFilePaths: false }), null,
+ 'the no-file-paths option stays respected');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { frame: false })), null,
+ 'a traceback without a standard file frame stays ordinary');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { prefixMarker: true })), null,
+ 'traceback marker text inside a line is not a traceback');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { wrapper: false })), null,
+ 'a traceback without a failed child wrapper stays ordinary');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { exitCode: 0 })), null,
+ 'a zero-exit child is not a blocked failure');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { trailingError: true })), null,
+ 'a different terminal exception after PermissionError stays ordinary');
+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { errno: 1 })), `file access "${outside}" (EACCES)`,
+ 'a nested EPERM-style Python errno remains recognized');
const result = box.run('submit', '1');
const output = `${result.out}\n${result.err}`;
assert.equal(result.code, 1, output);