Files
orca/src/shared/host-authority.test.ts
T
OrcaWinandm4air 6af18ab07a refactor(hosts): host authorities and owner resolution (#27176)
* refactor(hosts): host authorities and owner resolution

Adds HostAuthority {endpoint, at} with authorityKey (existing host-id
spellings kept; nested 'SSH target behind server' gets an in-memory key no
host-id parser accepts), HostRoute {target, at}, and resolveOwner, a
focus-free owner resolver over the existing route resolvers. Today's
focus-reading answer is kept behind resolveOwnerWithLegacyFocus, which
counts every answer focus changed. No caller migrates in this PR.

* fix(hosts): resolveOwner keeps nested SSH places and strict active selection

The active workspace's host now resolves through the strict path, so rival
servers proxying one ssh:t stay ambiguous. A folder or repo row on a paired
server that names an SSH connection resolves to that nested target instead
of the server's own machine.

---------

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-10-10 02:47:06 -07:00

82 lines
3.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
getExecutionHostIdFromWorktreeHostIdentity,
composeWorktreeHostIdentity
} from './worktree/host-qualified-identity'
import { parseExecutionHostId, UNRESOLVED_OWNER_HOST_ID } from './execution-host'
import {
authorityKey,
hostAuthorityFromOperationRoute,
parseHostAuthorityKey,
type HostAuthority
} from './host-authority'
const self = { kind: 'self' } as const
const env = (environmentId: string) => ({ kind: 'environment', environmentId }) as const
describe('authorityKey', () => {
it.each<[HostAuthority, string]>([
[{ endpoint: self, at: 'local' }, 'local'],
[{ endpoint: self, at: 'ssh:box' }, 'ssh:box'],
[{ endpoint: env('env/a'), at: 'local' }, 'runtime:env%2Fa'],
[{ endpoint: env('env/a'), at: 'ssh:my%2Fbox' }, 'nested:env%2Fa/my%2Fbox']
])('keeps existing spellings and round-trips %j', (authority, key) => {
expect(authorityKey(authority)).toBe(key)
expect(parseHostAuthorityKey(key)).toEqual(authority)
})
it('gives nested authorities a key no host-id parser accepts', () => {
const key = authorityKey({ endpoint: env('env-a'), at: 'ssh:box' })
expect(parseExecutionHostId(key)).toBeNull()
expect(
getExecutionHostIdFromWorktreeHostIdentity(composeWorktreeHostIdentity(undefined, key))
).toBeUndefined()
})
it('never parses the unresolved-owner sentinel, plain or nested', () => {
expect(parseHostAuthorityKey(UNRESOLVED_OWNER_HOST_ID)).toBeNull()
expect(parseHostAuthorityKey('nested:unresolved-owner/box')).toBeNull()
expect(parseHostAuthorityKey('nested:env-a')).toBeNull()
expect(parseHostAuthorityKey('nested:env-a/box/extra')).toBeNull()
expect(parseHostAuthorityKey('bogus')).toBeNull()
})
})
describe('hostAuthorityFromOperationRoute', () => {
it('reads the transport as the endpoint and the row host as the place on it', () => {
expect(
hostAuthorityFromOperationRoute({ executionHostId: 'ssh:t', runtimeEnvironmentId: 'env-a' })
).toEqual({ endpoint: env('env-a'), at: 'ssh:t' })
expect(
hostAuthorityFromOperationRoute({ executionHostId: 'local', runtimeEnvironmentId: 'env-a' })
).toEqual({ endpoint: env('env-a'), at: 'local' })
expect(
hostAuthorityFromOperationRoute({ executionHostId: null, runtimeEnvironmentId: 'env-a' })
).toEqual({ endpoint: env('env-a'), at: 'local' })
expect(
hostAuthorityFromOperationRoute({ executionHostId: 'ssh:t', runtimeEnvironmentId: null })
).toEqual({ endpoint: self, at: 'ssh:t' })
})
it('reports disagreeing hosts and refuses unusable ones', () => {
expect(
hostAuthorityFromOperationRoute({
executionHostId: 'runtime:env-b',
runtimeEnvironmentId: 'env-a'
})
).toBe('contradictory')
expect(
hostAuthorityFromOperationRoute({
executionHostId: UNRESOLVED_OWNER_HOST_ID,
runtimeEnvironmentId: 'unresolved-owner'
})
).toBeNull()
expect(
hostAuthorityFromOperationRoute({ executionHostId: 'garbage', runtimeEnvironmentId: null })
).toBeNull()
expect(
hostAuthorityFromOperationRoute({ executionHostId: null, runtimeEnvironmentId: null })
).toBeNull()
})
})