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
test(proof): break each board rule; gaps closed [B3,B4,B8,B9,B15]
Corey Olson4883e6c68fea
diff --git a/docs/proof/board-mutants.mjs b/docs/proof/board-mutants.mjsnew file mode 100644index 00000000..eb26fcb6--- /dev/null+++ b/docs/proof/board-mutants.mjs@@ -0,0 +1,45 @@+/**+ * The proof audit of the board rows that no accepted item had proven (item #53): for each row, one+ * or more changes to src/ that break the row's rule, and the tagged test that must go red under each.+ * The harness works on a temporary copy, never a real checkout.+ *+ * Run it from the repo root: node docs/proof/board-mutants.mjs+ */+import { audit } from './harness.mjs';++const COMMON_DIR = ['test/e2e.test.js', 'the board lives in the git common dir'];+const RACE = ['test/e2e.test.js', 'two agents racing for one item'];+const LEASE = ['test/board.test.js', 'a claim is a lease'];+const SHOUTS = ['test/board.test.js', 'shouts reach a lane, an agent or all'];+const BRIEF_EDIT = ['test/board.test.js', 'an item carries a brief; editing it'];+const BRIEF_SHOWN = ['test/e2e.test.js', 'an item carries a brief to whoever claims it'];+const ESCALATE = ['test/board.test.js', 'escalate frees an item one tier up'];++/** Row, the change, its edits as [file, from, to], the test that judges it, and the outcome expected. */+const MUTANTS = [+ ['B1', 'each worktree opens a board of its own', [['src/cli.js', "const file = join(info.commonDir, 'pullboard', 'board.sqlite');", "const file = join(info.gitDir, 'pullboard', 'board.sqlite');"]], COMMON_DIR, 'red'],+ ['B2', 'a claim skips the check for another live holder', [['src/board.js', 'notHeldByAnother: (found) => (isHeld(board, found) && found.item_owner !== agentId', 'notHeldByAnother: (found) => (false && isHeld(board, found) && found.item_owner !== agentId']], RACE, 'red'],+ ['B2', 'a move opens a deferred transaction, not an immediate one', [['src/board.js', "board.db.exec('BEGIN IMMEDIATE');", "board.db.exec('BEGIN');"]], RACE, 'red'],+ ['B3', 'the main checkout is not the coordinator', [['src/git.js', 'isMain: commonDir === gitDir', 'isMain: false']], COMMON_DIR, 'red'],+ ['B3', 'an agent is whichever lane agent joined first, not its worktree', [['src/cli.js', 'const agent = store.agentAt(board, ctx.info.root);', "const agent = store.listAgents(board).find((entry) => entry.agent_lane !== COORDINATOR);"]], COMMON_DIR, 'red'],+ ['B4', 'a lapsed claim stays held', [['src/board.js', "return item.item_status === 'claimed' && (item.item_lease_until ?? '') > now(board);", "return item.item_status === 'claimed';"]], LEASE, 'red'],+ ['B4', 'claiming again keeps the old lease', [['src/board.js', 'item_lease_until: leaseUntil,', "item_lease_until: isRenewal(found) ? found.item_lease_until : leaseUntil,"]], LEASE, 'red'],+ ['B4', 'the default lease is 3h', [['src/config.js', "lease: '2h',", "lease: '3h',"]], ['test/lanes.test.js', "a claim's lease is 2h"], 'red'],+ ['B6', 'an item may cite an id the spec does not have', [['src/spec.js', "if (!row) return [`${id} is not in ${spec.name ?? 'the spec'}`];", 'if (!row) return [];']], ['test/e2e.test.js', 'items cite spec ids that exist'], 'red'],+ ['B7', 'inbox never marks shouts read', [['src/board.js', " board.db.prepare('UPDATE agent SET agent_last_shout_id = ? WHERE agent_id = ?').run(last, agentId);\n", '']], SHOUTS, 'red'],+ ['B7', "a shout to a lane never reaches the lane's agents", [['src/board.js', '.all(agent.agent_last_shout_id, agentId, agent.agent_lane, agentId);', ".all(agent.agent_last_shout_id, agentId, '', agentId);"]], SHOUTS, 'red'],+ ['B7', 'a shout to all reaches nobody', [['src/board.js', "shout_to IN ('all', ?, ?)", "shout_to IN ('', ?, ?)"]], SHOUTS, 'red'],+ ['B8', 'an item waiting on another can be claimed anyway', [['src/board.js', "if (before.item_status !== 'verified') {", 'if (false) {']], ['test/board.test.js', 'an item can wait on others'], 'red'],+ ['B9', 'submit pins nothing', [['src/cli.js', " git(root, ['update-ref', pin, commit]);\n", '']], ['test/e2e.test.js', 'submit needs a clean tree, nothing untracked'], 'red'],+ ['B10', "a claimed item's brief cannot be edited", [['src/board.js', "const moved = ['item_route', 'item_criterion', 'item_check'].filter(", "const moved = ['item_route', 'item_criterion', 'item_check', 'item_brief'].filter("]], BRIEF_EDIT, 'red'],+ ['B10', 'next leaves out the brief', [['src/cli.js', ' sayBrief(io, item.item_brief);\n io.say(`when it is built and committed:', ' io.say(`when it is built and committed:']], BRIEF_SHOWN, 'red'],+ ['B10', 'show leaves out the brief', [['src/cli.js', ' sayBrief(io, item.item_brief);\n for (const { item: other, shared } of related) {', ' for (const { item: other, shared } of related) {']], BRIEF_SHOWN, 'red'],+ ['B12', 'any lane may claim any item', [['src/board.js', ' if (found.item_lane === lane) return null;', ' return null;']], ['test/board.test.js', 'one live top-level claim per agent'], 'red'],+ ['B13', 'any route takes any item', [['src/board.js', 'export const canTake = (agentRoute, itemRoute) => ROUTES.indexOf(itemRoute) <= ROUTES.indexOf(agentRoute);', 'export const canTake = () => true;']], ['test/board.test.js', 'routes are tiers'], 'red'],+ ['B14', 'an item below strong needs no brief, criterion or check', [['src/board.js', " if (route === 'strong') return;", ' return;']], ['test/board.test.js', 'below strong, an item is buildable cold'], 'red'],+ ['B15', 'escalate keeps the route', [['src/board.js', 'const nextRoute = (route) => ROUTES[Math.min(ROUTES.indexOf(route) + 1, ROUTES.length - 1)];', 'const nextRoute = (route) => route;']], ESCALATE, 'red'],+ ['B15', 'escalate drops what was tried', [['src/board.js', 'note: note.trim(), ...(attempt ? { attempt } : {})', "note: '', ...(attempt ? { attempt } : {})"]], ESCALATE, 'red'],+ ['B15', "the runner never pins a failed attempt", [['src/run.js', ' git(root, [\'update-ref\', ref, commit]);\n return ref;', ' return ref;']], ['test/e2e.test.js', 'run builds routed items unattended'], 'red'],+];++audit(MUTANTS);diff --git a/docs/proof/board.md b/docs/proof/board.mdnew file mode 100644index 00000000..2bafdf47--- /dev/null+++ b/docs/proof/board.md@@ -0,0 +1,39 @@+# Proof audit: the board rows++These board rows were built before the board could verify anything, so no accepted item vouched for them: B1, B2, B3, B4, B6, B7, B8, B9, B10, B12, B13, B14 and B15. This audit breaks each row's rule in `src/`, one change at a time, and checks that a test carrying the row's id goes red. Item #53 holds it; the verification rows have their own audit in [verification.md](verification.md).++Re-run it with `node docs/proof/board-mutants.mjs`. It shares its harness, `docs/proof/harness.mjs`, with the verification audit. The harness works on a temporary copy of the repo's tracked folders and changes nothing else. Before any change, it checks that each target test exists, matches exactly one test, and is green. It exits 1 if any change comes out other than expected.++| Row | Rule | Change that breaks it | Test that must go red | Result |+|---|---|---|---|---|+| B1 | One SQLite file in the git common dir; every worktree sees it. | each worktree opens a board of its own | the board lives in the git common dir; every worktree sees it; nothing is committed | red |+| B2 | Every move is one immediate transaction; two agents never hold one item. | a claim skips the check for another live holder | two agents racing for one item: exactly one wins, every time | red |+| B2 | | a move opens a deferred transaction | two agents racing for one item: exactly one wins, every time | red |+| B3 | An agent is its worktree; the main checkout is the coordinator. | the main checkout is not the coordinator | the board lives in the git common dir… | red |+| B3 | | an agent is whichever lane agent joined first | the board lives in the git common dir… | red, **after this audit** |+| B4 | A claim is a lease, 2h by default; claiming again renews it. | a lapsed claim stays held | a claim is a lease: renewable by its holder, free again once it lapses | red |+| B4 | | claiming again keeps the old lease | a claim is a lease… | red, **after this audit** |+| B4 | | the default lease is 3h | a claim's lease is 2h unless pullboard.json says otherwise | red, **new test** |+| B6 | Items cite spec ids that exist. | an item may cite an id the spec lacks | items cite spec ids that exist | red |+| B7 | Shouts reach a lane, an agent or all; inbox marks them read. | inbox never marks shouts read; a lane's shout misses its agents; a shout to all reaches nobody | shouts reach a lane, an agent or all; inbox marks them read | red, all three |+| B8 | An item can wait on others; claiming it is refused until they are verified. | an item waiting on another can be claimed | an item can wait on others: claiming it is refused until they are verified | red, **once tagged B8** |+| B9 | Submit pins the commit under refs/pullboard/items. | submit pins nothing | submit needs a clean tree, nothing untracked, and the gate green at HEAD | red, **once tagged B9** |+| B10 | An item carries a brief; next and show print it; edit changes it until verified. | a claimed item's brief cannot be edited | an item carries a brief; editing it changes how to build, never what | red |+| B10 | | next leaves out the brief; show leaves out the brief | an item carries a brief to whoever claims it | red, both |+| B12 | Every item is built in its own lane. | any lane may claim any item | one live top-level claim per agent; child items are free; lanes hold | red |+| B13 | Routes are tiers; an agent claims and verifies its tier and below. | any route takes any item | routes are tiers | red |+| B14 | Below strong, an item needs a criterion, a check and a brief. | an item below strong needs none of them | below strong, an item is buildable cold | red |+| B15 | Escalate frees an item one tier up, its attempt pinned and its failure attached. | escalate keeps the route | escalate frees an item one tier up, with what was tried attached | red |+| B15 | | escalate drops what was tried | escalate frees an item one tier up… | red, **after this audit** |+| B15 | | the runner never pins a failed attempt | run builds routed items unattended | red |++## What the audit changed++- **B3:** the test checked whoami in one lane worktree, so "the first agent that joined" passed for "this worktree's agent". It now adds a second worktree to the same lane, and each must say its own name.+- **B4:** the lease test renewed a claim without letting any time pass, so a renewal that kept the old expiry passed. It now renews an hour in and checks the claim still holds two hours after the first claim. The 2h default had no test at all; it has one now.+- **B8 and B9:** both were tested, B8 by a test whose title restates the row word for word, B9 inside the V4 test, but neither test named its row. They do now.+- **B15:** the escalate test checked the move and the route, not what travels with it. It now checks the event keeps the note and the pinned attempt.++## A gap in the audit harness itself++When `--test-name-pattern` matches no test, Node reports the test file itself as one passing test. The harness first counted reported tests, so a target that named no real test passed the baseline check. A change expected to stay green would then have looked proven while nothing ran. The harness now counts only results whose title holds the target's name, and refuses the run otherwise. The verification audit was re-run on the fixed harness: still 26 changes, 0 unexpected.diff --git a/docs/proof/harness.mjs b/docs/proof/harness.mjsnew file mode 100644index 00000000..3839d3d0--- /dev/null+++ b/docs/proof/harness.mjs@@ -0,0 +1,63 @@+/**+ * The harness every proof audit shares. It copies the repo's tracked folders to a fresh temporary+ * folder and works only there, so it never changes a real checkout. It checks that each named test+ * is green on the unchanged copy, since a red that was already there proves nothing. Then it makes+ * each change in turn and runs the test that should judge it.+ */+import { spawnSync } from 'node:child_process';+import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join, resolve } from 'node:path';++const ROOT = resolve(import.meta.dirname, '..', '..');+const COPIED = ['src', 'bin', 'test', 'skills', 'package.json', 'PRACTICE.md'];++/**+ * Run an audit and print one line per change. Sets the exit code to 1 if any change comes out other+ * than expected.+ *+ * @param {[string, string, [string, string, string][], [string, string], 'red' | 'green'][]} mutants+ * Each one: the row, the change in words, its edits as [file, from, to], the test that judges it as+ * [file, a unique part of its title], and the outcome expected.+ */+export function audit(mutants) {+ const copy = mkdtempSync(join(tmpdir(), 'pullboard-proof-'));+ try {+ for (const entry of COPIED) cpSync(join(ROOT, entry), join(copy, entry), { recursive: true });+ /**+ * Run one test by name in the copy: whether it passed, and how many tests the name matched. When+ * no test matches, Node reports the file itself as one passing test, so only results whose+ * title holds the name count.+ */+ const judge = ([file, name]) => {+ const result = spawnSync(process.execPath, ['--disable-warning=ExperimentalWarning', '--test', `--test-name-pattern=${name}`, file], { cwd: copy, encoding: 'utf8', timeout: 300_000 });+ const titles = [...(result.stdout ?? '').matchAll(/^(?:not )?ok \d+ - (.*)$/gm)].map((match) => match[1]);+ return { green: result.status === 0, matched: titles.filter((title) => title.includes(name)).length };+ };+ const targets = [...new Set(mutants.map(([, , , target]) => JSON.stringify(target)))].map((target) => JSON.parse(target));+ const unready = targets.filter((target) => {+ const { green, matched } = judge(target);+ return !green || matched !== 1;+ });+ if (unready.length) throw new Error(`not green on the unchanged copy, or not exactly one test: ${unready.map(([file, name]) => `${file}: ${name}`).join('; ')}`);+ let unexpected = 0;+ for (const [row, change, edits, target, expected] of mutants) {+ const before = new Map(edits.map(([file]) => [file, readFileSync(join(copy, file), 'utf8')]));+ const after = new Map(before);+ for (const [file, from, to] of edits) {+ if (!after.get(file).includes(from)) throw new Error(`${row}: the code to change is gone from ${file}; update this audit`);+ after.set(file, after.get(file).replace(from, to));+ }+ for (const [file, text] of after) writeFileSync(join(copy, file), text);+ const { green } = judge(target);+ for (const [file, text] of before) writeFileSync(join(copy, file), text);+ const outcome = green ? 'green' : 'red';+ if (outcome !== expected) unexpected += 1;+ console.log(`${outcome === expected ? 'ok ' : 'UNEXPECTED'} ${row} ${outcome.padEnd(5)} ${change} (${target[1]})`);+ }+ console.log(`${mutants.length} changes, ${unexpected} unexpected; the unchanged copy is green on all ${targets.length} targets`);+ process.exitCode = unexpected ? 1 : 0;+ } finally {+ rmSync(copy, { recursive: true, force: true });+ }+}diff --git a/docs/proof/verification-mutants.mjs b/docs/proof/verification-mutants.mjsindex f46a3f85..6aca939a 100644--- a/docs/proof/verification-mutants.mjs+++ b/docs/proof/verification-mutants.mjs@@ -1,17 +1,11 @@/**- * The proof audit of the verification rows, V1 to V9 (item #48) and V16 (item #51): for each row, one or more changes to- * src/ that break the row's rule, and the tagged test that must go red under each. It copies the- * repo to a fresh temporary folder and works only there, so it never changes a real checkout.+ * The proof audit of the verification rows, V1 to V9 (item #48) and V16 (item #51): for each row,+ * one or more changes to src/ that break the row's rule, and the tagged test that must go red under+ * each. The harness works on a temporary copy, never a real checkout.** Run it from the repo root: node docs/proof/verification-mutants.mjs*/-import { spawnSync } from 'node:child_process';-import { cpSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';-import { tmpdir } from 'node:os';-import { join, resolve } from 'node:path';--const ROOT = resolve(import.meta.dirname, '..', '..');-const COPIED = ['src', 'bin', 'test', 'skills', 'package.json', 'PRACTICE.md'];+import { audit } from './harness.mjs';const VERIFY_AT_COMMIT = ['test/e2e.test.js', 'verify runs at the submitted commit, against the criterion frozen at claim'];const CLEAN_TREE = ['test/e2e.test.js', 'submit needs a clean tree, nothing untracked, and the gate green at HEAD'];@@ -55,33 +49,4 @@ const MUTANTS = [['V16', 'submit misses a tracked file edited during the gate', [['src/cli.js', MOVED, 'if (headCommit(root) !== commit) {']], MOVED_TREE, 'red'],];-const copy = mkdtempSync(join(tmpdir(), 'pullboard-proof-'));-try {- for (const entry of COPIED) cpSync(join(ROOT, entry), join(copy, entry), { recursive: true });- /** Run one test by name in the copy: whether it passed, and how many tests the name matched. */- const judge = ([file, name]) => {- const result = spawnSync(process.execPath, ['--disable-warning=ExperimentalWarning', '--test', `--test-name-pattern=${name}`, file], { cwd: copy, encoding: 'utf8', timeout: 300_000 });- return { green: result.status === 0, matched: Number(/^# tests (\d+)/m.exec(result.stdout ?? '')?.[1] ?? 0) };- };- const baselines = [...new Set(MUTANTS.map(([, , , target]) => JSON.stringify(target)))].map((target) => judge(JSON.parse(target)));- if (!baselines.every(({ green, matched }) => green && matched === 1)) throw new Error('the unchanged copy is not green on every target, so no red below would mean anything');- let unexpected = 0;- for (const [row, change, edits, target, expected] of MUTANTS) {- const before = new Map(edits.map(([file]) => [file, readFileSync(join(copy, file), 'utf8')]));- const after = new Map(before);- for (const [file, from, to] of edits) {- if (!after.get(file).includes(from)) throw new Error(`${row}: the code to change is gone from ${file}; update this audit`);- after.set(file, after.get(file).replace(from, to));- }- for (const [file, text] of after) writeFileSync(join(copy, file), text);- const { green } = judge(target);- for (const [file, text] of before) writeFileSync(join(copy, file), text);- const outcome = green ? 'green' : 'red';- if (outcome !== expected) unexpected += 1;- console.log(`${outcome === expected ? 'ok ' : 'UNEXPECTED'} ${row} ${outcome.padEnd(5)} ${change} (${target[1]})`);- }- console.log(`${MUTANTS.length} changes, ${unexpected} unexpected; the unchanged copy is green on all ${baselines.length} targets`);- process.exitCode = unexpected ? 1 : 0;-} finally {- rmSync(copy, { recursive: true, force: true });-}+audit(MUTANTS);diff --git a/test/board.test.js b/test/board.test.jsindex 1a719eb7..6bb8d430 100644--- a/test/board.test.js+++ b/test/board.test.js@@ -51,8 +51,11 @@ test('a claim is a lease: renewable by its holder, free again once it lapses [B4const id = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Page' });claimAs(id, 'web-1', 'web');assert.throws(() => claimAs(id, 'web-2', 'web'), /HELD/);+ clock.advance(HOUR);assert.equal(claimAs(id, 'web-1', 'web').renewed, true);- clock.advance(2 * HOUR + 1);+ clock.advance(HOUR + 1);+ assert.throws(() => claimAs(id, 'web-2', 'web'), /HELD/, 'two hours after the first claim, the renewal still holds it');+ clock.advance(HOUR);assert.equal(store.getItem(board, id).item_status, 'open');assert.equal(claimAs(id, 'web-2', 'web').renewed, false);assert.equal(store.getItem(board, id).item_owner, 'web-2');@@ -200,7 +203,7 @@ test('every move lands in the event log; stats count items and verdicts [R1, R2]assert.equal(stats.rejected, 1);});-test('an item can wait on others: claiming it is refused until they are verified', () => {+test('an item can wait on others: claiming it is refused until they are verified [B8]', () => {const contract = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'Store module' });const user = store.addItem(board, { by: 'coordinator', lane: 'api', title: 'Uses the store', after: [contract] });assert.throws(() => claimAs(user, 'api-1', 'api'), /BLOCKED.*#2 waits on #1 \(open, web lane\)/);@@ -340,6 +343,8 @@ test('escalate frees an item one tier up, with what was tried attached [B15]', (assert.deepEqual(store.escalate(board, id, { agentId: 'coordinator', note: 'still stuck' }), { from: 'strong', to: 'strong' });const moves = store.events(board, { itemId: id }).map((event) => event.event_kind).filter((kind) => ['attempt', 'escalate'].includes(kind));assert.deepEqual(moves, ['attempt', 'escalate', 'escalate', 'escalate']);+ const first = store.events(board, { itemId: id }).find((event) => event.event_kind === 'escalate');+ assert.deepEqual(JSON.parse(first.event_detail), { from: 'light', to: 'mid', note: 'check failed twice', attempt: 'refs/pullboard/attempts/1/abc' }, 'the failure and the pinned attempt travel with it');});test('a fresh claim records where the work started; submit records what it changed, reworks included [N21]', () => {diff --git a/test/e2e.test.js b/test/e2e.test.jsindex 14b2adc1..7698d915 100644--- a/test/e2e.test.js+++ b/test/e2e.test.js@@ -155,6 +155,11 @@ test('the board lives in the git common dir; every worktree sees it; nothing isassert.equal(box.git(box.repo, 'status', '--porcelain'), '');assert.match(box.run(box.repo, 'whoami').out, /^coordinator/);assert.match(box.run(box.web, 'whoami').out, /^web-1 \(web lane\)/);+ const second = join(box.dir, 'web-2');+ box.git(box.repo, 'worktree', 'add', '-q', second, '-b', 'web/two');+ assert.match(box.run(second, 'join', 'web').out, /joined as web-2/);+ assert.match(box.run(second, 'whoami').out, /^web-2 \(web lane\)/, 'a second worktree in the same lane is its own agent');+ assert.match(box.run(box.web, 'whoami').out, /^web-1 \(web lane\)/, 'and the first stays itself');assert.match(box.run(box.web, 'init').err, /NOT_MAIN/);assert.match(box.run(box.repo, 'join', 'web').err, /MAIN_IS_COORDINATOR/);});@@ -185,7 +190,7 @@ test('a lane commits only inside its folders; an unjoined worktree cannot commitassert.match(moved.stderr, /outside the web lane: api\/a.html/);});-test('submit needs a clean tree, nothing untracked, and the gate green at HEAD [V4]', () => {+test('submit needs a clean tree, nothing untracked, and the gate green at HEAD [V4, B9]', () => {const box = project();box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1');assert.match(box.run(box.web, 'claim', '1').out, /claimed #1/);diff --git a/test/lanes.test.js b/test/lanes.test.jsindex f8cabb08..cd5089c8 100644--- a/test/lanes.test.js+++ b/test/lanes.test.js@@ -64,3 +64,15 @@ test('config merges nested groups over the defaults, and leases read as durationassert.equal(durationMs('1d'), 86_400_000);assert.throws(() => durationMs('soon'), /BAD_CONFIG/);});++test("a claim's lease is 2h unless pullboard.json says otherwise [B4]", () => {+ const root = mkdtempSync(join(tmpdir(), 'pullboard-lease-'));+ try {+ writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ gate: 'npm test' }));+ assert.equal(loadConfig(root).leaseMs, 2 * 3_600_000);+ writeFileSync(join(root, 'pullboard.json'), JSON.stringify({ gate: 'npm test', lease: '45m' }));+ assert.equal(loadConfig(root).leaseMs, 45 * 60_000);+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});