Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

2.3 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import { RpcIncompatibleReplyError } from './rpc-incompatible-reply-error'
import {
  relayCredentialProvision,
  relayPairingEndpointsRead
} from './mobile-relay-pairing-operations'
import type { RpcResponse } from './types'

// Pin shared credential readers so centralizing interpretation preserves the shipped strict pairing contract.

function success(result: unknown): RpcResponse {
  return { id: 'reply-1', ok: true, result }
}

const installed = {
  v: 1,
  reqId: 'req-1',
  authorizationMode: 'relay-basis',
  currentVersion: 2,
  resumeExpiresAt: 1700000000000
}

const endpoints = {
  v: 1,
  relay: null,
  installStatus: { v: 1, reqId: 'req-1', state: 'committed', result: installed }
}

describe('the provision reader is the install contract', () => {
  it('reads a committed install', () => {
    expect(relayCredentialProvision.interpret(success(installed))).toEqual(installed)
  })

  it('refuses an install the contract refuses, naming the method', () => {
    expect(() => relayCredentialProvision.interpret(success({ ...installed, v: 2 }))).toThrow(
      RpcIncompatibleReplyError
    )
    // Preserve the released native pairing surface’s strict contract.
    expect(() => relayCredentialProvision.interpret(success({ ...installed, extra: 1 }))).toThrow(
      RpcIncompatibleReplyError
    )
    expect(() => relayCredentialProvision.interpret(success(null))).toThrow(
      /could not read \(pairing\.provisionRelay\)/
    )
  })
})

describe('the endpoints reader is the endpoints contract', () => {
  it('reads the authoritative view every caller commits on', () => {
    expect(relayPairingEndpointsRead.interpret(success(endpoints))).toEqual(endpoints)
  })

  it('refuses an endpoints reply missing the nullable relay member', () => {
    expect(() => relayPairingEndpointsRead.interpret(success({ v: 1 }))).toThrow(
      RpcIncompatibleReplyError
    )
    expect(() => relayPairingEndpointsRead.interpret(success(undefined))).toThrow(
      /could not read \(pairing\.getEndpoints\)/
    )
  })

  it('still raises the host code and message on a refusal, ahead of the reader', () => {
    const refusal: RpcResponse = {
      id: 'reply-1',
      ok: false,
      error: { code: 'forbidden', message: 'no' }
    }
    expect(() => relayPairingEndpointsRead.interpret(refusal)).toThrow('forbidden: no')
  })
})