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): keep reuse proof separate from fresh binds [N26,N32]

Corey Olsonbced72b010bc
diff --git a/src/cli.js b/src/cli.js
index 3b6f7737..d2be90bb 100644
--- a/src/cli.js
+++ b/src/cli.js
@@ -1062,18 +1062,29 @@ function setupIdentity(board) {
setupStartedAt: store.listAgents(board).find(agent => agent.agent_id === COORDINATOR)?.agent_created_at };
}
-/** Read the view's typed fresh-bind or authenticated-reuse receipt for this board and setup. */
-function viewSetupComplete(ctx, board) {
+/** Read only the view's typed successful-bind receipt for this board and setup. */
+function viewBindComplete(ctx, board) {
let receipt;
try { receipt = JSON.parse(readFileSync(join(ctx.info.commonDir, 'pullboard', 'view-bind.json'), 'utf8')); }
catch (error) { if (error.code === 'ENOENT' || error instanceof SyntaxError) return false; throw error; }
const identity = setupIdentity(board);
- const observedAt = receipt?.type === 'pullboard.view.bound' ? receipt.boundAt
- : receipt?.type === 'pullboard.view.reused' ? receipt.openedAt : null;
- return receipt?.version === 1
+ return receipt?.type === 'pullboard.view.bound' && receipt.version === 1
&& receipt.boardId === identity.boardId && receipt.setupStartedAt === identity.setupStartedAt
- && Number.isFinite(Date.parse(observedAt))
- && Date.parse(observedAt) >= Date.parse(identity.setupStartedAt);
+ && Number.isFinite(Date.parse(receipt.boundAt))
+ && Date.parse(receipt.boundAt) >= Date.parse(identity.setupStartedAt);
+}
+
+/** A separately typed, authenticated reuse also proves that this board's view was opened. */
+function viewSetupComplete(ctx, board) {
+ if (viewBindComplete(ctx, board)) return true;
+ let receipt;
+ try { receipt = JSON.parse(readFileSync(join(ctx.info.commonDir, 'pullboard', 'view-reuse.json'), 'utf8')); }
+ catch (error) { if (error.code === 'ENOENT' || error instanceof SyntaxError) return false; throw error; }
+ const identity = setupIdentity(board);
+ return receipt?.type === 'pullboard.view.reused' && receipt.version === 1
+ && receipt.boardId === identity.boardId && receipt.setupStartedAt === identity.setupStartedAt
+ && Number.isFinite(Date.parse(receipt.openedAt))
+ && Date.parse(receipt.openedAt) >= Date.parse(identity.setupStartedAt);
}
/** Atomically record a successful real view bind, scoped to this board's current setup. */
@@ -1088,7 +1099,7 @@ function recordViewBind(ctx, board, boundAt) {
/** Record this board's authenticated reuse without claiming that its existing listener bound again. */
function recordViewReuse(ctx, board, view) {
- const file = join(ctx.info.commonDir, 'pullboard', 'view-bind.json');
+ const file = join(ctx.info.commonDir, 'pullboard', 'view-reuse.json');
const temporary = file + '.' + randomUUID() + '.tmp';
const receipt = { type: 'pullboard.view.reused', version: 1, ...setupIdentity(board),
openedAt: new Date().toISOString(), boundAt: view.boundAt, port: view.port, pid: view.pid };
diff --git a/test/resume-flow.test.js b/test/resume-flow.test.js
index 900c6154..5b01eb7a 100644
--- a/test/resume-flow.test.js
+++ b/test/resume-flow.test.js
@@ -327,11 +327,10 @@ function assertViewReceipt(box) {
test('a reused authenticated view completes setup for its new board [N26,N32]', async t => {
const firstBoard = releaseFixture(t);
- const secondBoard = releaseFixture(t);
- const refusedBoard = releaseFixture(t);
const lease = await takeDefaultViewPort(firstBoard.root);
t.after(() => lease.release());
- for (const box of [firstBoard, secondBoard, refusedBoard]) {
+ /** Prepare a real board through the first four setup steps, leaving only its view unopened. */
+ function awaitingView(box) {
box.env.PULLBOARD_HOME = firstBoard.env.PULLBOARD_HOME;
box.env.PULLBOARD_MACHINE_HOME = firstBoard.env.PULLBOARD_MACHINE_HOME;
delete box.env.PULLBOARD_VIEW_FOREGROUND;
@@ -344,6 +343,7 @@ test('a reused authenticated view completes setup for its new board [N26,N32]',
assert.equal(added.status, 0, added.failure || added.stderr || added.stdout);
assert.equal(JSON.parse(box.run(box.repo, 'resume', '--json').stdout).setup?.step, 5);
}
+ awaitingView(firstBoard);
const child = spawn(process.execPath, [join(firstBoard.root, 'cli/bin/pullboard.js'), 'view', '--no-open', '--json'],
{ cwd: firstBoard.repo, env: { ...firstBoard.env, PULLBOARD_VIEW_FOREGROUND: '1' }, stdio: ['ignore', 'pipe', 'pipe'] });
const closed = new Promise(resolve => child.once('close', resolve));
@@ -363,6 +363,10 @@ test('a reused authenticated view completes setup for its new board [N26,N32]',
});
assert.equal(first.port, 4890);
assert.equal(JSON.parse(firstBoard.run(firstBoard.repo, 'resume', '--json').stdout).setup, null);
+ const secondBoard = releaseFixture(t);
+ const refusedBoard = releaseFixture(t);
+ awaitingView(secondBoard);
+ awaitingView(refusedBoard);
const reused = secondBoard.run(secondBoard.repo, 'view', '--no-open', '--json');
assert.equal(reused.status, 0, reused.failure || reused.stderr || reused.stdout);
const second = JSON.parse(reused.stdout);
@@ -370,7 +374,7 @@ test('a reused authenticated view completes setup for its new board [N26,N32]',
assert.equal(second.url, first.url);
assert.equal(JSON.parse(secondBoard.run(secondBoard.repo, 'resume', '--json').stdout).setup, null,
'the exact offered view command completes setup on the second board');
- const receiptPath = join(secondBoard.repo, '.git/pullboard/view-bind.json');
+ const receiptPath = join(secondBoard.repo, '.git/pullboard/view-reuse.json');
const bytes = readFileSync(receiptPath);
const receipt = JSON.parse(bytes);
assert.equal(receipt.type, 'pullboard.view.reused');