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(check): pipefail exempts only as the first command [C7,V4]
Corey Olson31914230281d
diff --git a/src/check-mask.js b/src/check-mask.jsindex c114fd39..d4239d33 100644--- a/src/check-mask.js+++ b/src/check-mask.js@@ -75,30 +75,32 @@ function pipelines(command) {/*** Name the final stage of the first pipeline that would hide a check's exit status, or null when none does. A- * pipeline is exempt only when pipefail is on as it runs, or when its first stage prints a value captured earlier- * with NAME=$(...), the out=$(...) form this board uses; an untested capture excuses nothing. Pipefail is on only- * after a set -o pipefail (or set -euo pipefail) that always runs: it starts a statement outside any ( ) subshell- * and follows no && or ||. A later set +o pipefail turns it off again [C7,V4].+ * pipeline is exempt in two cases only: the check's first command is set -o pipefail (alone or with other set flags,+ * so it always runs) and nothing in the check clears it with a set +o form; or the pipeline's first stage prints a+ * value captured earlier with NAME=$(...), the out=$(...) form this board uses. An untested capture excuses nothing.+ * A nested shell (sh -c, bash -c), eval or script file is not read: the rule reads the check's own text [C7,V4].** @param {string} command* @returns {string | null}*/function maskingStage(command) {+ const all = pipelines(command);+ const statements = all.filter(pipeline => command.slice(pipeline.start, pipeline.end).trim());+ const cleared = statements.some(pipeline => /^\s*set\s+(?:[-+]\S+\s+)*\+\S*o\s+pipefail\b/u.test(command.slice(pipeline.start, pipeline.end)));+ const first = statements[0];+ const pipefail = !cleared && first !== undefined && first.after === 'start' && !first.pipes.length+ && /^\s*set\s+(?:[-+]\S+\s+)*-\S*o\s+pipefail\b/u.test(command.slice(first.start, first.end));+ if (pipefail) return null;const captured = new Set();- let pipefail = false;- for (const pipeline of pipelines(command)) {- const text = command.slice(pipeline.start, pipeline.end);- const assignment = /^\s*(\w+)="?\$\(/u.exec(text);+ for (const pipeline of all) {+ const assignment = /^\s*(\w+)="?\$\(/u.exec(command.slice(pipeline.start, pipeline.end));if (assignment) captured.add(assignment[1]);- if (/^\s*set\s+(?:[-+]\S+\s+)*\+\S*o\s+pipefail\b/u.test(text)) pipefail = false;- else if (/^\s*set\s+(?:[-+]\S+\s+)*-\S*o\s+pipefail\b/u.test(text) && !pipeline.pipes.length- && pipeline.depth === 0 && ['start', ';', '\n', ')'].includes(pipeline.after)) pipefail = true;- if (!pipeline.pipes.length || pipefail) continue;- const first = command.slice(pipeline.start, pipeline.pipes[0]);- const tested = /^\s*(?:printf|echo)\b/u.test(first)- && [...first.matchAll(/\$\{?(\w+)\}?/gu)].some((match) => captured.has(match[1]));+ if (!pipeline.pipes.length) continue;+ const head = command.slice(pipeline.start, pipeline.pipes[0]);+ const tested = /^\s*(?:printf|echo)\b/u.test(head)+ && [...head.matchAll(/\$\{?(\w+)\}?/gu)].some((match) => captured.has(match[1]));if (tested) continue;- return /^\s*([^\s;&|)]+)/u.exec(command.slice(pipeline.pipes.at(-1) + 1))?.[1] ?? 'a later stage';+ return /^\s*([^\s;&|)}]+)/u.exec(command.slice(pipeline.pipes.at(-1) + 1))?.[1] ?? 'a later stage';}return null;}diff --git a/test/check.test.js b/test/check.test.jsindex e438377e..55a5e242 100644--- a/test/check.test.js+++ b/test/check.test.js@@ -346,14 +346,14 @@ 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);});-test('an untested capture does not excuse a later masked pipe [C7,V4]', () => {+test('a pipe into tail inside a subshell or after an assignment is refused [C7,V4]', () => {+ const masked = `node -e "console.log('proof-red'); process.exit(7)" | tail -n1`;// A capture exempts only a pipeline that tests the captured value; this one is never read (#812 review).- assert.equal(maskRefusal(`out=$(printf ok); node -e "console.log('proof-red'); process.exit(7)" | tail -n1`), 'CHECK_MASKS_EXIT');-});--test('a masked pipe inside a plain subshell is refused [C7,V4]', () => {- // A ( ) subshell exits with its last stage, so its pipes count; only a $( ) substitution hides them (#812 review).- assert.equal(maskRefusal(`(node -e "console.log('proof-red'); process.exit(7)" | tail -n1)`), 'CHECK_MASKS_EXIT');+ assert.equal(maskRefusal(`out=$(printf ok); ${masked}`), 'CHECK_MASKS_EXIT');+ assert.equal(maskRefusal(`name=value; ${masked}`), 'CHECK_MASKS_EXIT', 'after a plain assignment');+ // A ( ) subshell or { ; } group exits with its last stage, so its pipes count; only $( ) hides them (#812 review).+ assert.equal(maskRefusal(`(${masked})`), 'CHECK_MASKS_EXIT');+ assert.equal(maskRefusal(`{ ${masked}; }`), 'CHECK_MASKS_EXIT');});test("the board's own captured-output form is accepted [C7,V4]", () => {@@ -361,13 +361,16 @@ test("the board's own captured-output form is accepted [C7,V4]", () => {assert.equal(maskRefusal(`out=$(node -e "process.exit(1)" | tail -5); echo "$out" | grep -q ok`), null, 'a pipe inside the capture is not a check pipeline');});-test('pipefail counts only when its set always runs and is still on [C7,V4]', () => {+test('a check that turns pipefail off or sets it conditionally is refused [C7,V4]', () => {const masked = `node -e "console.log('proof-red'); process.exit(7)" | tail -n1`;// /bin/sh never runs this set, since false fails first, so the pipe still exits 0 (#812 review).assert.equal(maskRefusal(`false && set -o pipefail; ${masked}`), 'CHECK_MASKS_EXIT');assert.equal(maskRefusal(`set -o pipefail; set +o pipefail; ${masked}`), 'CHECK_MASKS_EXIT', 'a later set +o pipefail turns it off');assert.equal(maskRefusal(`(set -o pipefail); ${masked}`), 'CHECK_MASKS_EXIT', 'a subshell keeps its pipefail to itself');- assert.equal(maskRefusal(`set -euo pipefail\n${masked}`), null, 'a set that always runs keeps the producer exit');+ assert.equal(maskRefusal(`set -euo pipefail; set +eo pipefail; ${masked}`), 'CHECK_MASKS_EXIT', 'a set +o form that clears it');+ assert.equal(maskRefusal(`if true; then set -o pipefail; fi; ${masked}`), 'CHECK_MASKS_EXIT', 'a set inside an if is conditional');+ assert.equal(maskRefusal(`cd .; set -o pipefail; ${masked}`), 'CHECK_MASKS_EXIT', 'pipefail must be the first command');+ assert.equal(maskRefusal(`set -euo pipefail\n${masked}`), null, 'a first-command set that always runs keeps the producer exit');});test('a pipe inside a shell comment is not a pipeline [C7,V4]', () => {