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): account generated affected phases safely [C7,V4]

Corey Olson8f947e1bd5bb
diff --git a/src/gate-stages.js b/src/gate-stages.js
index eb1d1784..91ab9bf3 100644
--- a/src/gate-stages.js
+++ b/src/gate-stages.js
@@ -6,6 +6,23 @@ import {
} from 'node:fs';
import { join } from 'node:path';
+/**
+ * Preserve accounting for the generated landing gate plus affected phase. Both phase bodies must
+ * already be readable without groups; arbitrary subshells still have no guessed account [C7,V4].
+ */
+export function gateStages(command) {
+ const source = String(command).trim();
+ const separator = '\n) && ';
+ const boundary = source.lastIndexOf(separator);
+ if (!source.startsWith('(\n') || boundary < 0) return ordinaryStages(source);
+ const gate = ordinaryStages(source.slice(2, boundary));
+ const affected = ordinaryStages(source.slice(boundary + separator.length));
+ if (!gate || !affected) return null;
+ gate[0] = { ...gate[0], groupStart: true };
+ gate[gate.length - 1] = { ...gate.at(-1), groupEnd: true };
+ return [...gate, ...affected];
+}
+
/**
* Split a gate command into its top-level stages, the commands joined by `&&`, `||`, `;` or a newline,
* and each stage into its pipeline components, the commands joined by `|`. Anything the split cannot
@@ -15,7 +32,7 @@ import { join } from 'node:path';
* @param {string} command
* @returns {Array<{ text: string, op: string, pipeline: string[] }> | null}
*/
-export function gateStages(command) {
+function ordinaryStages(command) {
const source = String(command).trim();
const stages = [];
let current = '';
@@ -87,8 +104,8 @@ export function stagedScript(stages, marker, pipes) {
+ `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=$?; `
- + `printf '\\n${marker} end ${index} %s\\n' "$pullboard_stage_status"; (exit "$pullboard_stage_status"); } ${stage.op}`;
+ return `${stage.groupStart ? '(\n' : ''}{ printf '\\n${marker} begin ${index}\\n'; {\n${body}\n}; pullboard_stage_status=$?; `
+ + `printf '\\n${marker} end ${index} %s\\n' "$pullboard_stage_status"; (exit "$pullboard_stage_status"); } ${stage.op}${stage.groupEnd ? '\n) &&' : ''}`;
}).join('\n');
}
diff --git a/src/land.js b/src/land.js
index 7ce9797d..917744c3 100644
--- a/src/land.js
+++ b/src/land.js
@@ -337,7 +337,12 @@ function completionAccount() {
let early = false;
let plan = null;
let topLevel = 0;
- const counts = {};
+ let counts = {};
+ let prior = true;
+ /** Require every completed TAP stream, not just the last appended phase, to account for its tests. */
+ const finished = () => !early && Number.isSafeInteger(plan) && plan > 0 && plan === topLevel && Number.isSafeInteger(counts.tests)
+ && Number.isSafeInteger(counts.pass) && Number.isSafeInteger(counts.fail) && (counts.cancelled ?? 0) === 0
+ && counts.pass + counts.fail + (counts.skipped ?? 0) + (counts.todo ?? 0) === counts.tests;
/** Recognize canonical incomplete accounts even when only a bounded line prefix is retained. */
const markerPrefix = (text) => {
if (/^(?:Landing gate stopped early after |Files not run: |Interrupted test files: )/u.test(text)) early = true;
@@ -347,6 +352,9 @@ function completionAccount() {
/** Consume one complete output line without retaining test output or diagnostic blocks. */
line(text) {
markerPrefix(text);
+ if (/^TAP version \d+\s*$/u.test(text) && (plan !== null || topLevel || Object.keys(counts).length)) {
+ prior = prior && finished(); plan = null; topLevel = 0; counts = {};
+ }
if (/^(?:not )?ok \d+\b/u.test(text)) topLevel++;
const planned = /^1\.\.(\d+)\s*$/u.exec(text);
if (planned) plan = Number(planned[1]);
@@ -355,10 +363,7 @@ function completionAccount() {
},
/** A complete plan accounts for every test and contains no interrupted or cancelled work. */
complete() {
- return !early && Number.isSafeInteger(plan) && plan > 0 && plan === topLevel && Number.isSafeInteger(counts.tests)
- && Number.isSafeInteger(counts.pass) && Number.isSafeInteger(counts.fail)
- && (counts.cancelled ?? 0) === 0
- && counts.pass + counts.fail + (counts.skipped ?? 0) + (counts.todo ?? 0) === counts.tests;
+ return prior && finished();
},
};
}
diff --git a/test/landing-stage-composition.test.js b/test/landing-stage-composition.test.js
new file mode 100644
index 00000000..7b2fb742
--- /dev/null
+++ b/test/landing-stage-composition.test.js
@@ -0,0 +1,60 @@
+/** Generated affected phases retain real shell boundaries without guessing opaque commands [C7,V4]. */
+import assert from 'node:assert/strict';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import { accountedFailures } from '../src/land.js';
+import { runShell } from '../src/shell-run.js';
+import { runFixtureGit } from './fixture-child.js';
+
+/** Build two genuine shell children with distinct TAP accounts and observable working directories. */
+function fixture(t) {
+ const root = realpathSync(mkdtempSync(join(tmpdir(), 'pullboard-affected-stages-')));
+ t.after(() => rmSync(root, { recursive: true, force: true }));
+ assert.equal(runFixtureGit(root, ['init', '-q']).status, 0);
+ mkdirSync(join(root, 'work'));
+ for (const [name, red] of [['floor', false], ['affected', true]]) {
+ const output = `TAP version 13\n${red ? 'not ok' : 'ok'} 1 - ${name}\n`
+ + (red ? ' ---\n location: test/red.test.js:1:1\n ...\n' : '')
+ + `1..1\n# tests 1\n# pass ${red ? 0 : 1}\n# fail ${red ? 1 : 0}\n`;
+ writeFileSync(join(root, `${name}.cjs`), `require('node:fs').writeFileSync(${JSON.stringify(join(root, `${name}.cwd`))}, process.cwd());\n`
+ + `process.stdout.write(${JSON.stringify(output)});\nprocess.exitCode = ${red ? 1 : 0};\n`);
+ }
+ return root;
+}
+
+/** Match the exact composition emitted by landing, using the actual declared Node runtime. */
+function composed(root, original) {
+ return runShell(root, `(\n${original}\n) && '${process.execPath}' affected.cjs`, { stages: true, pipefail: true });
+}
+
+test('generated phases retain original directory changes and separate affected failures [C7,V4]', t => {
+ const root = fixture(t);
+ const run = composed(root, `cd work && '${process.execPath}' ../floor.cjs`);
+ assert.equal(run.isGreen, false);
+ assert.equal(readFileSync(join(root, 'floor.cwd'), 'utf8'), join(root, 'work'));
+ assert.equal(readFileSync(join(root, 'affected.cwd'), 'utf8'), root);
+ assert.deepEqual(run.stages.map(stage => stage.status), [0, 0, 1]);
+ assert.deepEqual(accountedFailures(run, root), [{ file: 'test/red.test.js', name: 'affected' }]);
+});
+
+test('generated phases retain independent pipeline failures rather than borrowing TAP [C7,V4]', t => {
+ const root = fixture(t);
+ const bad = composed(root, `false | '${process.execPath}' affected.cjs`);
+ assert.equal(bad.isGreen, false);
+ assert.equal(bad.stages[0].pipeline[0].status, 1);
+ assert.equal(accountedFailures(bad, root), null);
+ const good = composed(root, `'${process.execPath}' floor.cjs | cat`);
+ assert.deepEqual(good.stages[0].pipeline.map(component => component.status), [0, 0]);
+ assert.deepEqual(accountedFailures(good, root), [{ file: 'test/red.test.js', name: 'affected' }]);
+});
+
+test('an exit in the configured phase cannot skip the affected phase or earn a waiver [C7,V4]', t => {
+ const root = fixture(t);
+ const run = composed(root, `'${process.execPath}' floor.cjs; exit 0`);
+ assert.equal(run.isGreen, false);
+ assert.equal(existsSync(join(root, 'affected.cwd')), true, 'the affected child actually executes');
+ assert.equal(run.stages[1].status, null, 'the interrupted original stage never gains an exit receipt');
+ assert.equal(accountedFailures(run, root), null);
+});