import assert from 'node:assert/strict'; import { isValidReceipt, validateReceipt } from '../src/continuity/receipt-validator.mjs'; function test(name, fn) { try { fn(); console.log(`ok - ${name}`); } catch (error) { console.error(`not ok - ${name}`); throw error; } } test('accepts full receipt contract', () => { const receipt = { planId: 'plan-1', currentTask: 'task-7', nextDerivedAction: { type: 'message_subagent' }, dispatchedAt: '2026-04-24T09:00:00.000Z', dispatchRunId: 'run-1', childSessionKey: 'child-1', replyClosureState: 'completed', }; const result = validateReceipt(receipt); assert.equal(result.ok, true); assert.equal(isValidReceipt(receipt), true); }); test('rejects non-object receipt', () => { const result = validateReceipt(null); assert.equal(result.ok, false); assert.match(result.errors.join('\n'), /expected object/); }); test('rejects missing required fields', () => { const result = validateReceipt({ planId: 'plan-1' }); assert.equal(result.ok, false); assert.match(result.errors.join('\n'), /currentTask/); assert.match(result.errors.join('\n'), /nextDerivedAction/); assert.match(result.errors.join('\n'), /replyClosureState/); }); console.log('continuity.receipt-validator.test.mjs PASS');