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(verify): retain bounded sanitized check diagnostics [V19,V18]

Corey Olson10813d5f239b
diff --git a/docs/api.md b/docs/api.md
index a3e04408..ada4ea2e 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -136,6 +136,8 @@ Only the coordinator sets or edits an item's `--check`. `pullboard check [id]` p
The result and refusal tables are checked against `JSON_SHAPES` in `src/json.js` by `docs/api.test.js`.
+When `verify <id> accept` runs a frozen check and refuses with `CHECK_RED` or `CHECK_UNVERIFIED`, `error.message` includes its output digest, up to 40 sanitized tail lines, and `full output file: <path>`. The file is written with owner-only permissions. If diagnostic storage fails, the message says `full output file: (unavailable: CODE)` while retaining the bounded sanitized lines; the JSON error object remains `{ code, message, next }`. An item with no frozen check produces no check-output section.
+
## Local HTTP API v1
Run `pullboard serve --port 0` to print a private API address on `127.0.0.1`. Authenticate each call with the address's `k` query parameter, an `X-Pullboard-Key` header, or `Authorization: Bearer <key>`. The secret belongs to that server session. Board ids are random 128-bit values stored in each board; reopening or moving a repo preserves its id.
diff --git a/docs/lifecycle.md b/docs/lifecycle.md
index 73b95609..cf22551e 100644
--- a/docs/lifecycle.md
+++ b/docs/lifecycle.md
@@ -8,7 +8,7 @@ An item starts open. Its final states, verified and withdrawn, cannot be left, a
The coordinator may set `check.install` and `check.timeout` in committed `pullboard.json`; the defaults are no install command and `5m`. Accept runs the configured install and the frozen item check in a private clone, under one timeout budget. It reuses the verifier’s npm cache when available. Install commands that need network downloads conflict with P2 (offline); configure an offline install or make its needed packages available in the cache.
-Private commands drain their output through pipes, retaining a bounded 8 MiB capture of its beginning and end. Output beyond that cap does not fail a successful command, and dependency files and build artifacts have no capture-size limit. A timeout kills the command's process group. An unverified check names how to restore the environment and retry; a failing check names rejection or builder rework as the next step.
+Private commands drain their output through pipes, retaining a bounded 8 MiB capture of its beginning and end. Failed or unverifiable checks stream the complete log through secret scanning into an owner-readable artifact; lines over 64 KiB of UTF-8 data are replaced with a safe-scan marker. Output beyond the capture cap does not fail a successful command, and dependency files and build artifacts have no capture-size limit. A timeout kills the command's process group. An unverified check names how to restore the environment and retry; a failing check names rejection or builder rework as the next step.
```mermaid
stateDiagram-v2
@@ -123,3 +123,5 @@ Each move checks its guards in this order and refuses with the first one that do
| BAD_REASON | a reject names one of the reject reasons | --reason TEST_FAILURE, BEHAVIOR_MISMATCH, INSUFFICIENT_EVIDENCE, STALE_HEAD or OTHER |
| NOTE_REQUIRED | the move carries a note: what failed, what was tried, or why | --note "..." or --note-file <file> |
| BAD_DECISION | a verdict is accept or reject | pullboard verify <id> accept, or reject --reason CODE --note "..." |
+
+For check diagnostics, a refusal from a failed or unverifiable check includes an output digest, sanitized tail, and a private full-output path in the CLI message (also `error.message` in JSON). The artifact is owner-readable only. If it cannot be saved, the tail remains available and the message names the storage error instead of claiming a path.
diff --git a/src/cli.js b/src/cli.js
index 9d3bfd18..108a4331 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1494,8 +1494,11 @@ async function verifyHere(ctx, id, { second, values }) {
if (decision === 'ACCEPT') {
if (digest !== item.item_frozen_digest) throw new Refused('CRITERIA_CHANGED', 'the criterion changed; ask the coordinator to refreeze this item before checking it');
const check = checkAtCommit(root, item);
- if (check.state === 'unverified') throw new Refused('CHECK_UNVERIFIED', `the frozen ${check.stage} could not be verified at the submitted commit; restore the install or check environment, then retry verification; output digest:\n${check.report.replace(/^/gm, ' ')}`);
- if (check.state === 'red') throw new Refused('CHECK_RED', `the frozen item check is red at the submitted commit; check.install may be needed for dependencies; reject with the failing behavior or ask the builder to fix and resubmit; output digest:\n${check.report.replace(/^/gm, ' ')}`);
+ const evidence = check.checked
+ ? `\nlast output lines (up to 40):\n${(check.outputTail ?? '(no output)').split('\n').map((line) => ` ${line}`).join('\n')}\nfull output file: ${check.outputPath ?? `(unavailable${check.outputError ? `: ${check.outputError}` : ''})`}`
+ : '';
+ if (check.state === 'unverified') throw new Refused('CHECK_UNVERIFIED', `the frozen ${check.stage} could not be verified at the submitted commit; restore the install or check environment, then retry verification; output digest:\n${check.report.replace(/^/gm, ' ')}${evidence}`);
+ if (check.state === 'red') throw new Refused('CHECK_RED', `the frozen item check is red at the submitted commit (${check.stage}); check.install may be needed for dependencies; reject with the failing behavior or ask the builder to fix and resubmit; output digest:\n${check.report.replace(/^/gm, ' ')}${evidence}`);
const receipt = store.events(board, { itemId: id }).filter(event => event.event_kind === 'submit').map(event => JSON.parse(event.event_detail)).find(event => event.commit === commit);
submissionPaths(root, item, commit, { mainCommit: receipt?.policyCommit, dependencies: dependencySnapshots(board.db, item) });
}
diff --git a/src/machine.js b/src/machine.js
index bc5e76a4..d13be1f9 100644
--- a/src/machine.js
+++ b/src/machine.js
@@ -508,7 +508,7 @@ export function lifecycleMarkdown(machine = MACHINE) {
'',
'The coordinator may set `check.install` and `check.timeout` in committed `pullboard.json`; the defaults are no install command and `5m`. Accept runs the configured install and the frozen item check in a private clone, under one timeout budget. It reuses the verifier’s npm cache when available. Install commands that need network downloads conflict with P2 (offline); configure an offline install or make its needed packages available in the cache.',
'',
- "Private commands drain their output through pipes, retaining a bounded 8 MiB capture of its beginning and end. Output beyond that cap does not fail a successful command, and dependency files and build artifacts have no capture-size limit. A timeout kills the command's process group. An unverified check names how to restore the environment and retry; a failing check names rejection or builder rework as the next step.",
+ "Private commands drain their output through pipes, retaining a bounded 8 MiB capture of its beginning and end. Failed or unverifiable checks stream the complete log through secret scanning into an owner-readable artifact; lines over 64 KiB of UTF-8 data are replaced with a safe-scan marker. Output beyond the capture cap does not fail a successful command, and dependency files and build artifacts have no capture-size limit. A timeout kills the command's process group. An unverified check names how to restore the environment and retry; a failing check names rejection or builder rework as the next step.",
'',
'```mermaid',
'stateDiagram-v2',
@@ -543,6 +543,8 @@ export function lifecycleMarkdown(machine = MACHINE) {
'| --- | --- | --- |',
...[...new Set([...wrongState, ...refusals, unknown])],
'',
+ 'For check diagnostics, a refusal from a failed or unverifiable check includes an output digest, sanitized tail, and a private full-output path in the CLI message (also `error.message` in JSON). The artifact is owner-readable only. If it cannot be saved, the tail remains available and the message names the storage error instead of claiming a path.',
+ '',
].join('\n');
}
diff --git a/src/private-check-worker.js b/src/private-check-worker.js
index 990826cd..1cd8e241 100644
--- a/src/private-check-worker.js
+++ b/src/private-check-worker.js
@@ -1,8 +1,8 @@
/** Collect private command output through pipes; dependency files are never size-limited [V18,V2]. */
import { spawn } from 'node:child_process';
-import { readFileSync, writeFileSync } from 'node:fs';
+import { createWriteStream, readFileSync, writeFileSync } from 'node:fs';
-const { command, timeout, pidFile } = JSON.parse(readFileSync(0, 'utf8'));
+const { command, timeout, pidFile, logPath } = JSON.parse(readFileSync(0, 'utf8'));
const LIMIT = 8 * 1024 * 1024;
const HALF = LIMIT / 2;
let head = Buffer.alloc(0);
@@ -10,6 +10,14 @@ let tail = Buffer.alloc(0);
let bytes = 0;
let timedOut = false;
let error = null;
+let logError = null;
+const log = createWriteStream(logPath, { flags: 'wx', mode: 0o600 });
+log.on('error', cause => {
+ logError = { code: cause.code ?? 'CHECK_LOG' };
+ // A failed log must not leave either pipe paused forever waiting for a drain that cannot happen.
+ child.stdout?.resume();
+ child.stderr?.resume();
+});
/** Drain every byte while retaining only the beginning and end of the combined output. */
function capture(chunk) {
@@ -18,6 +26,11 @@ function capture(chunk) {
if (take) head = Buffer.concat([head, chunk.subarray(0, take)]);
const rest = chunk.subarray(take);
if (rest.length) tail = Buffer.concat([tail, rest]).subarray(-HALF);
+ if (!logError && !log.write(chunk)) {
+ child.stdout.pause();
+ child.stderr.pause();
+ log.once('drain', () => { child.stdout.resume(); child.stderr.resume(); });
+ }
}
const child = spawn('sh', ['-c', `(\n${command}\n) 2>&1`], { detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -38,7 +51,16 @@ child.once('exit', stop);
child.once('close', (status, signal) => {
clearTimeout(timer);
stop();
- const marker = bytes > LIMIT ? '\n[output capped at 8 MiB; middle omitted]\n' : '';
- const output = head.toString('utf8') + marker + tail.toString('utf8');
- process.stdout.write(JSON.stringify({ status, signal, error: timedOut ? { code: 'ETIMEDOUT' } : error, output }));
+ let sent = false;
+ /** Return one bounded result after the output file has either closed or failed. */
+ const finish = () => {
+ if (sent) return;
+ sent = true;
+ const marker = bytes > LIMIT ? '\n[output capped at 8 MiB; middle omitted]\n' : '';
+ const output = head.toString('utf8') + marker + tail.toString('utf8');
+ process.stdout.write(JSON.stringify({ status, signal, error: timedOut ? { code: 'ETIMEDOUT' } : error, logError, output }));
+ };
+ log.once('close', finish);
+ if (log.closed) finish();
+ else log.end();
});
diff --git a/src/trusted-policy.js b/src/trusted-policy.js
index 46f7bdfb..cdcd71e7 100644
--- a/src/trusted-policy.js
+++ b/src/trusted-policy.js
@@ -1,12 +1,15 @@
/** 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 } from './gate.js';
-import { existsSync, mkdtempSync, mkdirSync, readFileSync, rmSync } from 'node:fs';
+import { closeSync, existsSync, mkdtempSync, mkdirSync, openSync, readFileSync, readSync, rmSync, writeSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join } from 'node:path';
+import { StringDecoder } from 'node:string_decoder';
import { fileURLToPath } from 'node:url';
import { configFromSource } from './config.js';
import { cleanGitEnvironment, mainCheckout } from './git.js';
+import { secretsIn } from './hooks.js';
import { outOfLane } from './lanes.js';
import { Refused } from './refused.js';
@@ -94,7 +97,7 @@ export function checkAtCommit(root, item) {
if (!command) return { state: 'pass', green: true, checked: false, report: '' };
let config;
try { config = itemPolicy(root, item).config; }
- catch { return checkResult('unverified', 'policy', '', ''); }
+ catch { return checkResult('unverified', 'policy', '', '', { root, item }); }
const install = config.check.install;
const timeout = config.check.timeoutMs;
const scratch = mkdtempSync(join(tmpdir(), 'pullboard-criterion-'));
@@ -107,26 +110,38 @@ export function checkAtCommit(root, item) {
delete env.PULLBOARD_RELAY_TOKEN;
let installOutput = '';
let checkOutput = '';
+ let installLogPath = '';
+ let checkLogPath = '';
+ /** Format one completed check phase with the private captures and durable artifact locations. */
+ const finish = (state, stage) => checkResult(state, stage, installOutput, checkOutput, {
+ root, item, installLogPath, checkLogPath,
+ });
try {
const common = policyGit(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim();
const clone = spawnSync('git', ['clone', '--quiet', '--shared', '--no-checkout', common, copy], { env, stdio: 'ignore' });
const checkout = clone.status === 0 && spawnSync('git', ['checkout', '--quiet', '--detach', item.item_commit], { cwd: copy, env, stdio: 'ignore' });
- if (!checkout || checkout.status !== 0) return checkResult('unverified', 'clone or checkout', installOutput, checkOutput);
+ if (!checkout || checkout.status !== 0) return finish('unverified', 'clone or checkout could not start');
const deadline = Date.now() + timeout;
if (install) {
- const run = runPrivateCommand(copy, env, install, Math.max(1, deadline - Date.now()), join(scratch, 'install.log'));
+ installLogPath = join(scratch, 'install.log');
+ const run = runPrivateCommand(copy, env, install, Math.max(1, deadline - Date.now()), installLogPath);
installOutput = run.output;
- if (run.error?.code === 'ETIMEDOUT') return checkResult('unverified', 'install timed out', installOutput, checkOutput);
- if (run.status !== 0) return checkResult('unverified', 'install failed', installOutput, checkOutput);
+ if (run.error?.code === 'ETIMEDOUT') return finish('unverified', 'install timed out');
+ if (run.error) return finish('unverified', `install could not start (${run.error.code})`);
+ if (run.logError) return finish('unverified', `install output could not be saved (${run.logError.code})`);
+ if (run.status !== 0) return finish('unverified', 'install failed');
}
const remaining = deadline - Date.now();
- if (remaining <= 0) return checkResult('unverified', 'check timed out', installOutput, checkOutput);
- const run = runPrivateCommand(copy, env, command, remaining, join(scratch, 'check.log'));
+ if (remaining <= 0) return finish('unverified', 'check timed out');
+ checkLogPath = join(scratch, 'check.log');
+ const run = runPrivateCommand(copy, env, command, remaining, checkLogPath);
checkOutput = run.output;
- if (run.error?.code === 'ETIMEDOUT') return checkResult('unverified', 'check timed out', installOutput, checkOutput);
- if (run.error || run.status === null) return checkResult('unverified', 'check could not complete', installOutput, checkOutput);
- return checkResult(run.status === 0 ? 'pass' : 'red', 'check', installOutput, checkOutput);
- } catch { return checkResult('unverified', 'check', installOutput, checkOutput); }
+ if (run.error?.code === 'ETIMEDOUT') return finish('unverified', 'check timed out');
+ if (run.error) return finish('unverified', `check could not start (${run.error.code})`);
+ if (run.logError) return finish('unverified', `check output could not be saved (${run.logError.code})`);
+ if (run.status === null) return finish('unverified', 'check could not start (CHECK_RUNNER)');
+ return finish(run.status === 0 ? 'pass' : 'red', run.status === 0 ? 'check' : `check failed (exit ${run.status})`);
+ } catch { return finish('unverified', 'check could not complete'); }
finally { rmSync(scratch, { recursive: true, force: true }); }
}
@@ -136,7 +151,7 @@ function runPrivateCommand(root, env, command, timeout, logPath) {
try {
// The worker drains pipes even after its capture cap, so noisy successful commands still pass.
const run = spawnSync(process.execPath, [fileURLToPath(new URL('./private-check-worker.js', import.meta.url))], {
- cwd: root, env, input: JSON.stringify({ command, timeout, pidFile }), encoding: 'utf8',
+ cwd: root, env, input: JSON.stringify({ command, timeout, pidFile, logPath }), encoding: 'utf8',
timeout: timeout + 1000, killSignal: 'SIGKILL', maxBuffer: 64 * 1024 * 1024,
});
if (run.error) return { status: null, error: { code: run.error.code }, output: '' };
@@ -153,10 +168,183 @@ function runPrivateCommand(root, env, command, timeout, logPath) {
}
}
-/** Summarize both private command outputs for verifier and doctor diagnostics. */
-function checkResult(state, stage, installOutput, checkOutput) {
- const install = digestOf(installOutput) || '(no output)';
- const check = digestOf(checkOutput) || '(not run or no output)';
- const output = `install:\n${installOutput || '(no output)'}\ncheck:\n${checkOutput || '(not run or no output)'}`;
- return { state, green: state === 'pass', checked: true, stage, report: `install output:\n${install}\ncheck output:\n${check}`, output };
+const CHECK_LOG_READ_BYTES = 32 * 1024;
+const CHECK_LINE_SCAN_LIMIT = 64 * 1024;
+const CHECK_OVERSIZED_LINE = '[redacted output line exceeds 64 KiB safe-scan limit]';
+
+/** Replace a detected secret line without including its value in diagnostics. */
+function scanOutputLine(line, path, number) {
+ if (Buffer.byteLength(line, 'utf8') > CHECK_LINE_SCAN_LIMIT) return CHECK_OVERSIZED_LINE;
+ const findings = secretsIn([{ path, line: number, text: line }]);
+ if (!findings.length) return line;
+ const labels = findings.map(finding => finding.slice(0, finding.lastIndexOf(' at ')));
+ return `[redacted ${labels.join(', ')}]`;
+}
+
+/** Summarize bounded private command output for verifier and doctor diagnostics. */
+function secretScanned(output, path) {
+ return output.split('\n').map((line, index) => scanOutputLine(line, path, index + 1)).join('\n');
+}
+
+/** Stream one worker log into a private artifact while retaining only its bounded sanitized tail. */
+function streamSanitizedLog(path, fallback, label, writeArtifact) {
+ const decoder = new StringDecoder('utf8');
+ const tail = [];
+ let line = '';
+ let lineBytes = 0;
+ let lineNumber = 1;
+ let oversized = false;
+ let pending = '';
+ let sawOutput = false;
+ let finishedWithNewline = false;
+
+ /** Flush buffered sanitized text using complete synchronous writes. */
+ function flush() {
+ if (!pending || !writeArtifact) { pending = ''; return; }
+ const buffer = Buffer.from(pending, 'utf8');
+ let offset = 0;
+ while (offset < buffer.length) {
+ const written = writeArtifact(buffer, offset);
+ if (written <= 0) throw new Error('diagnostic artifact write made no progress');
+ offset += written;
+ }
+ pending = '';
+ }
+
+ /** Retain one bounded tail line and append its scanned form to the artifact buffer. */
+ function emitLine(newline) {
+ const sanitized = oversized ? CHECK_OVERSIZED_LINE : scanOutputLine(line, label, lineNumber);
+ const bounded = sanitized.length > 2000
+ ? `${sanitized.slice(0, 1000)}…[line truncated]…${sanitized.slice(-1000)}` : sanitized;
+ tail.push(bounded);
+ if (tail.length > 40) tail.shift();
+ pending += sanitized + (newline ? '\n' : '');
+ sawOutput = true;
+ line = '';
+ lineBytes = 0;
+ oversized = false;
+ lineNumber += 1;
+ if (pending.length >= CHECK_LOG_READ_BYTES) flush();
+ }
+
+ /** Consume decoded text without retaining an oversized logical line. */
+ function consume(text) {
+ let start = 0;
+ while (start < text.length) {
+ const end = text.indexOf('\n', start);
+ const stop = end < 0 ? text.length : end;
+ if (!oversized) {
+ const part = text.slice(start, stop);
+ const partBytes = Buffer.byteLength(part, 'utf8');
+ if (lineBytes + partBytes > CHECK_LINE_SCAN_LIMIT) {
+ line = '';
+ lineBytes = 0;
+ oversized = true;
+ } else {
+ line += part;
+ lineBytes += partBytes;
+ }
+ }
+ if (end < 0) {
+ if (stop > start) finishedWithNewline = false;
+ break;
+ }
+ emitLine(true);
+ finishedWithNewline = true;
+ start = end + 1;
+ }
+ }
+
+ /** Decode a bounded fallback capture when the worker log is unavailable. */
+ function feedFallback(text) {
+ consume(decoder.write(Buffer.from(text, 'utf8')));
+ consume(decoder.end());
+ if (line || oversized) emitLine(false);
+ else if (finishedWithNewline) { tail.push(''); if (tail.length > 40) tail.shift(); }
+ }
+
+ if (path && existsSync(path)) {
+ const input = openSync(path, 'r');
+ const chunk = Buffer.alloc(CHECK_LOG_READ_BYTES);
+ try {
+ let count;
+ while ((count = readSync(input, chunk, 0, chunk.length, null)) > 0) {
+ consume(decoder.write(chunk.subarray(0, count)));
+ }
+ consume(decoder.end());
+ if (line || oversized) emitLine(false);
+ else if (finishedWithNewline) { tail.push(''); if (tail.length > 40) tail.shift(); }
+ } finally { closeSync(input); }
+ } else feedFallback(fallback);
+ flush();
+ return { tail, sawOutput };
+}
+
+/** Persist a sanitized full diagnostic outside the temporary checkout so a refusal can name it. */
+function checkResult(state, stage, installCapture, checkCapture, { root = '', item = {}, installLogPath = '', checkLogPath = '' } = {}) {
+ const boundedInstall = secretScanned(installCapture, 'check install capture');
+ const boundedCheck = secretScanned(checkCapture, 'frozen check capture');
+ const install = digestOf(boundedInstall) || '(no output)';
+ const check = digestOf(boundedCheck) || '(not run or no output)';
+ const report = `install output:\n${install}\ncheck output:\n${check}`;
+ let outputPath = null;
+ let outputError = null;
+ let artifactFd = null;
+ if (state !== 'pass' && root) {
+ try {
+ const common = policyGit(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']).trim();
+ const directory = join(common, 'pullboard', 'check-output');
+ mkdirSync(directory, { recursive: true, mode: 0o700 });
+ outputPath = join(directory, `check-${item.item_id ?? 'unknown'}-${String(item.item_commit ?? 'unknown').slice(0, 12)}-${randomUUID()}.log`);
+ artifactFd = openSync(outputPath, 'wx', 0o600);
+ } catch (error) {
+ outputPath = null;
+ outputError = error.code ?? 'CHECK_DIAGNOSTIC';
+ }
+ }
+ /** Write complete text to the private artifact, handling short synchronous writes. */
+ const appendArtifact = (text) => {
+ if (artifactFd === null) return;
+ const buffer = Buffer.from(text, 'utf8');
+ let offset = 0;
+ while (offset < buffer.length) {
+ const written = writeSync(artifactFd, buffer, offset, buffer.length - offset);
+ if (written <= 0) throw new Error('diagnostic artifact write made no progress');
+ offset += written;
+ }
+ };
+ /** 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 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;
+ });
+ if (!result.sawOutput) appendArtifact(`${absentText}\n`);
+ return result;
+ };
+ let installLog;
+ let checkLog;
+ try {
+ installLog = writePhase('install', installLogPath, installCapture, 'check install output', '(no output)');
+ appendArtifact('\n');
+ checkLog = writePhase('check', checkLogPath, checkCapture, 'frozen check output',
+ !checkLogPath && !checkCapture ? '(not run or no output)' : '(no output)');
+ if (artifactFd !== null) closeSync(artifactFd);
+ } catch (error) {
+ if (artifactFd !== null) { try { closeSync(artifactFd); } catch { /* The descriptor may already be closed. */ } }
+ if (outputPath) { try { rmSync(outputPath, { force: true }); } catch { /* Keep the refusal typed if cleanup also fails. */ } }
+ outputPath = null;
+ outputError = error.code ?? 'CHECK_DIAGNOSTIC';
+ installLog = streamSanitizedLog('', installCapture, 'check install capture', null);
+ checkLog = streamSanitizedLog('', checkCapture, 'frozen check capture', null);
+ }
+ const relevant = stage.startsWith('install') ? installLog : (checkLog.sawOutput ? checkLog : installLog);
+ const outputTail = relevant.tail.map((line) => line.length > 2000
+ ? `${line.slice(0, 1000)}…[line truncated]…${line.slice(-1000)}` : line).join('\n') || '(no output)';
+ const failure = state === 'red' ? 'failed' : /timed out/u.test(stage) ? 'timed out'
+ : /could not start/u.test(stage) ? "couldn't start" : state === 'unverified' ? 'could not be verified' : 'passed';
+ const output = `install output:\n${boundedInstall || '(no output)'}\ncheck output:\n${boundedCheck || '(not run or no output)'}`;
+ return { state, green: state === 'pass', checked: true, stage, failure, report, output, outputTail, outputPath, outputError };
}
diff --git a/test/e2e.test.js b/test/e2e.test.js
index fad5b0c7..1dbadd94 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -12,6 +12,8 @@ import {
readFileSync,
realpathSync,
rmSync,
+ statSync,
+ symlinkSync,
writeFileSync,
} from 'node:fs';
import { tmpdir } from 'node:os';
@@ -637,7 +639,7 @@ test('a red gate refuses submit [V4]', () => {
assert.match(refused.err, /GATE_RED/);
});
-test('verify runs at the submitted commit, against the criterion frozen at claim [V3, V7, V9]', () => {
+test('verify runs at the submitted commit, against the criterion frozen at claim [V3, V7, V9, V19]', () => {
const box = project();
box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1', '--criterion', 'renders a heading');
box.run(box.web, 'claim', '1');
@@ -1820,6 +1822,114 @@ test('accept without check.install keeps CHECK_RED and names the missing setting
assert.match(error.next, /^reject with the failing behavior or ask the builder to fix and resubmit/);
});
+test('check refusal shows secret-scanned failure lines and a durable full-output file [V18,V2]', () => {
+ const planted = 'sk-proj-' + 'a'.repeat(40);
+ const box = privateCheckSubmission({ check: `i=1; while [ "$i" -le 45 ]; do echo "CHECK-LINE-$i"; i=$((i + 1)); done; printf '%s\\n' 'ASSERTION: expected 4, received 3' 'OPENAI_KEY=${planted}'; exit 1` });
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the frozen assertion fails', '--json');
+ assert.equal(refused.code, 1, refused.err);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_RED');
+ assert.match(error.message, /check failed \(exit 1\)/);
+ assert.match(error.message, /ASSERTION: expected 4, received 3/);
+ assert.match(error.message, /redacted OpenAI key/);
+ assert.doesNotMatch(error.message, new RegExp(planted));
+ assert.match(error.message, /last output lines \(up to 40\)/);
+ const tail = /last output lines \(up to 40\):\n([\s\S]*?)\nfull output file:/.exec(error.message)?.[1] ?? '';
+ assert.match(tail, /CHECK-LINE-9/);
+ assert.doesNotMatch(tail, /CHECK-LINE-8/);
+ assert.match(tail, /CHECK-LINE-45/);
+ const artifact = /full output file: ([^\n]+)/.exec(error.message)?.[1];
+ assert.ok(artifact && existsSync(artifact), `missing diagnostic artifact: ${artifact}`);
+ const saved = readFileSync(artifact, 'utf8');
+ assert.match(saved, /ASSERTION: expected 4, received 3/);
+ assert.match(saved, /redacted OpenAI key/);
+ assert.doesNotMatch(saved, new RegExp(planted));
+ assert.equal((statSync(artifact).mode & 0o777), 0o600, 'private verifier artifacts are owner-readable only');
+});
+
+test('check refusal stays typed and includes bounded diagnostics when artifact storage is unavailable [V18,V19]', () => {
+ const box = privateCheckSubmission({ check: 'echo diagnostic-tail-marker; exit 1' });
+ const gitDir = box.git(box.repo, 'rev-parse', '--git-common-dir');
+ const outputDirectory = join(box.repo, gitDir, 'pullboard');
+ mkdirSync(outputDirectory, { recursive: true });
+ writeFileSync(join(outputDirectory, 'check-output'), 'blocks the diagnostic directory');
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the failing check cannot save a full artifact', '--json');
+ assert.equal(refused.code, 1);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_RED');
+ assert.match(error.message, /diagnostic-tail-marker/);
+ assert.match(error.message, /full output file: \(unavailable: EEXIST\)/);
+ assert.match(error.next, /^reject with the failing behavior/);
+});
+
+test('private worker drains noisy output and reports a failed log path instead of timing out [V18,V19]', () => {
+ const box = project();
+ const worker = resolve(import.meta.dirname, '../src/private-check-worker.js');
+ const output = spawnSync(process.execPath, [worker], {
+ input: JSON.stringify({ command: `node -e 'process.stdout.write("START-WORKER\\n"); process.stdout.write(Buffer.alloc(20 * 1024 * 1024, 120)); process.stdout.write("\\nEND-WORKER\\n")'`,
+ timeout: 10_000, pidFile: join(box.dir, 'worker.pid'), logPath: join(box.dir, 'missing', 'check.log') }),
+ encoding: 'utf8', timeout: 15_000, maxBuffer: 64 * 1024 * 1024,
+ });
+ assert.equal(output.status, 0, output.stderr);
+ const result = JSON.parse(output.stdout);
+ assert.equal(result.status, 0);
+ assert.deepEqual(result.error, null);
+ assert.deepEqual(result.logError, { code: 'ENOENT' });
+ assert.match(result.output, /START-WORKER/);
+ assert.match(result.output, /END-WORKER/);
+ assert.match(result.output, /output capped at 8 MiB; middle omitted/);
+});
+
+test('full multiline output artifact streams beyond the bounded capture under a constrained heap [V18,V2]', () => {
+ const box = privateCheckSubmission({ check: `node -e 'const fs=require("node:fs"); const line=Buffer.alloc(1023,120); fs.writeSync(1,"START-FULL\\n"); for(let i=0;i<9000;i++){fs.writeSync(1,line);fs.writeSync(1,"\\n")} fs.writeSync(1,"TAIL-FULL-OUTPUT\\n"); process.exitCode=1'` });
+ box.env.NODE_OPTIONS = '--max-old-space-size=96';
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the full failing check output is retained', '--json');
+ assert.equal(refused.code, 1, refused.err);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_RED');
+ assert.match(error.message, /TAIL-FULL-OUTPUT/);
+ const artifact = /full output file: ([^\n]+)/.exec(error.message)?.[1];
+ assert.ok(artifact && existsSync(artifact));
+ const saved = readFileSync(artifact, 'utf8');
+ assert.ok(Buffer.byteLength(saved) > 8 * 1024 * 1024);
+ assert.match(saved, /START-FULL/);
+ assert.match(saved, /TAIL-FULL-OUTPUT/);
+ assert.equal((statSync(artifact).mode & 0o777), 0o600);
+});
+
+test('oversized single output lines are discarded with an explicit safe-scan marker [V18,V2]', () => {
+ const planted = 'sk-proj-' + 'z'.repeat(40);
+ const box = privateCheckSubmission({ check: `node -e 'process.stdout.write("BEGIN-LONG\\n"+"😀".repeat(17*1024)+"${planted}\\nTAIL-LONG\\n");process.exitCode=1'` });
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the oversized diagnostic line must fail closed', '--json');
+ assert.equal(refused.code, 1, refused.err);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_RED');
+ assert.match(error.message, /redacted output line exceeds 64 KiB safe-scan limit/);
+ assert.match(error.message, /TAIL-LONG/);
+ const artifact = /full output file: ([^\n]+)/.exec(error.message)?.[1];
+ assert.ok(artifact && existsSync(artifact));
+ const saved = readFileSync(artifact, 'utf8');
+ assert.match(saved, /redacted output line exceeds 64 KiB safe-scan limit/);
+ assert.doesNotMatch(saved, new RegExp(planted));
+});
+
+test('stream scanning handles UTF-8 and a secret split across read chunks [V18,V2]', () => {
+ const planted = 'sk-proj-' + 'b'.repeat(40);
+ const box = privateCheckSubmission({ check: `node -e 'const fs=require("node:fs"); fs.writeSync(1,"x".repeat(32766)+"😀\\n"); fs.writeSync(1,"x".repeat(32762)+"${planted}\\nTAIL-CHUNK\\n"); process.exitCode=1'` });
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the streamed scanner handles chunk boundaries', '--json');
+ assert.equal(refused.code, 1, refused.err);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_RED');
+ assert.match(error.message, /redacted OpenAI key/);
+ const artifact = /full output file: ([^\n]+)/.exec(error.message)?.[1];
+ assert.ok(artifact && existsSync(artifact));
+ const saved = readFileSync(artifact, 'utf8');
+ assert.match(saved, /😀/);
+ assert.match(saved, /redacted OpenAI key/);
+ assert.doesNotMatch(saved, new RegExp(planted));
+ assert.match(saved, /TAIL-CHUNK/);
+});
+
test('accept reports failed install as CHECK_UNVERIFIED with an output digest [V18,V2]', () => {
const box = privateCheckSubmission({ install: 'echo install-failed; exit 9', check: 'true' });
const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'install must complete before verification', '--json');
@@ -1847,6 +1957,12 @@ test('private check digest keeps install and noisy check output in separate sect
assert.match(proof.report, /check output:[\s\S]*check-failed/);
});
+test('a submission without a frozen check keeps the no-check pass path [V18,V2]', () => {
+ assert.deepEqual(checkAtCommit('/missing/private/repository', {}), {
+ state: 'pass', green: true, checked: false, report: '',
+ });
+});
+
test('accept runs a successful frozen check that writes a file larger than the log cap [V18,V2]', () => {
const box = privateCheckSubmission({ check: 'mkdir -p web/.deps; node -e \'require("node:fs").writeFileSync("web/.deps/check.bin", Buffer.alloc(20 * 1024 * 1024)); console.log("large-check-file-written")\'' });
const accepted = box.run(box.review, 'verify', '1', 'accept', '--note', 'the check wrote its real 20 MiB artifact', '--json');
@@ -1882,16 +1998,34 @@ test('a successful noisy check drains beyond the log cap and keeps bounded head
});
test('accept reports a frozen check timeout as CHECK_UNVERIFIED [V18,V2]', () => {
- const box = privateCheckSubmission({ timeout: '100ms', check: 'case "$PULLBOARD_HOME" in */pullboard-criterion-*/home/.pullboard) while :; do :; done;; *) exit 1;; esac' });
+ const box = privateCheckSubmission({ timeout: '100ms', check: 'echo timeout-marker; case "$PULLBOARD_HOME" in */pullboard-criterion-*/home/.pullboard) while :; do :; done;; *) exit 1;; esac' });
const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the frozen check exceeded its configured timeout', '--json');
assert.equal(refused.code, 1);
const error = JSON.parse(refused.out).error;
assert.equal(error.code, 'CHECK_UNVERIFIED');
assert.match(error.message, /check timed out/);
+ assert.match(error.message, /timeout-marker/);
+ assert.match(error.message, /full output file:/);
assert.match(error.message, /output digest/);
assert.match(error.next, /^restore the install or check environment, then retry verification/);
});
+test('a frozen check whose shell cannot start is identified as a startup failure [V18,V2]', () => {
+ const box = privateCheckSubmission({ check: 'echo forbidden-shell-ran' });
+ const isolatedPath = join(box.dir, 'git-only-path');
+ mkdirSync(isolatedPath);
+ const gitPath = execFileSync('which', ['git'], { encoding: 'utf8' }).trim();
+ symlinkSync(gitPath, join(isolatedPath, 'git'));
+ box.env.PATH = isolatedPath;
+ const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the shell is unavailable', '--json');
+ assert.equal(refused.code, 1, refused.err);
+ const error = JSON.parse(refused.out).error;
+ assert.equal(error.code, 'CHECK_UNVERIFIED');
+ assert.match(error.message, /check could not start \(ENOENT\)/);
+ assert.doesNotMatch(error.message, /forbidden-shell-ran/);
+ assert.match(error.message, /full output file:/);
+});
+
test('accept reports a frozen install timeout before running the check [V18,V2]', () => {
const box = privateCheckSubmission({ timeout: '100ms', install: 'echo install-started; while :; do :; done', check: 'echo forbidden-check-ran' });
const refused = box.run(box.review, 'verify', '1', 'accept', '--note', 'the install must finish within its frozen deadline', '--json');