fix(terminals): negotiate explicit close intent for paired runtimes (#10129)

This commit is contained in:
OrcaWin
2026-07-27 15:22:55 -07:00
committed by GitHub
parent 0f91af821d
commit 24706ccff0
29 changed files with 1231 additions and 45 deletions
+19 -3
View File
@@ -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())