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(board): initialize a separate fresh project from linked code [C7]

Corey Olson59d97b2a9d84
diff --git a/src/board-schema.js b/src/board-schema.js
index 9629b5ab..187e92e4 100644
--- a/src/board-schema.js
+++ b/src/board-schema.js
@@ -10,7 +10,10 @@ import {
join,
resolve,
} from 'node:path';
-import { codeIsFromMain } from './git.js';
+import {
+ codeIsFromMain,
+ codeUsesRepository,
+} from './git.js';
import { Refused } from './refused.js';
const reported = new Set();
@@ -79,9 +82,10 @@ const declarations = new WeakMap();
export function sharedSchemaOwner(file, hint) {
let owner = isRepositoryBoard(file) ? hint !== false && codeIsFromMain() : hint;
if (file !== ':memory:' && owner === false && !existsSync(file)) {
- // Linked repositories need trunk to initialize their common board; a fresh private project
- // has no existing shared schema to replace.
- if (isRepositoryBoard(file) && existsSync(join(dirname(dirname(file)), 'worktrees'))) {
+ // Unmerged source cannot initialize its own shared board. A separate fresh project has no
+ // existing schema to replace, even when it created linked worktrees before its first command.
+ const commonDir = dirname(dirname(file));
+ if (isRepositoryBoard(file) && existsSync(join(commonDir, 'worktrees')) && codeUsesRepository(commonDir)) {
throw new Refused('UNMERGED_SCHEMA', 'the shared board is missing; run pullboard status from the main checkout to initialize it before using this worktree');
}
owner = true;
diff --git a/src/git.js b/src/git.js
index de73fbb1..55d56d5c 100644
--- a/src/git.js
+++ b/src/git.js
@@ -542,6 +542,12 @@ export function codeIsFromMain(root = CODE_ROOT) {
return fact(key, () => readCodeIsFromMain(root));
}
+/** Identify the running source's repository without letting an inherited hook redirect Git. */
+export function codeUsesRepository(commonDir, root = CODE_ROOT) {
+ const info = tryGit(root, ['rev-parse', '--path-format=absolute', '--git-common-dir'], { env: gitChildEnv(root) });
+ return info.status === 0 && realpathSync.native(info.stdout.trim()) === realpathSync.native(commonDir);
+}
+
/** Determine whether the code is from its main checkout, retaining the non-repository fallback. */
function readCodeIsFromMain(root) {
const env = gitChildEnv(root);
diff --git a/test/branch-worktree-isolation.js b/test/branch-worktree-isolation.js
index cb3ab38c..d494cb75 100644
--- a/test/branch-worktree-isolation.js
+++ b/test/branch-worktree-isolation.js
@@ -1,7 +1,7 @@
/** Private-Git regression helper for a branch source whose unversioned DDL must not install [A5,A6,C7]. */
import assert from 'node:assert/strict';
import { spawnSync } from 'node:child_process';
-import { cpSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
import { DatabaseSync } from 'node:sqlite';
@@ -50,10 +50,14 @@ export async function assertBranchWorktreeBoardIsolation(t, sourceRoot) {
git('add', '-A');
git('commit', '-q', '-m', 'chore: initialize board isolation fixture');
- const initialized = cli(repo, 'init');
- assert.equal(initialized.status, 0, initialized.stderr + initialized.stdout);
const linked = run('git', ['worktree', 'add', '-q', '-b', 'schema/drift', branch, 'main'], repo, env);
assert.equal(linked.status, 0, linked.stderr + linked.stdout);
+ const missing = cli(branch, 'status');
+ assert.equal(missing.status, 1, missing.stderr + missing.stdout);
+ assert.equal(JSON.parse(missing.stdout).error.code, 'UNMERGED_SCHEMA', 'branch source still cannot initialize its own missing shared board');
+ assert.equal(existsSync(join(repo, '.git', 'pullboard', 'board.sqlite')), false, 'the refused open creates no shared database');
+ const initialized = cli(repo, 'init');
+ assert.equal(initialized.status, 0, initialized.stderr + initialized.stdout);
const joined = cli(branch, 'join', 'web', '--model', 'fixture-worker');
assert.equal(joined.status, 0, joined.stderr + joined.stdout);
const joinedDocument = JSON.parse(joined.stdout);