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
test(grant): fence activation and history overrides [E21,V4,H16]
Corey Olson61fc85a81e0b
diff --git a/test/review-queue.test.js b/test/review-queue.test.jsindex 7fa24dcb..aed324f7 100644--- a/test/review-queue.test.js+++ b/test/review-queue.test.js@@ -410,3 +410,40 @@ test('automatic conflict returns bind native evidence and replay without callererror => error.code === 'NOT_CONFLICTING', 'a clean submitted head cannot acquire computed conflict evidence');assert.equal(store.getItem(source, clean).item_status, 'submitted');});+++/** A cached immutable merge is not permission to replay through a locally overridden object graph. */+test('automatic conflict returns reject local history overrides before replay [V4,H16]', t => {+ const { box, conflicted, reviewer } = staleHeadFixture(t);+ const source = store.openBoard(join(box.repo, '.git', 'pullboard', 'board.sqlite'));+ const copies = [source];+ t.after(() => copies.forEach(board => store.closeBoard(board)));+ const actor = store.agentAt(source, reviewer).agent_id;+ const snapshot = exportBoard(source);+ const move = prepareEngineMove(source, 'reopen', [conflicted, { agentId: actor, automaticConflict: true }]);+ const evidence = move.args[1].computedConflict;+ const receipt = { sequence: 1, at: new Date().toISOString() };+ const results = [];+ for (const kind of ['grafts', 'replace']) {+ const board = store.openBoard(join(box.dir, `history-${kind}.sqlite`));+ copies.push(board); importBoard(board, snapshot);+ // This positive preparation also warms the normal per-board immutable-object verification cache.+ assert.ok(prepareEngineMove(board, 'reopen', [conflicted, { agentId: actor, computedConflict: evidence }]));+ const graft = join(box.repo, '.git', 'info', 'grafts');+ if (kind === 'grafts') writeFileSync(graft, evidence.head + '\n');+ else box.git(box.repo, 'replace', evidence.head, evidence.trunk);+ try {+ assert.throws(() => applyEngineMove(board, move, receipt),+ error => error.code === (kind === 'grafts' ? 'GIT_GRAFTS' : 'GIT_REPLACE_REFS'),+ 'local ancestry overrides refuse by name even after a prior clean verification');+ assert.equal(appliedSequence(board), 0, 'history refusal does not consume the replay cursor');+ assert.equal(store.getItem(board, conflicted).item_status, 'submitted');+ } finally {+ if (kind === 'grafts') rmSync(graft);+ else box.git(box.repo, 'replace', '-d', evidence.head);+ }+ results.push(applyEngineMove(board, move, receipt));+ assert.equal(results.at(-1).error, undefined, 'the same position succeeds once the private repository is clean');+ }+ assert.deepEqual(results[0], results[1], 'cleaned replicas apply the same actual recorded conflict');+});diff --git a/test/team.test.js b/test/team.test.jsindex 78ad6ed5..d6851279 100644--- a/test/team.test.js+++ b/test/team.test.js@@ -1162,3 +1162,59 @@ test('an agent grant narrows at claim but any joined seat can append attributedfinding(2, actor, expired, 'An expired build claim cannot block a finding');finding(3, actor, expired, 'No review reservation is required for a finding');});+++/** The activation boundary is an ordered engine prefix, not a client opening the database. */+test('an agent grant narrows at claim after the recorded engine high-water mark [E21,H16]', async t => {+ const { AGENT_GRANT_ENGINE } = await import('../src/agent-grant-engine.js');+ const box = helpers.project();+ const directory = join(box.dir, 'actual-pre-grant-writer');+ unpackRelease('e4b7c30d674cde73803f8e8cb3f53fb2f9f62621', directory);+ const oldStore = await import(pathToFileURL(join(directory, 'src/board.js')).href);+ const oldEngine = await import(pathToFileURL(join(directory, 'src/engine.js')).href);+ const oldExchange = await import(pathToFileURL(join(directory, 'src/exchange.js')).href);+ const old = oldStore.openBoard(':memory:');+ const replicas = [store.openBoard(':memory:'), store.openBoard(':memory:')];+ t.after(() => { oldStore.closeBoard(old); replicas.forEach(board => store.closeBoard(board)); });+ let sequence = 0;+ const at = new Date().toISOString();+ /** The accepted old writer records actual legacy move bytes and outcomes before activation. */+ const recordOld = (operation, args) => {+ const move = oldEngine.prepareEngineMove(old, operation, args);+ const receipt = { sequence: ++sequence, at };+ const outcome = oldEngine.applyEngineMove(old, move, receipt);+ assert.equal(outcome.error, undefined, JSON.stringify(outcome));+ return { move, receipt, outcome };+ };+ recordOld('register', [{ lane: 'coordinator', path: box.repo }]);+ const actor = recordOld('register', [{ lane: 'web', path: box.web }]).outcome.result;+ recordOld('addItem', [{ by: 'coordinator', lane: 'web', title: 'Legacy unclaimed work', criterion: 'Keep old history.' }]);+ const acknowledged = recordOld('appendFact', [1, { agentId: actor, kind: 'note', text: 'Recorded before activation.' }]);+ const snapshot = oldExchange.exportBoard(old);+ assert.ok(snapshot.tables.event.filter(event => ['join', 'claim', 'renew'].includes(event.event_kind))+ .every(event => JSON.parse(event.event_detail).grantEngine === undefined), 'the old writer emits no future marker');+ const frozen = JSON.stringify({ title: 'Legacy unclaimed work', criterion: 'Keep old history.', check: '', rows: [] });+ const staleClaim = oldEngine.prepareEngineMove(old, 'claim', [1, { agentId: actor, lane: 'web', leaseMs: 60_000,+ freeze: () => ({ text: frozen, digest: createHash('sha256').update(frozen).digest('hex') }) }]);+ const staleAdd = oldEngine.prepareEngineMove(old, 'addItem', [{ by: actor, lane: 'web', title: 'Fresh old-engine item', criterion: 'Must not bypass activation.' }]);+ assert.ok(staleClaim.engine < AGENT_GRANT_ENGINE);+ for (const board of replicas) importBoard(board, snapshot);+ const activation = prepareEngineMove(replicas[0], 'shout', [{ from: 'coordinator', to: actor, text: 'The modern engine is now recorded.', lanes: ['web'] }]);+ assert.ok(activation.engine >= AGENT_GRANT_ENGINE);+ const activationReceipt = { sequence: sequence + 1, at };+ const activated = replicas.map(board => applyEngineMove(board, activation, activationReceipt));+ assert.deepEqual(activated[0], activated[1]);+ assert.equal(activated[0].error, undefined);+ for (const board of replicas) {+ assert.deepEqual(applyEngineMove(board, acknowledged.move, acknowledged.receipt), acknowledged.outcome,+ 'the acknowledged pre-activation receipt replays byte-for-byte after activation');+ const before = appliedSequence(board);+ for (const move of [staleClaim, staleAdd]) {+ assert.throws(() => applyEngineMove(board, move, { sequence: before + 1, at }),+ error => error.code === 'RELAY_MOVE' && error.message.includes(String(AGENT_GRANT_ENGINE)),+ 'a newly ordered old-engine move cannot use wholly unmarked legacy seats or targets');+ assert.equal(appliedSequence(board), before, 'a version refusal leaves the ordered position retryable');+ }+ assert.equal(store.getItem(board, 1).item_status, 'open');+ }+});