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.

feat(land): publish pushes only a trunk head the suite passed [C7,V4]

Corey Olson4e9ec8f174a6
diff --git a/src/cli.js b/src/cli.js
index a3cf7436..0389ed76 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -43,6 +43,7 @@ import * as gateReceipt from './gate-receipt.js';
import * as itemSessions from './item-sessions.js';
import * as seatCheckout from './seat-checkout.js';
import { submitPreflight } from './submit-preflight.js';
+import { publishTrunk } from './publish.js';
import * as store from './board.js';
import * as nativeFlakes from './native-flake-cli.js';
import {
@@ -3700,6 +3701,13 @@ function workCommands(io, args) {
if (!result.batch) io.say(result.items ? `would land: ${result.items.map((id) => `#${id}`).join(', ') || 'none'}` : 'no verified items ready to land');
return 0;
}),
+ publish: () => act(async (ctx, board, me) => {
+ if (me.id !== COORDINATOR || !ctx.info.isMain) throw new Refused('COORDINATOR_ONLY', 'only the coordinator publishes the trunk; ask your coordinator to run pullboard publish');
+ if (first || second || rest.length) throw new Refused('USAGE', 'pullboard publish');
+ const result = await publishTrunk({ root: ctx.info.root, board, config: mainPolicy(ctx.info.root).config, say: io.say, onWait: gateWaitReporter(io) });
+ io.result?.(result);
+ return result.published || result.waiting ? 0 : 1;
+ }),
merged: () => act(async (ctx, board, me) => {
const recovered = await relayCommandReceipt(ctx.info.root, io.relayCommand);
if (recovered) {
diff --git a/src/help.js b/src/help.js
index 33979cc4..8ac06e58 100644
--- a/src/help.js
+++ b/src/help.js
@@ -146,6 +146,7 @@ Coordinator
file one item per file a linter, type checker or test reporter flags
pullboard land [--max N] [--dry-run] [--adopt] gate and push a durable batch of verified items
pullboard land --waive <test> --until <date> --reason \"why\" the person records an expiring test waiver
+ pullboard publish coordinator: run the whole suite on the trunk head; push it only when every test passes
pullboard merged <id> <commit> record where verified work landed
pullboard withdraw <id> <reason> drop an item nobody should build
pullboard refreeze <id> adopt a corrected criterion or changed spec rows
@@ -276,6 +277,7 @@ const HELP_EXAMPLES = {
runner: 'pullboard runner add studio --slots 2 --browser 1', 'runner add': 'pullboard runner add studio --slots 2 --browser 1',
edit: 'pullboard edit 12 --brief "Add the upload page"', release: 'pullboard release 12',
land: 'pullboard land --max 4',
+ publish: 'pullboard publish',
health: 'pullboard health',
reopen: 'pullboard reopen 12 --note "correct the frozen criterion"',
escalate: 'pullboard escalate 12 --note "needs a manual step"', next: 'pullboard next',
diff --git a/src/publish.js b/src/publish.js
new file mode 100644
index 00000000..0be72dbb
--- /dev/null
+++ b/src/publish.js
@@ -0,0 +1,110 @@
+/**
+ * Tier 2 of landing (#801): publish runs the whole suite on the exact local trunk head and pushes that head to the
+ * remote only when every test passes. A red head is never pushed: the report names every failing test from the one
+ * run and, for each failing file, the items landed since the last published head whose merges touched it. The same
+ * red head is not run again; publish waits for a new head.
+ */
+import { randomUUID } from 'node:crypto';
+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 * as store from './board.js';
+import { runGate } from './gate.js';
+import { git } from './git.js';
+import { mainCheckout } from './git.js';
+import { repoInfo } from './git.js';
+import { tryGit } from './git.js';
+import { landingFailures } from './land.js';
+import { landingRemote } from './land.js';
+import { Refused } from './refused.js';
+
+/** Where publish remembers the last head it found red, so the same head is not run again. */
+function stateFile(root) {
+ return join(repoInfo(root).commonDir, 'pullboard', 'publish.json');
+}
+
+/** The head publish last found red, or null. */
+function lastRed(root) {
+ try { return JSON.parse(readFileSync(stateFile(root), 'utf8')).red ?? null; } catch { return null; }
+}
+
+/** The commit the remote branch names now, or null when it names none. */
+function remoteHead(root, remote, branch) {
+ const listed = tryGit(root, ['ls-remote', remote, `refs/heads/${branch}`]);
+ return listed.status === 0 ? listed.stdout.split(/\s+/u)[0] || null : null;
+}
+
+/**
+ * For each failing file, the items landed between the published head and this head whose merge touched it: each
+ * first-parent merge on the trunk is matched to the item whose merged commit it is, and to the files it changed.
+ */
+function touchedBy(root, board, published, head, files) {
+ const range = published ? `${published}..${head}` : head;
+ const merges = tryGit(root, ['rev-list', '--first-parent', range]).stdout.split('\n').filter(Boolean);
+ const items = store.listItems(board, { all: true }).filter(item => item.item_merged_commit);
+ const byMerge = new Map(items.map(item => [item.item_merged_commit, item.item_id]));
+ const touched = new Map(files.map(file => [file, []]));
+ for (const merge of merges) {
+ const id = byMerge.get(merge);
+ if (!id) continue;
+ const changed = tryGit(root, ['diff', '--name-only', `${merge}^1`, merge]).stdout.split('\n').filter(Boolean);
+ for (const file of files) if (changed.includes(file) && !touched.get(file).includes(id)) touched.get(file).push(id);
+ }
+ return touched;
+}
+
+/**
+ * Publish the local trunk head (#801): run the whole suite on exactly that head in a private worktree; push it when
+ * green; otherwise report every failing test with the landed items that touched its file, and remember the head so
+ * the next publish waits for a new one.
+ *
+ * @param {{ root: string, board: any, config: any, say: (line: string) => void, onWait?: Function }} options
+ * @returns {Promise<{ head: string, published: boolean, red: Array<{ file: string|null, name: string, items: number[] }>, waiting?: boolean }>}
+ */
+export async function publishTrunk({ root, board, config, say, onWait }) {
+ const trunk = mainCheckout(root);
+ if (!trunk?.commit) throw new Refused('LAND_TRUNK', 'publish needs the coordinator’s primary branch; return its checkout to the trunk');
+ const branch = trunk.branch.replace(/^refs\/heads\//u, '');
+ const remote = landingRemote(root, trunk.branch);
+ if (!remote) throw new Refused('LAND_PUSH', `the landing push failed: this repo has no remote to push ${branch} to; add one with git remote add origin <url> and run pullboard publish again`);
+ const head = trunk.commit;
+ const published = remoteHead(root, remote, branch);
+ if (published === head) {
+ say(`${branch} at ${head.slice(0, 12)} is already published`);
+ return { head, published: true, red: [] };
+ }
+ if (lastRed(root) === head) {
+ say(`${branch} at ${head.slice(0, 12)} was red; publish waits for a new head: land a fix, then run pullboard publish again`);
+ return { head, published: false, red: [], waiting: true };
+ }
+ const directory = join(repoInfo(root).commonDir, 'pullboard', 'publish', randomUUID());
+ mkdirSync(join(directory, '..'), { recursive: true });
+ git(root, ['worktree', 'add', '--detach', directory, head]);
+ let gate;
+ try {
+ gate = await runGate(directory, config, { trustStamp: false, landing: true, agent: 'coordinator', onWait });
+ } finally {
+ tryGit(root, ['worktree', 'remove', '--force', directory]);
+ if (existsSync(directory)) rmSync(directory, { recursive: true, force: true });
+ }
+ if (gate.isGreen) {
+ const pushed = tryGit(root, ['push', remote, `${head}:refs/heads/${branch}`]);
+ if (pushed.status !== 0) throw new Refused('LAND_PUSH', `the landing push failed: ${pushed.stderr || pushed.stdout}; inspect the remote and hooks, then run pullboard publish again`);
+ writeFileSync(stateFile(root), JSON.stringify({ published: head }) + '\n');
+ say(`published ${branch} at ${head.slice(0, 12)}: the whole suite passed`);
+ return { head, published: true, red: [] };
+ }
+ const failures = landingFailures(gate.output ?? '', directory);
+ const files = [...new Set(failures.map(failure => failure.file).filter(Boolean))];
+ const touched = touchedBy(root, board, published, head, files);
+ const red = failures.map(failure => ({ file: failure.file, name: failure.name, items: failure.file ? touched.get(failure.file) : [] }));
+ writeFileSync(stateFile(root), JSON.stringify({ red: head, published }) + '\n');
+ say(`${branch} at ${head.slice(0, 12)} is red and was not pushed; ${red.length} failing ${red.length === 1 ? 'test' : 'tests'}:`);
+ for (const entry of red) {
+ say(` ${entry.file ?? '(no file)'}: ${entry.name}; ${entry.items.length ? 'touched by ' + entry.items.map(id => `#${id}`).join(', ') : 'touched by no item landed since the last published head'}`);
+ }
+ return { head, published: false, red };
+}
diff --git a/test/land.test.js b/test/land.test.js
index 127e2485..4a5b1068 100644
--- a/test/land.test.js
+++ b/test/land.test.js
@@ -1357,3 +1357,36 @@ test('an item with no spec rows lands under a header its commit hook accepts [B3
const [subject] = mergeSubjects(box, base, result.batch.tip);
assert.equal(subject, 'docs(merge): docs fixture with no rows', 'a docs-lane item with no rows lands under docs(merge)');
});
+
+test('publish pushes only a head the whole suite passed and names every red [B3,R3]', () => {
+ const box = landProject();
+ const entries = verifiedFour(box, { red: 1 });
+ const before = box.git(box.remote, 'rev-parse', 'main');
+ // Tier 1 by hand: each verified item lands on the local trunk only, as pullboard merged records it.
+ for (const entry of entries) {
+ box.git(box.repo, 'merge', '-q', '--no-ff', '-m', `chore(merge): land fixture ${entry.item} [G1]`, entry.commit);
+ const merged = box.run(box.repo, 'merged', String(entry.item), box.git(box.repo, 'rev-parse', 'HEAD'));
+ assert.equal(merged.code, 0, merged.err);
+ }
+ const head = box.git(box.repo, 'rev-parse', 'main');
+ const start = calls(box).length;
+ const red = box.run(box.repo, 'publish', '--json');
+ assert.equal(red.code, 1, 'a red head fails publish');
+ const report = JSON.parse(red.out);
+ assert.equal(report.published, false);
+ assert.equal(box.git(box.remote, 'rev-parse', 'main'), before, 'a red head is never pushed');
+ assert.deepEqual(report.red.map((entry) => entry.file), [FILES[1]], 'every failing test is named from the one run');
+ assert.deepEqual(report.red[0].items, [entries[1].item], 'the failing file names the landed item whose merge touched it');
+ assert.equal(calls(box).length - start, 1, 'one whole-suite run');
+ const again = box.run(box.repo, 'publish', '--json');
+ assert.equal(again.code, 0);
+ assert.equal(JSON.parse(again.out).waiting, true, 'the same red head waits for a new head');
+ assert.equal(calls(box).length - start, 1, 'waiting runs no tests');
+ // A fix lands on the trunk; the new head passes the whole suite and is pushed exactly.
+ assert.equal(commitFile(box, box.repo, FILES[1], 'PASS\n', 'fix(web): land fixture 2 passes again [G1]').status, 0);
+ const fixed = box.git(box.repo, 'rev-parse', 'main');
+ assert.notEqual(fixed, head);
+ const green = json(box, box.repo, 'publish');
+ assert.equal(green.published, true);
+ assert.equal(box.git(box.remote, 'rev-parse', 'main'), fixed, 'only the head the whole suite passed reaches the remote');
+});