Files
orca/src/shared/ssh-retained-payload-admission.test.ts
T
JinjingandOrcaWin a40183389b feat: bound direct SSH reconnect fan-out and recovery (#11003)
* docs: design for direct SSH reconnect fan-out

Capture the implementation-ready plan for host-qualified, epoch-fenced
SSH reconnect recovery after two rounds of multi-model LLM counsel review.

* docs: reconcile SSH reconnect fan-out design

* docs: close reconnect design consistency gaps

* feat: implement bounded direct SSH reconnect recovery

* fix: bound direct SSH retry settlement

* fix: harden direct SSH reconnect authority

* fix: preserve split SSH retry ownership

* fix: preserve SSH split continuation authority

* docs: record final SSH reconnect validation

* fix: preserve SSH authority through retained and detached state

* fix: retain SSH authority across delayed split mounts

* fix: close SSH authority recovery gaps

* fix: fence stale SSH transport replacement

* fix: serialize SSH target teardown

* fix: settle SSH teardown failures before reconnect

* fix: retire failed SSH reset sessions

* test: reconcile current main E2E contracts

* fix: close direct SSH reconnect review gaps

* fix: fence stale SSH reconnect side effects

* fix: close final SSH reconnect lifecycle gaps

* test: stabilize current-main reliability gates

* test: prove plugin navigation containment

* test: make plugin navigation oracle authoritative

* test: make plugin navigation oracle deterministic

* ci: allow sharded e2e suite to finish

* test: wait for runtime pane publication

* test: classify pane readiness by error code

* test: select close persistence terminal by tab identity

* docs: mark reconnect implementation validated

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-07-28 12:33:17 -07:00

206 lines
5.8 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getUtf8ByteLength } from './utf8-byte-limits'
import {
admitSshConnectionState,
admitSshDetectedPorts,
SSH_CONNECTION_ERROR_MAX_UTF8_BYTES,
SSH_DETECTED_PORTS_MAX_ENTRIES,
SSH_DETECTED_PORT_ADVERTISED_URL_MAX_UTF8_BYTES,
SSH_DETECTED_PORT_PROCESS_NAME_MAX_UTF8_BYTES,
SSH_PROVIDER_EPOCH_MAX_UTF8_BYTES,
SSH_RETAINED_IDENTIFIER_MAX_UTF8_BYTES,
admitSshConnectionStateForAuthorityReconciliation,
isAdmissibleDirectSshAuthority
} from './ssh-retained-payload-admission'
describe('SSH retained payload admission', () => {
it('keeps ordinary connection state while stripping unknown payload fields', () => {
const admitted = admitSshConnectionState(
{
targetId: 'ssh-a',
status: 'connected',
error: null,
reconnectAttempt: 2,
providerEpoch: 'provider-a',
connectionGeneration: 3,
supportsFolderDownload: true,
remotePlatform: 'linux',
unexpected: 'x'.repeat(1024)
},
'ssh-a'
)
expect(admitted).toEqual({
targetId: 'ssh-a',
status: 'connected',
error: null,
reconnectAttempt: 2,
providerEpoch: 'provider-a',
connectionGeneration: 3,
supportsFolderDownload: true,
remotePlatform: 'linux'
})
})
it('rejects partial and malformed provider authority', () => {
const state = {
targetId: 'ssh-a',
status: 'connected',
error: null,
reconnectAttempt: 0
}
expect(admitSshConnectionState({ ...state, providerEpoch: 'provider-a' }, 'ssh-a')).toBeNull()
expect(admitSshConnectionState({ ...state, connectionGeneration: 3 }, 'ssh-a')).toBeNull()
expect(
admitSshConnectionState(
{
...state,
providerEpoch: 'x'.repeat(SSH_PROVIDER_EPOCH_MAX_UTF8_BYTES + 1),
connectionGeneration: 3
},
'ssh-a'
)
).toBeNull()
})
it('admits only bounded complete direct SSH authority', () => {
expect(
isAdmissibleDirectSshAuthority({
targetId: 'ssh-a',
providerEpoch: 'provider-a',
connectionGeneration: 3
})
).toBe(true)
expect(
isAdmissibleDirectSshAuthority({
targetId: 'ssh-a',
providerEpoch: 'provider-a'
})
).toBe(false)
expect(
isAdmissibleDirectSshAuthority({
targetId: 'x'.repeat(SSH_RETAINED_IDENTIFIER_MAX_UTF8_BYTES + 1),
providerEpoch: 'provider-a',
connectionGeneration: 3
})
).toBe(false)
expect(
isAdmissibleDirectSshAuthority({
targetId: 'ssh-a',
providerEpoch: 'x'.repeat(SSH_PROVIDER_EPOCH_MAX_UTF8_BYTES + 1),
connectionGeneration: 3
})
).toBe(false)
})
it('normalizes only partial authority for bounded reconciliation', () => {
const state = {
targetId: 'ssh-a',
status: 'connected',
error: null,
reconnectAttempt: 0
}
expect(
admitSshConnectionStateForAuthorityReconciliation(
{ ...state, providerEpoch: 'provider-a' },
'ssh-a'
)
).toEqual({ ...state, providerEpoch: null })
expect(
admitSshConnectionStateForAuthorityReconciliation(
{ ...state, providerEpoch: '', connectionGeneration: 3 },
'ssh-a'
)
).toBeNull()
})
it('normalizes legacy authority to unknown', () => {
expect(
admitSshConnectionState(
{
targetId: 'ssh-a',
status: 'disconnected',
error: null,
reconnectAttempt: 0
},
'ssh-a'
)
).toEqual({
targetId: 'ssh-a',
status: 'disconnected',
error: null,
reconnectAttempt: 0,
providerEpoch: null
})
})
it('caps connection errors without splitting a UTF-8 code point', () => {
const admitted = admitSshConnectionState(
{
targetId: 'ssh-a',
status: 'error',
error: `${'x'.repeat(SSH_CONNECTION_ERROR_MAX_UTF8_BYTES - 1)}🙂tail`,
reconnectAttempt: 0
},
'ssh-a'
)
expect(admitted).not.toBeNull()
expect(getUtf8ByteLength(admitted?.error ?? '')).toBeLessThanOrEqual(
SSH_CONNECTION_ERROR_MAX_UTF8_BYTES
)
expect(admitted?.error?.endsWith('\ud83d')).toBe(false)
})
it('rejects mismatched and oversized target identifiers', () => {
const state = {
targetId: 'ssh-a',
status: 'connected',
error: null,
reconnectAttempt: 0
}
expect(admitSshConnectionState(state, 'ssh-b')).toBeNull()
expect(
admitSshConnectionState(
{ ...state, targetId: 'x'.repeat(SSH_RETAINED_IDENTIFIER_MAX_UTF8_BYTES + 1) },
'x'.repeat(SSH_RETAINED_IDENTIFIER_MAX_UTF8_BYTES + 1)
)
).toBeNull()
})
it('caps port rows and their retained strings', () => {
const rows = Array.from({ length: SSH_DETECTED_PORTS_MAX_ENTRIES + 10 }, (_, index) => ({
port: 1000 + index,
host: '127.0.0.1',
pid: index + 1,
processName: '🙂'.repeat(SSH_DETECTED_PORT_PROCESS_NAME_MAX_UTF8_BYTES),
advertisedUrl: `https://example.test/${'x'.repeat(
SSH_DETECTED_PORT_ADVERTISED_URL_MAX_UTF8_BYTES
)}`,
unexpected: 'retained only without admission'
}))
const admitted = admitSshDetectedPorts(rows)
expect(admitted).toHaveLength(SSH_DETECTED_PORTS_MAX_ENTRIES)
expect(getUtf8ByteLength(admitted[0].processName ?? '')).toBeLessThanOrEqual(
SSH_DETECTED_PORT_PROCESS_NAME_MAX_UTF8_BYTES
)
expect(admitted[0].advertisedUrl).toBeUndefined()
expect(admitted[0]).not.toHaveProperty('unexpected')
})
it('drops malformed rows instead of retaining their payloads', () => {
expect(
admitSshDetectedPorts([
{ port: 0, host: '127.0.0.1' },
{ port: 3000, host: '' },
{ port: 3001, host: '127.0.0.1', processName: 'node' }
])
).toEqual([{ port: 3001, host: '127.0.0.1', processName: 'node' }])
})
})