Files
orca/src/main/ipc/runtime-environment-status-connection.test.ts
T
OrcaWinandm4air 34e2e5f469 refactor(remote): clients connect through a paired-connection handle, not a pairing offer (#27533)
Desktop, CLI, web and runtime transports now take a PairedRuntimeConnection
(endpoint, pinned host key, credential) instead of a PairingOffer. Offers stay on
the pairing input path (codes, QR, links, environment add) and are converted with
pairedRuntimeConnectionFromOffer. The credential is token-only today; request
envelopes still carry the same deviceToken, so the wire is unchanged.

This lets device-key and ticket credentials replace the token later without
touching every connect call site again.

Co-authored-by: m4air <m4air@Mac.localdomain>
2026-10-11 14:02:03 -07:00

66 lines
2.4 KiB
TypeScript

import { mkdtempSync, rmSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { afterEach, expect, it, vi } from 'vitest'
import { encodePairingOffer } from '../../shared/pairing'
import { addEnvironmentFromPairingCode } from '../../shared/runtime-environment-store'
import { REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY } from '../../shared/protocol-version'
import {
createSharedControlTestServer,
closeSharedControlTestServers
} from '../../shared/remote-runtime-shared-control-test-server'
import { getRuntimeEnvironmentStatus } from './runtime-environment-transport-routing'
import {
getRuntimeEnvironmentStatusOwner,
resetRuntimeEnvironmentStatusOwners
} from './runtime-environment-request-connections'
vi.mock('electron', () => ({ BrowserWindow: { getAllWindows: () => [] } }))
const profiles: string[] = []
afterEach(async () => {
resetRuntimeEnvironmentStatusOwners()
await closeSharedControlTestServers()
profiles.splice(0).forEach((profile) => rmSync(profile, { recursive: true, force: true }))
})
it('publishes real same-socket verification after every authenticated reconnect', async () => {
let runtimeId = 'host-before'
const server = await createSharedControlTestServer({
resultForRequest: () => ({
runtimeId,
capabilities: [REMOTE_RUNTIME_SHARED_CONTROL_CAPABILITY]
})
})
const profile = mkdtempSync(join(tmpdir(), 'orca-status-socket-'))
profiles.push(profile)
const environment = addEnvironmentFromPairingCode(profile, {
name: 'host',
pairingCode: encodePairingOffer(server.offer)
})
await getRuntimeEnvironmentStatus(profile, environment.id)
const owner = getRuntimeEnvironmentStatusOwner(profile, environment.id)
await vi.waitFor(
() => {
expect(owner.read()).toMatchObject({ transport: 'ready', verification: 'verified' })
expect(server.requests).toHaveLength(2)
},
{ timeout: 3_000 }
)
expect(server.connectionCount()).toBe(2) // Bootstrap plus persistent control.
runtimeId = 'host-after'
server.closeClients()
await vi.waitFor(
() => {
expect(owner.read().status?.runtimeId).toBe('host-after')
expect(owner.read().verification).toBe('verified')
},
{ timeout: 3_000 }
)
expect(server.connectionCount()).toBe(3)
expect(server.requests.map((request) => request.method)).toEqual([
'status.get',
'status.get',
'status.get'
])
})