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): guard relay and init schema opens [A5,A6]

Corey Olson45e02b58dc05
diff --git a/src/cli.js b/src/cli.js
index a1d01b95..0563b163 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -59,6 +59,11 @@ const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.u
export const VERSION = PACKAGE.version;
const CODE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
+/** Published installs lack Git metadata; source checkouts may upgrade only from their main tree. */
+function codeIsFromMain() {
+ return tryGit(CODE_ROOT, ['rev-parse', '--show-toplevel']).status !== 0 || repoInfo(CODE_ROOT).isMain;
+}
+
export const HELP = `pullboard ${VERSION}: the local-first work board for teams of coding agents.
Nothing ships until a second agent verifies it.
@@ -349,8 +354,7 @@ function sayBrief(io, brief) {
*/
function context(io) {
const info = repoInfo(io.cwd);
- const codeIsInGit = tryGit(CODE_ROOT, ['rev-parse', '--show-toplevel']).status === 0;
- const allowSchemaUpgrade = !codeIsInGit || repoInfo(CODE_ROOT).isMain;
+ const allowSchemaUpgrade = codeIsFromMain();
const config = configHere(info);
const file = join(info.commonDir, 'pullboard', 'board.sqlite');
return { info, config, file, allowSchemaUpgrade, doctrine: loadDoctrine(info.root, config), io, clock: io.clock ?? store.systemClock };
@@ -759,7 +763,7 @@ function setupCommands(io, { first, values }) {
const info = repoInfo(io.cwd);
const notes = initRepo({
info,
- openBoardHere: () => store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), io.clock, { isMain: info.isMain }),
+ openBoardHere: () => store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), io.clock, { isMain: codeIsFromMain() }),
register: store.register,
closeBoard: store.closeBoard,
});
diff --git a/src/relay.js b/src/relay.js
index db2a2d64..4aa99848 100644
--- a/src/relay.js
+++ b/src/relay.js
@@ -2,6 +2,7 @@
import { randomUUID } from 'node:crypto';
import { existsSync, lstatSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
import { dirname, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
import * as store from './board.js';
import { exportBoard } from './exchange.js';
import { repoInfo, tryGit } from './git.js';
@@ -12,6 +13,12 @@ import { Refused } from './refused.js';
export const DEFAULT_RELAY = 'https://app.pullboard.dev';
const LINK_FILES = new WeakMap();
+const CODE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
+
+/** A linked source worktree is unmerged; a published install has no Git metadata. */
+function codeIsFromMain() {
+ return tryGit(CODE_ROOT, ['rev-parse', '--show-toplevel']).status !== 0 || repoInfo(CODE_ROOT).isMain;
+}
/** Require a trusted origin; HTTP exists only for loopback development and test relays. */
function relayOrigin(address) {
@@ -125,9 +132,9 @@ async function request(state, path, { method = 'GET', body } = {}, io) {
}
/** Read durable local event rows; their ids are the crash-safe outbox after the saved cursor. */
-function localRecords(root, work) {
+export function localRecords(root, work) {
const info = repoInfo(root);
- const board = store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'));
+ const board = store.openBoard(join(info.commonDir, 'pullboard', 'board.sqlite'), undefined, { isMain: codeIsFromMain() });
try { return work(board); } finally { store.closeBoard(board); }
}
diff --git a/test/api.test.js b/test/api.test.js
index 9358bfae..07cc479e 100644
--- a/test/api.test.js
+++ b/test/api.test.js
@@ -162,7 +162,7 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
const repo = join(box.dir, 'repo');
const sourceRoot = resolve(import.meta.dirname, '..');
mkdirSync(repo);
- for (const name of ['bin', 'src']) cpSync(join(sourceRoot, name), join(repo, name), { recursive: true });
+ for (const name of ['bin', 'src', 'skills']) cpSync(join(sourceRoot, name), join(repo, name), { recursive: true });
cpSync(join(sourceRoot, 'package.json'), join(repo, 'package.json'));
writeFileSync(join(repo, 'pullboard.json'), `${JSON.stringify({
gate: 'true', spec: 'SPEC.md', practice: 'PRACTICE.md',
@@ -252,6 +252,14 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
'a future-schema worktree refuses migration even when invoked from the main checkout directory');
assert.deepEqual(readFileSync(dbFile), before, 'cwd cannot make worktree code migrate the shared board');
+ const initFromMain = spawnSync(process.execPath, [join(linked, 'bin/pullboard.js'), 'init', '--json'], {
+ cwd: repo, env: box.env, encoding: 'utf8',
+ });
+ assert.equal(initFromMain.status, 1, initFromMain.stderr + initFromMain.stdout);
+ assert.equal(JSON.parse(initFromMain.stdout).error.code, 'UNMERGED_SCHEMA',
+ 'the setup command uses the running source identity when it opens the board');
+ assert.deepEqual(readFileSync(dbFile), before, 'setup cannot migrate the shared board from unmerged code');
+
const envBypass = spawnSync(process.execPath, [join(linked, 'bin/pullboard.js'), 'status', '--json'], {
cwd: repo, env: { ...box.env, PULLBOARD_CODE_IS_MAIN: '1' }, encoding: 'utf8',
});
@@ -260,6 +268,25 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main ca
'PULLBOARD_CODE_IS_MAIN cannot impersonate main-checkout source provenance');
assert.deepEqual(readFileSync(dbFile), before, 'the removed environment override cannot migrate the shared board');
+ const relayProbe = join(linked, '.schema-relay-probe.mjs');
+ writeFileSync(relayProbe, `
+ import { localRecords } from './src/relay.js';
+ try {
+ localRecords(process.env.PULLBOARD_FIXTURE_REPO, (board) => board.db.prepare('PRAGMA user_version').get());
+ console.log(JSON.stringify({ code: 'UNEXPECTED_OPEN' }));
+ } catch (error) {
+ console.log(JSON.stringify({ code: error.code, message: error.message }));
+ }
+ `);
+ const relayRecords = spawnSync(process.execPath, [relayProbe], {
+ cwd: repo, env: { ...box.env, PULLBOARD_FIXTURE_REPO: repo }, encoding: 'utf8',
+ });
+ assert.equal(relayRecords.status, 0, relayRecords.stderr + relayRecords.stdout);
+ const relayRefusal = JSON.parse(relayRecords.stdout);
+ assert.equal(relayRefusal.code, 'UNMERGED_SCHEMA', 'relay localRecords uses its source worktree identity even from main cwd');
+ assert.match(relayRefusal.message, /worktree expects board schema 3, newer than the shared board's version 2/);
+ assert.deepEqual(readFileSync(dbFile), before, 'relay localRecords refuses before it can migrate the shared board');
+
const specCheck = runFixture(linked, 'spec', 'check', '--json');
assert.equal(specCheck.status, 0, specCheck.stderr + specCheck.stdout);
assert.deepEqual(readFileSync(dbFile), before, 'spec check reads the spec without opening the shared board');