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(core): refuse old-client adds after milestone ship [N26,H16]

Corey Olson108e709b4d8a
diff --cc src/milestones.js
index 5d52f638,00000000..8f4c4a96
mode 100644,000000..100644
--- a/src/milestones.js
+++ b/src/milestones.js
@@@ -1,330 -1,0 +1,330 @@@
+/**
+ * The roadmap's milestones: ordered names, notes, targets and item references kept in one
+ * board_meta value, and the moves that change them (N26). Only the coordinator changes them.
+ *
+ * An item counts toward a milestone only once it has landed on main: it is verified and its merge
+ * commit is recorded. Shipping a milestone records main's commit and carries every unlanded item
+ * into the next milestone, so the roadmap stays the one place that says what is planned.
+ */
+import { COORDINATOR } from './config.js';
+import { ENGINE_VERSION, MILESTONE_RANK_ENGINE } from './machine.js';
+import { Refused } from './refused.js';
+import { atomic, itemById, listItems, logEvent, milestones, PERSON } from './board.js';
+
+/** The engine at which a milestone carries a target and ships; older moves replay as they did. */
+export const MILESTONE_SHIP_ENGINE = 39;
+
+/** The engine a move runs under: its recorded one during replay, else this client's. */
+function engineOf(board) {
+ return board.executionEngineVersion ?? ENGINE_VERSION;
+}
+
+/**
+ * An item's roadmap state: landed once its merge onto main is recorded, accepted while verified
+ * but not yet landed, and otherwise its board status.
+ *
+ * @param {string} status
+ * @param {boolean} landed
+ * @returns {string}
+ */
+export function roadmapState(status, landed) {
+ if (status === 'verified' && landed) return 'landed';
+ return status === 'verified' ? 'accepted' : status;
+}
+
+/**
+ * Return milestones with each item's current status and state, a landed count, and the
+ * milestone's target and shipment. `done` is the landed count: accepted work has not shipped yet.
+ *
+ * @param {any} board
+ * @param {((reference: string) => any) | null} [resolveExternal]
+ * @returns {any[]}
+ */
+export function roadmap(board, resolveExternal = null) {
+ const items = new Map(listItems(board, { all: true }).map((item) => [item.item_id, item]));
+ const at = board.clock.now().getTime();
+ return milestones(board).map((milestone) => {
+ const entries = milestone.items.map((id) => {
+ if (typeof id === 'number') {
+ const item = items.get(id);
+ return item
+ ? { id, title: item.item_title, status: item.item_status, state: roadmapState(item.item_status, Boolean(item.item_merged_commit)) }
+ : { id, title: `#${id}`, status: 'missing', state: 'missing' };
+ }
+ const external = resolveExternal?.(id) ?? { id, title: id, status: 'unavailable' };
+ return { id: external.id, title: external.title, status: external.status, state: roadmapState(external.status, Boolean(external.landed)) };
+ });
+ const landed = entries.filter((item) => item.state === 'landed').length;
+ const target = milestone.target ?? null;
+ return {
+ name: milestone.name,
+ note: milestone.note,
+ target,
+ pastTarget: !milestone.shipped && target !== null && Date.parse(target) <= at,
+ shipped: milestone.shipped ?? null,
+ items: entries,
+ landed,
+ done: landed,
+ total: entries.length,
+ };
+ });
+}
+
+/** Validate a coordinator identity before changing roadmap metadata. */
+function requireCoordinator(agentId) {
+ if (agentId !== COORDINATOR) throw new Refused('COORDINATOR_ONLY', 'only the coordinator changes milestones; ask your coordinator to update the roadmap');
+}
+
+/** Parse an ordered list of local item ids and repo-qualified ids. */
+function normalizeMilestoneItems(items) {
+ if (!Array.isArray(items)) throw new Refused('MILESTONE_ITEMS', 'milestone items need comma-separated item ids; use pullboard milestone add --items 1,2');
+ const result = items.map((value) => {
+ if (Number.isSafeInteger(value) && value > 0) return value;
+ if (typeof value === 'string') {
+ const text = value.trim();
+ if (/^[1-9]\d*$/.test(text) && Number.isSafeInteger(Number(text))) return Number(text);
+ if (/^[^#,\s][^#,]*#[1-9]\d*$/.test(text)) return text;
+ }
+ throw new Refused('MILESTONE_ITEMS', `invalid item id ${String(value)}; use a positive id or repo#id`);
+ });
+ if (new Set(result.map((value) => JSON.stringify(value))).size !== result.length) {
+ throw new Refused('MILESTONE_ITEMS', 'a milestone cannot list the same item twice; remove duplicate ids and retry');
+ }
+ return result;
+}
+
+/** Refuse local item ids that do not exist while leaving repo-qualified ids for board lookup. */
+function validateLocalMilestoneItems(board, items) {
+ for (const id of items) if (typeof id === 'number') itemById(board, id);
+}
+
+/** Validate a milestone name and note before storing them. */
+function normalizeMilestoneText(name, note = null) {
+ if (typeof name !== 'string' || !name.trim()) throw new Refused('MILESTONE_NAME', 'a milestone needs a name; use pullboard milestone add <name>');
+ if (typeof note !== 'string' && note !== null) throw new Refused('MILESTONE_NOTE', 'a milestone note needs text; use --note <text>');
+ return { name: name.trim(), note: note?.trim() || null };
+}
+
+/**
+ * The instant a target the coordinator typed names, read in this machine's time zone, as UTC ISO
+ * text, or `none` unchanged. The move is prepared with this value, so the ordered envelope never
+ * carries a local time that another replica would read in its own zone.
+ *
+ * @param {unknown} target
+ * @returns {unknown}
+ */
+export function canonicalMilestoneTarget(target) {
+ if (target === 'none' || typeof target !== 'string' || !/\d/.test(target)) return target;
+ const at = Date.parse(target.trim());
+ return Number.isFinite(at) ? new Date(at).toISOString() : target;
+}
+
+/**
+ * A target as ISO text, or null for `none`, which clears it. Applying a move accepts only a date or
+ * a date and time with an explicit zone, so every replica reads the same instant: a bare local
+ * time would mean a different moment on a machine in another zone.
+ *
+ * @param {unknown} target
+ * @returns {string | null}
+ */
+function normalizeMilestoneTarget(target) {
+ if (target === 'none') return null;
+ const text = typeof target === 'string' ? target.trim() : '';
+ const zoned = /^\d{4}-\d{2}-\d{2}$/.test(text) || /T.*(?:Z|[+-]\d{2}:?\d{2})$/i.test(text);
+ const at = zoned ? Date.parse(text) : NaN;
+ if (!Number.isFinite(at)) throw new Refused('MILESTONE_TARGET', 'a target needs a date, or a date and time with its zone, like 2026-10-20T18:00Z; use --target <date and time>, or --target none to clear it');
+ return new Date(at).toISOString();
+}
+
+/** Save the whole milestone list in one board_meta value. */
+function saveMilestones(board, entries) {
+ board.db.prepare('INSERT INTO board_meta (meta_key, meta_value) VALUES (?, ?) ON CONFLICT(meta_key) DO UPDATE SET meta_value = excluded.meta_value')
+ .run('milestones', JSON.stringify(entries));
+}
+
+/** The refusal for adding work to a milestone that already shipped. */
+function shippedRefusal(entry) {
+ return new Refused('MILESTONE_SHIPPED', `milestone ${entry.name} shipped at ${entry.shipped.commit}; add the item to the next milestone instead`);
+}
+
+/** Add an ordered milestone without changing any referenced board items. */
+export function addMilestone(board, { agentId, name, note = null, items = [] }) {
+ requireCoordinator(agentId);
+ const text = normalizeMilestoneText(name, note);
+ const normalized = normalizeMilestoneItems(items);
+ validateLocalMilestoneItems(board, normalized);
+ return atomic(board, () => {
+ const entries = milestones(board);
+ if (entries.some((entry) => entry.name === text.name)) throw new Refused('MILESTONE_EXISTS', `milestone ${text.name} already exists; edit it or choose another name`);
+ saveMilestones(board, [...entries, { ...text, items: normalized }]);
+ logEvent(board, agentId, 'milestone_add', null, { name: text.name, items: normalized });
+ return text.name;
+ });
+}
+
+/**
- * Add or remove item references while preserving the remaining order. From engine 39 a shipped
- * milestone takes no new items; removing one is still allowed.
++ * Add or remove item references while preserving the remaining order. Shipment is receiver state,
++ * so a shipped milestone takes no new items even from older clients; removing one is still allowed.
+ */
+export function editMilestoneItems(board, name, { agentId, add = [], remove = [] }) {
+ requireCoordinator(agentId);
+ const additions = normalizeMilestoneItems(add);
+ const removals = normalizeMilestoneItems(remove);
+ validateLocalMilestoneItems(board, additions);
+ if (additions.length && removals.length) throw new Refused('MILESTONE_ITEMS', 'add or remove milestone items in separate commands');
+ if (!additions.length && !removals.length) throw new Refused('MILESTONE_ITEMS', 'name ids with --add or --remove');
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const index = entries.findIndex((entry) => entry.name === name);
+ if (index < 0) throw new Refused('NO_MILESTONE', `no milestone named ${name}; list them with pullboard roadmap`);
+ const current = entries[index];
- if (additions.length && current.shipped && engineOf(board) >= MILESTONE_SHIP_ENGINE) throw shippedRefusal(current);
++ if (additions.length && current.shipped) throw shippedRefusal(current);
+ const nextItems = additions.length
+ ? [...current.items, ...additions]
+ : current.items.filter((id) => !removals.some((removeId) => JSON.stringify(removeId) === JSON.stringify(id)));
+ if (additions.length && new Set(nextItems.map((value) => JSON.stringify(value))).size !== nextItems.length) {
+ throw new Refused('MILESTONE_ITEMS', 'a milestone cannot list the same item twice; remove duplicate ids and retry');
+ }
+ if (removals.some((id) => current.items.every((present) => JSON.stringify(id) !== JSON.stringify(present)))) {
+ throw new Refused('MILESTONE_ITEMS', 'one or more ids are not in this milestone; read pullboard roadmap and retry');
+ }
+ entries[index] = { ...current, items: nextItems,
+ ...((board.executionEngineVersion ?? ENGINE_VERSION) >= MILESTONE_RANK_ENGINE && current.order
+ ? { order: current.order.filter(id => nextItems.includes(id)) } : {}) };
+ saveMilestones(board, entries);
+ logEvent(board, agentId, 'milestone_items', null, { name, add: additions, remove: removals });
+ return nextItems;
+ });
+}
+
+/** Replace this milestone's explicit ranks; omitted items retain the ordinary queue order [N2,B13]. */
+export function orderMilestoneItems(board, name, { agentId, items }) {
+ if ((board.executionEngineVersion ?? ENGINE_VERSION) < MILESTONE_RANK_ENGINE) throw new Refused('ENGINE_VERSION', 'milestone order requires engine 34; upgrade Pullboard before ranking work');
+ if (agentId !== COORDINATOR && (agentId === PERSON || !board.db.prepare('SELECT 1 FROM agent WHERE agent_id = ?').get(agentId))) {
+ throw new Refused('NO_AGENT', 'milestone order is an agent or coordinator move; join an agent worktree or ask the coordinator');
+ }
+ const order = normalizeMilestoneItems(items);
+ if (!order.length) throw new Refused('MILESTONE_ITEMS', 'name the ranked item ids: pullboard milestone order <name> 1,2');
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const index = entries.findIndex(entry => entry.name === name);
+ if (index < 0) throw new Refused('NO_MILESTONE', `no milestone named ${name}; list them with pullboard roadmap`);
+ if (order.some(id => !entries[index].items.includes(id))) throw new Refused('MILESTONE_ITEMS', 'rank only items in this milestone; read pullboard roadmap and retry');
+ entries[index] = { ...entries[index], order };
+ saveMilestones(board, entries);
+ logEvent(board, agentId, 'milestone_order', null, { name, items: order });
+ return order;
+ });
+}
+
+/** Move a milestone before another while retaining all item and note data. */
+export function moveMilestone(board, name, { agentId, before }) {
+ requireCoordinator(agentId);
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const index = entries.findIndex((entry) => entry.name === name);
+ const target = entries.findIndex((entry) => entry.name === before);
+ if (index < 0 || target < 0) throw new Refused('NO_MILESTONE', `name both milestones in pullboard milestone move ${name} --before <other>`);
+ if (name === before) throw new Refused('MILESTONE_ORDER', 'choose a different milestone to move before');
+ const [entry] = entries.splice(index, 1);
+ entries.splice(entries.findIndex((value) => value.name === before), 0, entry);
+ saveMilestones(board, entries);
+ logEvent(board, agentId, 'milestone_move', null, { name, before });
+ return entries;
+ });
+}
+
+/**
+ * Rename a milestone, update its note, or set its target without touching its items. A target is
+ * an engine-39 meaning, so an older engine's edit replays exactly as it did.
+ */
+export function editMilestone(board, name, { agentId, newName, note, target }) {
+ requireCoordinator(agentId);
+ const engine = engineOf(board);
+ if (target !== undefined && engine < MILESTONE_SHIP_ENGINE) {
+ throw new Refused('ENGINE_VERSION', `a milestone target requires engine ${MILESTONE_SHIP_ENGINE}; this board uses engine ${engine}; upgrade Pullboard before using --target`);
+ }
+ if (newName === undefined && note === undefined && target === undefined) {
+ throw new Refused('MILESTONE_EDIT', engine < MILESTONE_SHIP_ENGINE ? 'supply --name or --note to edit a milestone' : 'supply --name, --note or --target to edit a milestone');
+ }
+ const targetValue = target === undefined ? undefined : normalizeMilestoneTarget(target);
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const index = entries.findIndex((entry) => entry.name === name);
+ if (index < 0) throw new Refused('NO_MILESTONE', `no milestone named ${name}; list them with pullboard roadmap`);
+ const renamed = newName === undefined ? name : normalizeMilestoneText(newName).name;
+ if (renamed !== name && entries.some((entry) => entry.name === renamed)) throw new Refused('MILESTONE_EXISTS', `milestone ${renamed} already exists; choose another name`);
+ entries[index] = { ...entries[index], name: renamed, ...(note === undefined ? {} : { note: normalizeMilestoneText(renamed, note).note }) };
+ if (targetValue !== undefined) entries[index].target = targetValue;
+ saveMilestones(board, entries);
+ logEvent(board, agentId, 'milestone_edit', null, { before: name, after: renamed, noteChanged: note !== undefined,
+ ...(targetValue === undefined ? {} : { target: targetValue }) });
+ return entries[index];
+ });
+}
+
+/** Remove one milestone only; its referenced work items remain on their boards. */
+export function removeMilestone(board, name, { agentId }) {
+ requireCoordinator(agentId);
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const remaining = entries.filter((entry) => entry.name !== name);
+ if (remaining.length === entries.length) throw new Refused('NO_MILESTONE', `no milestone named ${name}; list them with pullboard roadmap`);
+ saveMilestones(board, remaining);
+ logEvent(board, agentId, 'milestone_remove', null, { name });
+ return name;
+ });
+}
+
+/**
+ * Ship a milestone: record main's commit on it, keep the items that landed, and move every other
+ * local item into the next milestone (the first unshipped one after it, or `next`), recording the
+ * move on each item's thread. A withdrawn item stays, since it will never land; a repo#id
+ * reference stays too, since its board, not this one, says whether it landed.
+ *
+ * @param {any} board
+ * @param {string} name
+ * @param {{ agentId: string, commit: string | null, next?: string }} options
+ * @returns {{ milestone: any, into: string | null, moved: number[], notMoved: string[] }}
+ */
+export function shipMilestone(board, name, { agentId, commit, next }) {
+ requireCoordinator(agentId);
+ if (typeof commit !== 'string' || !/^(?:[0-9a-f]{40}|[0-9a-f]{64})$/.test(commit)) {
+ throw new Refused('MILESTONE_COMMIT', "shipping records main's commit and main has none here; commit to main, then ship from the main checkout");
+ }
+ return atomic(board, () => {
+ const entries = milestones(board);
+ const index = entries.findIndex((entry) => entry.name === name);
+ if (index < 0) throw new Refused('NO_MILESTONE', `no milestone named ${name}; list them with pullboard roadmap`);
+ const current = entries[index];
+ if (current.shipped) throw shippedRefusal(current);
+ const items = new Map(listItems(board, { all: true }).map((item) => [item.item_id, item]));
+ const notMoved = current.items.filter((id) => typeof id === 'string');
+ const stays = (id) => {
+ const item = typeof id === 'number' ? items.get(id) : null;
+ return !item || item.item_status === 'withdrawn' || roadmapState(item.item_status, Boolean(item.item_merged_commit)) === 'landed';
+ };
+ const moved = current.items.filter((id) => !stays(id));
+ let into = null;
+ if (next !== undefined) {
+ into = entries.findIndex((entry) => entry.name === next);
+ if (into < 0) throw new Refused('NO_MILESTONE', `no milestone named ${next}; list them with pullboard roadmap`);
+ if (into === index) throw new Refused('MILESTONE_ORDER', 'choose a different milestone for --next than the one shipping');
+ if (entries[into].shipped) throw shippedRefusal(entries[into]);
+ } else if (moved.length) {
+ into = entries.findIndex((entry, position) => position > index && !entry.shipped);
+ if (into < 0) throw new Refused('NO_NEXT_MILESTONE', `no unshipped milestone follows ${name} to take its unlanded items; add one with pullboard milestone add, or name one with --next`);
+ }
+ const intoName = into === null ? null : entries[into].name;
+ const at = board.clock.now().toISOString();
+ if (into !== null) entries[into] = { ...entries[into], items: [...entries[into].items, ...moved.filter((id) => !entries[into].items.includes(id))] };
+ entries[index] = { ...current, items: current.items.filter(stays), shipped: { commit, at, by: agentId } };
+ saveMilestones(board, entries);
+ logEvent(board, agentId, 'milestone_ship', null, { name, commit, into: intoName, moved, notMoved });
+ for (const id of moved) {
+ logEvent(board, agentId, 'milestone_moved', id, { from: name, to: intoName, commit,
+ note: `moved from ${name} to ${intoName}: ${name} shipped at ${commit.slice(0, 12)} before this item landed` });
+ }
+ return { milestone: entries[index], into: intoName, moved, notMoved };
+ });
+}
diff --cc test/milestones.test.js
index d6a590b0,00000000..e20a16e4
mode 100644,000000..100644
--- a/test/milestones.test.js
+++ b/test/milestones.test.js
@@@ -1,237 -1,0 +1,270 @@@
+/** The roadmap counts what landed on main, and shipping a milestone carries the rest forward [N26]. */
+import assert from 'node:assert/strict';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { chmodSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join, resolve } from 'node:path';
+import { after, test } from 'node:test';
+import * as store from '../src/board.js';
+
+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');
+const HOUR = 3_600_000;
+const TEMP_DIRS = [];
+
+after(() => {
+ for (const dir of TEMP_DIRS) rmSync(dir, { recursive: true, force: true });
+});
+
+/**
+ * A real repo on main with an initialized board and a builder agent, and items in each state
+ * the roadmap tells apart: landed (verified with a merge commit), accepted (verified only) and open.
+ * Git runs with every GIT_* variable stripped, so a hook's repository never leaks into the fixture.
+ */
+function fixture(t) {
+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-milestones-'));
+ TEMP_DIRS.push(dir);
+ const repo = join(dir, 'repo');
+ const bin = join(dir, 'bin');
+ mkdirSync(bin);
+ // The repo's hooks call pullboard by name, so the fixture puts this checkout's CLI on PATH.
+ const word = (value) => `'${String(value).replaceAll("'", "'\\''")}'`;
+ writeFileSync(join(bin, 'pullboard'), `#!/bin/sh\nexec ${word(process.execPath)} ${word(BIN)} "$@"\n`);
+ chmodSync(join(bin, 'pullboard'), 0o755);
+ const env = { ...process.env };
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
+ Object.assign(env, { HOME: join(dir, 'home'), PULLBOARD_HOME: join(dir, 'pullboard-home'),
+ PULLBOARD_MACHINE_HOME: join(dir, 'machine-home'), GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'Milestone fixture', GIT_AUTHOR_EMAIL: '[email protected]',
+ GIT_COMMITTER_NAME: 'Milestone fixture', GIT_COMMITTER_EMAIL: '[email protected]', PATH: `${bin}:${process.env.PATH}` });
+ execFileSync('git', ['init', '-q', '-b', 'main', repo], { env });
+ /** Run Git inside the fixture repo with its private identity. */
+ const git = (...args) => execFileSync('git', args, { cwd: repo, env, encoding: 'utf8', stdio: 'pipe' }).trim();
+ /** Run pullboard from the main checkout, where it acts as the coordinator. */
+ const run = (...args) => {
+ const result = spawnSync(process.execPath, [BIN, ...args], { cwd: repo, env, encoding: 'utf8' });
+ return { status: result.status, stdout: result.stdout ?? '', stderr: result.stderr ?? '' };
+ };
+ /** Run a command that must succeed and return its JSON document. */
+ const json = (...args) => {
+ const result = run(...args, '--json');
+ assert.equal(result.status, 0, `${args.join(' ')}: ${result.stdout}${result.stderr}`);
+ return JSON.parse(result.stdout);
+ };
+ const initialized = run('init');
+ assert.equal(initialized.status, 0, initialized.stdout + initialized.stderr);
+ writeFileSync(join(repo, 'SPEC.md'), '# Fixture\n\n## G · Goals\n- G1 [approved, must] Work is tracked. | gate: true\n');
+ writeFileSync(join(repo, 'pullboard.json'), JSON.stringify({ gate: 'true', verify: 'any', lanes: { web: { owns: ['web/'], specs: ['G1'] } }, shared: [] }));
+ git('add', '-A');
+ git('commit', '-q', '-m', 'chore: initialize fixture');
+ const board = store.openBoard(join(repo, '.git', 'pullboard', 'board.sqlite'));
+ t.after(() => store.closeBoard(board));
+ store.ensureCoordinator(board, repo);
+ const builder = store.register(board, { lane: 'web', path: join(dir, 'builder'), model: 'Fixture Model' });
+ const freeze = () => ({ text: 'Tracked work', digest: 'digest:tracked' });
+ /** File an item and take it to the named state: open, accepted or landed. */
+ const item = (title, state) => {
+ const id = store.addItem(board, { by: 'coordinator', lane: 'web', title, criterion: 'Tracked work', specIds: ['G1'] });
+ if (state === 'open') return id;
+ const commit = String(id).repeat(40).slice(0, 40);
+ store.claim(board, id, { agentId: builder, lane: 'web', leaseMs: HOUR, freeze });
+ store.submit(board, id, { agentId: builder, commit, tree: 'tree' });
+ store.verify(board, id, { agentId: 'coordinator', decision: 'ACCEPT', note: 'checked it', head: commit, digest: 'digest:tracked', policy: 'any' });
+ if (state === 'landed') store.merged(board, id, { agentId: 'coordinator', commit: git('rev-parse', 'HEAD') });
+ return id;
+ };
+ return { repo, git, run, json, board, builder, item };
+}
+
+/** The milestone named `name` in a roadmap document. */
+function milestone(document, name) {
+ return document.milestones.find((entry) => entry.name === name);
+}
+
+/** The milestone moves recorded on an item's thread. */
+function moves(box, id) {
+ return box.json('show', String(id)).thread.filter((entry) => entry.kind === 'milestone_moved');
+}
+
+test('[N26] a milestone ships what landed and moves the rest', async (t) => {
+ const box = fixture(t);
+ const landed = box.item('Landed work', 'landed');
+ const accepted = box.item('Accepted work', 'accepted');
+ const open = box.item('Open work', 'open');
+ const later = box.item('Later work', 'open');
+ box.json('milestone', 'add', 'A', '--items', `${landed},${accepted},${open}`);
+ box.json('milestone', 'add', 'B', '--items', String(later));
+
+ // The target: set on A and shown in the roadmap and its JSON; a passed one is marked.
+ const edited = box.json('milestone', 'edit', 'A', '--target', '2026-01-02T03:04Z');
+ assert.equal(edited.milestone.target, '2026-01-02T03:04:00.000Z', 'the edit stores the target');
+ const before = box.json('roadmap');
+ assert.equal(milestone(before, 'A').target, '2026-01-02T03:04:00.000Z', 'the roadmap JSON shows the target');
+ assert.equal(milestone(before, 'A').pastTarget, true, 'an unshipped milestone past its target is marked');
+ assert.equal(milestone(before, 'B').pastTarget, false, 'a milestone with no target is never past it');
+
+ // Landed counting: only the merged item counts; each item shows landed, accepted or its status.
+ assert.equal(milestone(before, 'A').landed, 1, 'only the item merged onto main counts as landed');
+ assert.equal(milestone(before, 'A').done, 1, 'done means landed, so accepted work is not done');
+ assert.equal(milestone(before, 'A').total, 3);
+ assert.deepEqual(milestone(before, 'A').items.map(({ id, state }) => [id, state]),
+ [[landed, 'landed'], [accepted, 'accepted'], [open, 'open']], 'each item shows its roadmap state');
+ const text = box.run('roadmap');
+ assert.equal(text.status, 0, text.stdout + text.stderr);
+ assert.match(text.stdout, /^A: 1\/3 landed · target 2026-01-02T03:04:00\.000Z, past target$/m, 'the text shows N/M landed, the target and past target');
+ assert.match(text.stdout, /^ {2}#\d+ Landed work — landed$/m);
+ assert.match(text.stdout, /^ {2}#\d+ Accepted work — accepted$/m);
+ assert.match(text.stdout, /^ {2}#\d+ Open work — open$/m);
+
+ // Shipping is the coordinator's move, not a builder's.
+ assert.throws(() => store.shipMilestone(box.board, 'A', { agentId: box.builder, commit: box.git('rev-parse', 'main') }),
+ (error) => error.code === 'COORDINATOR_ONLY');
+
+ // Ship: A records main's commit, and the two unlanded items move into B.
+ const main = box.git('rev-parse', 'main');
+ const shipped = box.json('milestone', 'ship', 'A');
+ assert.equal(shipped.milestone.shipped.commit, main, "the milestone is shipped at main's commit");
+ assert.equal(shipped.into, 'B', 'the next milestone is the one after it');
+ assert.deepEqual(shipped.moved, [accepted, open]);
+ assert.deepEqual(shipped.notMoved, [], 'no external references were left behind');
+ const after = box.json('roadmap');
+ assert.equal(milestone(after, 'A').shipped.commit, main, "the roadmap shows main's commit on the shipped milestone");
+ assert.deepEqual(milestone(after, 'A').items.map(({ id }) => id), [landed], 'only the landed item stays in the shipped milestone');
+ assert.equal(milestone(after, 'A').pastTarget, false, 'a shipped milestone is no longer past its target');
+ assert.deepEqual(milestone(after, 'B').items.map(({ id }) => id), [later, accepted, open], 'the unlanded items are now in B');
+
+ // The threads: each moved item records the move; the landed one records none.
+ for (const id of [accepted, open]) {
+ const recorded = moves(box, id);
+ assert.equal(recorded.length, 1, `#${id}'s thread records its move`);
+ assert.equal(recorded[0].detail.from, 'A');
+ assert.equal(recorded[0].detail.to, 'B');
+ assert.equal(recorded[0].detail.commit, main);
+ }
+ assert.deepEqual(moves(box, landed), [], 'a landed item does not move');
+
+ // The refusal: a shipped milestone takes no new items.
+ const refused = box.run('milestone', 'items', 'A', '--add', String(later), '--json');
+ assert.notEqual(refused.status, 0, refused.stdout + refused.stderr);
+ assert.equal(JSON.parse(refused.stdout).error.code, 'MILESTONE_SHIPPED', 'adding to a shipped milestone is refused');
+ assert.deepEqual(milestone(box.json('roadmap'), 'A').items.map(({ id }) => id), [landed], 'the refusal changes nothing');
+
+ // A target means one instant on every replica: the move carries UTC, and a bare local time
+ // in an ordered envelope is refused alike in every zone instead of read in each one's own.
+ const { prepareEngineMove, applyEngineMove } = await import('../src/engine.js');
+ const { exportBoard, importBoard } = await import('../src/exchange.js');
+ store.addMilestone(box.board, { agentId: 'coordinator', name: 'Z' });
+ const snapshot = exportBoard(box.board);
+ const prepared = prepareEngineMove(box.board, 'editMilestone', ['Z', { agentId: 'coordinator', target: '2026-10-20T18:00' }], { id: 'zone-target', actor: 'coordinator' });
+ assert.match(prepared.args[1].target, /Z$/u, 'the prepared move carries the instant in UTC');
+ const bare = { ...prepared, id: 'bare-target', args: ['Z', { agentId: 'coordinator', target: '2026-10-20T18:00' }] };
+ const zone = process.env.TZ;
+ const replicas = [];
+ try {
+ for (const name of ['UTC', 'America/Chicago']) {
+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-target-zone-'));
+ TEMP_DIRS.push(dir);
+ const replica = store.openBoard(join(dir, 'board.sqlite'));
+ t.after(() => store.closeBoard(replica));
+ importBoard(replica, snapshot);
+ process.env.TZ = name;
+ const refused = applyEngineMove(replica, bare, { sequence: 1, at: '2026-10-17T04:00:00.000Z' });
+ assert.equal(refused.error?.code, 'MILESTONE_TARGET', `a bare local time is refused in ${name}: ${JSON.stringify(refused)}`);
+ const applied = applyEngineMove(replica, prepared, { sequence: 2, at: '2026-10-17T04:00:01.000Z' });
+ assert.equal(applied.error, undefined, JSON.stringify(applied));
+ replicas.push(store.milestones(replica).find((row) => row.name === 'Z').target);
+ }
+ } finally {
+ if (zone === undefined) delete process.env.TZ;
+ else process.env.TZ = zone;
+ }
+ assert.equal(replicas[0], replicas[1], `every replica stores the same target: ${JSON.stringify(replicas)}`);
+});
+
+test('[N26] milestone ship --next names where the unlanded items go', (t) => {
+ const box = fixture(t);
+ const open = box.item('Open work', 'open');
+ box.json('milestone', 'add', 'A', '--items', String(open));
+ box.json('milestone', 'add', 'B');
+ box.json('milestone', 'add', 'C');
+ const shipped = box.json('milestone', 'ship', 'A', '--next', 'C');
+ assert.equal(shipped.into, 'C', '--next overrides the milestone after it');
+ const document = box.json('roadmap');
+ assert.deepEqual(milestone(document, 'B').items, [], 'the milestone after it gets nothing');
+ assert.deepEqual(milestone(document, 'C').items.map(({ id }) => id), [open], 'the --next milestone gets the unlanded item');
+ assert.equal(moves(box, open)[0].detail.to, 'C', 'the thread names the --next milestone');
+});
+
+test('[N26] milestone ship leaves external references in place and names them as not moved', (t) => {
+ const box = fixture(t);
+ box.json('milestone', 'add', 'JSON release', '--items', 'other-repo#17,third-repo#29');
+ const shipped = box.json('milestone', 'ship', 'JSON release');
+ assert.deepEqual(shipped.notMoved, ['other-repo#17', 'third-repo#29'], 'JSON lists each reference that remains on another board');
+ assert.deepEqual(shipped.moved, [], 'shipping does not move foreign items');
+ assert.deepEqual(milestone(box.json('roadmap'), 'JSON release').items.map(({ id }) => id),
+ ['other-repo#17', 'third-repo#29'], 'the foreign references remain on the shipped milestone');
+
+ box.json('milestone', 'add', 'Text release', '--items', 'other-repo#31,third-repo#33');
+ const text = box.run('milestone', 'ship', 'Text release');
+ assert.equal(text.status, 0, text.stdout + text.stderr);
+ assert.match(text.stdout, /not moved across boards: other-repo#31, third-repo#33/,
+ 'human output names every foreign reference that stayed in place');
+});
+
+test('[N26,H16] engine 38 cannot ship a milestone or set its target', async (t) => {
+ const box = fixture(t);
+ box.json('milestone', 'add', 'A');
+ box.json('milestone', 'add', 'B');
+ const { applyEngineMove, appliedSequence, engineReceipt, prepareEngineMove } = await import('../src/engine.js');
+ const { exportBoard } = await import('../src/exchange.js');
+ const main = box.git('rev-parse', 'main');
+ const moves = [
+ prepareEngineMove(box.board, 'shipMilestone', ['A', { agentId: 'coordinator', commit: main, next: 'B' }],
+ { id: 'engine38-milestone-ship', actor: 'coordinator' }),
+ prepareEngineMove(box.board, 'editMilestone', ['A', { agentId: 'coordinator', target: '2026-10-20T18:00:00Z' }],
+ { id: 'engine38-milestone-target', actor: 'coordinator' }),
+ ];
+ const before = exportBoard(box.board);
+
+ for (const move of moves) {
+ const oldEnvelope = { ...move, engine: 38 };
+ assert.throws(() => applyEngineMove(box.board, oldEnvelope, { sequence: 1, at: '2026-10-17T12:00:00.000Z' }),
+ (error) => error.code === 'RELAY_MOVE' && /introduced in engine 39/u.test(error.message),
+ `${move.operation} was introduced in engine 39 and must not run as engine 38`);
+ assert.deepEqual(exportBoard(box.board), before, 'an unsupported engine-38 meaning changes no rows or event history');
+ assert.equal(appliedSequence(box.board), 0, 'pre-validation refusal does not advance the relay cursor');
+ assert.equal(engineReceipt(box.board, move.id), null, 'pre-validation refusal creates no move receipt');
+ }
+});
++
++/** Supported older clients can add before shipment, then obey the receiver's shipped state. */
++test('[N26,H16] an older-engine client cannot add work after a milestone ships', async (t) => {
++ const { applyRelayMove, prepareEngineMove } = await import('../src/engine.js');
++ const dir = mkdtempSync(join(tmpdir(), 'pullboard-milestone-legacy-'));
++ const board = store.openBoard(join(dir, 'board.sqlite'));
++ t.after(() => { store.closeBoard(board); rmSync(dir, { recursive: true, force: true }); });
++ store.ensureCoordinator(board, dir);
++ const id = store.addItem(board, { by: 'coordinator', lane: 'core', title: 'Still owed',
++ criterion: 'An obligation remains recorded', specIds: [] });
++ store.addMilestone(board, { agentId: 'coordinator', name: 'A', items: [] });
++ store.addMilestone(board, { agentId: 'coordinator', name: 'B', items: [] });
++ const sender = { kind: 'person', userId: 'milestone-fixture-user' };
++ const before = prepareEngineMove(board, 'editMilestoneItems',
++ ['B', { agentId: 'coordinator', add: [id], remove: [] }], { id: 'before38', actor: 'coordinator' });
++ before.engine = 38;
++ const added = applyRelayMove(board, before, { sequence: 1, at: '2026-10-18T01:00:00.000Z', sender, kind: 'move' });
++ assert.equal(added.error, undefined, 'an engine38 addition to an unshipped milestone stays replayable');
++ assert.deepEqual(store.milestones(board)[1].items, [id]);
++ const ship = prepareEngineMove(board, 'shipMilestone',
++ ['A', { agentId: 'coordinator', commit: '1'.repeat(40) }], { id: 'ship39', actor: 'coordinator' });
++ assert.equal(ship.engine, 39, 'the current milestone writer is exercised');
++ const shipped = applyRelayMove(board, ship, { sequence: 2, at: '2026-10-18T01:00:01.000Z', sender, kind: 'move' });
++ assert.equal(shipped.error, undefined, JSON.stringify(shipped));
++ assert.equal(store.milestones(board)[0].shipped.commit, '1'.repeat(40));
++ const after = prepareEngineMove(board, 'editMilestoneItems',
++ ['A', { agentId: 'coordinator', add: [id], remove: [] }], { id: 'after38', actor: 'coordinator' });
++ after.engine = 38;
++ const outcome = applyRelayMove(board, after, { sequence: 3, at: '2026-10-18T01:00:02.000Z', sender, kind: 'move' });
++ assert.equal(outcome.error?.code, 'MILESTONE_SHIPPED', 'a supported older client cannot add work after shipment');
++ assert.deepEqual(store.milestones(board)[0].items, [], 'refusal preserves the shipped milestone membership');
++ assert.deepEqual(store.milestones(board)[1].items, [id], 'the legacy addition before shipment remains');
++});