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(offers): durable retries and minimal receipts [B2,H3,H16]

Corey Olson133cdab00b35
diff --git a/test/item-offer.test.js b/test/item-offer.test.js
new file mode 100644
index 00000000..551c5365
--- /dev/null
+++ b/test/item-offer.test.js
@@ -0,0 +1,75 @@
+/** Durable offers disclose content only to their recipient; private receipts carry references [B2,H3,H16]. */
+import assert from 'node:assert/strict';
+import { createHmac } from 'node:crypto';
+import { execFileSync } from 'node:child_process';
+import { existsSync, mkdirSync, mkdtempSync, rmSync } from 'node:fs';
+import { tmpdir } from 'node:os';
+import { join } from 'node:path';
+import { test } from 'node:test';
+import * as store from '../src/board.js';
+
+test('an accepted offer makes at most one child and a receipt carries no text [B2,H3,H16]', async t => {
+ const module = new URL('../src/item-offer.js', import.meta.url);
+ assert.ok(existsSync(module), 'the shared item-offer contract must exist');
+ const api = await import(module.href);
+ const directory = mkdtempSync(join(tmpdir(), 'pullboard-item-offer-'));
+ t.after(() => rmSync(directory, { recursive: true, force: true }));
+ const boards = [];
+ for (const name of ['source', 'destination']) {
+ const root = join(directory, name);
+ mkdirSync(root);
+ const env = { ...process.env };
+ for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
+ execFileSync('git', ['init', '-q', '-b', 'main', root], { env });
+ const file = join(root, '.git', 'board.sqlite'), board = store.openBoard(file);
+ store.ensureCoordinator(board, root);
+ boards.push({ board, file, id: store.boardId(board) });
+ }
+ t.after(() => { for (const entry of boards) store.closeBoard(entry.board); });
+ const [source, destination] = boards;
+ const parent = store.addItem(source.board, { by: 'coordinator', lane: 'web', title: 'Private parent' });
+ const offer = { version: 1, offerId: 'offer-1', sourceBoardId: source.id, parentItem: parent,
+ destinationBoardId: destination.id, proposedContent: { lane: 'web', title: 'Disclosed child', criterion: 'Disclosed bar' },
+ disposition: 'pending', childRef: null, reason: null };
+ const resolveBoardRef = id => boards.some(entry => entry.id === id) ? { boardId: id } : null;
+ // The consumer's explicit authority port binds intent; this fixture never claims native person presence.
+ let allowed = true;
+ const ports = { boardId: destination.id, resolveBoardRef, authorize: () => allowed,
+ createChild: content => store.addItem(destination.board, { by: 'coordinator', ...content }) };
+ const accepted = api.acceptItemOffer(destination.board, offer, ports);
+ assert.equal(accepted.childRef.boardId, destination.id);
+ assert.equal(store.listItems(destination.board, { all: true }).length, 1);
+ assert.equal(store.getItem(destination.board, accepted.childRef.item).item_parent_id, null, 'foreign parent id never becomes a local parent');
+ store.closeBoard(destination.board);
+ destination.board = store.openBoard(destination.file);
+ assert.deepEqual(api.acceptItemOffer(destination.board, offer, ports), accepted, 'retry after reopen returns the saved child');
+ assert.equal(store.listItems(destination.board, { all: true }).length, 1);
+ assert.throws(() => api.acceptItemOffer(destination.board, { ...offer, proposedContent: { ...offer.proposedContent, title: 'Changed' } }, ports), { code: 'OFFER_CONFLICT' });
+ assert.throws(() => api.acceptItemOffer(destination.board, { ...offer, offerId: 'bad', title: 'Hidden' }, ports), { code: 'ITEM_OFFER' });
+ allowed = false;
+ assert.throws(() => api.acceptItemOffer(destination.board, { ...offer, offerId: 'denied' }, ports), { code: 'OFFER_AUTHORITY' });
+ allowed = true;
+ const declined = api.declineItemOffer(destination.board, { ...offer, offerId: 'offer-2' }, 'No capacity', ports);
+ const announcement = api.itemOfferAnnouncement(declined);
+ assert.equal(Object.hasOwn(announcement, 'proposedContent'), false);
+ assert.equal(JSON.stringify(announcement).includes('Disclosed'), false);
+ api.recordItemOfferResult(source.board, announcement, { ...ports, boardId: source.id });
+ assert.equal(api.readItemOffer(source.board, source.id, 'offer-2').reason, 'No capacity');
+ assert.equal(api.readItemOffer(destination.board, source.id, 'offer-2').reason, 'No capacity');
+ assert.throws(() => api.recordItemOfferResult(source.board, { ...announcement, reason: 'Changed' }, { ...ports, boardId: source.id }), { code: 'OFFER_CONFLICT' });
+ const key = 'fixture-only-authority-key';
+ const sign = text => createHmac('sha256', key).update(text).digest('hex');
+ const fields = { version: 1, sourceBoardId: destination.id, item: accepted.childRef.item,
+ commit: 'a'.repeat(40), verifier: 'review-1', verdict: 'verdict-1' };
+ const receipt = api.minimalItemReceipt(fields, { sign });
+ assert.equal(api.verifyItemReceipt(receipt, { resolveBoardRef, verify: (text, signature) => sign(text) === signature }, fields), true);
+ assert.deepEqual(Object.keys(receipt).sort(), [...Object.keys(fields), 'integrity'].sort());
+ for (const extra of ['title', 'criterion', 'note']) {
+ assert.throws(() => api.minimalItemReceipt({ ...fields, [extra]: 'Private' }, { sign }), { code: 'ITEM_RECEIPT' });
+ assert.throws(() => api.verifyItemReceipt({ ...receipt, [extra]: 'Private' }, { resolveBoardRef, verify: () => true }, fields), { code: 'ITEM_RECEIPT' });
+ }
+ for (const change of [{ sourceBoardId: source.id }, { item: 999 }, { commit: 'b'.repeat(40) }, { verifier: 'other' }, { verdict: 'other' }]) {
+ assert.throws(() => api.verifyItemReceipt(receipt, { resolveBoardRef, verify: () => true }, { ...fields, ...change }), { code: 'ITEM_RECEIPT' });
+ }
+ assert.throws(() => api.verifyItemReceipt(receipt, { resolveBoardRef, verify: () => false }, fields), { code: 'ITEM_RECEIPT' });
+});