local-inventory.test.ts (3291B)
1 import { describe, expect, it } from 'vitest'; 2 import type { PublicOperationRecord } from '../../src/lib/contracts/local-records.ts'; 3 import { 4 publicRecordSettlement, 5 publicInventoryRow, 6 PUBLIC_CLEANUP_CONSEQUENCES 7 } from '../../src/lib/persistence/local-inventory.ts'; 8 const id = '3d030bf5-901d-45e1-8251-41cbdf805e96'; 9 const row: PublicOperationRecord = { 10 schema: 1, 11 family: 'public_operation', 12 owner: '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', 13 id, 14 revision: 0, 15 source: { type: 'draft', id, revision: 0 }, 16 capture: { 17 kind: 30402, 18 wire: 'controlled policy input only', 19 hash: 'a'.repeat(64), 20 targets: ['wss://one.example.org', 'wss://two.example.org'], 21 policyFingerprint: 'b'.repeat(64) 22 }, 23 artifact: null, 24 receipts: [] 25 }; 26 // Pure classification only; these deliberately controlled policy inputs grant 27 // no storage capability. Actual codecs/native IDB qualify browser admission. 28 function receipt( 29 origin: string, 30 status: 'accepted' | 'refused' | 'unknown' | 'timed_out' | 'stopped' 31 ) { 32 return { 33 actionId: id, 34 origin, 35 role: 'publication' as const, 36 attempt: 1, 37 eventId: 'a'.repeat(64), 38 status, 39 observedAtMilliseconds: 1000, 40 readbackWire: null 41 }; 42 } 43 describe('conservative public cleanup policy', () => { 44 it('unsigned capture and signed intent with no receipts stay protected', () => { 45 expect(publicRecordSettlement(row)).toBe('protected'); 46 expect( 47 publicRecordSettlement({ 48 ...row, 49 artifact: { eventId: 'a'.repeat(64), wire: 'controlled' } 50 }) 51 ).toBe('protected'); 52 }); 53 it('missing target evidence stays protected', () => { 54 expect( 55 publicRecordSettlement({ 56 ...row, 57 artifact: { eventId: 'a'.repeat(64), wire: 'controlled' }, 58 receipts: [receipt(row.capture.targets[0], 'accepted')] 59 }) 60 ).toBe('protected'); 61 }); 62 for (const status of ['unknown', 'timed_out', 'stopped'] as const) 63 it( 64 'retains unresolved ' + 65 status + 66 ' even alongside later positive observations', 67 () => { 68 expect( 69 publicRecordSettlement({ 70 ...row, 71 artifact: { eventId: 'a'.repeat(64), wire: 'controlled' }, 72 receipts: [ 73 receipt(row.capture.targets[0], status), 74 receipt(row.capture.targets[0], 'accepted'), 75 receipt(row.capture.targets[1], 'accepted') 76 ] 77 }) 78 ).toBe('protected'); 79 } 80 ); 81 it('all named terminal observations allow local settlement without claiming remote deletion', () => { 82 const record = { 83 ...row, 84 artifact: { eventId: 'a'.repeat(64), wire: 'controlled' }, 85 receipts: [ 86 receipt(row.capture.targets[0], 'accepted'), 87 receipt(row.capture.targets[1], 'refused') 88 ] 89 }; 90 expect(publicRecordSettlement(record)).toBe('settled'); 91 expect(publicInventoryRow(record, 123)).toEqual({ 92 key: 'public_operation:' + id, 93 family: 'public_operation', 94 id, 95 revision: 0, 96 logicalBytes: 123, 97 state: 'settled' 98 }); 99 expect(PUBLIC_CLEANUP_CONSEQUENCES).toContain( 100 'does not delete remote copies' 101 ); 102 expect(PUBLIC_CLEANUP_CONSEQUENCES).toContain('not a backup'); 103 }); 104 });