reply-controller.test.ts (2870B)
1 import { describe, expect, it } from 'vitest'; 2 import { 3 createReplyController, 4 replySnapshot, 5 replyText, 6 updateReplyText, 7 sendReply, 8 requestReplyNavigation, 9 keepReplyEditing, 10 discardReplyNavigation, 11 closeReplyController, 12 type ReplyController 13 } from '../../src/lib/messaging/reply-controller.ts'; 14 import { captureAuthenticatedReplyRumor } from '../../src/lib/messaging/rumor-plan.ts'; 15 import type { InboxView } from '../../src/lib/messaging/inbox-view.ts'; 16 import type { IdentitySession } from '../../src/lib/runtime/identity-session.ts'; 17 import type { PrivateSession } from '../../src/lib/runtime/private-session.ts'; 18 import type { UnlockedSession } from '../../src/lib/messaging/unlocked-session.ts'; 19 import type { AdmittedConversation } from '../../src/lib/messaging/admit-conversation.ts'; 20 21 const id = '12345678-1234-4234-8234-123456789abc'; 22 describe('reply entry points reject detached custody and SSR effects', () => { 23 it('SSR cannot allocate an effect-capable reply controller or run discovery', () => { 24 let lookups = 0; 25 expect( 26 createReplyController({} as InboxView, id, 'a'.repeat(64), { 27 lookupPeer: () => { 28 lookups++; 29 throw Error('must not query'); 30 } 31 }) 32 ).toBeUndefined(); 33 expect(lookups).toBe(0); 34 }); 35 it('plain copied reply tokens expose no private body or lifecycle state', () => { 36 const fake = Object.freeze({}) as ReplyController; 37 expect(replySnapshot(fake)).toBeUndefined(); 38 expect(replyText(fake)).toBeUndefined(); 39 expect( 40 updateReplyText(fake, 'Private sentinel', 'reviewed_private_text') 41 ).toBe(false); 42 closeReplyController(fake); 43 expect(replyText(fake)).toBeUndefined(); 44 }); 45 it('fake Send cannot manufacture native reservation or remote success', async () => { 46 expect( 47 await sendReply({} as ReplyController, 'reviewed_reply_send') 48 ).toEqual({ status: 'invalid' }); 49 expect(await sendReply({} as ReplyController, undefined)).toEqual({ 50 status: 'invalid' 51 }); 52 }); 53 it('fake dirty-navigation tokens cannot discard a genuine draft', () => { 54 const fake = {} as ReplyController; 55 expect(requestReplyNavigation(fake)).toBe('invalid'); 56 expect(keepReplyEditing(fake)).toBe(false); 57 expect(discardReplyNavigation(fake, 'reviewed_discard_private_text')).toBe( 58 'invalid' 59 ); 60 }); 61 it('same-owner strings and copied rooms cannot issue an authenticated reply rumor', () => { 62 expect( 63 captureAuthenticatedReplyRumor( 64 {} as IdentitySession, 65 {} as PrivateSession, 66 {} as UnlockedSession, 67 { 68 owner: 'a'.repeat(64), 69 peer: 'b'.repeat(64), 70 rumorId: 'c'.repeat(64) 71 } as unknown as AdmittedConversation, 72 'Reply must not redirect to a body contact', 73 1700000000 74 ) 75 ).toBeUndefined(); 76 }); 77 });