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(board): next selects read-only; migrate only when behind [C7]
Corey Olsona7841e93ec06
diff --git a/src/board-migrate.js b/src/board-migrate.jsindex 752bb9b0..55118fda 100644--- a/src/board-migrate.js+++ b/src/board-migrate.js@@ -78,18 +78,42 @@ function schemaStamp(db, digest) {}/**- * True when the board already carries this code's schema: its user_version is current and its- * PRAGMA application_id holds the stamp of `digest` and its present shape. Reads only, so it takes- * no write lock. The stamp lives in the file header, not in board_meta, so exports never see it.+ * Where the board stands against this code. 'behind': its user_version or event log version is older,+ * the only case a write open migrates and audits. Otherwise its PRAGMA application_id decides:+ * 'current' when it holds the stamp of `digest` and the present shape, 'unstamped' when it was never+ * stamped, 'drifted' when the shape changed outside pullboard, which is reported and left alone.+ * Reads only, so it takes no write lock. The stamp lives in the file header, so exports never see it.** @param {import('node:sqlite').DatabaseSync} db* @param {string} digest* @param {number} schemaVersion- * @returns {boolean}+ * @param {boolean} [logBehind] whether the event log version is older than this code's+ * @returns {'behind' | 'current' | 'unstamped' | 'drifted'}*/+export function boardStanding(db, digest, schemaVersion, logBehind = false) {+ if (logBehind || db.prepare('PRAGMA user_version').get().user_version < schemaVersion) return 'behind';+ const stamp = db.prepare('PRAGMA application_id').get().application_id;+ return stamp === schemaStamp(db, digest) ? 'current' : stamp === 0 ? 'unstamped' : 'drifted';+}++/** True when the board carries this code's schema and stamp, so a read may trust its shape. */export function boardIsCurrent(db, digest, schemaVersion) {- if (db.prepare('PRAGMA user_version').get().user_version < schemaVersion) return false;- return db.prepare('PRAGMA application_id').get().application_id === schemaStamp(db, digest);+ return boardStanding(db, digest, schemaVersion) === 'current';+}++const reportedDrift = new Set();++/**+ * Say once per board file, on stderr or the caller's diagnostics, that its shape changed outside+ * pullboard at this schema version. Why once: every command opens the board, and one line is news.+ *+ * @param {string} file+ * @param {(message: string) => void} [onDiagnostic]+ */+export function reportDrift(file, onDiagnostic = (message) => process.stderr.write(`${message}\n`)) {+ if (reportedDrift.has(file)) return;+ reportedDrift.add(file);+ onDiagnostic(`pullboard: the board at ${file} has this version's schema number but a different shape (a table, index or trigger changed outside pullboard); it is left as it is`);}/**diff --git a/src/board.js b/src/board.jsindex ef0baa83..90cec64a 100644--- a/src/board.js+++ b/src/board.js@@ -32,8 +32,10 @@ import { boardBusyError } from './board-access.js';export { boardBusyError } from './board-access.js';import {boardIsCurrent,+ boardStanding,migrate,recordSchemaStamp,+ reportDrift,schemaDigest,} from './board-migrate.js';export { schemaMissing, writeRefused } from './board-migrate.js';@@ -330,14 +332,16 @@ export function openBoard(file, clock = systemClock, { isMain, onDiagnostic } =if (file !== ':memory:' && isMain !== false) db.exec('PRAGMA journal_mode = WAL');const board = { db, clock };if (isMain !== false || file === ':memory:') {- // A board this code already migrated skips the migration, its write lock and the trigger audit (#1047).- if (!boardIsCurrent(db, SCHEMA_DIGEST, SCHEMA_VERSION)) {+ // Migrate and audit only a board whose version is behind; a drifted shape is reported and left alone (#1047).+ const standing = boardStanding(db, SCHEMA_DIGEST, SCHEMA_VERSION, readEventLogVersion(db) < EVENT_LOG_VERSION);+ if (standing === 'behind') {migrateEventLogVersion(db);migrate(db);db.prepare('INSERT OR IGNORE INTO board_meta (meta_key, meta_value) VALUES (?, ?)').run('board_id', randomBytes(16).toString('hex'));guardStore(board);- recordSchemaStamp(db, SCHEMA_DIGEST);}+ if (standing === 'behind' || standing === 'unstamped') recordSchemaStamp(db, SCHEMA_DIGEST);+ if (standing === 'drifted') reportDrift(file, onDiagnostic);} else {// Read compatibility before any local effect; persistent schema belongs to trunk alone.readEventLogVersion(db);diff --git a/src/cli.js b/src/cli.jsindex 35b8d51c..d3aa156e 100644--- a/src/cli.js+++ b/src/cli.js@@ -34,7 +34,6 @@ import { pathToFileURL } from 'node:url';import { parseArgs } from 'node:util';import {mainLaneWork,- reviewQueueLine,refuseNextIdle,} from './next-steps.js';import { reviewerStartup } from './next-steps.js';@@ -1968,30 +1967,15 @@ async function nextSeatContext(ctx, board, me, item, seats) {* @returns {{ item?: any, held?: boolean, retry?: boolean, reasons?: string[] }}*/export async function nextOnce(ctx, values) {+ // Select on a read-only board; only a claim, or a review reservation, opens it for writing (#1047).+ const looked = values.verify ? { claim: true } : withBoardRead(ctx, (board) => nextPick(ctx, board, values));+ if (!looked.claim) return looked;return await withBoard(ctx, async (board) => {if (values.verify) checkMainVerifier(ctx, board, values);- const me = whoAmI(ctx, board);- if (values.verify) return nextReview(ctx, board, me, values, { ordered: (operation, args) => ordered(ctx, board, operation, args), idArg, trunkMerge });- const warm = warmFiles(ctx, board, me);- const seats = nextSessionSeats(ctx, board);- // A claim belongs to the seat that made it: seats of one session share its environment, so a sibling's claim is- // never this seat's to resume or be pointed at (#958).- const heldItem = seats ? store.listItems(board).find((item) => item.item_status === 'claimed'- && item.item_parent_id === null && item.item_owner === me.id- && store.ROUTES.indexOf(item.item_route) <= store.ROUTES.indexOf(me.route)) : undefined;- const { item, reasons, shared } = heldItem ? { item: heldItem, reasons: [], shared: [] }- : store.nextFor(board, { agentId: me.id, lane: me.lane, runnable: values.runnable, routes: values.routes, warm,- ...(seats ? { lanes: laneNames(ctx.config).filter((lane) => lane !== COORDINATOR) } : {}),- priority: mainRedReworkItems(ctx.info.root, board) });- const held = item?.item_status === 'claimed';- /** Offer only reviews this seat may give; a linked board previews its engine-27 verifier standing (#579). */- const findOffer = () => store.reviewOffer(board, { agentId: me.id, lane: me.lane, policy: ctx.config.verify.policy,- familyPolicy: ctx.config.verify.family, ratio: ctx.config.verify.reviewRatio, runnable: values.runnable, routes: values.routes });- const offer = held ? null : relayLinked(ctx.info.root) ? store.withVerifierStanding(board, { root: true }, findOffer) : findOffer();- if (offer && !values.build) return { item: offer.item, offer, build: item ?? null };- if (!item) return { reasons, laneWork: ctx.info.isMain ? mainLaneWork(store.listItems(board)) : null };- const reviewSkipped = values.build && !held- ? { offeredItem: offer?.item.item_id ?? null, ratio: ctx.config.verify.reviewRatio, ...store.reviewQueue(board) } : null;+ if (values.verify) return nextReview(ctx, board, whoAmI(ctx, board), values, { ordered: (operation, args) => ordered(ctx, board, operation, args), idArg, trunkMerge });+ const picked = nextPick(ctx, board, values);+ if (!picked.claim) return picked;+ const { me, item, held, shared, reasons, reviewSkipped, seats } = picked;const routed = seats ? await nextSeatContext(ctx, board, me, item, seats) : { context: ctx };const target = routed.context;const holder = whoAmI(target, board);@@ -2006,34 +1990,30 @@ export async function nextOnce(ctx, values) {});}--/** Print an unreserved review first, then the build available through an explicit opt-out. */-export function sayReviewOffer(ctx, found) {- const command = `pullboard next --verify ${found.item.item_id}${ctx.info.isMain ? ' --as coordinator' : ''}`;- const offer = { item: found.item.item_id, command, queue: found.offer.queue, ratio: found.offer.ratio };- ctx.io.result?.({ item: found.item, review: true, held: false, shared: [], offer, build: found.build });- ctx.io.say(`${reviewQueueLine(ctx, offer.queue, span)}; ratio ${offer.ratio} reached (zero active reviewers counts as one)`);- const agents = withBoardRead(ctx, (board) => store.listAgents(board));- ctx.io.say(`review offered: #${found.item.item_id} ${found.item.item_title}, built by ${agentDisplayName(agents, ctx.config, found.item.item_built_by)}; reserve it explicitly: ${command}`);- if (found.build) ctx.io.say(`build available: #${found.build.item_id} ${found.build.item_title}; claim it explicitly: pullboard next --build`);- else ctx.io.say('no build is currently free in your lane; this review is available');-}---/**- * A review search that found nothing while another agent is still building: say so, with the wait,- * so a reviewer who starts first is not told NOTHING_FREE as if the board were idle [C7,P4].- *- * @param {any} ctx- */-export function refuseWhileBuilding(ctx) {- const building = withBoardRead(ctx, (board) => {- const me = whoAmI(ctx, board).id;- const items = store.listItems(board);- if (items.some((item) => item.item_status === 'submitted' && item.item_built_by !== me)) return [];- return items.filter((item) => item.item_status === 'claimed' && item.item_owner !== me).map((item) => `#${item.item_id}`).reverse();- });- if (building.length) throw new Refused('REVIEW_NOT_READY', `nothing to review yet; the builder is still working on ${building.join(', ')}`);+/** The selection half of one next loop: the item to claim, or what to print instead. It only reads (#1047). */+function nextPick(ctx, board, values) {+ const me = whoAmI(ctx, board);+ const warm = warmFiles(ctx, board, me);+ const seats = nextSessionSeats(ctx, board);+ // A claim belongs to the seat that made it: seats of one session share its environment, so a sibling's claim is+ // never this seat's to resume or be pointed at (#958).+ const heldItem = seats ? store.listItems(board).find((item) => item.item_status === 'claimed'+ && item.item_parent_id === null && item.item_owner === me.id+ && store.ROUTES.indexOf(item.item_route) <= store.ROUTES.indexOf(me.route)) : undefined;+ const { item, reasons, shared } = heldItem ? { item: heldItem, reasons: [], shared: [] }+ : store.nextFor(board, { agentId: me.id, lane: me.lane, runnable: values.runnable, routes: values.routes, warm,+ ...(seats ? { lanes: laneNames(ctx.config).filter((lane) => lane !== COORDINATOR) } : {}),+ priority: mainRedReworkItems(ctx.info.root, board) });+ const held = item?.item_status === 'claimed';+ /** Offer only reviews this seat may give; a linked board previews its engine-27 verifier standing (#579). */+ const findOffer = () => store.reviewOffer(board, { agentId: me.id, lane: me.lane, policy: ctx.config.verify.policy,+ familyPolicy: ctx.config.verify.family, ratio: ctx.config.verify.reviewRatio, runnable: values.runnable, routes: values.routes });+ const offer = held ? null : relayLinked(ctx.info.root) ? store.withVerifierStanding(board, { root: true }, findOffer) : findOffer();+ if (offer && !values.build) return { item: offer.item, offer, build: item ?? null };+ if (!item) return { reasons, laneWork: ctx.info.isMain ? mainLaneWork(store.listItems(board)) : null };+ const reviewSkipped = values.build && !held+ ? { offeredItem: offer?.item.item_id ?? null, ratio: ctx.config.verify.reviewRatio, ...store.reviewQueue(board) } : null;+ return { claim: true, me, item, held, shared, reasons, reviewSkipped, seats };}diff --git a/src/commands/next.js b/src/commands/next.jsindex b2c8e57f..9f0e5c7a 100644--- a/src/commands/next.js+++ b/src/commands/next.js@@ -18,13 +18,12 @@ import {displayedWait,idArg,nextOnce,- refuseWhileBuilding,sayBrief,- sayReviewOffer,span,withBoard,withBoardRead,} from '../cli.js';+import { refuseWhileBuilding, sayReviewOffer } from '../next-say.js';/*** `pullboard next` (N2): the whole start of an agent's loop in one command. With --wait, it keepsdiff --git a/src/next-say.js b/src/next-say.jsnew file mode 100644index 00000000..5dfe2e70--- /dev/null+++ b/src/next-say.js@@ -0,0 +1,34 @@+/** What next prints when it reserves nothing: an offered review, or a builder still at work [C7,P4]. */+import * as store from './board.js';+import { agentDisplayName, span, whoAmI } from './cli.js';+import { withBoardRead } from './board-read.js';+import { reviewQueueLine } from './next-steps.js';+import { Refused } from './refused.js';++/** Print an unreserved review first, then the build available through an explicit opt-out. */+export function sayReviewOffer(ctx, found) {+ const command = `pullboard next --verify ${found.item.item_id}${ctx.info.isMain ? ' --as coordinator' : ''}`;+ const offer = { item: found.item.item_id, command, queue: found.offer.queue, ratio: found.offer.ratio };+ ctx.io.result?.({ item: found.item, review: true, held: false, shared: [], offer, build: found.build });+ ctx.io.say(`${reviewQueueLine(ctx, offer.queue, span)}; ratio ${offer.ratio} reached (zero active reviewers counts as one)`);+ const agents = withBoardRead(ctx, (board) => store.listAgents(board));+ ctx.io.say(`review offered: #${found.item.item_id} ${found.item.item_title}, built by ${agentDisplayName(agents, ctx.config, found.item.item_built_by)}; reserve it explicitly: ${command}`);+ if (found.build) ctx.io.say(`build available: #${found.build.item_id} ${found.build.item_title}; claim it explicitly: pullboard next --build`);+ else ctx.io.say('no build is currently free in your lane; this review is available');+}++/**+ * A review search that found nothing while another agent is still building: say so, with the wait,+ * so a reviewer who starts first is not told NOTHING_FREE as if the board were idle [C7,P4].+ *+ * @param {any} ctx+ */+export function refuseWhileBuilding(ctx) {+ const building = withBoardRead(ctx, (board) => {+ const me = whoAmI(ctx, board).id;+ const items = store.listItems(board);+ if (items.some((item) => item.item_status === 'submitted' && item.item_built_by !== me)) return [];+ return items.filter((item) => item.item_status === 'claimed' && item.item_owner !== me).map((item) => `#${item.item_id}`).reverse();+ });+ if (building.length) throw new Refused('REVIEW_NOT_READY', `nothing to review yet; the builder is still working on ${building.join(', ')}`);+}diff --git a/test/api.test.js b/test/api.test.jsindex f1d9af71..0ce3a2cb 100644--- a/test/api.test.js+++ b/test/api.test.js@@ -1534,7 +1534,8 @@ test('one move recomputes only the items it touched [A2,N26]', async (t) => {await api.close();const legacy = new DatabaseSync(boardFile);- try { legacy.exec('DROP INDEX event_item_id_event_id; DROP INDEX verdict_item_id_verdict_id;'); }+ // A board from before these indexes carries an older user_version; only that makes an open migrate (#1047).+ try { legacy.exec('DROP INDEX event_item_id_event_id; DROP INDEX verdict_item_id_verdict_id; PRAGMA user_version = 1;'); }finally { legacy.close(); }// This positive migration control uses a private database; branch code cannot repair// persistent indexes on the repository-shared board by supplying isMain: true.diff --git a/test/board-read-lock.test.js b/test/board-read-lock.test.jsindex fbe98373..41e308f9 100644--- a/test/board-read-lock.test.js+++ b/test/board-read-lock.test.js@@ -1,5 +1,5 @@/** @pullboard-test-input source-tree */-/** @pullboard-test-loads src/cli.js src/board.js src/board-migrate.js src/board-read.js src/commands/status.js src/commands/show.js */+/** @pullboard-test-loads src/cli.js src/board.js src/board-migrate.js src/board-read.js src/commands/status.js src/commands/show.js src/commands/list.js src/commands/version.js *//** A read command opens the board read-only, so a writer holding the lock never stalls it [C7]. */import assert from 'node:assert/strict';import { performance } from 'node:perf_hooks';@@ -8,7 +8,7 @@ import { DatabaseSync } from 'node:sqlite';import { cpSync } from 'node:fs';import { join, resolve } from 'node:path';import * as store from '../src/board.js';-import { main } from '../src/cli.js';+import { pathToFileURL } from 'node:url';import { createE2eHelpers } from './e2e-helpers.js';import { runFixtureChild, startFixtureChild as spawn } from './fixture-child.js';@@ -41,10 +41,21 @@ async function holdWriteLock(file, ms) {const HOMES = ['PULLBOARD_HOME', 'PULLBOARD_MACHINE_HOME'];/**- * Run one CLI command in this process under the fixture's homes, with the time it took. Why in- * process: a fresh node's startup varies by hundreds of ms on a loaded machine, the lock does not.+ * Copy this source outside any checkout, as a release is installed. Why: only trunk code opens a+ * shared board for writing (#1031), so code run from a branch worktree would never meet the lock.+ */+function released(box) {+ const release = join(box.dir, 'release');+ for (const path of ['src', 'bin', 'package.json']) cpSync(resolve(import.meta.dirname, '..', path), join(release, path), { recursive: true });+ return release;+}++/**+ * Run one command of the released code in this process under the fixture's homes, with the time it+ * took. Why in process: a fresh node's startup varies by hundreds of ms on a loaded machine.*/async function timed(box, cwd, ...argv) {+ const { main } = await import(pathToFileURL(join(box.release, 'src', 'cli.js')).href);const saved = HOMES.map((name) => process.env[name]);for (const name of HOMES) process.env[name] = box.env[name];let out = '';@@ -58,57 +69,95 @@ async function timed(box, cwd, ...argv) {}}-/** The fastest of two runs of each read, so one scheduling stall is not read as the lock. */-async function reads(box) {- const runs = [];- for (let round = 0; round < 2; round += 1) runs.push([await timed(box, box.repo, 'status'), await timed(box, box.repo, 'show', '1')]);- const fastest = (index) => runs.map((pair) => pair[index]).reduce((best, run) => (run.ms < best.ms ? run : best));- return { status: fastest(0), show: fastest(1) };+/** The median of an odd list of numbers. */+const median = (values) => [...values].sort((x, y) => x - y)[Math.floor(values.length / 2)];++const ITEMS = 1_000;+const EVENTS = 45_000;+const SHOUTS = 23_000;++/**+ * Seed the board to our size (22 Oct: about 1,000 items, 45,000 events, 23,000 shouts) in one+ * transaction of plain inserts, so the timing below reads a board as big as the real one.+ */+function seed(file) {+ const db = new DatabaseSync(file);+ try {+ db.exec('BEGIN IMMEDIATE');+ const at = '2026-10-22T00:00:00.000Z';+ db.prepare(`WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < ?)+ INSERT INTO item (item_lane, item_title, item_criterion, item_created_by, item_created_at, item_updated_at)+ SELECT 'web', 'Seeded item ' || i, 'renders', 'coordinator', ?, ? FROM n`).run(ITEMS, at, at);+ db.prepare(`WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < ?)+ INSERT INTO event (event_at, event_by, event_kind, item_id, event_detail) SELECT ?, 'coordinator', 'note', 1 + i % ?, '{}' FROM n`).run(EVENTS, at, ITEMS);+ db.prepare(`WITH RECURSIVE n(i) AS (SELECT 1 UNION ALL SELECT i + 1 FROM n WHERE i < ?)+ INSERT INTO shout (shout_from, shout_to, shout_text, shout_at) SELECT 'coordinator', 'web', 'seeded shout ' || i, ? FROM n`).run(SHOUTS, at);+ db.exec('COMMIT');+ } finally { db.close(); }+}++const READS = [['version'], ['show', '1'], ['status'], ['list']];+const RUNS = 5;++/** Each read's median over RUNS in-process runs, failing on any refusal. */+async function medians(box, argv) {+ const times = [];+ for (let run = 0; run < RUNS; run += 1) {+ const result = await timed(box, box.repo, ...argv);+ assert.equal(result.code, 0, `${argv.join(' ')}: ${result.err}`);+ times.push(result.ms);+ }+ return median(times);}test('a read answers while a writer holds the lock [C7]', async (t) => {const box = e2e.project();+ box.release = released(box);assert.equal(box.run(box.repo, 'add', 'web', 'Page', '--specs', 'G1', '--criterion', 'renders').code, 0);const file = join(box.repo, '.git', 'pullboard', 'board.sqlite');- // Both reads without a writer first: what is left over under the lock is the lock's cost.- const free = await reads(box);- for (const [name, run] of Object.entries(free)) assert.equal(run.code, 0, `${name}: ${run.err}`);-- const holder = await holdWriteLock(file, 3000);- const startedAt = performance.now();- const { status, show } = await reads(box);- const heldFor = performance.now() - startedAt;- assert.equal((await holder.closed).code, 0, 'the holder kept the lock and committed');- assert.ok(heldFor < 3000, `every read finished inside the 3 s hold (${Math.round(heldFor)} ms)`); // budget: ceiling is the 3 s hold declared above; a read that waits out the lock ends after it- assert.equal(status.code, 0, status.err);- assert.match(status.out, /board: 1 open/u);- assert.equal(show.code, 0, show.err);- assert.match(show.out, /^#1 /mu);- for (const [name, run] of Object.entries({ status, show })) {- const waited = run.ms - free[name].ms;- t.diagnostic(`${name}: ${Math.round(run.ms)} ms under a held write lock, ${Math.round(free[name].ms)} ms unlocked`);- assert.ok(run.ms < 200 || waited < 200, `${name} under a held write lock took ${Math.round(run.ms)} ms, ${Math.round(waited)} ms more than unlocked`);+ seed(file);+ for (const argv of READS) {+ const free = await medians(box, argv);+ // Each read gets its own 3 s hold, so all five locked runs fall inside it.+ const holder = await holdWriteLock(file, 3000);+ const startedAt = performance.now();+ const held = await medians(box, argv);+ const heldFor = performance.now() - startedAt;+ assert.equal((await holder.closed).code, 0, 'the holder kept the lock and committed');+ assert.ok(heldFor < 3000, `every ${argv[0]} run finished inside the 3 s hold (${Math.round(heldFor)} ms)`); // budget: ceiling is the 3 s hold declared above; a read that waits out the lock ends after it+ t.diagnostic(`${argv[0]}: median ${Math.round(held)} ms with a writer holding the lock, ${Math.round(free)} ms without, over ${RUNS} runs`);+ assert.ok(held - free < 100, `${argv[0]}: a held writer added ${Math.round(held - free)} ms to the median`); // budget: approved row criterion bar, under 100 ms over the unlocked median (shout #23649)}- // An older board is still migrated by the next command that writes. Only trunk code migrates a- // shared board, so the write runs from a released copy outside any checkout.+ // An older board is still migrated by the next command that writes, from the released copy.const db = new DatabaseSync(file);db.exec('PRAGMA user_version = 1');db.close();- const release = join(box.dir, 'release');- for (const path of ['src', 'bin', 'package.json']) cpSync(resolve(import.meta.dirname, '..', path), join(release, path), { recursive: true });- const released = (...argv) => runFixtureChild(process.execPath, [join(release, 'bin', 'pullboard.js'), ...argv], { cwd: box.repo, env: box.env, encoding: 'utf8' });+ const cli = (...argv) => runFixtureChild(process.execPath, [join(box.release, 'bin', 'pullboard.js'), ...argv], { cwd: box.repo, env: box.env, encoding: 'utf8' });/** The board's PRAGMA user_version, read without touching it. */const version = () => {const board = store.openBoardReadOnly(file);try { return board.prepare('PRAGMA user_version').get().user_version; } finally { board.close(); }};// A read on the older board answers as it is and leaves it older, even from code that may migrate.- const read = released('status');+ const read = cli('status');assert.equal(read.status, 0, read.failure ?? read.stderr);- assert.match(read.stdout, /board: 1 open/u);+ assert.match(read.stdout, /board: 1001 open/u);assert.equal(version(), 1, 'status never migrates the board');- const write = released('add', 'web', 'Footer', '--specs', 'G1', '--criterion', 'renders');+ const write = cli('add', 'web', 'Footer', '--specs', 'G1', '--criterion', 'renders');assert.equal(write.status, 0, write.failure ?? write.stderr);assert.equal(version(), store.SCHEMA_VERSION, 'the next write command migrates it');++ // At the current version, a shape changed outside pullboard is reported once and left as it is.+ const drifted = new DatabaseSync(file);+ drifted.exec('DROP INDEX event_item_id_event_id; PRAGMA application_id = 7');+ drifted.close();+ const reported = cli('add', 'web', 'Header', '--specs', 'G1', '--criterion', 'renders');+ assert.equal(reported.status, 0, reported.failure ?? reported.stderr);+ assert.equal(reported.stderr.match(/different shape/gu)?.length, 1, reported.stderr);+ const left = store.openBoardReadOnly(file);+ try {+ assert.equal(left.prepare('PRAGMA application_id').get().application_id, 7, 'no migration restamped the drifted board');+ assert.equal(left.prepare("SELECT 1 FROM sqlite_master WHERE name = 'event_item_id_event_id'").get(), undefined, 'no migration rebuilt its index');+ } finally { left.close(); }});diff --git a/test/board.test.js b/test/board.test.jsindex 1186e1ac..0e9effca 100644--- a/test/board.test.js+++ b/test/board.test.js@@ -707,6 +707,8 @@ test('a board made by an older version is migrated on open [O3]', () => {for (const column of ['agent_route', 'agent_family']) old.db.exec(`ALTER TABLE agent DROP COLUMN ${column}`);old.db.exec('ALTER TABLE verdict DROP COLUMN verdict_verifier_family');old.db.exec('DROP TABLE hold');+ // An older version's board carries an older user_version; only that makes an open migrate (#1047).+ old.db.exec('PRAGMA user_version = 1');store.closeBoard(old);const reopened = store.openBoard(file, clock);const columns = (table) => reopened.db.prepare(`PRAGMA table_info(${table})`).all().map((column) => column.name);diff --git a/test/direct-open-board-regression.js b/test/direct-open-board-regression.jsindex 29989411..16394d25 100644--- a/test/direct-open-board-regression.js+++ b/test/direct-open-board-regression.js@@ -156,6 +156,9 @@ export function assertDirectOpenBoardIsolation(t, sourceRoot) {assert.deepEqual(sharedAfter.triggers, sharedBefore.triggers);assert.equal(sharedAfter.events, sharedBefore.events + 1, 'the normal claim still has its shared-board effect');+ // A private database migrates only when its user_version is behind (#1047), as an older board's is.+ const lowered = new DatabaseSync(privateFile);+ try { lowered.exec('PRAGMA user_version = 1'); } finally { lowered.close(); }const privateProbe = run(process.execPath, ['--input-type=module', '-e', `import { openBoard, closeBoard } from './src/board.js';const board = openBoard(${JSON.stringify(privateFile)});@@ -167,5 +170,5 @@ export function assertDirectOpenBoardIsolation(t, sourceRoot) {'a private database still receives the branch migration');assert.ok(privateAfter.triggers.find(row => row.name === 'machine_item_move').sql.includes('branch fixture moves'),'a private database still receives the branch machine trigger declaration');- assert.equal(privateAfter.version, privateBefore.version, 'same-version private migration remains supported');+ assert.equal(privateAfter.version, privateBefore.version, 'an older private database migrates back to the current version');}