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(schema): ignore inherited Git dirs [A5,A6]
Corey Olson39f4298cefde
diff --git a/src/api.js b/src/api.jsindex e32690bf..32ff0c96 100644--- a/src/api.js+++ b/src/api.js@@ -2,10 +2,9 @@import { randomBytes, timingSafeEqual } from 'node:crypto';import { createServer } from 'node:http';import { dirname, join } from 'node:path';-import { fileURLToPath } from 'node:url';import * as store from './board.js';import { COORDINATOR, loadConfig } from './config.js';-import { repoInfo, tryGit } from './git.js';+import { codeIsFromMain, repoInfo } from './git.js';import { refusalDocument } from './json.js';import { laneNames } from './lanes.js';import { listApiProjects } from './projects.js';@@ -15,12 +14,6 @@ import { createApiHandler } from './api-http.js';const ADDRESS = '127.0.0.1';const VERSION = 1;-const CODE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));--/** Whether this API module came from a Git main checkout, rather than a linked worktree. */-function codeIsFromMain() {- return tryGit(CODE_ROOT, ['rev-parse', '--show-toplevel']).status !== 0 || repoInfo(CODE_ROOT).isMain;-}/** Read a registered board and release its SQLite connection on every path.*diff --git a/src/cli.js b/src/cli.jsindex 0563b163..198652d0 100644--- a/src/cli.js+++ b/src/cli.js@@ -5,13 +5,13 @@import { spawn, spawnSync } from 'node:child_process';import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';-import { fileURLToPath, pathToFileURL } from 'node:url';+import { pathToFileURL } from 'node:url';import { parseArgs } from 'node:util';import * as store from './board.js';import { CONFIG_FILE, COORDINATOR, loadConfig } from './config.js';import { loadDoctrine } from './doctrine.js';import { digestOf, gateReport, runGate, runShell } from './gate.js';-import { bareWorktreeFinding, contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';+import { bareWorktreeFinding, codeIsFromMain, contains, differFromHead, git, headCommit, headTree, isClean, repoInfo, resolveCommit, tryGit, untracked } from './git.js';import {FIX_NOTE,applyFixers,@@ -57,12 +57,6 @@ import { relayOff, relayOn, relayStatus, syncRelay } from './relay.js';const PACKAGE = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));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.diff --git a/src/git.js b/src/git.jsindex bbc75048..7f2ff2c8 100644--- a/src/git.js+++ b/src/git.js@@ -5,9 +5,11 @@import { execFileSync, spawnSync } from 'node:child_process';import { existsSync, readdirSync, statSync } from 'node:fs';import { dirname, join, resolve } from 'node:path';+import { fileURLToPath } from 'node:url';import { Refused } from './refused.js';const GIT_FLAGS = ['-c', 'core.quotepath=false'];+const CODE_ROOT = dirname(dirname(fileURLToPath(import.meta.url)));/*** The environment for a gate or fixer: keep the user's settings, but remove Git's repository-local@@ -19,7 +21,14 @@ const GIT_FLAGS = ['-c', 'core.quotepath=false'];*/export function gitChildEnv(root) {const env = { ...process.env };- for (const name of git(root, ['rev-parse', '--local-env-vars']).split('\n')) delete env[name];+ const result = spawnSync('git', ['rev-parse', '--local-env-vars'], {+ cwd: root,+ env: { PATH: process.env.PATH },+ encoding: 'utf8',+ stdio: ['ignore', 'pipe', 'ignore'],+ });+ if (result.status === 0) for (const name of result.stdout.split('\n')) delete env[name];+ else for (const name of ['GIT_DIR', 'GIT_WORK_TREE', 'GIT_COMMON_DIR', 'GIT_INDEX_FILE', 'GIT_PREFIX']) delete env[name];return env;}@@ -28,11 +37,13 @@ export function gitChildEnv(root) {** @param {string} cwd* @param {string[]} args+ * @param {{env?: NodeJS.ProcessEnv}} [options]* @returns {string}*/-export function git(cwd, args) {+export function git(cwd, args, { env = process.env } = {}) {return execFileSync('git', [...GIT_FLAGS, ...args], {cwd,+ env,encoding: 'utf8',stdio: ['ignore', 'pipe', 'pipe'],}).trim();@@ -43,10 +54,11 @@ export function git(cwd, args) {** @param {string} cwd* @param {string[]} args+ * @param {{env?: NodeJS.ProcessEnv}} [options]* @returns {{ status: number, stdout: string }}*/-export function tryGit(cwd, args) {- const result = spawnSync('git', [...GIT_FLAGS, ...args], { cwd, encoding: 'utf8' });+export function tryGit(cwd, args, { env = process.env } = {}) {+ const result = spawnSync('git', [...GIT_FLAGS, ...args], { cwd, env, encoding: 'utf8' });return { status: result.status ?? 1, stdout: (result.stdout ?? '').trim() };}@@ -94,21 +106,33 @@ export function bareWorktreeFinding(cwd) {* The main checkout's git dir is the common dir; a linked worktree has its own under it.** @param {string} cwd+ * @param {{env?: NodeJS.ProcessEnv}} [options]* @returns {{ root: string, commonDir: string, gitDir: string, isMain: boolean }}*/-export function repoInfo(cwd) {- const top = tryGit(cwd, ['rev-parse', '--show-toplevel']);+export function repoInfo(cwd, { env = process.env } = {}) {+ const top = tryGit(cwd, ['rev-parse', '--show-toplevel'], { env });if (top.status !== 0) {const bare = bareWorktreeFinding(cwd);if (bare) throw new Refused(bare.code, `${bare.message}; run ${bare.next}`);throw new Refused('NOT_A_REPO', 'not inside a git work tree; run git init, or cd into a repo');}const root = top.stdout;- const commonDir = git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir']);- const gitDir = git(root, ['rev-parse', '--path-format=absolute', '--git-dir']);+ const commonDir = git(root, ['rev-parse', '--path-format=absolute', '--git-common-dir'], { env });+ const gitDir = git(root, ['rev-parse', '--path-format=absolute', '--git-dir'], { env });return { root, commonDir, gitDir, isMain: commonDir === gitDir };}+/** Determine code provenance without letting a caller's active hook redirect Git's repository.+ *+ * @param {string} [root]+ * @returns {boolean}+ */+export function codeIsFromMain(root = CODE_ROOT) {+ const env = gitChildEnv(root);+ const top = tryGit(root, ['rev-parse', '--show-toplevel'], { env });+ return top.status !== 0 || repoInfo(root, { env }).isMain;+}+/*** The full id of a commit-ish, or null when it names no commit here.*diff --git a/src/relay.js b/src/relay.jsindex 4aa99848..e519a30a 100644--- a/src/relay.js+++ b/src/relay.js@@ -2,10 +2,9 @@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';+import { codeIsFromMain, repoInfo, tryGit } from './git.js';import { forgetBoardKey, readBoardKey, storeBoardKey } from './relay-key.js';import { encodeBoardKey, generateBoardKey, seal } from './seal.js';import { terminalQr } from './qr.js';@@ -13,12 +12,6 @@ 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) {diff --git a/test/api.test.js b/test/api.test.jsindex 07cc479e..c56298e0 100644--- a/test/api.test.js+++ b/test/api.test.js@@ -243,7 +243,34 @@ test('[A5, A6] a future-schema worktree cannot migrate the shared board; main cabox.git(linked, 'add', 'src/board.js');box.git(linked, 'commit', '-q', '-m', 'feat: simulate an unmerged schema bump');- const before = readFileSync(dbFile);+ let before = readFileSync(dbFile);+ const mainGitDir = box.git(repo, 'rev-parse', '--path-format=absolute', '--git-dir');+ const linkedGitDir = box.git(linked, 'rev-parse', '--path-format=absolute', '--git-dir');+ const commonGitDir = box.git(linked, 'rev-parse', '--path-format=absolute', '--git-common-dir');+ const inheritedMain = {+ ...box.env, GIT_DIR: mainGitDir, GIT_WORK_TREE: repo, GIT_COMMON_DIR: mainGitDir,+ };+ const inheritedLinked = {+ ...box.env, GIT_DIR: linkedGitDir, GIT_WORK_TREE: linked, GIT_COMMON_DIR: commonGitDir,+ };+ const spoofedWorktree = spawnSync(process.execPath, [join(linked, 'bin/pullboard.js'), 'status', '--json'], {+ cwd: repo, env: inheritedMain, encoding: 'utf8',+ });+ assert.equal(spoofedWorktree.status, 1, spoofedWorktree.stderr + spoofedWorktree.stdout);+ assert.equal(JSON.parse(spoofedWorktree.stdout).error.code, 'UNMERGED_SCHEMA',+ 'GIT_DIR pointing at main cannot make unmerged worktree source appear merged');+ assert.deepEqual(readFileSync(dbFile), before, 'inherited main Git variables cannot migrate from worktree source');++ const mainFromHook = spawnSync(process.execPath, [join(repo, 'bin/pullboard.js'), 'status', '--json'], {+ cwd: linked, env: inheritedLinked, encoding: 'utf8',+ });+ assert.equal(mainFromHook.status, 0, mainFromHook.stderr + mainFromHook.stdout);+ const upgradedFromHook = new DatabaseSync(dbFile, { readOnly: true });+ assert.equal(upgradedFromHook.prepare('PRAGMA user_version').get().user_version, 2,+ 'main source upgrades even when a linked-worktree hook exports its Git directory');+ upgradedFromHook.close();+ before = readFileSync(dbFile);+const worktreeCodeFromMain = spawnSync(process.execPath, [join(linked, 'bin/pullboard.js'), 'status', '--json'], {cwd: repo, env: box.env, encoding: 'utf8',});diff --git a/test/git-provenance.test.js b/test/git-provenance.test.jsnew file mode 100644index 00000000..9b6a5769--- /dev/null+++ b/test/git-provenance.test.js@@ -0,0 +1,61 @@+/** Running source provenance ignores inherited Git hook repository overrides [A5,A6]. */+import assert from 'node:assert/strict';+import { spawnSync } from 'node:child_process';+import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';+import { tmpdir } from 'node:os';+import { join, resolve } from 'node:path';+import { pathToFileURL } from 'node:url';+import { test } from 'node:test';++/** Run Git in a disposable fixture without depending on user or system config. */+function git(cwd, args, env) {+ return spawnSync('git', args, { cwd, env, encoding: 'utf8' });+}++/** Ask a fresh Node process for source provenance under inherited Git directory variables. */+function probe(moduleURL, root, env) {+ const script = `import { codeIsFromMain } from ${JSON.stringify(moduleURL)}; process.stdout.write(String(codeIsFromMain(process.argv[1])));`;+ const result = spawnSync(process.execPath, ['--input-type=module', '-e', script, root], { cwd: root, env, encoding: 'utf8' });+ assert.equal(result.status, 0, result.stderr);+ return result.stdout === 'true';+}++test('[A5,A6] code provenance strips inherited GIT_DIR in both worktree-to-main directions', (t) => {+ const fixture = mkdtempSync(join(tmpdir(), 'pullboard-git-provenance-'));+ t.after(() => rmSync(fixture, { recursive: true, force: true }));+ const main = join(fixture, 'main');+ const linked = join(fixture, 'linked');+ mkdirSync(main);+ const baseEnv = {+ ...process.env,+ GIT_CONFIG_GLOBAL: '/dev/null',+ GIT_CONFIG_NOSYSTEM: '1',+ GIT_AUTHOR_NAME: 'Provenance test',+ GIT_AUTHOR_EMAIL: '[email protected]',+ GIT_COMMITTER_NAME: 'Provenance test',+ GIT_COMMITTER_EMAIL: '[email protected]',+ };+ const init = git(main, ['init', '-q', '-b', 'main'], baseEnv);+ assert.equal(init.status, 0, init.stderr);+ writeFileSync(join(main, 'README.md'), 'fixture\n');+ for (const args of [['add', 'README.md'], ['commit', '-q', '-m', 'fixture']]) {+ const result = git(main, args, baseEnv);+ assert.equal(result.status, 0, result.stderr);+ }+ const worktree = git(main, ['worktree', 'add', '-q', '-b', 'feature', linked], baseEnv);+ assert.equal(worktree.status, 0, worktree.stderr);+ const mainGitDir = git(main, ['rev-parse', '--path-format=absolute', '--git-dir'], baseEnv).stdout.trim();+ const linkedGitDir = git(linked, ['rev-parse', '--path-format=absolute', '--git-dir'], baseEnv).stdout.trim();+ const commonGitDir = git(main, ['rev-parse', '--path-format=absolute', '--git-common-dir'], baseEnv).stdout.trim();+ const helperURL = pathToFileURL(resolve(import.meta.dirname, '../src/git.js')).href;++ const worktreeAsMain = probe(helperURL, linked, {+ ...baseEnv, GIT_DIR: mainGitDir, GIT_WORK_TREE: main, GIT_COMMON_DIR: mainGitDir,+ });+ assert.equal(worktreeAsMain, false, 'worktree source remains unmerged when its process inherits main checkout variables');++ const mainAsWorktree = probe(helperURL, main, {+ ...baseEnv, GIT_DIR: linkedGitDir, GIT_WORK_TREE: linked, GIT_COMMON_DIR: commonGitDir,+ });+ assert.equal(mainAsWorktree, true, 'main source can upgrade in a hook that inherits linked-worktree variables');+});