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(person): distinguish inserted events from execution [E22,H16]

Corey Olsone44e3a62d2c7
diff --git a/src/person-request.js b/src/person-request.js
index 2039f86f..639fb73a 100644
--- a/src/person-request.js
+++ b/src/person-request.js
@@ -36,11 +36,11 @@ export function preparePersonRequest(body, id = crypto.randomUUID(), rows) {
/** Keep shown rows to bounded `{id, text}` pairs, one per decided row. */
function shownRows(rows) {
- if (!Array.isArray(rows) || !rows.length || rows.length > 200 || rows.some((row) => !row || typeof row !== 'object' || Object.keys(row).sort().join() !== 'id,text'
- || typeof row.id !== 'string' || !/^(?:doctrine:)?[A-Za-z][A-Za-z0-9._-]{0,79}$/u.test(row.id) || typeof row.text !== 'string' || row.text.length > 8000)) {
+ if (!Array.isArray(rows) || !rows.length || rows.length > 200 || rows.some((row) => !row || typeof row !== 'object' || Object.keys(row).some(key => !['id', 'text', 'source'].includes(key))
+ || typeof row.id !== 'string' || !/^(?:doctrine:)?[A-Za-z][A-Za-z0-9._-]{0,79}$/u.test(row.id) || typeof row.text !== 'string' || row.text.length > 8000 || row.source !== undefined && (typeof row.source !== 'string' || row.source.length > 16000 || /[\r\n\0]/u.test(row.source)))) {
throw new Refused('BAD_REQUEST', 'a signed row decision names each row it shows with its id and exact text; reload the paired view and retry');
}
- return rows.map(({ id, text }) => ({ id, text }));
+ return rows.map(({ id, text, source }) => ({ id, text, ...(source === undefined ? {} : { source }) }));
}
/** Refuse malformed or newer request formats before any CLI can interpret their intent. */
diff --git a/src/relay-requests.js b/src/relay-requests.js
index 014b3bb0..68a1a5e6 100644
--- a/src/relay-requests.js
+++ b/src/relay-requests.js
@@ -266,6 +266,7 @@ export function recordRequestMove(board, move, outcome, sequence, at) {
} else if (tag.phase === 'execute') {
record.result = outcome.result;
record.resultSequence = sequence;
+ record.resultMove = move.id;
if (!['spec-approve', 'spec-decline', 'spec-answer'].includes(record.move.verb)) record.status = 'done';
} else if (tag.phase === 'repo-request') {
record.coordinatorRequest = outcome.result;
diff --git a/test/person-optional-apply-fixture.js b/test/person-optional-apply-fixture.js
index eb9acc81..0f3c4051 100644
--- a/test/person-optional-apply-fixture.js
+++ b/test/person-optional-apply-fixture.js
@@ -43,7 +43,7 @@ function sshPublicLine(publicKey) {
}
/** Exercise actual engine receipt validation and native apply on an owned project, with a separately pinned fixture relay key. */
-export async function optionalPasskeyApply(t, { throughCli = false, fabricatedMetadata = false } = {}) {
+export async function optionalPasskeyApply(t, { throughCli = false, fabricatedMetadata = false, syntheticEvent = false } = {}) {
const box = await relayClientFixture(t);
const specFile = join(box.root, 'SPEC.md');
const text = 'An optional SSH row approved by its exact passkey request.';
@@ -60,7 +60,7 @@ export async function optionalPasskeyApply(t, { throughCli = false, fabricatedMe
signing.pinAuthority(board, 'https://fixture-relay.invalid', { version: 1, algorithm: 'Ed25519',
publicKey: authority.publicKey.export({ format: 'der', type: 'spki' }).toString('base64url') });
signing.setPersonSigning(board, { agentId: 'coordinator', signed: true });
- const document = preparePersonRequest({ verb: 'spec-approve', args: { ids: 'G21' } }, randomUUID(), [{ id: 'G21', text }]);
+ const document = preparePersonRequest({ verb: 'spec-approve', args: { ids: 'G21' } }, randomUUID(), [{ id: 'G21', text, source: readFileSync(specFile, 'utf8').split(/\r?\n/u).find(line => line.startsWith('- G21 ')) }]);
const boardId = board.db.prepare("SELECT meta_value FROM board_meta WHERE meta_key='board_id'").get().meta_value;
const presence = { board: boardId, request: document.id, digest: createHash('sha256').update(JSON.stringify(document)).digest('hex'),
credential: 'fixture-passkey', at: Date.now() };
@@ -94,7 +94,23 @@ export async function optionalPasskeyApply(t, { throughCli = false, fabricatedMe
const fabricated = { ...genuine, event: missingEvent, source: genuine.source.replace('gate: review', 'gate: true'),
replacement: genuine.replacement.replace('gate: review', 'gate: true') };
assert.notEqual(fabricated.source, genuine.source, 'the attack changes a real row gate, not its signed displayed text');
- const records = personRequestRecords(board).map(record => record.id === document.id ? { ...record, result: [fabricated] } : record);
+ let syntheticMove;
+ if (syntheticEvent) {
+ const { event, at: recordedAt, applied, appliedAt, ...body } = fabricated;
+ board.db.prepare('INSERT INTO event(event_id,event_at,event_by,event_kind,item_id,event_detail) VALUES (?,?,?,?,?,?)')
+ .run(missingEvent, recordedAt, 'person', 'row_decision', null, JSON.stringify({ record: body, channel: 'view' }));
+ const original = personRequestRecords(board).find(record => record.id === document.id);
+ const receipt = JSON.parse(board.db.prepare('SELECT meta_value FROM board_meta WHERE meta_key=?').get('relay_receipt_' + original.resultMove).meta_value);
+ syntheticMove = JSON.parse(receipt.move);
+ syntheticMove.id = randomUUID();
+ syntheticMove.args[0].decisions = [body];
+ receipt.move = JSON.stringify(syntheticMove);
+ receipt.outcome.result = [fabricated];
+ receipt.outcome.events = [board.db.prepare('SELECT * FROM event WHERE event_id=?').get(missingEvent)];
+ board.db.prepare('INSERT INTO board_meta(meta_key,meta_value) VALUES (?,?)').run('relay_receipt_' + syntheticMove.id, JSON.stringify(receipt));
+ }
+ const records = personRequestRecords(board).map(record => record.id === document.id
+ ? { ...record, result: [fabricated], ...(syntheticMove ? { resultMove: syntheticMove.id } : {}) } : record);
board.db.prepare('UPDATE board_meta SET meta_value=? WHERE meta_key=?').run(JSON.stringify(records), 'relay_person_requests');
board.db.prepare('UPDATE board_meta SET meta_value=? WHERE meta_key=?').run(JSON.stringify([fabricated]), 'row_decisions');
const before = readFileSync(specFile, 'utf8');
@@ -103,8 +119,8 @@ export async function optionalPasskeyApply(t, { throughCli = false, fabricatedMe
const status = await box.cli('status');
assert.equal(status.code, 0, JSON.stringify(status.document));
assert.equal(status.document.specApprovalBaseline?.pending, false);
- assert.equal(board.db.prepare('SELECT event_id FROM event WHERE event_id=?').get(missingEvent), undefined,
- 'no real immutable event is ever created for the fabricated metadata');
+ assert.equal(Boolean(board.db.prepare('SELECT event_id FROM event WHERE event_id=?').get(missingEvent)), syntheticEvent,
+ 'the control explicitly distinguishes fabricated metadata from a raw-inserted event and fabricated engine receipt');
assert.deepEqual({ verified: signing.verifiedPasskeyRowDecision(board, fabricated),
falselyConfirmed: !status.document.needs.some(need => need.kind === 'agent-approved' && need.id === 'G21') },
{ verified: false, falselyConfirmed: false }, 'mutable receipt metadata cannot invent a committed approval or clear its changed gate');
@@ -136,3 +152,6 @@ export function optionalPasskeyApplyThroughCli(t) { return optionalPasskeyApply(
/** A copied valid signature cannot authenticate a fabricated mutable result or nonexistent committed event. */
export function rejectFabricatedPasskeyMetadata(t) { return optionalPasskeyApply(t, { fabricatedMetadata: true }); }
+
+/** An appended row event and mutable engine receipt still cannot change the source bound by a genuine passkey. */
+export function rejectSyntheticPasskeyEvent(t) { return optionalPasskeyApply(t, { fabricatedMetadata: true, syntheticEvent: true }); }
diff --git a/test/team.test.js b/test/team.test.js
index 78a4fd45..a871e44c 100644
--- a/test/team.test.js
+++ b/test/team.test.js
@@ -58,6 +58,7 @@ import {
optionalPasskeyApply,
optionalPasskeyApplyThroughCli,
rejectFabricatedPasskeyMetadata,
+ rejectSyntheticPasskeyEvent,
} from './person-optional-apply-fixture.js';
import { firstUnpairedAuthorityInsertion } from './person-first-pin-fixture.js';
import { refuseNamedSigners } from '../src/person-signing-cli.js';
@@ -1226,3 +1227,6 @@ test('person-only moves are signed through native CLI apply [E22,H16]', optional
/** Initial trust and committed execution provenance are separate signing boundaries. */
test('person-only moves are signed against fabricated receipt metadata [E22,H16]', rejectFabricatedPasskeyMetadata);
+
+/** A local event insertion is not an authenticated execution of a different row source. */
+test('person-only moves are signed against synthetic execution events [E22,H16]', rejectSyntheticPasskeyEvent);