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
refactor(gate): keep receipt validation in focused helpers [C7,V4]
Corey Olsonc16fbdd93b2e
diff --git a/src/board.js b/src/board.jsindex 247a96b8..fa2b4cab 100644--- a/src/board.js+++ b/src/board.js@@ -16,6 +16,9 @@ import { ENGINE_VERSION, GUARDS, IN_STATE, MOVES, STATES, UNKNOWN_MOVE, effectivimport { Refused } from './refused.js';import { parseSpec } from './spec.js';import { invariantEvidence } from './submit-invariants.js';+import { preserveInvariantEvidence } from './submit-invariants.js';+import { validateLandingBatch } from './submit-invariants.js';+import { validateLandingRevision } from './submit-invariants.js';import { submissionProof } from './submit-invariants.js';import { SUBMISSION_PROOF_ENGINE } from './submit-invariants.js';@@ -2693,30 +2696,11 @@ export function landingBatches(board) {export function recordLandingBatch(board, { agentId, batch, revision = 0 }) {coordinatorOnly(agentId, 'records landing batches');const evidence = (board.executionEngineVersion ?? ENGINE_VERSION) >= SUBMISSION_PROOF_ENGINE ? invariantEvidence(batch?.invariantEvidence) : undefined;- if (!batch || batch.version !== 1 || typeof batch.id !== 'string' || !/^[a-zA-Z0-9_-]{1,80}$/u.test(batch.id)- || !['merging', 'gating', 'bisecting', 'flaky', 'blocked', 'ready', 'pushed', 'landed'].includes(batch.state)- || !/^[a-f0-9]{40,64}$/u.test(batch.base ?? '') || !/^[a-f0-9]{40,64}$/u.test(batch.tip ?? '')- || typeof batch.root !== 'string' || !batch.root || typeof batch.branch !== 'string' || !batch.branch.startsWith('refs/heads/')- || !Array.isArray(batch.items) || batch.items.some((entry) => !Number.isSafeInteger(entry?.id) || entry.id < 1 || !/^[a-f0-9]{40,64}$/u.test(entry.commit ?? ''))- || typeof batch.owner !== 'string' || !batch.owner || typeof batch.logPath !== 'string' || !batch.logPath- || !Number.isSafeInteger(revision) || revision < 0) {- throw new Refused('LAND_BATCH', 'a landing batch needs its exact base, tip, items, state, owner and log path; run pullboard land');- }+ validateLandingBatch(batch, revision);return atomic(board, () => {const previous = landingBatches(board).find((entry) => entry.id === batch.id);- if (previous?.invariantEvidence && (board.executionEngineVersion ?? ENGINE_VERSION) >= SUBMISSION_PROOF_ENGINE) {- for (const kind of ['gates', 'diagnostics']) {- if (!evidence || JSON.stringify(evidence[kind].slice(0, previous.invariantEvidence[kind].length)) !== JSON.stringify(previous.invariantEvidence[kind])) {- throw new Refused('LAND_EVIDENCE', 'recorded landing evidence is append-only; preserve earlier gate and diagnostic receipts when adopting');- }- }- }- if ((previous?.revision ?? 0) !== revision || previous?.state === 'landed') {- throw new Refused('LAND_MOVED', 'the landing batch changed; read pullboard resume and adopt its current revision');- }- if (previous && (previous.base !== batch.base || previous.root !== batch.root || previous.branch !== batch.branch)) {- throw new Refused('LAND_BATCH', 'a batch keeps its original base and landing worktree; adopt it with pullboard land --adopt');- }+ preserveInvariantEvidence(previous, evidence, board.executionEngineVersion ?? ENGINE_VERSION);+ validateLandingRevision(previous, batch, revision);const recorded = { ...batch, revision: revision + 1, updatedAt: now(board) };delete recorded.invariantEvidence;if (evidence) recorded.invariantEvidence = evidence;diff --git a/src/submit-invariants.js b/src/submit-invariants.jsindex dba73531..aad32b8c 100644--- a/src/submit-invariants.js+++ b/src/submit-invariants.js@@ -123,3 +123,37 @@ export function submitInvariantLine(proposal) {const budget = proposal.withinBudget === null ? '' : proposal.withinBudget ? ' (within budget)' : ' (over budget)';return `submit invariant proposal: ${proposal.file}; ${proposal.escapes} escaped merge(s); runtime ${runtime} / 60 s${budget}; edit submitInvariants on main to accept`;}++/** Validate the existing canonical batch identity before its append-only snapshot is recorded. */+export function validateLandingBatch(batch, revision) {+ if (!batch || batch.version !== 1 || typeof batch.id !== 'string' || !/^[a-zA-Z0-9_-]{1,80}$/u.test(batch.id)+ || !['merging', 'gating', 'bisecting', 'flaky', 'blocked', 'ready', 'pushed', 'landed'].includes(batch.state)+ || !/^[a-f0-9]{40,64}$/u.test(batch.base ?? '') || !/^[a-f0-9]{40,64}$/u.test(batch.tip ?? '')+ || typeof batch.root !== 'string' || !batch.root || typeof batch.branch !== 'string' || !batch.branch.startsWith('refs/heads/')+ || !Array.isArray(batch.items) || batch.items.some((entry) => !Number.isSafeInteger(entry?.id) || entry.id < 1 || !/^[a-f0-9]{40,64}$/u.test(entry.commit ?? ''))+ || typeof batch.owner !== 'string' || !batch.owner || typeof batch.logPath !== 'string' || !batch.logPath+ || !Number.isSafeInteger(revision) || revision < 0) {+ throw new Refused('LAND_BATCH', 'a landing batch needs its exact base, tip, items, state, owner and log path; run pullboard land');+ }+}++/** Preserve earlier normalized gate and diagnostic receipts when an engine-17 batch is adopted. */+export function preserveInvariantEvidence(previous, evidence, engine) {+ if (previous?.invariantEvidence && engine >= SUBMISSION_PROOF_ENGINE) {+ for (const kind of ['gates', 'diagnostics']) {+ if (!evidence || JSON.stringify(evidence[kind].slice(0, previous.invariantEvidence[kind].length)) !== JSON.stringify(previous.invariantEvidence[kind])) {+ throw new Refused('LAND_EVIDENCE', 'recorded landing evidence is append-only; preserve earlier gate and diagnostic receipts when adopting');+ }+ }+ }+}++/** Keep the original revision, terminal-state and immutable batch-identity guards together. */+export function validateLandingRevision(previous, batch, revision) {+ if ((previous?.revision ?? 0) !== revision || previous?.state === 'landed') {+ throw new Refused('LAND_MOVED', 'the landing batch changed; read pullboard resume and adopt its current revision');+ }+ if (previous && (previous.base !== batch.base || previous.root !== batch.root || previous.branch !== batch.branch)) {+ throw new Refused('LAND_BATCH', 'a batch keeps its original base and landing worktree; adopt it with pullboard land --adopt');+ }+}diff --git a/test/submit-invariants.test.js b/test/submit-invariants.test.jsindex 41253798..e10192ea 100644--- a/test/submit-invariants.test.js+++ b/test/submit-invariants.test.js@@ -78,6 +78,7 @@ test('a landing escape is proposed as a submit invariant [C7,V4]', async () => {const first = 'a'.repeat(40);const second = 'b'.repeat(40);const third = 'c'.repeat(40);+ landing(box, 'earlier-green', submit, first, [], [], true);landing(box, 'first-escape', submit, first, [{ path: 'test/repeated.test.js', durationMs: 4000 },{ path: 'test/once.test.js', durationMs: 1000 },@@ -96,6 +97,16 @@ test('a landing escape is proposed as a submit invariant [C7,V4]', async () => {]);// A second receipt of the same merge is evidence custody, not another escaped merge.landing(box, 'duplicate-receipt', submit, second, [{ path: 'test/repeated.test.js', durationMs: 4500 }]);+ const recoveredCommit = 'f'.repeat(40);+ landing(box, 'full-recovery-red', submit, recoveredCommit, [{ path: 'test/full-recovered.test.js', durationMs: 25 }]);+ landing(box, 'later-full-green', submit, recoveredCommit, [], [], true);+ onBoard(box, board => {+ const previous = store.landingBatches(board).find(batch => batch.id === 'first-escape');+ const eventCount = store.events(board).length;+ assert.throws(() => store.recordLandingBatch(board, { agentId: 'coordinator', revision: previous.revision,+ batch: { ...previous, invariantEvidence: { ...previous.invariantEvidence, gates: [] } } }), { code: 'LAND_EVIDENCE' });+ assert.equal(store.events(board).length, eventCount, 'a prior receipt cannot be removed or rewritten');+ });const untouchedConfig = readFileSync(configPath, 'utf8');const proposals = json(box, box.repo, 'status').submitInvariantProposals;assert.equal(proposals[0].file, 'test/repeated.test.js', 'a repeated escape below budget is first');@@ -108,6 +119,8 @@ test('a landing escape is proposed as a submit invariant [C7,V4]', async () => {assert.equal(byFile.get('test/unknown.test.js').runtimeMs, null, 'unmeasured is not zero');assert.equal(byFile.get('test/unknown.test.js').withinBudget, null);assert.ok(byFile.has('test/other-commit.test.js'), 'green on a different commit cannot erase the escape');+ assert.ok(byFile.has('test/once.test.js'), 'an earlier green at the same commit does not erase a later failure');+ assert.equal(byFile.has('test/full-recovered.test.js'), false, 'a later full green at the exact commit suppresses the escape');assert.equal(byFile.has('test/recovered.test.js'), false, 'whole-file green at the exact merge suppresses it');assert.equal(byFile.has('web/page.test.js'), false, 'a selected file did not escape selection');const human = box.run(box.repo, 'status');@@ -176,6 +189,11 @@ test('submission selection replays on two replicas and legacy history remains unassert.deepEqual(store.events(copies[0]), store.events(copies[1]));assert.throws(() => applyEngineMove(copies[2], { ...move, engine: SUBMISSION_PROOF_ENGINE - 1 }, receipt), { code: 'RELAY_MOVE' });assert.equal(store.getItem(copies[2], id).item_status, 'claimed');+ const invalid = structuredClone(move);+ invalid.id = 'selection-invalid-path';+ invalid.args[1].submissionProof.files = ['../outside.test.js'];+ assert.equal(applyRelayMove(copies[2], invalid, receipt).error?.code, 'SUBMISSION_PROOF');+ assert.equal(store.getItem(copies[2], id).item_status, 'claimed', 'invalid coverage cannot submit the item');const legacy = structuredClone(move);legacy.engine = 12;delete legacy.args[1].submissionProof;