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
fix(land): propagate doctrine gate lease to nested runners [B3,R3,D1,D3]
Corey Olson9c1dcaca9592
diff --git a/src/doctrine-checks.js b/src/doctrine-checks.jsindex b3021801..2e5edcd1 100644--- a/src/doctrine-checks.js+++ b/src/doctrine-checks.js@@ -112,12 +112,13 @@ export function checkRulesAt(root, revision, name = DOCTRINE_FILE) {* @param {string} cwd* @param {string} command* @param {number} timeoutMs+ * @param {NodeJS.ProcessEnv} [gateEnvironment] Child markers supplied by an actual acquired gate lease.* @returns {{ problems: string[], broken: string, seconds: number }}*/-export function runRuleCheck(cwd, command, timeoutMs = DEFAULT_TIMEOUT_MS) {+export function runRuleCheck(cwd, command, timeoutMs = DEFAULT_TIMEOUT_MS, gateEnvironment = {}) {const started = Date.now();const result = spawnSync(`(\n${command}\n) 2>&1`, {- cwd, env: gitChildEnv(cwd), shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8',+ cwd, env: { ...gitChildEnv(cwd), ...gateEnvironment }, shell: true, stdio: ['ignore', 'pipe', 'pipe'], encoding: 'utf8',timeout: timeoutMs, killSignal: 'SIGKILL', maxBuffer: 64 * 1024 * 1024,});invalidateGitFacts();diff --git a/src/landing-doctrine.js b/src/landing-doctrine.jsindex ca3f1ef6..f11a0843 100644--- a/src/landing-doctrine.js+++ b/src/landing-doctrine.js@@ -13,6 +13,7 @@ import {} from './doctrine-checks.js';import { checkNeedsBrowser } from './browser-admission.js';import { withGateSlot } from './gate.js';+import { gateSlotEnvironment } from './resources.js';import {git,headCommit,@@ -30,8 +31,8 @@ export async function tightenLandingDoctrine(root, config, { onWait } = {}) {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) })),+ const reports = await withGateSlot(root, lease => rules.map(rule => ({ rule,+ ...runRuleCheck(root, rule.command, config.check?.timeoutMs, gateSlotEnvironment(lease)) })),{ 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);diff --git a/test/land-doctrine-fixture.js b/test/land-doctrine-fixture.jsindex f3ac205a..38a954b7 100644--- a/test/land-doctrine-fixture.js+++ b/test/land-doctrine-fixture.js@@ -1,7 +1,8 @@/** 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';+import { appendFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';+import { join, resolve } from 'node:path';+import { DatabaseSync } from 'node:sqlite';/** Configure private tier-one landing with one person-approved, held quality check. */function configure(box, command, count) {@@ -55,4 +56,62 @@ export function assertLandingDoctrineCounts({ landProject, itemWorktree, submitIassert.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');+ assertNestedDoctrineLease({ landProject, itemWorktree, submitItem, acceptItem });+}++/** A nested native test runner must reuse a real landing lease on a one-slot private machine. */+function assertNestedDoctrineLease({ landProject, itemWorktree, submitItem, acceptItem }) {+ const box = landProject();+ for (const name of ['PULLBOARD_GATE_SLOT_HELD', 'PULLBOARD_GATE_SLOT_POOL', 'PULLBOARD_GATE_SLOT_TOKEN', 'PULLBOARD_BROWSER_SLOT_HELD']) delete box.env[name];+ json(box, 'settings', 'browserSlots', '1');+ json(box, 'settings', 'gateSlots', '1');+ const armed = join(box.dir, 'nested-doctrine-armed');+ const receipt = join(box.dir, 'nested-doctrine-receipt.jsonl');+ const output = join(box.dir, 'nested-doctrine-output.log');+ const probe = join(box.dir, 'nested-doctrine-probe.test.mjs');+ writeFileSync(probe, [+ "import assert from 'node:assert/strict'; import { test } from 'node:test'; import { appendFileSync } from 'node:fs';",+ "import { DatabaseSync } from 'node:sqlite';",+ "test('nested doctrine inherits the actual landing gate [D1,D3]', () => {",+ " const pool = process.env.PULLBOARD_GATE_SLOT_POOL; assert.ok(pool, 'the real parent pool marker reaches the probe');",+ " const db = new DatabaseSync(pool, { readOnly: true }); let holder;",+ " try { holder = db.prepare(\"SELECT * FROM holder WHERE name = 'gate' AND token = ?\").get(process.env.PULLBOARD_GATE_SLOT_TOKEN);",+ " assert.equal(db.prepare(\"SELECT capacity FROM resource WHERE name = 'gate'\").get().capacity, 1); } finally { db.close(); }",+ " assert.equal(holder?.kind, 'doctrine', 'the original landing doctrine lease is still held, not a new test-runner lease');",+ ` appendFileSync(${JSON.stringify(receipt)}, JSON.stringify({ probe: true, pool, holderKind: holder.kind }) + '\\n');`,+ '});',+ ].join('\n'));+ const runner = resolve(import.meta.dirname, '../bin/run-tests.js');+ writeFileSync(join(box.repo, 'quality.cjs'), [+ "const fs = require('node:fs'); const { spawnSync } = require('node:child_process');",+ `if (fs.existsSync(${JSON.stringify(armed)})) {`,+ `const result = spawnSync(process.execPath, [${JSON.stringify(runner)}, ${JSON.stringify(probe)}], { cwd: process.cwd(), env: process.env, encoding: 'utf8', timeout: 10000, killSignal: 'SIGTERM' });`,+ `fs.appendFileSync(${JSON.stringify(output)}, (result.stdout || '') + (result.stderr || ''));`,+ `fs.appendFileSync(${JSON.stringify(receipt)}, JSON.stringify({ quality: true, childPid: result.pid, parentMarked: process.env.PULLBOARD_GATE_SLOT_HELD === '1', status: result.status, signal: result.signal, error: result.error?.code ?? null }) + '\\n');`,+ 'if (result.status !== 0) process.exit(2);',+ '}',+ "for (const line of fs.readFileSync('web/markers.txt', 'utf8').split('\\n')) if (line.includes('TODO')) console.log(line);",+ ].join('\n'));+ mkdirSync(join(box.repo, 'web'), { recursive: true });+ writeFileSync(join(box.repo, 'web/markers.txt'), 'TODO first\nTODO second\n');+ configure(box, 'node quality.cjs', 2);+ const improved = itemWorktree(box, 1, 'web/markers.txt');+ submitItem(box, improved, 'TODO second\n');+ acceptItem(box, improved);+ // Arm only after setup: this control isolates landing, not an unrelated submit gate.+ writeFileSync(armed, 'ready');+ const result = box.run(box.repo, 'land', '--json');+ assert.equal(result.code, 0, `${result.err}\n${result.out}\nnested receipt: ${existsSync(receipt) ? readFileSync(receipt, 'utf8') : '(absent)'}\nnested output: ${existsSync(output) ? readFileSync(output, 'utf8') : '(absent)'}`);+ const landed = JSON.parse(result.out);+ assert.deepEqual(landed.landed, [improved.item]);+ assert.match(box.git(box.repo, 'show', `${landed.batch.tip}:DOCTRINE.md`), /Q1 .*\| count: 1$/mu);+ assert.deepEqual(landed.batch.doctrineCounts, [{ id: 'Q1', before: 2, count: 1 }]);+ const rows = readFileSync(receipt, 'utf8').trim().split('\n').map(line => JSON.parse(line));+ assert.ok(rows.some(row => row.probe), 'the actual nested native runner executed the probe');+ assert.ok(rows.some(row => row.quality && row.status === 0), readFileSync(output, 'utf8'));+ const db = new DatabaseSync(join(box.env.PULLBOARD_MACHINE_HOME, 'resources.sqlite'), { readOnly: true });+ try {+ assert.equal(db.prepare("SELECT COUNT(*) AS n FROM holder WHERE name IN ('gate','browser')").get().n, 0, 'private resource holders drained');+ assert.equal(db.prepare("SELECT COUNT(*) AS n FROM waiter WHERE name IN ('gate','browser')").get().n, 0, 'private resource waiters drained');+ } finally { db.close(); }}