capability-gate.test.ts (2531B)
1 import { render } from 'svelte/server'; 2 import { describe, it, expect } from 'vitest'; 3 import Harness from './CapabilityGateHarness.svelte'; 4 const owner = 5 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'; 6 describe('shared safe connection capability presentation', () => { 7 it('guest exposes connection help and browse, with no private form or SSR effect', () => { 8 const forbidden = () => { 9 throw new Error('SSR effect'); 10 }; 11 const html = render(Harness, { props: { onconnect: forbidden } }).body; 12 expect(html).toContain('Connect extension'); 13 expect(html).toContain('Keep browsing'); 14 expect(html).toContain('private key stays in the extension'); 15 expect(html).not.toMatch(/<form|<textarea|nsec|password|HC_PRIVATE/); 16 }); 17 it('pending approval is visibly distinct and cannot schedule another connection', () => { 18 const html = render(Harness, { 19 props: { 20 identity: { state: 'pending', action: 'connect' }, 21 onconnect: () => {} 22 } 23 }).body; 24 expect(html).toContain('Waiting for extension'); 25 expect(html).toMatch(/<button[^>]*disabled/); 26 }); 27 it('missing or denied extension gets finite safe help, never provider diagnostics', () => { 28 for (const reason of ['missing', 'refused'] as const) { 29 const html = render(Harness, { 30 props: { identity: { state: 'guest', reason } } 31 }).body; 32 expect(html).toContain('Connection help'); 33 expect(html).not.toMatch(/stack|nsec|<input/); 34 } 35 }); 36 it('signing capability is not messaging readiness or inbox authority', () => { 37 const html = render(Harness, { 38 props: { 39 required: 'messaging', 40 identity: { 41 state: 'signing_only', 42 publicKey: owner, 43 messaging: 'unsupported' 44 }, 45 onprobe: () => {} 46 } 47 }).body; 48 expect(html).toContain('message encryption'); 49 expect(html).not.toMatch( 50 /Send message|Publish listing|inbox ready|<textarea/ 51 ); 52 }); 53 it('connected presentation never executes an earlier operation or exposes a private body', () => { 54 const html = render(Harness, { 55 props: { 56 identity: { 57 state: 'messaging_capable', 58 publicKey: owner, 59 messaging: 'capable' 60 }, 61 required: 'messaging', 62 onconnect: () => { 63 throw new Error('Send'); 64 } 65 } 66 }).body; 67 expect(html).toContain('Messaging support checked'); 68 expect(html).not.toMatch(/HC_PRIVATE|Send message|<form/); 69 }); 70 });