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.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
import { describe, expect, it } from 'vitest'
import { selectConnectableHostProfiles, sortHostsByLastConnected } from './host-catalog-selection'
import type { HostCatalogEntry, HostProfile, StoredHostProfile } from './types'
const stored: StoredHostProfile = {
id: 'host-ready',
name: 'Ready',
endpoint: 'ws://127.0.0.1:1',
publicKeyB64: 'key-ready',
lastConnected: 0
}
const profile: HostProfile = { ...stored, deviceToken: 'token' }
function unavailable(
id: string,
credentialStatus: 'temporarily-unavailable' | 'missing'
): HostCatalogEntry {
return {
id,
name: id,
endpoint: `ws://127.0.0.1/${id}`,
publicKeyB64: `key-${id}`,
lastConnected: 0,
credentialStatus,
profile: null
}
}
describe('selectConnectableHostProfiles', () => {
it('excludes unavailable catalog entries from connection priming', () => {
expect(
selectConnectableHostProfiles([
{ ...stored, credentialStatus: 'ready', profile },
unavailable('host-locked', 'temporarily-unavailable'),
unavailable('host-missing', 'missing')
])
).toEqual([profile])
})
it('sorts hosts by recency without copied-array methods or input mutation', () => {
const hosts = [
{ ...profile, id: 'oldest', lastConnected: 1 },
{ ...profile, id: 'newest', lastConnected: 3 },
{ ...profile, id: 'middle', lastConnected: 2 }
]
const descriptor = Object.getOwnPropertyDescriptor(Array.prototype, 'toSorted')
Reflect.deleteProperty(Array.prototype, 'toSorted')
try {
expect(sortHostsByLastConnected(hosts).map((host) => host.id)).toEqual([
'newest',
'middle',
'oldest'
])
expect(hosts.map((host) => host.id)).toEqual(['oldest', 'newest', 'middle'])
} finally {
if (descriptor) {
Reflect.defineProperty(Array.prototype, 'toSorted', descriptor)
}
}
})
})