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(gate): select tests only when projects opt in [V4,C7]

Corey Olson8bda4563f1f7
diff --git a/docs/formats.md b/docs/formats.md
index 7235641f..be8542e1 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -292,6 +292,10 @@ An approval of proposed new wording uses that same record: `source` is the exist
Migration preserves event rows and adds only schema objects that are missing.
+## Submit test selection
+
+`pullboard.json` may set `affectedTests` to a command prefix that runs selected test files. When it is absent, `submit` runs the configured `gate` in full. When present and the import graph can safely select a subset, Pullboard appends the selected file paths to this prefix; an uncertain selection still runs the full gate. For example, this repository opts in with `"affectedTests": "node bin/run-tests.js"`. Projects using another test framework can leave the setting out and keep their configured gate, such as `npm test`.
+
<!-- pass-rule:start -->
The `pass` event is emitted by `passDecision` only for the coordinator; another agent receives `COORDINATOR_ONLY`. Its event actor is the coordinator. The person receives the passed decision, while the event table records who performed the pass.
<!-- pass-rule:end -->
diff --git a/src/config.js b/src/config.js
index 82fc45f9..c74d7f02 100644
--- a/src/config.js
+++ b/src/config.js
@@ -153,6 +153,9 @@ export function configProblems(config) {
if (typeof config.spec !== 'string' || !config.spec) problems.push('"spec" names a file');
if (typeof config.practice !== 'string' || !config.practice) problems.push('"practice" names the doctrine file');
if (typeof config.gate !== 'string') problems.push('"gate" is a shell command, like "npm test"');
+ if (config.affectedTests !== undefined && (typeof config.affectedTests !== 'string' || !config.affectedTests.trim())) {
+ problems.push('"affectedTests" is a nonempty command prefix used to run selected test files');
+ }
if (!['any', COORDINATOR].includes(config.verify?.policy)) {
problems.push('"verify.policy" is "any" (any other agent) or "coordinator"');
}
diff --git a/src/gate.js b/src/gate.js
index 746d4c19..8183da45 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -11,7 +11,6 @@ import { Refused } from './refused.js';
import { takeResource } from './resources.js';
import { loadMachineSettings } from './settings.js';
import { selectAffectedTests } from './affected-tests.js';
-import { join } from 'node:path';
const STAMP = 'pullboard-gate-green';
const LOG = 'pullboard-gate.log';
@@ -198,7 +197,9 @@ function commandWord(value) {
*/
export async function runSubmitGate(root, config, { base, trunk, changed, check, onWait }) {
if (!config.gate.trim()) throw new Refused('NO_GATE', 'no gate configured; set "gate" in pullboard.json, e.g. "npm test"');
- const selection = selectAffectedTests(root, { base, trunk, changed });
+ const selection = config.affectedTests
+ ? selectAffectedTests(root, { base, trunk, changed })
+ : { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };
return await withGateSlot(root, () => {
const criterion = check ? runShell(root, check) : { isGreen: true, output: '', seconds: 0 };
const receipt = { command: check, green: criterion.isGreen, seconds: criterion.seconds, checked: Boolean(check) };
@@ -211,8 +212,7 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
if (selection.full) proof = fullGateRun(root, config);
else if (!selection.files.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log };
else {
- const runner = existsSync(join(root, 'bin/run-tests.js')) ? [process.execPath, 'bin/run-tests.js'] : [process.execPath, '--test'];
- const command = [...runner, ...selection.files.map(path => './' + path)].map(commandWord).join(' ');
+ const command = `${config.affectedTests.trimEnd()} ${selection.files.map(path => commandWord('./' + path)).join(' ')}`;
proof = { ...runShell(root, command), isCached: false, log };
}
writeFileSync(log, `item check:\n${criterion.output}\n${selection.full ? 'full gate' : 'affected tests'}:\n${proof.output}`);
diff --git a/test/e2e.test.js b/test/e2e.test.js
index d9e673e1..0ff748c8 100644
--- a/test/e2e.test.js
+++ b/test/e2e.test.js
@@ -288,7 +288,7 @@ test('submit needs a clean tree, nothing untracked, and the gate green at HEAD [
rmSync(join(box.web, 'web', 'stray.txt'));
const submitted = box.run(box.web, 'submit', '1');
assert.equal(submitted.code, 0, submitted.err);
- assert.match(submitted.out, /submitted #1 at [0-9a-f]{12}; no item check; full gate: no committed Node test files can be selected; gate green in \d+s/);
+ assert.match(submitted.out, /submitted #1 at [0-9a-f]{12}; no item check; full gate: affected-test selection is not enabled for this project; gate green in \d+s/);
const head = box.git(box.web, 'rev-parse', 'HEAD');
assert.equal(box.git(box.repo, 'rev-parse', `refs/pullboard/items/1/${head.slice(0, 12)}`), head, 'submit pins the commit');
});
diff --git a/test/release.test.js b/test/release.test.js
index 9505ccef..1645f96f 100644
--- a/test/release.test.js
+++ b/test/release.test.js
@@ -76,7 +76,7 @@ test('a packed release installs with no network and runs the whole loop from a f
git(builder, 'add', '-A');
git(builder, 'commit', '-q', '-m', 'feat(web): greet [G1]');
const commit = git(builder, 'rev-parse', 'HEAD');
- assert.match(pullboard(builder, 'submit', '1'), new RegExp(`submitted #1 at ${commit.slice(0, 12)}; no item check; full gate: no committed Node test files can be selected; gate green in \\d+s`));
+ assert.match(pullboard(builder, 'submit', '1'), new RegExp(`submitted #1 at ${commit.slice(0, 12)}; no item check; full gate: affected-test selection is not enabled for this project; gate green in \\d+s`));
assert.match(pullboard(repo, 'worktree', 'web'), /joined as web-2/);
const verifier = join(dir, 'repo-web-2');
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index 613b36fd..f0f8e675 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -9,6 +9,7 @@ import { tmpdir } from 'node:os';
import { dirname, join, resolve } from 'node:path';
import { after, test } from 'node:test';
import { selectAffectedTests } from '../src/affected-tests.js';
+import { configFromSource } from '../src/config.js';
const BIN = resolveBin();
const dirs = [];
@@ -163,7 +164,7 @@ test('submit runs the frozen check and affected test only; landing and explicit
const checkCommand = 'node -e "require(\'node:fs\').appendFileSync(process.env.ITEM_CHECK_MARKER, \'check\')"';
const checkMarker = join(box.dir, 'item-check.log');
box.env.ITEM_CHECK_MARKER = checkMarker;
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', spec: 'SPEC.md', verify: 'any', lease: '2h' }, null, 2));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test', spec: 'SPEC.md', verify: 'any', lease: '2h' }, null, 2));
put(box.root, 'SPEC.md', SPEC);
put(box.root, 'src/a.js', 'export const value = 1;\n');
put(box.root, 'test/a.test.js', [
@@ -221,9 +222,92 @@ test('submit runs the frozen check and affected test only; landing and explicit
assert.equal(existsSync(stamp), false, 'neither subset nor red full gate leaves a green full-gate stamp');
});
+test('a jest project submits with its own gate [V4,C7]', (t) => {
+ for (const optedIn of [false, true]) {
+ let box = privateRepo(t);
+ const gateMarker = join(box.dir, `jest-gate-${optedIn}.log`);
+ const testMarker = join(box.dir, `jest-tests-${optedIn}.log`);
+ box.env.JEST_GATE_MARKER = gateMarker;
+ box.env.JEST_TEST_MARKER = testMarker;
+ if (optedIn) box.env.FAIL_UNSELECTED = '1';
+ put(box.root, 'pullboard.json', JSON.stringify({
+ gate: 'npm test',
+ ...(optedIn ? { affectedTests: 'node test/jest-runner.js' } : {}),
+ }));
+ put(box.root, 'package.json', JSON.stringify({
+ type: 'module',
+ scripts: { test: 'node test/jest-runner.js' },
+ }));
+ put(box.root, 'src/a.js', 'export const value = 1;\n');
+ put(box.root, 'src/b.js', 'export const value = 8;\n');
+ put(box.root, 'test/jest-runner.js', [
+ "import { appendFileSync } from 'node:fs';",
+ "import { resolve } from 'node:path';",
+ "import { pathToFileURL } from 'node:url';",
+ "const files = process.argv.slice(2).length ? process.argv.slice(2) : ['./test/a.test.js', './test/b.test.js'];",
+ "appendFileSync(process.env.JEST_GATE_MARKER, process.argv.slice(2).length ? 'prefix\\n' : 'full\\n');",
+ 'const pending = [];',
+ "globalThis.describe = (_name, run) => run();",
+ "globalThis.it = (_name, run) => pending.push(Promise.resolve().then(run));",
+ "globalThis.expect = actual => ({ toBe(expected) { if (!Object.is(actual, expected)) throw new Error(`expected ${expected}, received ${actual}`); } });",
+ 'for (const file of files) await import(pathToFileURL(resolve(file)));',
+ 'const results = await Promise.allSettled(pending);',
+ 'const failed = results.find(result => result.status === \'rejected\');',
+ 'if (failed) { console.error(failed.reason); process.exitCode = 1; }',
+ ].join('\n') + '\n');
+ put(box.root, 'test/a.test.js', [
+ "import { appendFileSync } from 'node:fs';",
+ "import { value } from '../src/a.js';",
+ "describe('relative ESM imports', () => it('runs with jest-style globals', () => {",
+ " appendFileSync(process.env.JEST_TEST_MARKER, 'a\\n');",
+ ' expect(value).toBe(2);',
+ '}));',
+ ].join('\n') + '\n');
+ put(box.root, 'test/b.test.js', [
+ "import { appendFileSync } from 'node:fs';",
+ "import { value } from '../src/b.js';",
+ "describe('relative ESM imports', () => it('runs the other configured test', () => {",
+ " if (process.env.FAIL_UNSELECTED) throw new Error('unselected test ran');",
+ " appendFileSync(process.env.JEST_TEST_MARKER, 'b\\n');",
+ ' expect(value).toBe(8);',
+ '}));',
+ ].join('\n') + '\n');
+ commitAll(box);
+ box = builderRepo(box);
+ const added = box.coordinator('add', 'build', 'Jest-style project', '--check', 'true');
+ assert.equal(added.code, 0, added.err);
+ assert.equal(box.run('claim', '1').code, 0);
+ put(box.root, 'src/a.js', 'export const value = 2;\n');
+ commitAll(box, 'feat(core): change a jest project source [G1]');
+
+ const submitted = box.run('submit', '1', '--json');
+ assert.equal(submitted.code, 0, submitted.err || submitted.out);
+ const receipt = JSON.parse(submitted.out);
+ if (optedIn) {
+ assert.equal(receipt.gate.full, false);
+ assert.deepEqual(receipt.gate.files, ['test/a.test.js']);
+ assert.equal(readFileSync(gateMarker, 'utf8'), 'prefix\n', 'the configured prefix ran the selected file');
+ assert.equal(readFileSync(testMarker, 'utf8'), 'a\n', 'the unrelated test did not run');
+ } else {
+ assert.equal(receipt.gate.full, true);
+ assert.equal(readFileSync(gateMarker, 'utf8'), 'full\n', 'the configured project gate ran without opt-in');
+ assert.equal(readFileSync(testMarker, 'utf8'), 'a\nb\n', 'the full project gate ran both tests');
+ }
+ }
+});
+
+test('affectedTests accepts only a nonempty command prefix [V4,C7]', () => {
+ for (const affectedTests of ['', ' ', 4, false, null]) {
+ assert.throws(() => configFromSource(JSON.stringify({ affectedTests })), {
+ code: 'BAD_CONFIG', message: /affectedTests.*nonempty command prefix/u,
+ });
+ }
+ assert.equal(configFromSource(JSON.stringify({ affectedTests: 'node test/runner.js' })).affectedTests, 'node test/runner.js');
+});
+
test('submit without a frozen check reports no item check and still runs affected tests [V4,C7,V16]', (t) => {
let box = privateRepo(t);
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test' }));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test' }));
put(box.root, 'src/a.js', 'export const value = 1;\n');
put(box.root, 'test/a.test.js', "import '../src/a.js'; import { appendFileSync } from 'node:fs'; appendFileSync(process.env.AFFECTED_MARKER, 'ran');\n");
put(box.root, 'test/b.test.js', "import assert from 'node:assert/strict'; assert.fail('unrelated');\n");
@@ -248,7 +332,7 @@ test('submit without a frozen check reports no item check and still runs affecte
test('a red frozen item check refuses submit before affected tests run [V4,C7,V16]', (t) => {
let box = privateRepo(t);
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test' }));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test' }));
seedGraph(box);
box = builderRepo(box);
const added = box.coordinator('add', 'build', 'Frozen check', '--check', 'node -e "process.exit(process.env.CHECK_REFUSE ? 1 : 0)"');
@@ -301,7 +385,7 @@ test('CommonJS and nested package scopes fall back instead of silently missing r
for (const mode of ['topic parent', 'merge commit']) {
test(`affected tests include source changes carried by a ${mode} [V4,C7,V16]`, (t) => {
let box = privateRepo(t);
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test' }));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test' }));
seedGraph(box);
put(box.root, 'test/a.test.js', [
"import assert from 'node:assert/strict';",
@@ -387,7 +471,7 @@ test('affected selection reads old edges and all changes at the trunk merge base
test('affected submit includes branch changes made before the item claim [V4,C7,V16]', (t) => {
let box = privateRepo(t);
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test' }));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test' }));
seedGraph(box);
put(box.root, 'test/a.test.js', "import assert from 'node:assert/strict'; import { value } from '../src/middle.js'; assert.equal(value, 1);\n");
box = builderRepo(box);
@@ -408,7 +492,7 @@ test('affected submit includes branch changes made before the item claim [V4,C7,
for (const mode of ['deleted source', 'topic parent', 'merge commit']) {
test(`affected submit on main includes a ${mode} since its claim [V4,C7,V16]`, (t) => {
const box = privateRepo(t);
- put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', lanes: { core: { owns: ['src/', 'test/'], specs: ['G'] } } }));
+ put(box.root, 'pullboard.json', JSON.stringify({ gate: 'node --test', affectedTests: 'node --test', lanes: { core: { owns: ['src/', 'test/'], specs: ['G'] } } }));
seedGraph(box);
put(box.root, 'test/a.test.js', [
"import assert from 'node:assert/strict';",