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
feat(submit): refuse a head it cannot accept before any test [V4,C7]
Corey Olson7948865ebd18
diff --git a/src/cli.js b/src/cli.jsindex fd7449a1..ecaf27ff 100644--- a/src/cli.js+++ b/src/cli.js@@ -41,6 +41,7 @@ import {refuseNextIdle,} from './next-steps.js';import { reviewerStartup } from './next-steps.js';+import { submitPreflight } from './submit-preflight.js';import * as store from './board.js';import {CONFIG_FILE,@@ -2740,6 +2741,7 @@ async function submitHere(ctx, id) {if (stray.length) throw new Refused('UNTRACKED', `commit or ignore ${stray.length} untracked file(s), e.g. ${stray[0]}`);const commit = headCommit(root);if (!commit) throw new Refused('NO_COMMIT', 'nothing committed yet');+ withBoard(ctx, (board) => submitPreflight(board, id, { agentId: me.id, commit, tree: headTree(root) ?? '' }));const trunk = requireTrunkMerge(root, commit);withBoard(ctx, (board) => refuseUnverifiedStack(root, board, held, commit, trunk));// Doctrine counts only fall: accepted main's rules, at this exact commit (D1). No rule, no change.diff --git a/src/submit-preflight.js b/src/submit-preflight.jsnew file mode 100644index 00000000..73f48f44--- /dev/null+++ b/src/submit-preflight.js@@ -0,0 +1,31 @@+/**+ * Submit preflight (#924): the board's own submit guards, run before any check or test. A refusal that no test+ * result can change (HEAD_NOT_NEW, NOT_YOURS, a pending refreeze, open children) used to come back only after the+ * whole proof ran; on 19 Oct #890 spent 679 s before HEAD_NOT_NEW. Here the real submit move runs in a transaction+ * that always rolls back, with a stand-in proof, so every board guard decides now and nothing is recorded.+ */+import * as store from './board.js';++/** Thrown to roll back a preflight that passed; never escapes this module. */+const PASSED = Symbol('submit preflight passed');++/** A deferred proof that names no files: enough for the move's shape, never recorded. */+const STAND_IN_PROOF = Object.freeze({ version: 1, files: [], full: false, deferred: true, reason: 'submit preflight; no proof has run yet' });++/**+ * Refuse now, exactly as the submit itself would, when a board guard that needs no test result refuses.+ *+ * @param {any} board+ * @param {number} id+ * @param {{ agentId: string, commit: string, tree: string }} submission+ */+export function submitPreflight(board, id, { agentId, commit, tree }) {+ try {+ store.atomic(board, () => {+ store.submit(board, id, { agentId, commit, tree, files: [], submissionProof: STAND_IN_PROOF });+ throw PASSED;+ });+ } catch (error) {+ if (error !== PASSED) throw error;+ }+}diff --git a/test/submit-preflight.test.js b/test/submit-preflight.test.jsnew file mode 100644index 00000000..cf272999--- /dev/null+++ b/test/submit-preflight.test.js@@ -0,0 +1,55 @@+/** Submit refuses a head it cannot accept before any check or test runs [V4,C7]. */+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { existsSync } from 'node:fs';+import { mkdirSync } from 'node:fs';+import { readFileSync } from 'node:fs';+import { rmSync } from 'node:fs';+import { writeFileSync } from 'node:fs';+import { join } from 'node:path';+import { resolve } from 'node:path';+import { test } from 'node:test';+import { createE2eHelpers } from './e2e-helpers.js';++const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');++test('resubmitting a rejected head refuses HEAD_NOT_NEW before its slow check starts [V4,C7]', { timeout: 180_000 }, (t) => { // budget: the refused submit must return within 60 s; before #924 it waits on a 120 s check.+ const helpers = createE2eHelpers();+ t.after(helpers.cleanup);+ const box = helpers.project('true');+ const ran = join(box.dir, 'check-runs.log');+ const slow = join(box.dir, 'slow-check');+ // The item's check records every run; once armed, it takes two minutes, as a real suite can.+ writeFileSync(join(box.repo, 'check.cjs'), `const fs = require('node:fs');+fs.appendFileSync(${JSON.stringify(ran)}, 'ran\\n');+if (fs.existsSync(${JSON.stringify(slow)})) setTimeout(() => {}, 120000);+else process.exit(fs.existsSync('web/page.txt') && fs.readFileSync('web/page.txt', 'utf8').includes('built') ? 0 : 1);+`);+ box.git(box.repo, 'add', 'check.cjs');+ box.git(box.repo, 'commit', '-q', '-m', 'test: add the recorded check [G1]');+ box.git(box.web, 'merge', '-q', '--ff-only', 'main');+ /** Demand real command success and its versioned result. */+ const json = (result) => { assert.equal(result.code, 0, result.out + result.err); return JSON.parse(result.out); };+ json(box.run(box.repo, 'add', 'web', 'Build the page', '--criterion', 'the page is built', '--check', 'node check.cjs', '--json'));+ json(box.run(box.web, 'claim', '1', '--json'));+ mkdirSync(join(box.web, 'web'), { recursive: true });+ writeFileSync(join(box.web, 'web/page.txt'), 'built\n');+ box.git(box.web, 'add', 'web/page.txt');+ box.git(box.web, 'commit', '-q', '-m', 'feat(web): build the page [G1]');+ json(box.run(box.web, 'submit', '1', '--json'));+ // An outside reviewer rejects that exact head.+ const reviewer = join(box.dir, 'api-1');+ box.git(box.repo, 'worktree', 'add', '-q', '--detach', reviewer, box.git(box.web, 'rev-parse', 'HEAD'));+ json(box.run(reviewer, 'join', 'api', '--json'));+ json(box.run(reviewer, 'verify', '1', 'reject', '--reason', 'TEST_FAILURE', '--note', 'the page is not reachable', '--json'));+ json(box.run(box.web, 'claim', '1', '--json'));+ // Resubmit the same head with the check armed to run for minutes.+ rmSync(ran, { force: true });+ writeFileSync(slow, 'armed\n');+ const started = Date.now();+ const resubmit = spawnSync(process.execPath, [BIN, 'submit', '1', '--json'], { cwd: box.web, env: box.env, encoding: 'utf8', timeout: 60_000 });+ const seconds = (Date.now() - started) / 1000;+ assert.notEqual(resubmit.signal, 'SIGTERM', `the refusal came back before the 60 s limit, not after a check run (${seconds.toFixed(1)} s)`);+ assert.equal(JSON.parse(resubmit.stdout).error?.code, 'HEAD_NOT_NEW', resubmit.stdout + resubmit.stderr);+ assert.equal(existsSync(ran), false, `no check or test ran before the refusal: ${existsSync(ran) ? readFileSync(ran, 'utf8') : ''}`);+});