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(gate): retain project submit invariants [C7,V4]

Corey Olsond8d6457e9550
diff --git a/docs/formats.md b/docs/formats.md
index 53745ece..8a91fbe0 100644
--- a/docs/formats.md
+++ b/docs/formats.md
@@ -357,6 +357,8 @@ Migration preserves event rows and adds only schema objects that are missing.
`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`.
+A project with `"submitGate": "landing"` can also set `"submitInvariants": ["test/guard.test.js"]` to run a small set of project guard files on every submit, even when uncertain selection defers the full suite. The list defaults to empty and requires the project's explicit `affectedTests` runner; no framework or test files are added by default. Submit reads the list and its runner from accepted main, so a candidate cannot remove or replace its required files. Named affected tests and invariants run once per file, with their paths and results in the receipt. Missing invariant files refuse the submit, and subset passes never stamp the full gate. The coordinator still runs the configured full suite at landing.
+
<!-- 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/cli.js b/src/cli.js
index 9ccc8f9c..8867cee7 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -2136,7 +2136,10 @@ async function submitHere(ctx, id) {
withBoard(ctx, (board) => refuseUnverifiedStack(root, board, held, commit, trunk));
// Every submit proves its frozen check and reachable tests anew on this exact commit (V4,V16).
// A full-gate stamp never substitutes for either proof; only an actual full fallback may stamp.
- const submitConfig = { ...ctx.config, submitGate: acceptedMain.config.submitGate };
+ const submitConfig = { ...ctx.config, submitGate: acceptedMain.config.submitGate,
+ submitInvariants: acceptedMain.config.submitInvariants,
+ // The accepted project runner interprets its current invariant files; candidate config cannot replace it.
+ ...(acceptedMain.config.submitInvariants.length ? { affectedTests: acceptedMain.config.affectedTests } : {}) };
const gate = await runSubmitGate(root, submitConfig, { base: claimHead, trunk: acceptedMain.commit, check: frozenCheck(held), agent: me.id, item: String(id), onWait: gateWaitReporter(ctx.io), onBrowserFallback: browserAdmissionReporter(ctx.io, ctx.io.relayJson) });
if (!gate.isGreen) {
const message = `the submission proof is red at ${commit.slice(0, 12)}; fix it, commit, submit again. ${submitGateReport(gate)}`;
diff --git a/src/config.js b/src/config.js
index f06fe763..b5948861 100644
--- a/src/config.js
+++ b/src/config.js
@@ -41,6 +41,7 @@ export function defaults() {
spec: 'SPEC.md',
practice: DOCTRINE_FILE,
gate: '',
+ submitInvariants: [],
lease: '2h',
reviewLease: '30m',
verify: { policy: 'any', family: 'off', reviewRatio: 3 },
@@ -164,6 +165,13 @@ export function configProblems(config) {
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 (!isStringList(config.submitInvariants) || config.submitInvariants.some(path =>
+ !path || path.trim() !== path || /[\u0000-\u001f\u007f-\u009f\\]/u.test(path)
+ || path.startsWith('/') || /^[a-z]:/iu.test(path) || path.split('/').some(part => !part || part === '..' || part === '.'))) {
+ problems.push('"submitInvariants" is a list of literal repository-relative test file paths');
+ } else if (config.submitInvariants.length && (typeof config.affectedTests !== 'string' || !config.affectedTests.trim())) {
+ problems.push('"submitInvariants" requires an "affectedTests" command prefix for the project test runner');
+ }
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 f2154b49..331b76d0 100644
--- a/src/gate.js
+++ b/src/gate.js
@@ -6,7 +6,7 @@
*/
import { spawn, spawnSync } from 'node:child_process';
import { randomUUID } from 'node:crypto';
-import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
import { availableParallelism } from 'node:os';
import { gitChildEnv, gitPath, headTree, invalidateGitFacts, isClean, untracked } from './git.js';
@@ -362,9 +362,21 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
: { full: true, reason: 'affected-test selection is not enabled for this project', files: [] };
const deferred = config.submitGate === 'landing';
const deferFullFallback = deferred && selection.full;
+ const invariants = deferred ? [...new Set(config.submitInvariants ?? [])].sort() : [];
+ if (invariants.length && !config.affectedTests?.trim()) {
+ throw new Refused('BAD_CONFIG', 'submitInvariants requires the project affectedTests runner');
+ }
+ for (const path of invariants) {
+ let file = false;
+ try { file = statSync(join(root, path)).isFile(); } catch { /* Missing or unreadable invariants refuse rather than silently disappearing. */ }
+ if (!file) throw new Refused('BAD_CONFIG', `submitInvariants file ${path} is missing or unreadable; restore it or update the list on accepted main`);
+ }
+ const proofFiles = [...new Set([...(deferFullFallback ? [] : selection.files), ...invariants])].sort();
const allowBrowserFreeChecks = browserFreeChecksEnabled();
const checkUsesBrowser = check ? (!allowBrowserFreeChecks || await checkNeedsBrowser(root, check, { onFallback: onBrowserFallback })) : false;
- const proofUsesBrowser = !deferFullFallback && (selection.full || !allowBrowserFreeChecks || await testsNeedBrowser(root, selection.files, { onFallback: onBrowserFallback }));
+ const proofUsesBrowser = deferFullFallback
+ ? (proofFiles.length > 0 && (!allowBrowserFreeChecks || await testsNeedBrowser(root, proofFiles, { onFallback: onBrowserFallback })))
+ : (selection.full || !allowBrowserFreeChecks || await testsNeedBrowser(root, proofFiles, { onFallback: onBrowserFallback }));
const browser = checkUsesBrowser || proofUsesBrowser;
return await withGateSlot(root, (lease) => {
const startedAt = Date.now();
@@ -388,7 +400,7 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
format: [...new Set(profiles.map(value => value.format))].join('+'),
unavailable: profiles.some(value => value.unavailable) ? 'per-test timing unavailable: output was not TAP or JUnit (one or more phases)' : null,
});
- return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, deferred, deferFullFallback, check: receipt,
+ return { ...proof, log, seconds: criterion.seconds + proof.seconds, ...selection, ...(deferred ? { files: proofFiles, submitInvariants: invariants } : {}), deferred, deferFullFallback, check: receipt,
profile, profilePath, proofProfilePath: proof.profilePath, proofLog: proof.log };
};
if (!criterion.isGreen) {
@@ -398,15 +410,14 @@ export async function runSubmitGate(root, config, { base, trunk, changed, check,
// The proof already owns this lease: its phase profile has no additional queue wait.
const proofWait = check ? 0 : lease.waitMs;
let proof;
- if (deferFullFallback) proof = { isGreen: true, isCached: false, output: '', seconds: 0, log: '' };
- else if (selection.full) proof = fullGateRun(root, config, false, { waitMs: proofWait, log: proofLog, gateLease: lease });
- else if (!selection.files.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log: '' };
+ if (!deferFullFallback && selection.full) proof = fullGateRun(root, config, false, { waitMs: proofWait, log: proofLog, gateLease: lease });
+ else if (!proofFiles.length) proof = { isGreen: true, output: '', seconds: 0, isCached: false, log: '' };
else {
- const command = `${config.affectedTests.trimEnd()} ${selection.files.map(path => commandWord('./' + path)).join(' ')}`;
+ const command = `${config.affectedTests.trimEnd()} ${proofFiles.map(path => commandWord('./' + path)).join(' ')}`;
proof = { ...runProfiledShell(root, command, { waitMs: proofWait, profileFile: `${proofLog}.profile.json`, gateLease: lease }), isCached: false, log: proofLog };
writeFileSync(proofLog, proof.output);
}
- const phase = deferFullFallback ? 'full suite deferred to the landing gate' : selection.full ? 'full gate' : 'affected tests';
+ const phase = deferFullFallback ? `submit invariants: ${invariants.length ? invariants.join(', ') : 'none'}; full suite deferred to the landing gate` : selection.full ? 'full gate' : 'affected tests';
writeFileSync(log, `item check:\n${criterion.output}\n${phase}:\n${proof.output}`);
return finish(proof);
}, { browser, agent, item, kind, itemCheck: true, onWait });
@@ -420,9 +431,9 @@ export function submitGateReport(gate) {
const timings = timingDigest(gate.profile);
const detail = timings ? `\n${timings}\ntiming profile: ${gate.profilePath}` : '';
const proof = gate.deferFullFallback
- ? `full suite deferred to the landing gate${reason}`
+ ? `${gate.submitInvariants?.length ? 'submit invariants: ' + gate.submitInvariants.join(', ') + '; ' : ''}full suite deferred to the landing gate${reason}`
: `affected tests: ${gate.files.length ? gate.files.join(', ') : 'none'}; full suite deferred to the landing gate`;
- const result = gate.deferFullFallback ? '' : `; ${gate.isGreen ? `affected tests green in ${gate.seconds}s` : gateReport(gate)}`;
+ const result = gate.deferFullFallback && !gate.submitInvariants?.length ? '' : `; ${gate.isGreen ? `${gate.deferFullFallback ? 'submit invariants' : 'affected tests'} green in ${gate.seconds}s` : gateReport(gate)}`;
return `${check}; ${proof}${result}${detail}`;
}
const selection = gate.full ? `full gate: ${gate.reason}` : `affected tests: ${gate.files.length ? gate.files.join(', ') : 'none'}`;
diff --git a/test/submit-gate.test.js b/test/submit-gate.test.js
index 921c57db..d0350b92 100644
--- a/test/submit-gate.test.js
+++ b/test/submit-gate.test.js
@@ -364,6 +364,18 @@ test("a landing-gated submit runs the project's invariant tests [V4,C7]", (t) =>
assert.equal(existsSync(empty.marker), false, 'the empty default adds no tests');
unstamped(empty.box);
+ const mandatory = project(['test/invariant.test.js']);
+ change(mandatory.box);
+ const guarded = mandatory.box.run('submit', '1', '--json');
+ assert.equal(guarded.code, 0, guarded.err);
+ const guardedReceipt = JSON.parse(guarded.out);
+ assert.equal(guardedReceipt.gate.full, true, 'the selector still reports an uncertain full fallback');
+ assert.equal(guardedReceipt.gate.deferred, true);
+ assert.deepEqual(guardedReceipt.gate.files, ['test/invariant.test.js'], 'receipt names only the executed invariant subset');
+ assert.equal(readFileSync(mandatory.marker, 'utf8'), 'invariant\n', 'global fallback does not run unrelated selected/full tests');
+ assert.match(guardedReceipt.gate.report, /submit invariants: test\/invariant\.test\.js; full suite deferred/u);
+ unstamped(mandatory.box);
+
const red = project(['test/invariant.test.js'], true);
change(red.box);
const refused = red.box.run('submit', '1', '--json');
@@ -391,6 +403,14 @@ test("a landing-gated submit runs the project's invariant tests [V4,C7]", (t) =>
assert.doesNotMatch(ignored.err, /unrelated test must stay deferred/u);
unstamped(trusted.box);
+ const missing = project(['test/invariant.test.js']);
+ rmSync(join(missing.box.root, 'test/invariant.test.js'));
+ change(missing.box);
+ const absent = missing.box.run('submit', '1', '--json');
+ assert.notEqual(absent.code, 0, 'deleting a mandatory file cannot make the guard disappear');
+ assert.match(absent.err, /submitInvariants file test\/invariant\.test\.js is missing or unreadable/u);
+ unstamped(missing.box);
+
const named = project(['test/invariant.test.js', 'test/invariant.test.js']);
change(named.box, false);
const selected = named.box.run('submit', '1', '--json');
@@ -491,6 +511,15 @@ test('affectedTests accepts only a nonempty command prefix [V4,C7]', () => {
});
});
+test('submitInvariants names literal project files and requires its explicit runner [V4,C7]', () => {
+ assert.deepEqual(configFromSource('{}').submitInvariants, []);
+ for (const submitInvariants of [null, 'test/a.test.js', [false], [''], ['../outside.test.js'], ['/outside.test.js'], ['C:/outside.test.js'], ['test/../a.test.js'], ['test/a.test.js\n'], ['test//a.test.js']]) {
+ assert.throws(() => configFromSource(JSON.stringify({ affectedTests: 'pytest', submitInvariants })), { code: 'BAD_CONFIG', message: /submitInvariants/u });
+ }
+ assert.throws(() => configFromSource(JSON.stringify({ submitInvariants: ['tests/guard.py'] })), { code: 'BAD_CONFIG', message: /requires.*affectedTests/u });
+ assert.deepEqual(configFromSource(JSON.stringify({ affectedTests: 'pytest', submitInvariants: ['tests/guard.py'] })).submitInvariants, ['tests/guard.py']);
+});
+
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', affectedTests: 'node --test' }));