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(core): snapshot board exports [A7]
Corey Olsonaef4723591e9
diff --git a/src/exchange.js b/src/exchange.jsindex 735637b0..3711c74a 100644--- a/src/exchange.js+++ b/src/exchange.js@@ -41,11 +41,19 @@ function columnsOf(db, table) {* @returns {{ version: number, tables: Record<string, any[]> }}*/export function exportBoard(board) {- const tables = Object.fromEntries(tableNames(board.db).map((table) => [- table,- board.db.prepare(`SELECT * FROM ${identifier(table)} ORDER BY ${table === 'sqlite_sequence' ? 'name' : 'rowid'}`).all(),- ]));- return { version: VERSION, tables };+ const db = board.db;+ db.exec('BEGIN DEFERRED');+ try {+ const tables = Object.fromEntries(tableNames(db).map((table) => [+ table,+ db.prepare(`SELECT * FROM ${identifier(table)} ORDER BY ${table === 'sqlite_sequence' ? 'name' : 'rowid'}`).all(),+ ]));+ db.exec('COMMIT');+ return { version: VERSION, tables };+ } catch (error) {+ db.exec('ROLLBACK');+ throw error;+ }}/**diff --git a/test/exchange.test.js b/test/exchange.test.jsindex 5ecf5b19..f058bb67 100644--- a/test/exchange.test.js+++ b/test/exchange.test.js@@ -90,6 +90,59 @@ test('round trips every board row, state, history and AUTOINCREMENT counter [A7]}});+test('export keeps a single SQLite snapshot while another connection writes [A7]', () => {+ const directory = tempDirectory();+ const file = join(directory, 'shared.sqlite');+ const source = store.openBoard(file);+ const writer = store.openBoard(file);+ try {+ store.register(source, { lane: 'coordinator', path: '/shared' });+ store.register(source, { lane: 'web', path: '/shared/web-1' });+ store.register(source, { lane: 'web', path: '/shared/web-2' });+ store.addItem(source, { by: 'coordinator', lane: 'web', title: 'present before export' });+ const before = JSON.stringify(exportBoard(source));+ let wrote = false;+ const db = new Proxy(source.db, {+ get(target, property) {+ if (property === 'prepare') return (sql) => {+ const statement = target.prepare(sql);+ if (sql !== 'SELECT * FROM "item" ORDER BY rowid') return statement;+ return { all: (...args) => {+ const rows = statement.all(...args);+ if (!wrote) {+ wrote = true;+ writeAcceptedItem(writer);+ }+ return rows;+ } };+ };+ const value = Reflect.get(target, property, target);+ return typeof value === 'function' ? value.bind(target) : value;+ },+ });+ const duringWrite = JSON.stringify(exportBoard({ db }));+ assert.equal(wrote, true, 'the second connection wrote after the item table was read');+ assert.equal(duringWrite, before, 'every exported table came from the same pre-write snapshot');+ assert.equal(exportBoard(writer).tables.item.length, 2, 'the legitimate write committed to the board');+ } finally {+ store.closeBoard(writer);+ store.closeBoard(source);+ rmSync(directory, { recursive: true, force: true });+ }+});++/**+ * Create an item and finish its lifecycle on the second database connection.+ * @param {any} board+ */+function writeAcceptedItem(board) {+ const item = store.addItem(board, { by: 'coordinator', lane: 'web', title: 'written during export' });+ const freeze = (row) => ({ text: row.item_title, digest: `digest:${row.item_title}` });+ store.claim(board, item, { agentId: 'web-1', lane: 'web', leaseMs: 3_600_000, freeze });+ store.submit(board, item, { agentId: 'web-1', commit: 'b'.repeat(40), tree: 'tree:concurrent' });+ store.verify(board, item, { agentId: 'web-2', decision: 'ACCEPT', note: 'the check passed', head: 'b'.repeat(40), digest: 'digest:written during export', policy: 'any' });+}+test('import refuses a board with rows and leaves it unchanged [A7]', () => {const directory = tempDirectory();const source = populatedBoard(join(directory, 'source.sqlite'));