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(land): a pipeline failure is credited to its own output [B3,R3,C7]

Corey Olson891a423b158c
diff --git a/src/gate.js b/src/gate.js
index 07e31681..59f282ed 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -217,14 +217,16 @@ export function gateStages(command) {
* Wrap each stage so the shell prints its start and its exit status between private marker lines.
* Control flow is unchanged: each wrapper exits with its stage's status, and an `exit` inside a
* stage still ends the run, which leaves that stage without an end marker and so unaccounted.
- * A pipeline's components each append their own exit status to a private file instead of the
- * output, since a marker written into a pipe would land in the next component's input [B3,R3].
+ * A pipeline's components each keep their own exit status and their own standard output in
+ * private files instead of the run's output, since a marker written into a pipe would land in the
+ * next component's input. A failure is then credited only to the component that printed it [B3,R3].
*/
function stagedScript(stages, marker, pipes) {
- const quoted = `'${String(pipes).replaceAll("'", "'\\''")}'`;
- /** One component that records its own status, then exits with it so the pipeline is unchanged. */
- const component = (text, index, at) => `{ {\n${text}\n}; pullboard_pipe_status=$?; `
- + `printf '%s %s %s\\n' ${index} ${at} "$pullboard_pipe_status" >> ${quoted}; (exit "$pullboard_pipe_status"); }`;
+ /** Quote one private file of a component for the shell. */
+ const file = (index, at, kind) => `'${join(String(pipes), `${index}-${at}.${kind}`).replaceAll("'", "'\\''")}'`;
+ /** One component that records its own status and output, then exits with that status. */
+ const component = (text, index, at) => `{ { {\n${text}\n}; printf '%s\\n' "$?" >> ${file(index, at, 'status')}; } | tee ${file(index, at, 'out')}; `
+ + `pullboard_pipe_status=$(tail -n 1 ${file(index, at, 'status')} 2>/dev/null); (exit "\${pullboard_pipe_status:-125}"); }`;
return stages.map((stage, index) => {
const body = stage.pipeline.length > 1 ? stage.pipeline.map((text, at) => component(text, index, at)).join(' | ') : stage.text;
return `{ printf '\\n${marker} begin ${index}\\n'; {\n${body}\n}; pullboard_stage_status=$?; `
@@ -233,19 +235,21 @@ function stagedScript(stages, marker, pipes) {
}
/**
- * Read each pipeline component's recorded status. A component that recorded none, or more than one,
- * stays null, so a line forged into the private file can only make its stage unaccounted [B3,R3].
+ * Read each pipeline component's own status and, when it failed, its own output. A component that
+ * recorded no status, or more than one, has a null status, so a line forged into its private file
+ * can only make its stage unaccounted [B3,R3].
*/
function readPipes(split, pipes) {
- const records = new Map();
- const text = existsSync(pipes) ? readFileSync(pipes, 'utf8') : '';
- for (const line of text.split('\n')) {
- const found = /^(\d+) (\d+) (\d+)$/u.exec(line);
- if (found) records.set(`${found[1]} ${found[2]}`, [...(records.get(`${found[1]} ${found[2]}`) ?? []), Number(found[3])]);
- }
- return split.map((stage, index) => (stage.pipeline.length > 1
- ? stage.pipeline.map((_, at) => { const seen = records.get(`${index} ${at}`) ?? []; return seen.length === 1 ? seen[0] : null; })
- : null));
+ /** Read one private component file, or null when the component never wrote it. */
+ const read = (index, at, kind) => {
+ const path = join(pipes, `${index}-${at}.${kind}`);
+ return existsSync(path) ? readFileSync(path, 'utf8') : null;
+ };
+ return split.map((stage, index) => (stage.pipeline.length > 1 ? stage.pipeline.map((_, at) => {
+ const lines = (read(index, at, 'status') ?? '').split('\n').filter(Boolean);
+ const status = lines.length === 1 && /^\d+$/u.test(lines[0]) ? Number(lines[0]) : null;
+ return { status, output: status ? read(index, at, 'out') : null };
+ }) : null));
}
/** Cut a staged run's output back to the command's own lines and each stage's lines and status. */
@@ -278,7 +282,7 @@ function readStages(output, marker, count) {
* @param {string} root
* @param {string} command
* @param {{ pipefail?: boolean, env?: NodeJS.ProcessEnv, stages?: boolean }} [options] - Gate-only pipefail, additional child environment values and per-stage accounting.
- * @returns {{ isGreen: boolean, output: string, seconds: number, sandboxBlocked: string|null, stages?: Array<{ status: number|null, output: string, pipeline?: Array<number|null> }> | null }}
+ * @returns {{ isGreen: boolean, output: string, seconds: number, sandboxBlocked: string|null, stages?: Array<{ status: number|null, output: string, pipeline?: Array<{ status: number|null, output: string|null }> }> | null }}
*/
export function runShell(root, command, { pipefail = false, env = {}, stages = false } = {}) {
const started = Date.now();
@@ -294,13 +298,12 @@ export function runShell(root, command, { pipefail = false, env = {}, stages = f
}
const split = stages ? gateStages(command) : null;
const marker = `PULLBOARD_STAGE_${randomUUID().replaceAll('-', '')}`;
- const pipeDirectory = split?.some((stage) => stage.pipeline.length > 1) ? mkdtempSync(join(tmpdir(), 'pullboard-pipes-')) : null;
- const pipes = pipeDirectory ? join(pipeDirectory, 'status') : null;
+ const pipes = split?.some((stage) => stage.pipeline.length > 1) ? mkdtempSync(join(tmpdir(), 'pullboard-pipes-')) : null;
// Newlines, not spaces, around the command, so a trailing comment in it cannot swallow the `)`.
const result = spawnSync(`${prefix}(\n${split ? stagedScript(split, marker, pipes) : command}\n) 2>&1`, options);
invalidateGitFacts();
const pipeStatuses = pipes ? readPipes(split, pipes) : null;
- if (pipeDirectory) rmSync(pipeDirectory, { recursive: true, force: true });
+ if (pipes) rmSync(pipes, { recursive: true, force: true });
const raw = `${result.stdout ?? ''}${result.stderr ?? ''}`;
const seconds = Math.round((Date.now() - started) / 1000);
const blocked = (output) => (result.status === 0 ? null : sandboxBlockedOperation(root, output));
diff --git a/src/land.js b/src/land.js
index eb0124b7..0dfdbd07 100644
--- a/src/land.js
+++ b/src/land.js
@@ -278,15 +278,21 @@ export function tapFailures(output, root) {
* The failures that explain a red run, or null when anything else may have failed: the command
* could not be split into stages, a stage did not finish, a stage exited other than 0 without
* exactly 1 and a complete TAP account of its failures, or a pipeline in a stage had a component
- * that left no status or a second failing component. Waivers only ever subtract these [B3,R3].
+ * that left no status or failed without its own complete TAP account. Waivers only ever subtract
+ * these [B3,R3].
*/
export function accountedFailures(gate, root) {
if (gate.isGreen || !Array.isArray(gate.stages) || !gate.stages.length) return null;
const failures = [];
for (const stage of gate.stages) {
if (!Number.isInteger(stage.status)) return null;
- // In a pipeline every component's own status counts: at most one may fail, and only with exit 1 [B3,R3].
- if (stage.pipeline !== undefined && !pipelineAccounted(stage.pipeline)) return null;
+ if (stage.pipeline !== undefined) {
+ // In a pipeline each failing component must explain itself; a forwarded account credits no one else [B3,R3].
+ const own = pipelineFailures(stage.pipeline, root);
+ if (!own || (stage.status === 0) !== (own.length === 0)) return null;
+ failures.push(...own);
+ continue;
+ }
if (stage.status === 0) continue;
const own = stage.status === 1 ? tapFailures(stage.output ?? '', root) : null;
if (!own) return null;
@@ -296,13 +302,20 @@ export function accountedFailures(gate, root) {
}
/**
- * True when a stage's pipeline statuses leave one place a failure can come from. A producer that
- * fails beside a failing TAP consumer is an independent red no waiver names, so it voids the run.
+ * The failures a pipeline's components account for themselves, or null. Every component must have
+ * recorded its status, and every failing one must exit exactly 1 with a complete TAP account in its
+ * own output. A setup step that fails beside a consumer printing a waived test's TAP has no account
+ * of its own, so it is an independent red no waiver names, and it voids the run.
*/
-function pipelineAccounted(statuses) {
- if (!Array.isArray(statuses) || statuses.some((status) => !Number.isInteger(status))) return false;
- const failed = statuses.filter((status) => status !== 0);
- return failed.length === 0 || (failed.length === 1 && failed[0] === 1);
+function pipelineFailures(components, root) {
+ if (!Array.isArray(components) || components.some((entry) => !Number.isInteger(entry?.status))) return null;
+ const failures = [];
+ for (const { status, output } of components.filter((entry) => entry.status !== 0)) {
+ const own = status === 1 ? tapFailures(output ?? '', root) : null;
+ if (!own) return null;
+ failures.push(...own);
+ }
+ return failures;
}
/**
diff --git a/test/land.test.js b/test/land.test.js
index 2c00e95e..b9942875 100644
--- a/test/land.test.js
+++ b/test/land.test.js
@@ -888,6 +888,38 @@ test("a person's waiver lets a submit and a landing gate through only the waived
assert.match(healthyPipeSubmit.out, line, 'a healthy producer leaves only the waived test at submit');
assert.match(healthyPipeSubmit.out, /waived, not green/u);
+ // A failing component is credited only with the failures in its own output: a setup step that fails beside
+ // a consumer forwarding the waived TAP is unexplained, and a TAP producer piped through cat explains itself.
+ const forwarder = join(box.dir, 'pipeline-forwarder.cjs');
+ writeFileSync(forwarder, `process.stdin.resume(); process.stdin.on('end', () => { const child = require('node:child_process').spawnSync(${JSON.stringify(gateCommand)}, { shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8' }); process.stdout.write(child.stdout || ''); process.stderr.write(child.stderr || ''); process.exitCode = 0; });\n`);
+ setGate(`node ${JSON.stringify(setup)} | node ${JSON.stringify(forwarder)}`, 'chore: forward the waived tests behind a setup producer');
+ writeFileSync(broken, 'on\n');
+ const forwardRuns = readFileSync(runs, 'utf8').length;
+ const forwarded = box.run(box.repo, 'gate', '--landing', '--json');
+ assert.equal(readFileSync(runs, 'utf8').length, forwardRuns + 1, 'the failing setup producer really ran');
+ assert.match(gateLog(), /Error: separate setup stage failed/u, 'the setup producer failed on its own');
+ assert.match(gateLog(), /^# fail 1$/mu, 'the forwarded waived TAP is complete');
+ assert.equal(forwarded.code, 1, 'a failing setup producer is not explained by a consumer forwarding the waived tests');
+ assert.equal(JSON.parse(forwarded.out).waived, undefined, 'a forwarded account names no waived failures');
+ const forwardItem = itemWorktree(box, 5, FILES[3]);
+ assert.equal(commitFile(box, forwardItem.path, forwardItem.file, 'PASS\n', `feat(web): build land fixture ${forwardItem.item} [G1]`).status, 0);
+ const forwardedSubmit = box.run(forwardItem.path, 'submit', String(forwardItem.item), '--json');
+ assert.equal(JSON.parse(forwardedSubmit.out).error?.code, 'GATE_RED', 'a forwarded account refuses the submission');
+ assert.equal(readFileSync(runs, 'utf8').length, forwardRuns + 2, 'the submission ran the failing setup producer');
+ assert.ok(!events(box).some((event) => event.event_kind === 'fact' && event.item_id === forwardItem.item), 'a refused forwarded submission records nothing as waived');
+ rmSync(broken);
+ setGate(`${gateCommand} | cat`, 'chore: pipe the waived tests through cat');
+ const throughCat = box.run(box.repo, 'gate', '--landing', '--json');
+ assert.equal(throughCat.code, 0, `${throughCat.err}\n${throughCat.out}`);
+ assert.equal(JSON.parse(throughCat.out).green, false, 'a waived pipeline is never reported green');
+ assert.deepEqual(JSON.parse(throughCat.out).waived.map((entry) => [entry.file, entry.waiver]), [[FILES[0], waiver.id]], 'the TAP producer explains its own failure');
+ const catItem = itemWorktree(box, 6, FILES[3]);
+ assert.equal(commitFile(box, catItem.path, catItem.file, 'PASS\n', `feat(web): build land fixture ${catItem.item} [G1]`).status, 0);
+ const catSubmit = box.run(catItem.path, 'submit', String(catItem.item));
+ assert.equal(catSubmit.code, 0, `${catSubmit.err}\n${catSubmit.out}`);
+ assert.match(catSubmit.out, line, 'a TAP producer piped through cat is waived at submit');
+ assert.match(catSubmit.out, /waived, not green/u);
+
// A real landing run does not stop early on a waived failure: every other file still runs, then the waiver subtracts it.
const laterRan = join(box.dir, 'later-file-ran');
const waivedFile = 'test/landing-waived.test.cjs';