Adds the Orca Mobile companion app (Expo SDK 55 / React Native 0.83) with: - QR code pairing flow: scan orca://pair# URL, validate auth, save host profile - WebSocket RPC client with auto-reconnect, exponential backoff, streaming support - Three screens: host list, worktree list, terminal session with live output - Mock WebSocket server for development without a running Orca desktop instance - Desktop-side: TLS certificate management, device registry, mobile IPC handlers, WebSocket transport layer, and pairing offer encode/decode with Zod validation - Unit tests for WebSocket transport and pairing codec Co-authored-by: Orca <help@stably.ai>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { encodePairingOffer, decodePairingOffer, type PairingOffer } from './pairing'
|
|
|
|
describe('pairing offer', () => {
|
|
const offer: PairingOffer = {
|
|
v: 1,
|
|
endpoint: 'wss://192.168.1.10:6768',
|
|
deviceToken: 'abcdef1234567890abcdef1234567890abcdef1234567890',
|
|
certFingerprint: 'sha256:deadbeef'
|
|
}
|
|
|
|
it('encode then decode round-trips correctly', () => {
|
|
const url = encodePairingOffer(offer)
|
|
expect(url).toMatch(/^orca:\/\/pair#/)
|
|
|
|
const decoded = decodePairingOffer(url)
|
|
expect(decoded).toEqual(offer)
|
|
})
|
|
|
|
it('encoded URL uses base64url (no +, /, or = characters)', () => {
|
|
const url = encodePairingOffer(offer)
|
|
const fragment = url.split('#')[1]!
|
|
expect(fragment).not.toMatch(/[+/=]/)
|
|
})
|
|
|
|
it('rejects URLs with wrong scheme', () => {
|
|
expect(() => decodePairingOffer('https://example.com#abc')).toThrow('Invalid pairing URL')
|
|
})
|
|
|
|
it('rejects URLs without fragment', () => {
|
|
expect(() => decodePairingOffer('orca://pair')).toThrow('Invalid pairing URL')
|
|
})
|
|
|
|
it('rejects payloads with missing fields', () => {
|
|
const partial = { v: 1, endpoint: 'wss://host:1234' }
|
|
const base64 = Buffer.from(JSON.stringify(partial)).toString('base64')
|
|
expect(() => decodePairingOffer(`orca://pair#${base64}`)).toThrow()
|
|
})
|
|
|
|
it('rejects payloads with wrong version', () => {
|
|
const wrong = { ...offer, v: 2 }
|
|
const base64 = Buffer.from(JSON.stringify(wrong)).toString('base64')
|
|
expect(() => decodePairingOffer(`orca://pair#${base64}`)).toThrow()
|
|
})
|
|
|
|
it('rejects payloads with invalid fingerprint prefix', () => {
|
|
const wrong = { ...offer, certFingerprint: 'md5:abc' }
|
|
const base64 = Buffer.from(JSON.stringify(wrong)).toString('base64')
|
|
expect(() => decodePairingOffer(`orca://pair#${base64}`)).toThrow()
|
|
})
|
|
})
|