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): commit lower doctrine counts in the batch [B3,R3,D1,D3]

Corey Olsonbdaedbea63e5
diff --git a/src/land.js b/src/land.js
index fb0b199e..62d404d0 100644
--- a/src/land.js
+++ b/src/land.js
@@ -43,6 +43,7 @@ import { testsNeedBrowser } from './browser-admission.js';
import { laneOf } from './lanes.js';
import { Refused } from './refused.js';
import { browserFreeChecksEnabled } from './settings.js';
+import { tightenLandingDoctrine } from './landing-doctrine.js';
import { landingFileTimes } from './submit-invariants.js';
import {
flakeSource,
@@ -194,7 +195,15 @@ async function mergeGroup(state, items) {
.find((commit) => tryGit(batch.root, ['merge-base', '--is-ancestor', checked, commit]).status === 0);
merged.push({ id: item.item_id, commit: item.item_commit, ...(checked !== item.item_commit ? { reviewedCommit: checked } : {}), merge: first });
}
- return { items: merged, conflicts, tip: headCommit(batch.root) };
+ let doctrineCounts = [];
+ try {
+ if (merged.length) doctrineCounts = await tightenLandingDoctrine(batch.root, state.config, { onWait: state.onWait });
+ } catch (error) {
+ await save(state, { state: 'blocked', items: merged, conflicts, tip: headCommit(batch.root), doctrineCounts: [] });
+ throw error;
+ }
+ for (const change of doctrineCounts) state.say(`doctrine ${change.id}: ${change.before} -> ${change.count}`);
+ return { items: merged, conflicts, tip: headCommit(batch.root), doctrineCounts };
}
/** Read positive TAP completion counts while rejecting the canonical runner's incomplete accounts. */
diff --git a/src/landing-doctrine.js b/src/landing-doctrine.js
new file mode 100644
index 00000000..ca3f1ef6
--- /dev/null
+++ b/src/landing-doctrine.js
@@ -0,0 +1,61 @@
+/** Tighten held doctrine counts on the exact composed landing tree, before its gate [D1,D3,B3,R3]. */
+import {
+ readFileSync,
+ writeFileSync,
+} from 'node:fs';
+import { join } from 'node:path';
+import {
+ doctrineFile,
+} from './config.js';
+import {
+ checkRulesAt,
+ runRuleCheck,
+} from './doctrine-checks.js';
+import { checkNeedsBrowser } from './browser-admission.js';
+import { withGateSlot } from './gate.js';
+import {
+ git,
+ headCommit,
+ isClean,
+ untracked,
+} from './git.js';
+import { Refused } from './refused.js';
+import { parseSpec } from './spec.js';
+
+/** Count held submit rules, refuse increases atomically, and commit only measured lower count fields. */
+export async function tightenLandingDoctrine(root, config, { onWait } = {}) {
+ const rules = checkRulesAt(root, 'HEAD', config.practice).filter(rule => rule.runs === 'submit' && rule.mode === 'hold');
+ if (!rules.length) return [];
+ const head = headCommit(root);
+ if ((!isClean(root) || untracked(root).length)) throw new Refused('LAND_DIRTY', 'the merged landing tree changed before its doctrine counts were measured');
+ const browser = (await Promise.all(rules.map(rule => checkNeedsBrowser(root, rule.command)))).some(Boolean);
+ // Counts describe this exact merged checkout. A remote immutable checkout cannot carry its derived edits.
+ const reports = await withGateSlot(root, () => rules.map(rule => ({ rule,
+ ...runRuleCheck(root, rule.command, config.check?.timeoutMs) })),
+ { browser, remote: false, agent: 'coordinator', kind: 'doctrine', itemCheck: true, onWait });
+ if (headCommit(root) !== head || (!isClean(root) || untracked(root).length)) throw new Refused('LAND_DIRTY', 'a doctrine check changed the merged landing tree; inspect it before adopting');
+ const uncounted = reports.filter(report => report.broken);
+ if (uncounted.length) throw new Refused('RATCHET_UNCOUNTED', uncounted.map(report => `${report.rule.id} cannot count: ${report.broken}`).join('\n'));
+ const risen = reports.filter(report => report.problems.length > report.rule.count);
+ if (risen.length) throw new Refused('RATCHET_ROSE', risen.map(report =>
+ `${report.rule.id} rose to ${report.problems.length}, was ${report.rule.count}; only the person's signature raises a count`).join('\n'));
+ const lowered = reports.filter(report => report.problems.length < report.rule.count)
+ .map(report => ({ id: report.rule.id, before: report.rule.count, count: report.problems.length }));
+ if (!lowered.length) return [];
+ const file = doctrineFile(root, config.practice);
+ const source = readFileSync(join(root, file), 'utf8');
+ const rows = parseSpec(source, { strictGrammarVersion: false }).rows;
+ const lines = source.split('\n');
+ for (const change of lowered) {
+ const row = rows.find(candidate => candidate.id === change.id);
+ if (!row || Number(row.count) !== change.before) throw new Refused('LAND_DIRTY', `the committed count for ${change.id} changed while its landing was measured`);
+ const previous = lines[row.line - 1];
+ const next = previous.replace(/(\|\s*count:\s*)\d+(?=\s*(?:\||$))/u, (_, prefix) => prefix + change.count);
+ if (next === previous) throw new Refused('LAND_DIRTY', `the measured count field for ${change.id} could not be tightened`);
+ lines[row.line - 1] = next;
+ }
+ writeFileSync(join(root, file), lines.join('\n'));
+ git(root, ['add', '--', file]);
+ git(root, ['commit', '-m', 'chore(doctrine): record lower held counts']);
+ return lowered;
+}
diff --git a/test/land-doctrine-fixture.js b/test/land-doctrine-fixture.js
new file mode 100644
index 00000000..f3ac205a
--- /dev/null
+++ b/test/land-doctrine-fixture.js
@@ -0,0 +1,58 @@
+/** Real landing controls for automatically tightened doctrine counts [B3,R3,D1,D3]. */
+import assert from 'node:assert/strict';
+import { appendFileSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
+import { join } from 'node:path';
+
+/** Configure private tier-one landing with one person-approved, held quality check. */
+function configure(box, command, count) {
+ const path = join(box.repo, 'pullboard.json');
+ const config = JSON.parse(readFileSync(path, 'utf8'));
+ writeFileSync(path, JSON.stringify({ ...config, landing: { publish: 'separate' } }, null, 2));
+ appendFileSync(join(box.repo, 'DOCTRINE.md'),
+ `\n## Q · Quality\n- Q1 [approved, must] The quality count only falls. | gate: check ${command} | count: ${count}\n`);
+ box.git(box.repo, 'add', '-A');
+ box.git(box.repo, 'commit', '-q', '-m', 'chore: configure held landing quality');
+}
+
+/** Parse a successful private command without hiding its actual stdout or stderr. */
+function json(box, ...args) {
+ const result = box.run(box.repo, ...args, '--json');
+ assert.equal(result.code, 0, `${result.err}\n${result.out}`);
+ return JSON.parse(result.out);
+}
+
+/** Prove a lower count reaches the committed trunk, while interacting green items cannot raise it. */
+export function assertLandingDoctrineCounts({ landProject, itemWorktree, submitItem, acceptItem }) {
+ const falling = landProject();
+ mkdirSync(join(falling.repo, 'web'), { recursive: true });
+ writeFileSync(join(falling.repo, 'web/markers.txt'), 'TODO first\nTODO second\n');
+ configure(falling, 'grep -n TODO web/markers.txt', 2);
+ const improved = itemWorktree(falling, 1, 'web/markers.txt');
+ submitItem(falling, improved, 'TODO second\n');
+ acceptItem(falling, improved);
+ const oldRemote = falling.git(falling.remote, 'rev-parse', 'main');
+ const landed = json(falling, 'land');
+ assert.deepEqual(landed.landed, [improved.item]);
+ const committed = falling.git(falling.repo, 'show', `${landed.batch.tip}:DOCTRINE.md`);
+ assert.match(committed, /Q1 .*\| count: 1$/mu, 'the lower count is committed at the exact landed tip');
+ assert.match(readFileSync(join(falling.repo, 'DOCTRINE.md'), 'utf8'), /Q1 .*\| count: 1$/mu);
+ assert.equal(falling.git(falling.repo, 'rev-parse', 'HEAD'), landed.batch.tip);
+ assert.equal(falling.git(falling.remote, 'rev-parse', 'main'), oldRemote, 'tier-one tightening never publishes');
+ assert.deepEqual(landed.batch.doctrineCounts, [{ id: 'Q1', before: 2, count: 1 }], 'the durable report names both counts');
+ const unchanged = json(falling, 'land');
+ assert.deepEqual(unchanged.landed, [], 'a completed tightening is not committed twice');
+
+ const rising = landProject();
+ const source = "const fs = require('node:fs'); if (fs.existsSync('web/land-1.test.js') && fs.existsSync('web/land-2.test.js')) console.log('interacting problems');";
+ writeFileSync(join(rising.repo, 'quality.cjs'), source);
+ configure(rising, 'node quality.cjs', 0);
+ const entries = [itemWorktree(rising, 1), itemWorktree(rising, 2)];
+ for (const entry of entries) { submitItem(rising, entry); acceptItem(rising, entry); }
+ const before = rising.git(rising.repo, 'rev-parse', 'main');
+ const result = rising.run(rising.repo, 'land', '--json');
+ const report = JSON.parse(result.out);
+ assert.equal(rising.git(rising.repo, 'rev-parse', 'main'), before, 'combined higher count holds the trunk');
+ assert.deepEqual(report.landed ?? [], [], `${result.err}\n${result.out}`);
+ assert.match(`${result.err}\n${result.out}`, /Q1.*(?:rose|1.*0)/su, 'the higher count explains the hold');
+ assert.match(rising.git(rising.repo, 'show', 'main:DOCTRINE.md'), /Q1 .*\| count: 0$/mu, 'no count is raised');
+}
diff --git a/test/land.test.js b/test/land.test.js
index 9422d417..70d3da3f 100644
--- a/test/land.test.js
+++ b/test/land.test.js
@@ -10,6 +10,7 @@ import { landingFailures, landingSubject } from '../src/land.js';
import { createE2eHelpers } from './e2e-helpers.js';
import { startFixtureChild, runFixtureChild } from './fixture-child.js';
import { assertNoRemoteLanding } from './land-no-remote-fixture.js';
+import { assertLandingDoctrineCounts } from './land-doctrine-fixture.js';
const e2e = createE2eHelpers();
after(e2e.cleanup);
@@ -17,6 +18,10 @@ const { sandbox, project, commitFile, waitFor, BIN } = e2e;
const FILES = [1, 2, 3, 4].map((n) => `web/land-${n}.test.js`);
const MARKER_NOT_YET = Symbol('marker not yet written');
+test('a landing records a falling doctrine count and holds a rising count [B3,R3,D1,D3]', () => {
+ assertLandingDoctrineCounts({ landProject, itemWorktree, submitItem, acceptItem });
+});
+
test('a repo with no remote lands into the local trunk and status reads as normal [I1,B3,R3,H5]', () => {
assertNoRemoteLanding(sandbox, commitFile);
});