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(gate): recognize real TAP permission denials [I1,C7]
Corey Olsond6aec7943508
diff --git a/src/gate.js b/src/gate.jsindex 3a0a9b9e..bc473aa3 100644--- a/src/gate.js+++ b/src/gate.js@@ -168,21 +168,71 @@ function diagnosticPath(path) {}}+/** Describe one OS permission message, resolving file targets against the command's worktree. */+function permissionOperation(root, message) {+ const network = /^(listen|bind) (EPERM|EACCES)\b/u.exec(message);+ if (network) return { code: network[2], operation: `${network[1]} (${network[2]})` };+ 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, 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. */+export function sandboxBlockedScanner(root) {+ let failureIndent = null;+ let fieldIndent = null;+ let permission = null;+ let code = null;+ /** Read one line, retaining only the current failed TAP record's permission and code fields. */+ return (raw) => {+ const line = raw.trim().replace(/^#\s*/u, '');+ if (/^(?:Error: |PermissionError: )/u.test(line)) {+ const direct = permissionOperation(root, line.replace(/^Error: /u, ''));+ if (direct) return direct.operation;+ }+ const indent = raw.length - raw.trimStart().length;+ if (/^(?:not )?ok \d+\b/u.test(line)) {+ failureIndent = /^not ok /u.test(line) ? indent : null;+ fieldIndent = null; permission = null; code = null;+ } else if (line === '---' && failureIndent !== null && indent === failureIndent + 2) {+ fieldIndent = indent;+ } else if (line === '...' && indent === fieldIndent) {+ failureIndent = null; fieldIndent = null; permission = null; code = null;+ } else if (fieldIndent !== null && indent === fieldIndent) {+ const field = /^(error|code): (.*)$/u.exec(line);+ if (field) {+ const value = tapScalar(field[2]);+ if (field[1] === 'error') permission = typeof value === 'string' ? permissionOperation(root, value) : null;+ else code = value;+ if (permission && permission.code === code) return permission.operation;+ }+ }+ return null;+ };+}+/** Recognize concrete OS permission diagnostics, keeping ordinary assertion failures ordinary. */export function sandboxBlockedOperation(root, output) {- for (const raw of output.split('\n')) {- const line = raw.trim().replace(/^#\s*/u, '');- const network = /^Error: (listen|bind) (EPERM|EACCES)\b/u.exec(line);- if (network) return `${network[1]} (${network[2]})`;- const file = /^Error: (EPERM|EACCES): [^\n]*?, (open|mkdir|read|write|rename|unlink|scandir|access) ['"]([^'"\n]+)['"]/u.exec(line);- const python = /^PermissionError: \[Errno (?:1|13)\] [^\n]*?: ['"]([^'"\n]+)['"]/u.exec(line);- if (!file && !python) continue;- const path = diagnosticPath(resolve(root, file ? file[3] : python[1]));- const tree = diagnosticPath(root);- if (!path || !tree) continue;- const within = relative(tree, path);- if (within !== '..' && !within.startsWith('../') && !isAbsolute(within)) continue;- return `${file ? file[2] : 'file access'} ${JSON.stringify(path)} (${file ? file[1] : 'EACCES'})`;+ const scan = sandboxBlockedScanner(root);+ for (const line of output.split('\n')) {+ const operation = scan(line);+ if (operation) return operation;}return null;}diff --git a/src/trusted-policy.js b/src/trusted-policy.jsindex 99602b48..26ac9d9b 100644--- a/src/trusted-policy.js+++ b/src/trusted-policy.js@@ -1,7 +1,7 @@/** Coordinator policy and immutable submission checks cannot come from a builder's candidate [V4,V16,L3,M3]. */import { randomUUID } from 'node:crypto';import { spawnSync } from 'node:child_process';-import { digestOf, sandboxBlockedOperation, writeTimingProfile } from './gate.js';+import { digestOf, sandboxBlockedScanner, writeTimingProfile } from './gate.js';import { timingFromOutput, timingFromLog, timingRunner } from './timing.js';import { closeSync, existsSync, mkdtempSync, mkdirSync, openSync, readFileSync, readSync, rmSync, writeSync } from 'node:fs';import { tmpdir } from 'node:os';@@ -402,11 +402,12 @@ function checkResult(state, stage, installCapture, checkCapture, { root = '', it/** Give a missing phase the same explicit placeholder used by the former complete-string path. */const writePhase = (title, path, capture, label, absentText) => {appendArtifact(`${title}:\n`);+ const scan = sandboxBlockedScanner(commandRoot);const result = streamSanitizedLog(path, capture, label, artifactFd === null ? null : (buffer, offset) => {const written = writeSync(artifactFd, buffer, offset, buffer.length - offset);if (written <= 0) throw new Error('diagnostic artifact write made no progress');return written;- }, line => { if (state !== 'pass' && title === (stage.startsWith('install') ? 'install' : 'check')) sandboxBlocked ??= sandboxBlockedOperation(commandRoot, line); });+ }, line => { if (state !== 'pass' && title === (stage.startsWith('install') ? 'install' : 'check')) sandboxBlocked ??= scan(line); });if (!result.sawOutput) appendArtifact(`${absentText}\n`);return result;};diff --git a/test/submit-gate.test.js b/test/submit-gate.test.jsindex 7e66a210..87205998 100644--- a/test/submit-gate.test.js+++ b/test/submit-gate.test.js@@ -6,7 +6,7 @@*/import assert from 'node:assert/strict';import { runFixtureExecFile as execFileSync, runFixtureChild as spawnSync, runFixtureChild, runFixtureGit } from './fixture-child.js';-import { appendFileSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';+import { appendFileSync, chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import { dirname, join, resolve } from 'node:path';import { after, test } from 'node:test';@@ -798,6 +798,52 @@ test('a sandbox-blocked gate asks the person [I1,C7]', async (t) => {assert.equal(green.code, 0, green.err);assert.doesNotMatch(green.out + green.err, /SANDBOX_BLOCKED/u, 'a successful diagnostic is not a refusal');});+ await t.test('real outside-file TAP denials refuse while permission assertions stay ordinary [I1,C7]', () => {+ let box = privateRepo(t);+ const runner = `${JSON.stringify(process.execPath)} ${JSON.stringify(resolve(import.meta.dirname, '../bin/run-tests.js'))} test/permission.test.js`;+ const directory = join(box.dir, 'readonly-outside-worktree');+ mkdirSync(directory);+ const outside = join(directory, "outside'quote.txt");+ put(box.root, 'pullboard.json', JSON.stringify({ gate: runner }));+ seedGraph(box);+ const operation = `writeFileSync(${JSON.stringify(outside)}, 'blocked')`;+ const prefix = "import { test } from 'node:test';\nimport { writeFileSync } from 'node:fs';\nimport assert from 'node:assert/strict';\n";+ const denied = prefix + `test('actual outside write', () => ${operation});\n`;+ put(box.root, 'test/permission.test.js', denied);+ commitAll(box);+ box = builderRepo(box);+ assert.equal(box.coordinator('add', 'build', 'Real permission check', '--check', runner).code, 0);+ assert.equal(box.run('claim', '1').code, 0);+ put(box.root, 'src/a.js', 'export const value = 2;\n');+ commitAll(box, 'feat(core): update selected source [G1]');+ const item = { ...JSON.parse(box.coordinator('show', '1', '--json').out), item_commit: box.git('rev-parse', 'HEAD').trim() };+ chmodSync(directory, 0o500);+ try {+ assert.throws(() => writeFileSync(outside, 'sentinel'), { code: 'EACCES' }, 'the operating system actually denies this write');+ blocked(box.run('gate'), outside);+ blocked(box.run('check', '1', '--yes'), outside);+ blocked(box.run('submit', '1'), outside);+ const privateResult = checkAtCommit(box.root, item);+ assert.equal(privateResult.state, 'red');+ assert.ok(privateResult.sandboxBlocked?.includes(outside), 'the real private checker scans the TAP record');+ assert.throws(() => refuseSandboxBlocked(privateResult), { code: 'SANDBOX_BLOCKED' });+ const raw = readFileSync(privateResult.outputPath, 'utf8');+ assert.match(raw, /code: 'EACCES'/u);+ assert.ok(raw.includes(outside));+ assert.ok(existsSync(privateResult.profilePath));+ put(box.root, 'test/permission.test.js', prefix + `test('ordinary assertion mentioning permission', () => { try { ${operation}; } catch (error) { assert.fail(error.message); } });\n`);+ commitAll(box);+ const ordinary = box.run('gate');+ assert.equal(ordinary.code, 1);+ assert.match(ordinary.out, /ERR_ASSERTION/u);+ assert.doesNotMatch(ordinary.out + ordinary.err, /SANDBOX_BLOCKED/u);+ put(box.root, 'test/permission.test.js', denied);+ commitAll(box);+ } finally { chmodSync(directory, 0o700); }+ const allowed = box.run('gate');+ assert.equal(allowed.code, 0, allowed.out + allowed.err);+ assert.equal(readFileSync(outside, 'utf8'), 'blocked', 'the unchanged real write succeeds when access is restored');+ });await t.test('frozen checks retain outside-file refusal before submit proof [I1,C7]', () => {let box = privateRepo(t);put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test' }));