mirror of
https://github.com/stablyai/orca.git
synced 2026-09-22 08:02:28 +00:00
fix(terminals): negotiate explicit close intent for paired runtimes (#10129)
This commit is contained in:
@@ -18,7 +18,8 @@ import { addEnvironmentFromPairingCode } from './environments'
|
||||
import { RuntimeClientError } from './types'
|
||||
import {
|
||||
MIN_COMPATIBLE_RUNTIME_CLIENT_VERSION,
|
||||
RUNTIME_PROTOCOL_VERSION
|
||||
RUNTIME_PROTOCOL_VERSION,
|
||||
SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY
|
||||
} from '../../shared/protocol-version'
|
||||
|
||||
vi.mock('./launch', () => ({
|
||||
@@ -29,6 +30,7 @@ type TestRuntime = {
|
||||
endpoint: string
|
||||
publicKeyB64: string
|
||||
deviceToken: string
|
||||
authFrames: Record<string, unknown>[]
|
||||
close: () => Promise<void>
|
||||
}
|
||||
|
||||
@@ -55,6 +57,11 @@ describe('CLI remote WebSocket transport', () => {
|
||||
|
||||
expect(response.ok).toBe(true)
|
||||
expect(response.result.runtimeId).toBe('runtime-ws-1')
|
||||
expect(runtime.authFrames).toContainEqual(
|
||||
expect.objectContaining({
|
||||
clientCapabilities: [SESSION_TAB_CLOSE_INTENT_RUNTIME_CAPABILITY]
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it('rejects malformed remote pairing codes before local runtime lookup', () => {
|
||||
@@ -206,6 +213,7 @@ async function startTestRuntime(
|
||||
const deviceToken = `token-${runtimeId}`
|
||||
const httpServer = createServer()
|
||||
const wss = new WebSocketServer({ server: httpServer })
|
||||
const authFrames: Record<string, unknown>[] = []
|
||||
|
||||
wss.on('connection', (ws) => {
|
||||
let sharedKey: Uint8Array | null = null
|
||||
@@ -214,7 +222,10 @@ async function startTestRuntime(
|
||||
ws.on('message', (data) => {
|
||||
const frame = data.toString()
|
||||
if (!sharedKey) {
|
||||
const hello = JSON.parse(frame) as { type?: string; publicKeyB64?: string }
|
||||
const hello = JSON.parse(frame) as Record<string, unknown> & {
|
||||
type?: string
|
||||
publicKeyB64?: string
|
||||
}
|
||||
const clientPublicKey = Buffer.from(hello.publicKeyB64 ?? '', 'base64')
|
||||
sharedKey = deriveSharedKey(serverKeyPair.secretKey, clientPublicKey)
|
||||
ws.send(JSON.stringify({ type: 'e2ee_ready' }))
|
||||
@@ -227,7 +238,11 @@ async function startTestRuntime(
|
||||
return
|
||||
}
|
||||
if (!authenticated) {
|
||||
const auth = JSON.parse(plaintext) as { type?: string; deviceToken?: string }
|
||||
const auth = JSON.parse(plaintext) as Record<string, unknown> & {
|
||||
type?: string
|
||||
deviceToken?: string
|
||||
}
|
||||
authFrames.push(auth)
|
||||
if (auth.type !== 'e2ee_auth' || auth.deviceToken !== deviceToken) {
|
||||
ws.send(encrypt(JSON.stringify({ type: 'e2ee_error' }), sharedKey))
|
||||
ws.close(4001, 'auth failed')
|
||||
@@ -283,6 +298,7 @@ async function startTestRuntime(
|
||||
endpoint: `ws://127.0.0.1:${address.port}`,
|
||||
publicKeyB64: publicKeyToBase64(serverKeyPair.publicKey),
|
||||
deviceToken,
|
||||
authFrames,
|
||||
close: async () => {
|
||||
await new Promise<void>((resolve) => {
|
||||
wss.close(() => resolve())
|
||||
|
||||
Reference in New Issue
Block a user