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(core): preserve child denials in the shared scanner [C7,B26,I1]
Corey Olson183642fc407f
diff --cc src/sandbox-denial.jsindex 00000000,a44b7d40..3e602a3dmode 000000,100644..100644--- a/src/sandbox-denial.js+++ b/src/sandbox-denial.js@@@ -1,0 -1,198 +1,279 @@@+ /**+ * Sandbox denials (I1, C7): the one classifier for an operating-system permission refusal in gate+ * output, shared by the local gate and the remote runner worker. It ships to runners as a trusted+ * runtime file, so a file denial is resolved against the worktree it happened in, on the machine+ * it happened on, and only its evidence travels.+ */+ import { realpathSync } from 'node:fs';+ import { dirname, isAbsolute, relative, resolve } from 'node:path';++ /** Resolve existing path prefixes so a symlink cannot hide an outside-worktree operation. */+ function diagnosticPath(path) {+ let current = resolve(path);+ const missing = [];+ for (;;) {+ try { return resolve(realpathSync(current), ...missing); }+ catch (error) {+ if (!['ENOENT', 'ENOTDIR'].includes(error.code)) return null;+ const parent = dirname(current);+ if (parent === current) return null;+ missing.unshift(relative(parent, current));+ current = parent;+ }+ }+ }++ /** Describe one OS permission message, resolving file targets against the command's worktree. */+ function permissionOperation(root, message, { includeFilePaths = true } = {}) {+ const network = /^(listen|bind) (EPERM|EACCES)\b/u.exec(message);+ if (network) return { code: network[2], syscall: network[1], operation: `${network[1]} (${network[2]})` };+ if (!includeFilePaths) return null;+ const file = /^(EPERM|EACCES): [^\n]*?, (open|mkdir|read|write|rename|unlink|scandir|access) (['"])([^\n]+?)\3(?= -> |$)/u.exec(message);+ const python = /^PermissionError: \[Errno (?:1|13)\] [^\n]*?: ['"]([^'"\n]+)['"]/u.exec(message);+ if (!file && !python) return null;+ const path = diagnosticPath(resolve(root, file ? file[4] : python[1]));+ const tree = diagnosticPath(root);+ if (!path || !tree) return null;+ const within = relative(tree, path);+ if (within !== '..' && !within.startsWith('../') && !isAbsolute(within)) return null;+ const code = file ? file[1] : 'EACCES';+ return { code, path, syscall: file ? file[2] : null,+ operation: `${file ? file[2] : 'file access'} ${JSON.stringify(path)} (${code})` };+ }++ /** Decode the single-line quoted YAML scalars emitted by Node's TAP reporter. */+ function tapScalar(value) {+ if (value.startsWith('"')) {+ try { return JSON.parse(value); } catch { return null; }+ }+ if (value.startsWith("'") && value.endsWith("'")) return value.slice(1, -1).replace(/''/gu, "'");+ return /^[A-Z_]+$/u.test(value) ? value : null;+ }+-/**- * Scan complete lines with bounded TAP state so assertion messages cannot impersonate OS codes.- * With `evidence`, a hit is the whole denial (code, syscall, path, operation) rather than its words.++/** Recognize a bounded child fatal denial carried inside one failed TAP error block. */++function nestedChildPermission(root, lines, { includeFilePaths = true, parentCode = null } = {}) {++ 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);++ // A malformed or zero child-exit statement is evidence against using the footer fallback.++ const childExitMention = /\b(?:child|app|server|process)\b[^\n]{0,120}\bexited\b[^\n]{0,100}\bcode\b/iu.test(detail);++ // Some TAP reporters preserve only stderr as the assertion message. Accept that++ // shape only with an ERR_ASSERTION nonzero-vs-zero footer and a complete fatal++ // signature for the child runtime. Its diagnostic fields below remain mandatory. Scanner lines are++ // trimmed before collection, so stack frames start with `at`, without indentation.++ const bareAssertionExit = !childExit && !childExitMention && parentCode === 'ERR_ASSERTION'++ ? /\n{2,}([1-9]\d*) !== 0\s*$/u.exec(detail) : null;++ const bareFatalDetail = bareAssertionExit ? detail.slice(0, bareAssertionExit.index) : '';++ const completeNodeFatal = bareAssertionExit++ && /(?:^|\n)Node\.js v\d+\.\d+\.\d+\s*$/u.test(bareFatalDetail)++ && /(?:^|\n)at [^\n]+/u.test(bareFatalDetail);++ const childExitCode = childExit ? Number(childExit[1]) : bareAssertionExit ? Number(bareAssertionExit[1]) : null;++ if (!Number.isSafeInteger(childExitCode) || childExitCode <= 0) return null;++++ const errorLine = /^\s*Error: (.+)$/mu.exec(detail);++ if (errorLine) {++ if (!childExit && !completeNodeFatal) return null;++ 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;++ }++ }++++ // Python child failures have a standard traceback frame and terminal PermissionError,++ // rather than Node's structured `Error` code/syscall/path object.++ // Node appends this exact assertion comparison to TAP's error scalar after the child stderr.++ // Strip it only for an AssertionError whose nonzero child exit matches `actual !== 0`.++ const assertionFooter = parentCode === 'ERR_ASSERTION'++ ? new RegExp(`\\n{2,}${childExitCode} !== 0\\s*$`, 'u') : null;++ const tracebackDetail = assertionFooter?.test(detail) ? detail.replace(assertionFooter, '') : detail;++ const tracebackMarker = /(?:^|\n)Traceback \(most recent call last\):\n/u.exec(tracebackDetail);++ const tracebackError = /(?:^|\n)(PermissionError: \[Errno (?:1|13)\] [^\n]+)\s*$/u.exec(tracebackDetail);++ if (!tracebackMarker || !tracebackError || tracebackError.index <= tracebackMarker.index) return null;++ const tracebackBody = tracebackDetail.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.++ * With evidence, return the complete denial for the remote file watcher; otherwise keep the local operation string.+ */+ export function sandboxBlockedScanner(root, { includeFilePaths = true, evidence = false } = {}) {+ const hit = denial => evidence ? denial : denial.operation;+ let failureIndent = null;+ let fieldIndent = null;+ let permission = null;+ let code = null;+ let comment = null;+ let startup = null;+ 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, '');+ const indent = raw.length - raw.trimStart().length;+ // Node's TAP reporter prints test-console output as comments and assertion details+ // as indented YAML. Neither is a standalone gate diagnostic, even when it contains+ // text that looks exactly like an operating-system denial.+ if (indent === 0 && !raw.startsWith('#') && /^(?:Error: |PermissionError: )/u.test(line)) {+ const direct = permissionOperation(root, line.replace(/^Error: /u, ''), { includeFilePaths });+ if (direct) return hit(direct);+ }+ if (/^TAP version \d+$/u.test(raw)) {+ 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+ // to start. A test logging a caught error and then asserting is not that record.+ if (indent === 0 && raw.startsWith('#')) {+ if (line.startsWith('Error: ')) {+ const operation = permissionOperation(root, line.slice('Error: '.length), { includeFilePaths });+ comment = operation ? { operation, code: null, syscall: null, path: null, closed: false, fatal: false } : null;+ } else if (comment) {+ const field = /^(code|syscall|path): (.*)$/u.exec(line);+ if (field) comment[field[1]] = tapScalar(field[2].replace(/,$/u, ''));+ else if (line === '}') comment.closed = true;+ else if (/^Node\.js v\d+\./u.test(line)) comment.fatal = true;+ else if (line && !/^at |^errno: |^address: |^port: /u.test(line)+ && !(comment.closed && comment.fatal && line.startsWith('Subtest: '))) comment = null;+ }+ }+ if (/^(?:not )?ok \d+\b/u.test(line)) {+ failureIndent = /^not ok /u.test(line) ? indent : null;+ const operation = comment?.operation;+ startup = failureIndent !== null && comment?.closed && comment.fatal+ && comment.code === operation.code && comment.syscall === operation.syscall+ && (!operation.path || (typeof comment.path === 'string'+ && diagnosticPath(resolve(root, comment.path)) === operation.path)) ? operation : null;+ 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, parentCode: code }) : null;++ if (nestedPermission) return hit(nestedPermission);+ if (permission && permission.code === code) return hit(permission);+ if (startup && code === 'ERR_TEST_FAILURE' && failureMessage === 'test failed'+ && failureType && exitCode !== null) return hit(startup);+ }+ }+ return null;+ };+ }++ /** Recognize concrete OS permission diagnostics, keeping ordinary assertion failures ordinary. */+ export function sandboxBlockedOperation(root, output, options) {+ const scan = sandboxBlockedScanner(root, options);+ for (const line of output.split('\n')) {+ const operation = scan(line);+ if (operation) return operation;+ }+ return null;+ }++ const FILE_OPERATIONS = new Set(['open', 'mkdir', 'read', 'write', 'rename', 'unlink', 'scandir', 'access', 'file access']);+ const LINE_LIMIT = 64 * 1024;++ /**+ * Watch streamed command output on the machine that ran it for a file denial outside `root`.+ * Only the evidence leaves: the operation, that its path was outside the worktree, and the errno.+ * Why here: a path can be resolved only on its own machine, so a controller never realpaths a+ * remote path. An over-long line is skipped whole, as the local scanner never sees one either.+ */+ export function fileDenialWatcher(root) {+ const scan = sandboxBlockedScanner(root, { evidence: true });+ const decoder = new TextDecoder();+ let pending = '';+ let skipping = false;+ let found = null;+ /** Classify one complete line unless a denial is already in hand. */+ const take = line => {+ const denial = found || skipping ? null : scan(line);+ if (denial?.path) found = { operation: denial.syscall ?? 'file access', outside: true, errno: denial.code };+ };+ return {+ /** Feed one raw output chunk. */+ push(chunk) {+ if (found) return;+ pending += decoder.decode(chunk, { stream: true });+ let newline;+ while ((newline = pending.indexOf('\n')) >= 0) {+ take(pending.slice(0, newline));+ pending = pending.slice(newline + 1);+ skipping = false;+ }+ if (pending.length > LINE_LIMIT) { pending = ''; skipping = true; }+ },+ /** Finish the stream and return the evidence, or null for an ordinary failure. */+ end() {+ pending += decoder.decode();+ if (pending) take(pending);+ pending = '';+ return found;+ },+ };+ }++ /**+ * Name a runner's file denial from its evidence alone, with the runner host; null when the+ * evidence is not a well-formed denial, so a malformed receipt cannot pass as one.+ */+ export function remoteFileDenial(denial, host) {+ if (!denial || typeof denial !== 'object' || Object.keys(denial).sort().join() !== 'errno,operation,outside'+ || !FILE_OPERATIONS.has(denial.operation) || !['EACCES', 'EPERM'].includes(denial.errno) || denial.outside !== true) return null;+ return `${denial.operation} outside its worktree (${denial.errno}) on runner ${host}`;+ }diff --cc test/submit-gate.test.jsindex 027e578b,40d4b1a4..796c38f4--- a/test/submit-gate.test.js+++ b/test/submit-gate.test.js@@@ -13,7 -13,7 +13,8 @@@ 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';++import { fileDenialWatcher } from '../src/sandbox-denial.js';const BIN = resolveBin();const dirs = [];@@@ -98,217 -98,6 +99,227 @@@ function commitAll(box, message = 'chorreturn 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);+ // This fixture proves multiline TAP diagnostics; Node's default reporter varies by runtime.+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test --test-reporter=tap', affectedTests: 'node --test --test-reporter=tap', 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');+}++/** 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, assertionFooter = null, footerSeparator = '\n\n\n', parentCode = 'ERR_ASSERTION' } = {}) {+ 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}`;+ const renderedDetail = assertionFooter === null ? detail : `${detail}${footerSeparator}${assertionFooter}`;+ return [+ 'TAP version 13',+ 'not ok 1 - child reads a file',+ ' ---',+ " failureType: 'testCodeFailure'",+ ' error: |-',+ ...(wrapper ? [` Child process exited with code ${exitCode}:`] : []),+ ...renderedDetail.split('\n').map((line) => ` ${line}`),+ ` code: '${parentCode}'`,+ ' ...',+ ].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);++ const explanatory = " assert.equal(child.status, 0, `App exited before listening (code ${child.status}, signal ${child.signal}):\\n${child.stderr}`);";+ const original = childListenerTestSource();+ assert.equal(original.split(explanatory).length, 2, 'replace exactly one explanatory message');+ const bareSource = original.replace(explanatory, ' assert.equal(child.status, 0, child.stderr);');+ const bareBox = childFailureSubmitBox(t, bareSource);+ const bare = bareBox.run('submit', '1');+ const bareOutput = `${bare.out}\n${bare.err}`;+ assert.equal(bare.code, 1, bareOutput);+ assert.match(bareOutput, /SANDBOX_BLOCKED/u, 'bare stderr with structured fatal fields still names the denial');+ assert.match(bareOutput, /listen \(EPERM\)/u);+ assert.doesNotMatch(bareOutput, /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);++ const pythonSource = childPythonTestSource();+ const pythonExplanation = " assert.equal(child.status, 0, `Child process exited with code ${child.status}:\\n${child.stderr}`);";+ assert.equal(pythonSource.split(pythonExplanation).length - 1, 1, 'the bare Python counter changes exactly one parent message');+ const barePythonBox = childFailureSubmitBox(t, pythonSource.replace(pythonExplanation, ' assert.equal(child.status, 0, child.stderr);'));+ barePythonBox.env.CHILD_PERMISSION_PATH = join(barePythonBox.dir, 'outside-bare-python-denial.txt');+ const barePython = barePythonBox.run('submit', '1');+ const barePythonOutput = `${barePython.out}\n${barePython.err}`;+ assert.equal(barePython.code, 1, barePythonOutput);+ assert.match(barePython.err, /SANDBOX_BLOCKED/u, 'complete bare Python stderr still names the known denial');+ assert.match(barePython.err, /file access .*\(EACCES\)/u);+ assert.doesNotMatch(barePythonOutput, /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 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 recognized = `file access "${outside}" (EACCES)`;++ const streamed = fileDenialWatcher(box.root);++ const childTap = pythonChildTap(outside, { wrapper: false, assertionFooter: '1 !== 0' });++ const boundary = childTap.indexOf('PermissionError') + 5;++ streamed.push(Buffer.from(childTap.slice(0, boundary)));++ streamed.push(Buffer.from(childTap.slice(boundary)));++ assert.deepEqual(streamed.end(), { operation: 'file access', outside: true, errno: 'EACCES' },++ 'the shared runner watcher retains structured evidence for a nested child denial across chunks');++ const ordinaryStream = fileDenialWatcher(box.root);++ ordinaryStream.push(Buffer.from(pythonChildTap(outside, { traceback: false, assertionFooter: '1 !== 0' })));++ assert.equal(ordinaryStream.end(), null, 'the runner watcher keeps ordinary permission-looking assertions ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 0' })), recognized,+ 'the matching Node assertion footer does not hide the terminal child denial');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '2 !== 0' })), null,+ 'a footer exit code different from the child wrapper stays ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 1' })), null,+ 'a footer with a nonzero expected value stays ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 0', footerSeparator: '\nnot blank\n' })), null,+ 'a comparison without the blank-line boundary stays ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 0\nextra text' })), null,+ 'arbitrary text after the comparison stays ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 0', parentCode: 'ERR_TEST_FAILURE' })), null,+ 'the footer is accepted only in an assertion failure record');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { trailingError: true, assertionFooter: '1 !== 0' })), null,+ 'a later Python exception stays ordinary even when the Node assertion footer follows');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { assertionFooter: '1 !== 0', footerSeparator: '\n' })), null,+ 'a comparison without a blank-line boundary stays ordinary');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { traceback: false, assertionFooter: '1 !== 0' })), null,+ 'an assertion footer does not turn non-traceback text into a Python denial');+ for (const errno of [1, 13]) {+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { wrapper: false, errno, assertionFooter: '1 !== 0' })), recognized,+ 'a complete bare traceback and positive assertion exit prove a known child denial');+ }+ for (const [label, options] of [+ ['missing traceback', { traceback: false }],+ ['missing frame', { frame: false }],+ ['prefixed traceback marker', { prefixMarker: true }],+ ['later exception', { trailingError: true }],+ ['unknown errno', { errno: 2 }],+ ['zero exit', { assertionFooter: '0 !== 0' }],+ ['nonzero expected status', { assertionFooter: '1 !== 1' }],+ ['unsafe exit integer', { assertionFooter: '9007199254740992 !== 0' }],+ ['missing footer separation', { footerSeparator: '\n' }],+ ['text after footer', { assertionFooter: '1 !== 0\nextra text' }],+ ['non-assertion parent', { parentCode: 'ERR_TEST_FAILURE' }],+ ]) {+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { wrapper: false, assertionFooter: '1 !== 0', ...options })), null,+ `bare Python ${label} stays unclassified`);+ }+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(join(box.root, 'inside.txt'), { wrapper: false, assertionFooter: '1 !== 0' })), null,+ 'bare Python in-repo access stays an ordinary failure');+ assert.equal(sandboxBlockedOperation(box.root, pythonChildTap(outside, { wrapper: false, assertionFooter: '1 !== 0' }), { includeFilePaths: false }), null,+ 'bare Python does not bypass the file-path classification switch');+ 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');