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(gate): a private clone's run keeps its release rank [C7,O5]

Corey Olsond92333bc6ec7
diff --git a/src/release-queue.js b/src/release-queue.js
index 39726049..063a3e0a 100644
--- a/src/release-queue.js
+++ b/src/release-queue.js
@@ -1,12 +1,13 @@
/** Capture one board's release priority before joining the machine resource transaction [C7,V4]. */
+import { spawnSync } from 'node:child_process';
import { existsSync } from 'node:fs';
-import { join } from 'node:path';
+import { isAbsolute, join } from 'node:path';
import {
boardId,
openBoardReadOnly,
roadmap,
} from './board.js';
-import { repoInfo } from './git.js';
+import { cleanGitEnvironment, repoInfo } from './git.js';
/**
* Capture the item's roadmap rank once, without opening or migrating a board for writing.
@@ -20,10 +21,8 @@ import { repoInfo } from './git.js';
* @returns {{ board: string, rank: number }|undefined}
*/
export function captureReleaseQueue(root, item) {
- let info;
- try { info = repoInfo(root); } catch { return undefined; }
- const file = join(info.commonDir, 'pullboard', 'board.sqlite');
- if (!existsSync(file)) return undefined;
+ const file = boardFileFor(root);
+ if (!file) return undefined;
const db = openBoardReadOnly(file);
try {
const board = { db, clock: { now: () => new Date() } };
@@ -31,6 +30,26 @@ export function captureReleaseQueue(root, item) {
} finally { db.close(); }
}
+/**
+ * Find the board database a gate caller queues under: the checkout's own, or, for a private clone of the
+ * board repo (a builder's integration clone), the board of the repo it was cloned from. Without a board
+ * anywhere the run keeps its queue position, as before [C7,O5].
+ *
+ * @param {string} root - The gate caller's checkout.
+ * @param {number} [hops] - How many clone origins may be followed.
+ * @returns {string|null}
+ */
+function boardFileFor(root, hops = 3) {
+ let info;
+ try { info = repoInfo(root); } catch { return null; }
+ const file = join(info.commonDir, 'pullboard', 'board.sqlite');
+ if (existsSync(file)) return file;
+ if (hops <= 0) return null;
+ const origin = spawnSync('git', ['config', '--get', 'remote.origin.url'], { cwd: root, env: cleanGitEnvironment(), encoding: 'utf8' });
+ const url = origin.status === 0 ? origin.stdout.trim() : '';
+ return url && isAbsolute(url) && existsSync(url) ? boardFileFor(url, hops - 1) : null;
+}
+
/**
* Rank local work using the board's own verified-item completion. A repo-qualified reference
* cannot pin this board to an old milestone: its state belongs to another board and is not read.
diff --git a/test/queue-order.test.js b/test/queue-order.test.js
index 80f4f4cb..4bfcce04 100644
--- a/test/queue-order.test.js
+++ b/test/queue-order.test.js
@@ -1,7 +1,12 @@
/** Local release completion and deterministic ordering boundaries [C7,V4]. */
import assert from 'node:assert/strict';
+import { mkdirSync, mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
import { test } from 'node:test';
-import { localReleaseRank } from '../src/release-queue.js';
+import { addItem, addMilestone, closeBoard, openBoard } from '../src/board.js';
+import { runFixtureGit } from './fixture-child.js';
+import { captureReleaseQueue, localReleaseRank } from '../src/release-queue.js';
import { orderedWaiters } from '../src/queue-order.js';
test('release priority uses only local verified work, leaving external references alone [C7,V4]', () => {
@@ -30,3 +35,36 @@ test('release ordering preserves opportunity positions and already aged arrivals
assert.deepEqual(orderedWaiters([row(1, 'A', 2, 61_000), row(2, 'A', 0)], now, order).map(entry => entry.ticket), [1, 2],
'release-only admission also protects an aged unplanned run');
});
+
+test('a run from a private clone keeps its release rank [C7,O5]', () => {
+ const dir = mkdtempSync(join(tmpdir(), 'pullboard-clone-rank-'));
+ try {
+ const env = { ...Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.startsWith('GIT_'))), GIT_CONFIG_GLOBAL: '/dev/null', GIT_CONFIG_NOSYSTEM: '1',
+ GIT_AUTHOR_NAME: 'F', GIT_AUTHOR_EMAIL: '[email protected]', GIT_COMMITTER_NAME: 'F', GIT_COMMITTER_EMAIL: '[email protected]' };
+ const git = (cwd, ...args) => runFixtureGit(args, { cwd, env, encoding: 'utf8', stdio: 'pipe' });
+ const repo = join(dir, 'repo');
+ mkdirSync(repo);
+ git(repo, 'init', '-q', '-b', 'main');
+ git(repo, 'commit', '-q', '--allow-empty', '-m', 'chore: init');
+ mkdirSync(join(repo, '.git', 'pullboard'));
+ const board = openBoard(join(repo, '.git', 'pullboard', 'board.sqlite'));
+ const current = addItem(board, { by: 'coordinator', lane: 'web', title: 'Current' });
+ const later = addItem(board, { by: 'coordinator', lane: 'web', title: 'Later' });
+ addMilestone(board, { agentId: 'coordinator', name: 'Now', items: [current] });
+ addMilestone(board, { agentId: 'coordinator', name: 'Next', items: [later] });
+ closeBoard(board);
+ const clone = join(dir, 'clone');
+ git(dir, 'clone', '-q', '--shared', repo, clone);
+ const fromClone = captureReleaseQueue(clone, current);
+ const fromBoard = captureReleaseQueue(repo, current);
+ assert.ok(fromClone, 'the clone finds the board it was cloned from');
+ assert.deepEqual(fromClone, fromBoard, 'the clone and the board checkout see the same board and rank');
+ const now = Date.UTC(2026, 9, 17, 2);
+ const order = { reviewsFirst: false, currentReleaseFirst: true, ageMs: 60_000 };
+ const row = (ticket, queued) => ({ ticket, board_key: queued.board, release_rank: queued.rank, release_aware: 1, since: new Date(now).toISOString() });
+ const ordinary = row(1, captureReleaseQueue(repo, later));
+ const cloned = row(2, fromClone);
+ assert.deepEqual(orderedWaiters([ordinary, cloned], now, order).map(entry => entry.ticket), [2, 1], 'the clone-started current-release run is admitted first');
+ assert.equal(captureReleaseQueue(dir, current), undefined, 'a directory with no board keeps its queue position');
+ } finally { rmSync(dir, { recursive: true, force: true }); }
+});