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.

feat(check): refuse a check whose pipe hides its exit [C7,V4]

Corey Olson79c5c6558cdc
diff --git a/src/board.js b/src/board.js
index fa15d4b8..fd5eeed7 100644
--- a/src/board.js
+++ b/src/board.js
@@ -44,6 +44,7 @@ import {
storeTriggers,
} from './machine.js';
import { Refused } from './refused.js';
+import { refuseMaskedExit } from './check-mask.js';
import {
ROUTES,
canTake,
@@ -692,6 +693,7 @@ function checkRouted({ brief, route, criterion, check }) {
if (brief.length > BRIEF_LIMIT) {
throw new Refused('BRIEF_TOO_LONG', `the brief is ${brief.length} characters; keep it under ${BRIEF_LIMIT} and point to longer docs by path`);
}
+ refuseMaskedExit(check);
if (route === 'strong') return;
const sections = briefSections(brief);
const missing = [
diff --git a/src/check-mask.js b/src/check-mask.js
new file mode 100644
index 00000000..3be6f9e6
--- /dev/null
+++ b/src/check-mask.js
@@ -0,0 +1,61 @@
+/**
+ * Refuse a check whose pipeline would hide a red proof's exit status [C7,V4]. Kept out of board.js,
+ * which is already over the 1500-line cap (C9).
+ */
+import { Refused } from './refused.js';
+
+/**
+ * Blank out the text inside quotes, keeping its length and the quote marks, so a pipe, a word or
+ * the pipefail option inside quotes is never read as shell syntax [C7,V4].
+ *
+ * @param {string} command
+ * @returns {string}
+ */
+function unquoted(command) {
+ let out = '';
+ let quote = null;
+ for (const char of command) {
+ if (quote) {
+ if (char === quote) { quote = null; out += char; } else out += ' ';
+ } else if (char === '"' || char === "'") { quote = char; out += char; } else out += char;
+ }
+ return out;
+}
+
+/**
+ * Name the final pipeline stage that would hide a check's exit status, or null when none does. Any
+ * top-level pipe is masking unless the check sets pipefail as a real command (set -o pipefail or
+ * set -euo pipefail) or captures its proof first with out=$(...), the approved forms [C7,V4]. Pipes
+ * inside $( ) and || are not pipelines.
+ *
+ * @param {string} command
+ * @returns {string | null}
+ */
+function maskingStage(command) {
+ const shell = unquoted(command);
+ if (/(?:^|[\s;&(])\w+=\$\(/u.test(shell)) return null;
+ if (/(?:^|[;&(\n])\s*set\s+(?:-\S+\s+)*-\S*o\s+pipefail\b/u.test(shell)) return null;
+ let depth = 0;
+ let lastPipe = -1;
+ for (let i = 0; i < shell.length; i++) {
+ const char = shell[i];
+ if (char === '(') depth++;
+ else if (char === ')') depth--;
+ else if (char === '|' && shell[i + 1] === '|') i++;
+ else if (char === '|' && depth === 0) lastPipe = i;
+ }
+ if (lastPipe < 0) return null;
+ return /^\s*([^\s;&|)]+)/u.exec(command.slice(lastPipe + 1))?.[1] ?? 'a later stage';
+}
+
+/**
+ * Refuse a check whose pipeline would hide a red proof, naming the fix (CHECK_MASKS_EXIT) [C7,V4].
+ * Without the refusal the board records a failing command as passed.
+ *
+ * @param {string} check
+ */
+export function refuseMaskedExit(check) {
+ const stage = maskingStage(check ?? '');
+ if (stage === null) return;
+ throw new Refused('CHECK_MASKS_EXIT', `the check pipes its proof into ${stage}, so a failing proof still exits 0; set pipefail (set -o pipefail), run the proof alone, or capture the output first and test it: out=$(<proof>); printf '%s\\n' "$out" | grep -Eq '<expected>'`);
+}
diff --git a/src/next-steps.js b/src/next-steps.js
index 65c07c40..58726dfe 100644
--- a/src/next-steps.js
+++ b/src/next-steps.js
@@ -149,6 +149,7 @@ export const NEXT_STEPS = Object.freeze({
BAD_BROWSER_RESOURCE: 'request the "gate" resource with browser: true',
BAD_CHECK: 'ask your coordinator to set the check: pullboard edit <id> --check "<command>"',
BAD_CHECK_BASELINE: 'the coordinator sets the check again: pullboard edit <id> --check "<command>"',
+ CHECK_MASKS_EXIT: 'set the check to run its proof alone, or capture the output first and test it, then retry: pullboard edit <id> --check "<command>"',
BAD_CONFIG: 'fix pullboard.json as the message says, then commit it: git commit -m "chore: fix pullboard config" pullboard.json',
BAD_CURSOR: 'pass a nonnegative integer from the last response you received',
BAD_DECISION: 'choose accept or reject with a supported reason: pullboard verify <id> reject --reason TEST_FAILURE --note "<what failed>"',
diff --git a/test/check.test.js b/test/check.test.js
index 99b41bc6..b80d6a46 100644
--- a/test/check.test.js
+++ b/test/check.test.js
@@ -6,7 +6,7 @@ import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
import { after, test } from 'node:test';
-import { addItem, closeBoard, openBoard } from '../src/board.js';
+import { addItem, closeBoard, openBoard, validateItemAddition } from '../src/board.js';
import { prepareCheckBaseline } from '../src/check-baseline.js';
import { removeFixtureDirectory } from './cleanup-diagnostics.js';
@@ -303,3 +303,45 @@ test('check cleanup waits for every background writer [C7]', async () => {
await waitForFile(startedFile, child, `background writer ${baseline.request} started its check`);
assert.equal(existsSync(completedFile), false, 'the baseline is still writing after the test body reaches cleanup');
});
+
+test('a check that pipes its proof into tail is refused [C7,V4]', () => {
+ const board = openBoard(':memory:');
+ try {
+ const masked = { by: 'coordinator', lane: 'core', title: 'Masked proof', criterion: 'the proof passes', route: 'strong', check: `${shellWord(process.execPath)} -e "process.exit(1)" | tail -5` };
+ assert.throws(() => validateItemAddition(board, masked), (error) => error.code === 'CHECK_MASKS_EXIT'
+ && /pipes its proof into tail/u.test(error.message) && /pipefail/u.test(error.message));
+ } finally { closeBoard(board); }
+});
+
+test('a captured-output check is accepted [C7,V4]', () => {
+ const board = openBoard(':memory:');
+ try {
+ const captured = `out=$(${shellWord(process.execPath)} -e "process.exit(1)"); printf '%s\\n' "$out" | grep -Eq 'never'`;
+ assert.doesNotThrow(() => validateItemAddition(board, { by: 'coordinator', lane: 'core', title: 'Captured proof', criterion: 'the proof passes', route: 'strong', check: captured }));
+ } finally { closeBoard(board); }
+});
+
+/** Return the refusal code a check gets from the same validator add and edit use, or null when it passes [C7,V4]. */
+function maskRefusal(check) {
+ const board = openBoard(':memory:');
+ try {
+ validateItemAddition(board, { by: 'coordinator', lane: 'core', title: 'Mask probe', criterion: 'the proof passes', route: 'strong', check });
+ return null;
+ } catch (error) { return error.code; } finally { closeBoard(board); }
+}
+
+test('an uncaptured grep that decides the exit is refused [C7,V4]', () => {
+ assert.equal(maskRefusal('node -e "process.exit(1)" | grep -q x'), 'CHECK_MASKS_EXIT');
+});
+
+test('a pipe into xargs that hides the exit is refused [C7,V4]', () => {
+ assert.equal(maskRefusal('node -e "process.exit(1)" | xargs echo'), 'CHECK_MASKS_EXIT');
+});
+
+test('a bare pipefail mention in an echo does not stop a masked pipe being refused [C7,V4]', () => {
+ assert.equal(maskRefusal('echo pipefail; node -e "process.exit(1)" | tail -5'), 'CHECK_MASKS_EXIT');
+});
+
+test('a check that sets pipefail as a command is accepted [C7,V4]', () => {
+ assert.equal(maskRefusal('set -o pipefail; node -e "process.exit(1)" | tail -5'), null);
+});