api-helpers.client.spec.ts 891 B

123456789101112131415161718192021
  1. /**
  2. * Contract-layer helpers: transport-error folding and response unwrapping.
  3. * (The assistant block classifier half of the legacy spec lives in
  4. * runtime/tests — the classifier moved there.)
  5. */
  6. import { describe, expect, it } from 'vitest'
  7. import { RpcId, resultOf, transportError } from '../src/client/api.ts'
  8. describe('transportError', () => {
  9. it('folds an Error to internal keeping the message, and stringifies non-Errors', () => {
  10. expect(transportError(new Error('线断了'))).toEqual({ ok: false, error: { code: 'gateway/internal', message: '线断了', details: {} } })
  11. expect(transportError('raw string')).toMatchObject({ ok: false, error: { message: 'raw string' } })
  12. })
  13. })
  14. describe('resultOf', () => {
  15. it('unwraps the result slot', () => {
  16. expect(resultOf({ rpcId: RpcId('r'), result: { ok: true, value: 7 } })).toEqual({ ok: true, value: 7 })
  17. })
  18. })