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.

1.8 KB
Raw Blame
import { describe, expect, it } from 'vitest'
import type { z } from 'zod'
import { hostStatusSchema } from './host-status-reply-schema'

function reads<T>(schema: z.ZodType<T, unknown>, value: unknown): T {
  const parsed = schema.safeParse(value)
  if (!parsed.success) {
    throw new Error(`expected a readable reply: ${parsed.error.message}`)
  }
  return parsed.data
}

function refuses(schema: z.ZodType<unknown, unknown>, value: unknown): boolean {
  return !schema.safeParse(value).success
}

describe('the host status decodes from every version the gate admits', () => {
  it('reads the status a current host sends', () => {
    const status = {
      protocolVersion: 5,
      minCompatibleMobileVersion: 1,
      appVersion: '1.4.200',
      capabilities: ['mobile.tasks.v1', 'push.v1', 'a', 'b'],
      floatingWorkspaceEnabled: true,
      hostPlatform: 'darwin',
      machineName: 'Studio'
    }
    expect(reads(hostStatusSchema, status)).toMatchObject(status)
  })

  it('reads a host that answers none of the status fields', () => {
    expect(reads(hostStatusSchema, {})).toEqual({})
    expect(reads(hostStatusSchema, { error: 'refused' })).toMatchObject({ error: 'refused' })
  })

  it('names a reply that is not a status object at all', () => {
    expect(refuses(hostStatusSchema, null)).toBe(true)
    expect(refuses(hostStatusSchema, undefined)).toBe(true)
  })
})

describe('capabilities salvage whole, not per element', () => {
  it('drops the whole list for one non-string, which is what the probe published', () => {
    // Drop the whole mixed-type list to preserve the legacy probe’s all-or-nothing capability policy.
    expect(reads(hostStatusSchema, { capabilities: ['push.v1', 7] }).capabilities).toBe(undefined)
    expect(reads(hostStatusSchema, { capabilities: 'push.v1' }).capabilities).toBe(undefined)
  })
})