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.

test(lanes): retain ordered replay and malformed argument guards [H16]

Corey Olsone6b8433e6b67
diff --git a/src/board.js b/src/board.js
index 5c2e25a0..4bdf7861 100644
--- a/src/board.js
+++ b/src/board.js
@@ -1,6 +1,6 @@
+import { applyLaneLead } from './lane-lead-policy.js';
import { applyHealthFindings } from './board-health.js';
import {
- applyLaneLead,
isLaneEscalation,
laneLeads,
leadOwnsDecision,
diff --git a/src/lane-lead-policy.js b/src/lane-lead-policy.js
new file mode 100644
index 00000000..150d72e9
--- /dev/null
+++ b/src/lane-lead-policy.js
@@ -0,0 +1,21 @@
+/** Coordinator-only ordered lane policy mutation [B21,H16]. */
+import { Refused } from './refused.js';
+import { laneLeads } from './lane-lead.js';
+
+/** Name an existing same-lane seat through the normal coordinator-only ordered transaction. */
+export function applyLaneLead(board, { agentId, lane, seat, lanes }, { atomic, logEvent }) {
+ return atomic(board, () => {
+ if (agentId !== 'coordinator') throw new Refused('COORDINATOR_ONLY', 'ask the coordinator to name or remove a lane lead');
+ if (!lanes.includes(lane) || lane === 'coordinator') throw new Refused('BAD_LANE_LEAD', 'name a configured non-coordinator lane');
+ if (seat !== null && !board.db.prepare('SELECT 1 FROM agent WHERE agent_id=? AND agent_lane=?').get(seat, lane)) {
+ throw new Refused('BAD_LANE_LEAD', 'name an existing seat in the same lane, or use off');
+ }
+ const leads = laneLeads(board);
+ if (seat === null) delete leads[lane]; else leads[lane] = seat;
+ board.db.prepare('INSERT INTO board_meta(meta_key,meta_value) VALUES (?,?) ON CONFLICT(meta_key) DO UPDATE SET meta_value=excluded.meta_value')
+ .run('lane_leads', JSON.stringify(leads));
+ logEvent(board, agentId, 'lane-lead', null, { lane, seat });
+ return leads;
+ });
+}
+
diff --git a/src/lane-lead.js b/src/lane-lead.js
index 96007e22..9ec653a8 100644
--- a/src/lane-lead.js
+++ b/src/lane-lead.js
@@ -6,27 +6,10 @@ import { LANE_LEAD_ENGINE } from './lane-lead-engine.js';
export function laneLeads(board) {
const row = board.db.prepare('SELECT meta_value FROM board_meta WHERE meta_key=?').get('lane_leads');
const values = row ? JSON.parse(row.meta_value) : {};
- return Object.fromEntries(Object.entries(values).filter(([lane, seat]) => lane !== 'coordinator'
+ return Object.fromEntries(Object.entries(values).filter(([lane, seat]) => lane !== 'coordinator' && typeof seat === 'string'
&& board.db.prepare('SELECT 1 FROM agent WHERE agent_id=? AND agent_lane=?').get(seat, lane)));
}
-/** Name an existing same-lane seat through the normal coordinator-only ordered transaction. */
-export function applyLaneLead(board, { agentId, lane, seat, lanes }, { atomic, logEvent }) {
- return atomic(board, () => {
- if (agentId !== 'coordinator') throw new Refused('COORDINATOR_ONLY', 'ask the coordinator to name or remove a lane lead');
- if (!lanes.includes(lane) || lane === 'coordinator') throw new Refused('BAD_LANE_LEAD', 'name a configured non-coordinator lane');
- if (seat !== null && !board.db.prepare('SELECT 1 FROM agent WHERE agent_id=? AND agent_lane=?').get(seat, lane)) {
- throw new Refused('BAD_LANE_LEAD', 'name an existing seat in the same lane, or use off');
- }
- const leads = laneLeads(board);
- if (seat === null) delete leads[lane]; else leads[lane] = seat;
- board.db.prepare('INSERT INTO board_meta(meta_key,meta_value) VALUES (?,?) ON CONFLICT(meta_key) DO UPDATE SET meta_value=excluded.meta_value')
- .run('lane_leads', JSON.stringify(leads));
- logEvent(board, agentId, 'lane-lead', null, { lane, seat });
- return leads;
- });
-}
-
/** Route only explicitly typed upward coordination; ordinary and item-specific notes stay unchanged. */
export function routeLaneMessage(board, message, engine) {
const { from, to, item } = message;
@@ -59,7 +42,7 @@ export function isLaneEscalation(board, ask) {
/** Floor only operations that execute the new lane policy; historical untyped messages retain old semantics. */
export function laneAnswerFloor(board, args) {
- if (!board?.db) return 1;
+ if (!board?.db || !Number.isSafeInteger(args?.[0]) && typeof args?.[0] !== 'string') return 1;
const ask = board.db.prepare('SELECT * FROM shout WHERE shout_id=?').get(args?.[0]);
return ask && (leadOwnsDecision(board, ask, args?.[1]?.agentId) || isLaneEscalation(board, ask)) ? LANE_LEAD_ENGINE : 1;
}
@@ -68,6 +51,7 @@ export function laneAnswerFloor(board, args) {
export function laneMessageFloor(board, message) {
if (message?.kind !== undefined) return LANE_LEAD_ENGINE;
if (!board?.db || !message?.decision || message.answers != null || message.to !== 'coordinator' || message.item !== undefined) return 1;
+ if (typeof message.from !== 'string') return 1;
const lane = board.db.prepare('SELECT agent_lane FROM agent WHERE agent_id=?').get(message.from)?.agent_lane;
return lane && laneLeads(board)[lane] ? LANE_LEAD_ENGINE : 1;
}
diff --git a/test/lane-lead.test.js b/test/lane-lead.test.js
index b335718f..ea57fbe9 100644
--- a/test/lane-lead.test.js
+++ b/test/lane-lead.test.js
@@ -1,6 +1,22 @@
/** Real lane coordination retains claims and the existing person boundary [B7,B21,B26,N26]. */
import assert from 'node:assert/strict';
import { join } from 'node:path';
+import {
+ mkdtempSync,
+ rmSync,
+} from 'node:fs';
+import { tmpdir } from 'node:os';
+import * as store from '../src/board.js';
+import {
+ applyEngineMove,
+ prepareEngineMove,
+} from '../src/engine.js';
+import {
+ exportBoard,
+ importBoard,
+} from '../src/exchange.js';
+import { LANE_LEAD_ENGINE } from '../src/lane-lead-engine.js';
+import { minimumMoveEngine } from '../src/move-registry.js';
import { test } from 'node:test';
import { createE2eHelpers } from './e2e-helpers.js';
@@ -64,3 +80,31 @@ test('a lane question reaches its lead and only the decision reaches the coordin
const restored = document(box, box.web, 'shout', 'coordinator', 'Lead removed', '--kind', 'question', '--decision');
assert.equal(message(box, restored.id).shout_to, 'coordinator');
});
+
+
+test('lane policy replays identically and an older engine cannot reroute a new question [B21,H16]', t => {
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-lane-lead-'));
+ const boards = ['origin', 'left', 'right'].map(name => store.openBoard(join(directory, name + '.sqlite')));
+ t.after(() => { for (const board of boards) store.closeBoard(board); rmSync(directory, { recursive: true, force: true }); });
+ const [source, left, right] = boards;
+ store.register(source, { lane: 'coordinator', path: '/private/lane-fixture' });
+ store.register(source, { lane: 'web', path: '/private/lane-fixture/worker' });
+ store.register(source, { lane: 'web', path: '/private/lane-fixture/lead' });
+ const initial = exportBoard(source);
+ for (const board of [left, right]) importBoard(board, initial);
+ const policy = prepareEngineMove(source, 'setLaneLead', [{ agentId: 'coordinator', lane: 'web', seat: 'web-2', lanes: ['web'] }]);
+ const at = new Date().toISOString();
+ assert.throws(() => applyEngineMove(left, { ...policy, engine: LANE_LEAD_ENGINE - 1 }, { sequence: 1, at }),
+ error => error.code === 'RELAY_MOVE');
+ const policies = boards.map(board => applyEngineMove(board, policy, { sequence: 1, at }));
+ assert.deepEqual(policies[1], policies[2]);
+ const question = prepareEngineMove(source, 'shout', [{ from: 'web-1', to: 'coordinator', text: 'Choose a path', decision: true, lanes: ['web'] }]);
+ assert.throws(() => applyEngineMove(left, { ...question, engine: LANE_LEAD_ENGINE - 1 }, { sequence: 2, at }),
+ error => error.code === 'RELAY_MOVE', 'a caller cannot discard the named lead by lowering its engine');
+ const results = boards.map(board => applyEngineMove(board, question, { sequence: 2, at }));
+ assert.deepEqual(results[1], results[2]);
+ assert.equal(store.getShout(left, results[1].result).shout_to, 'web-2');
+ assert.deepEqual(exportBoard(left), exportBoard(right));
+ assert.equal(minimumMoveEngine('answerDecision', [{}, {}], left, new Date(at)), 1,
+ 'malformed historical arguments retain their ordinary validator instead of failing in routing lookup');
+});