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(board): expose busy write transaction refusal [C7,P4,B2]
Corey Olson1f72f7313054
diff --git a/test/board-busy.test.js b/test/board-busy.test.jsnew file mode 100644index 00000000..968b90a2--- /dev/null+++ b/test/board-busy.test.js@@ -0,0 +1,93 @@+/** @pullboard-test-input source-tree */+import assert from 'node:assert/strict';+import { after, test } from 'node:test';+import { DatabaseSync } from 'node:sqlite';+import { join, resolve } from 'node:path';+import { exportBoard } from '../src/exchange.js';+import { createE2eHelpers } from './e2e-helpers.js';+import { runFixtureChild, startFixtureChild } from './fixture-child.js';++const e2e = createE2eHelpers();+after(e2e.cleanup);+const BIN = resolve(import.meta.dirname, '../bin/pullboard.js');++/** Snapshot the real private board without acquiring a write lock. */+function snapshot(file) {+ const db = new DatabaseSync(file, { readOnly: true });+ try { return exportBoard({ db }); }+ finally { db.close(); }+}++/** Hold only this test's SQLite write lock until the parent explicitly releases it. */+async function holdWriteLock(box, file) {+ const source = `+ import { DatabaseSync } from 'node:sqlite';+ const db = new DatabaseSync(process.argv[1]);+ db.exec('PRAGMA busy_timeout = 10000; BEGIN IMMEDIATE');+ /** Release the private lock on request or loss of its owning parent. */+ function release() {+ db.exec('ROLLBACK');+ db.close();+ process.removeListener('disconnect', release);+ if (process.connected) process.disconnect();+ }+ process.once('disconnect', release);+ process.once('message', release);+ process.send({ kind: 'locked' });+ `;+ const child = startFixtureChild(process.execPath, ['--input-type=module', '-e', source, file], {+ cwd: box.repo, env: box.env, stdio: ['ignore', 'ignore', 'pipe', 'ipc'],+ });+ const closed = new Promise((resolveClosed) => child.once('close', (code, signal) => resolveClosed({ code, signal })));+ await new Promise((resolveReady, rejectReady) => {+ child.once('error', rejectReady);+ child.once('close', (code, signal) => rejectReady(new Error(`private lock holder exited before readiness: ${code}/${signal}`)));+ child.on('message', (message) => { if (message?.kind === 'locked') resolveReady(); });+ });+ let released = false;+ return async () => {+ if (released) return;+ released = true;+ if (child.connected) child.send({ kind: 'release' });+ const result = await closed;+ assert.deepEqual(result, { code: 0, signal: null }, child.fixtureFailure);+ };+}++/** Prove a real ordered CLI move refuses contention atomically, then succeeds exactly once. */+async function proveBusyWrite(t, args, table) {+ const box = e2e.project();+ const file = join(box.repo, '.git', 'pullboard', 'board.sqlite');+ const before = snapshot(file);+ const release = await holdWriteLock(box, file);+ t.after(release);+ const refused = runFixtureChild(process.execPath, [BIN, ...args, '--json'], {+ cwd: box.repo, env: box.env, encoding: 'utf8',+ });+ assert.equal(refused.status, 1, refused.context);+ const output = `${refused.stdout}\n${refused.stderr}`;+ assert.match(output, /BOARD_BUSY/u, output);+ const document = JSON.parse(refused.stdout);+ assert.equal(document.error.code, 'BOARD_BUSY');+ assert.match(document.error.message, /remained held by another process after \d+ms/u);+ assert.ok(document.error.message.includes(file), document.error.message);+ assert.match(document.error.next, /retry/u);+ assert.doesNotMatch(output, /Error: database is locked|\n\s+at (?:\S+\s+\()?file:|ERR_SQLITE_ERROR/u);+ assert.deepEqual(snapshot(file), before, 'refused move must not partially change any board table');+ await release();+ const retried = runFixtureChild(process.execPath, [BIN, ...args, '--json'], {+ cwd: box.repo, env: box.env, encoding: 'utf8',+ });+ assert.equal(retried.status, 0, retried.context);+ const after = snapshot(file);+ assert.equal(after.tables[table].length, before.tables[table].length + 1, 'one retry makes exactly one move');+ assert.equal(after.tables.event.length, before.tables.event.length + 1, 'only the successful retry records an event');+}++test('a board write that outwaits the busy timeout is refused by name, never a stack trace [C7,P4,B2]', async (t) => {+ await proveBusyWrite(t, ['shout', 'all', 'private busy shout'], 'shout');+});++test('a busy ordered item addition leaves no partial item and retries once [C7,P4,B2]', async (t) => {+ await proveBusyWrite(t, ['add', 'web', 'private busy item', '--specs', 'G1', '--criterion', 'the page renders'], 'item');+});