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): rerun waived incomplete gates [C7,V4]
Corey Olson67a6d4e6885c
diff --git a/src/land.js b/src/land.jsindex 03816629..44b5997b 100644--- a/src/land.js+++ b/src/land.js@@ -1,6 +1,6 @@/** Coordinator landing batches retain exact Git and gate receipts across interruptions [B3,R3]. */import { createHash, randomUUID } from 'node:crypto';-import { copyFileSync, existsSync, mkdirSync, readFileSync } from 'node:fs';+import { closeSync, copyFileSync, existsSync, mkdirSync, openSync, readFileSync, readSync } from 'node:fs';import { dirname, isAbsolute, join, relative } from 'node:path';import * as store from './board.js';import { git, headCommit, headTree, isClean, mainCheckout, repoInfo, tryGit, untracked } from './git.js';@@ -119,10 +119,73 @@ async function mergeGroup(state, items) {return { items: merged, conflicts, tip: headCommit(batch.root) };}+/** Read positive TAP completion counts while rejecting the canonical runner's incomplete accounts. */+function completionAccount() {+ let early = false;+ let plan = null;+ let topLevel = 0;+ const counts = {};+ return {+ /** Consume one complete output line without retaining test output or diagnostic blocks. */+ line(text) {+ if (/^(?:Landing gate stopped early after |Files not run: |Interrupted test files: )/u.test(text)) early = true;+ if (/^(?:not )?ok \d+\b/u.test(text)) topLevel++;+ const planned = /^1\.\.(\d+)\s*$/u.exec(text);+ if (planned) plan = Number(planned[1]);+ const count = /^# (tests|pass|fail|cancelled|skipped|todo) (\d+)\s*$/u.exec(text);+ if (count) counts[count[1]] = Number(count[2]);+ },+ /** A complete plan accounts for every test and contains no interrupted or cancelled work. */+ complete() {+ return !early && Number.isSafeInteger(plan) && plan > 0 && plan === topLevel && Number.isSafeInteger(counts.tests)+ && Number.isSafeInteger(counts.pass) && Number.isSafeInteger(counts.fail)+ && (counts.cancelled ?? 0) === 0+ && counts.pass + counts.fail + (counts.skipped ?? 0) + (counts.todo ?? 0) === counts.tests;+ },+ };+}++/** Require positive completion evidence from this run, or stream the retained legacy raw account. */+function completeGate(gate) {+ if (typeof gate.complete === 'boolean') return gate.complete;+ const account = completionAccount();+ if (typeof gate.output === 'string') {+ for (const line of gate.output.split('\n')) account.line(line);+ return account.complete();+ }+ if (!gate.logPath || !existsSync(gate.logPath)) return false;+ const input = openSync(gate.logPath, 'r');+ const chunk = Buffer.alloc(64 * 1024);+ let pending = '';+ let oversized = false;+ try {+ let count;+ while ((count = readSync(input, chunk, 0, chunk.length, null)) > 0) {+ const parts = chunk.toString('latin1', 0, count).split('\n');+ for (const [index, part] of parts.entries()) {+ if (index) {+ if (!oversized) account.line(pending);+ pending = ''; oversized = false;+ }+ if (!oversized && pending.length + part.length <= 256) pending += part;+ else { pending = ''; oversized = true; }+ }+ }+ if (!oversized) account.line(pending);+ return account.complete();+ } finally { closeSync(input); }+}++/** Whether current person waivers cover every named failure of this exact recorded run. */+function coveredFailures(state, gate) {+ return gate.failures.length > 0 && gate.failures.every((failure) => failure.file && store.landingWaiverFor(state.board, failure));+}+/** Run one full landing gate and retain its complete output under this batch's immutable phase path. */async function gateGroup(state, label) {const tree = headTree(state.batch.root);- if (state.gates.has(tree)) return state.gates.get(tree);+ const cached = state.gates.get(tree);+ if (cached && (completeGate(cached) || !coveredFailures(state, cached))) return cached;const directory = join(dirname(state.batch.root), 'logs');mkdirSync(directory, { recursive: true });const logPath = join(directory, `${label}-${state.batch.revision}.log`);@@ -130,9 +193,11 @@ async function gateGroup(state, label) {const gate = await runGate(state.batch.root, state.config, { trustStamp: false, landing: true, agent: 'coordinator', onWait: state.onWait });copyFileSync(gate.log, logPath);if (gate.profilePath) copyFileSync(gate.profilePath, `${logPath}.profile.json`);- const result = { ...gate, failures: landingFailures(gate.output, state.batch.root), tree, logPath };+ const result = { ...gate, failures: landingFailures(gate.output, state.batch.root), complete: completeGate(gate),+ requiresGreen: Boolean(cached && !completeGate(cached)), tree, logPath };state.gates.set(tree, result);- await save(state, { gateResults: [...state.gates.values()].map(({ tree: testedTree, isGreen, failures, logPath: log }) => ({ tree: testedTree, isGreen, failures, logPath: log })) });+ await save(state, { gateResults: [...state.gates.values()].map(({ tree: testedTree, isGreen, failures, complete, requiresGreen, logPath: log }) =>+ ({ tree: testedTree, isGreen, failures, complete: complete ?? null, requiresGreen: Boolean(requiresGreen), logPath: log })) });return result;}@@ -157,6 +222,7 @@ async function diagnose(state, failures) {/** Record every failure's exact live waiver rather than changing which tests the gate runs. */function waivedProof(state, gate) {+ if (!completeGate(gate) || gate.requiresGreen) return null;if (!gate.failures.length || gate.failures.some((entry) => !entry.file)) return null;const failures = gate.failures.map((failure) => ({ ...failure, waiver: store.landingWaiverFor(state.board, failure)?.id }));return failures.every((entry) => entry.waiver) ? { tree: gate.tree, failures, logPath: gate.logPath } : null;diff --git a/test/land.test.js b/test/land.test.jsindex 6ebbbdb4..5f14ed98 100644--- a/test/land.test.js+++ b/test/land.test.js@@ -637,6 +637,69 @@ test('land holds a flake without retries and person waivers cover every failureassert.equal(calls(box).length, beforeHook, 'expired proof is refused without rerunning the red gate');});+test('a waiver after an early-stopped gate runs the gate again [C7,V4]', async (t) => {+ for (const mode of ['early green', 'early red', 'unaccounted', 'complete']) await t.test(`${mode} keeps the exact landing proof [C7,V4]`, () => {+ const box = landProject();+ const gate = join(box.dir, 'land-gate.cjs');+ writeFileSync(gate, [+ "const fs = require('node:fs'); const path = require('node:path');",+ `const calls = ${JSON.stringify(box.calls)}; const trace = ${JSON.stringify(box.trace)};`,+ "const args = process.argv.slice(2); const alone = args.includes('--alone'); fs.appendFileSync(calls, JSON.stringify(args) + '\\n');",+ "const files = alone ? args.filter(arg => arg !== '--alone') : fs.readdirSync('web').filter(name => /^land-\\d+\\.test\\.js$/.test(name)).map(name => 'web/' + name);",+ "console.log('TAP version 13'); let count = 0; let failed = 0;",+ "for (const file of files) { const text = fs.readFileSync(file, 'utf8'); count++; fs.appendFileSync(trace, JSON.stringify({ alone, file }) + '\\n');",+ " const red = !alone && process.env.LAND_SUPPRESS_RED !== '1' && text.includes('FLAKE');",+ " console.log((red ? 'not ok ' : 'ok ') + count + ' - ' + file + ' keeps the landed behavior');",+ " if (red) { failed++; console.log(' ---\\n location: ' + path.resolve(file) + ':1:1\\n error: fixture failure\\n ...');",+ " if (process.env.LAND_EARLY_STOP === '1') { console.error('Landing gate stopped early after ' + file + ': fixture failure'); console.error('Files not run: ' + files.slice(count).join(', ')); break; } }",+ "}",+ "if (process.env.LAND_UNACCOUNTED === '1' && failed) process.exit(1);",+ "console.log('1..' + count); console.log('# tests ' + count); console.log('# pass ' + (count - failed)); console.log('# fail ' + failed); process.exitCode = failed ? 1 : 0;",+ ].join('\n'));+ const entries = verifiedFour(box, { flaky: 0 });+ if (mode.startsWith('early')) box.env.LAND_EARLY_STOP = '1';+ if (mode === 'unaccounted') box.env.LAND_UNACCOUNTED = '1';+ const base = box.git(box.repo, 'rev-parse', 'HEAD');+ const held = json(box, box.repo, 'land');+ assert.equal(held.batch.state, 'flaky');+ assert.deepEqual(held.landed, []);+ const before = calls(box).length;+ const initial = readFileSync(held.batch.logPath, 'utf8');+ if (mode.startsWith('early')) {+ assert.match(initial, /Landing gate stopped early/u);+ assert.ok(initial.includes(`Files not run: ${FILES.slice(1).join(', ')}`));+ assert.doesNotMatch(initial, /ok 2 -/u, 'later files actually did not run');+ } else {+ assert.doesNotMatch(initial, /stopped early|Files not run/u);+ if (mode === 'unaccounted') assert.doesNotMatch(initial, /^# fail /mu, 'the interrupted account has no positive completion footer');+ }+ json(box, box.repo, 'land', '--waive', FILES[0], '--until', '2099-01-01', '--reason', 'private first failure exception');+ delete box.env.LAND_EARLY_STOP;+ delete box.env.LAND_UNACCOUNTED;+ if (mode === 'early green' || mode === 'unaccounted') box.env.LAND_SUPPRESS_RED = '1';+ const result = json(box, box.repo, 'land');+ if (mode === 'complete') {+ assert.equal(calls(box).length, before, 'a complete recorded gate is reused after its waiver');+ assert.deepEqual(result.landed, entries.map(entry => entry.item));+ } else {+ assert.deepEqual(calls(box).slice(before), [[]], 'exactly one fresh full gate runs after the waiver');+ const rerun = readFileSync(result.batch.logPath, 'utf8');+ assert.match(rerun, /ok 4 - web\/land-4/u, 'the fresh run reaches the previously untouched final file');+ assert.doesNotMatch(rerun, /stopped early|Files not run/u);+ if (mode === 'early green' || mode === 'unaccounted') {+ assert.match(rerun, /# fail 0/u);+ assert.deepEqual(result.landed, entries.map(entry => entry.item));+ assert.equal(box.git(box.remote, 'rev-parse', 'main'), result.batch.tip);+ } else {+ assert.match(rerun, /# fail 1/u);+ assert.deepEqual(result.landed, [], 'a fresh red gate cannot borrow the earlier waived partial proof');+ assert.equal(box.git(box.repo, 'rev-parse', 'HEAD'), base);+ assert.equal(box.git(box.remote, 'rev-parse', 'main'), base);+ }+ }+ });+});+test('land stops again with an expired waiver, and a changed test on main releases the held batch [B3,R3]', () => {const box = landProject();box.env.LAND_SUPPRESS_RED = '1';