mirror of
https://github.com/stablyai/orca.git
synced 2026-10-30 08:37:49 +00:00
* Revert "feat(orcad): source-side dormant export of a relay-hosted SSH target (#16741 T6-8) (#24519)" This reverts commit783101b304. * Revert "feat(ssh): update, roll back, recover and stop a managed orcad server (#16741 T6-5 follow-up) (#24463)" This reverts commit38c2d1dcb9. * Revert "feat(ssh): deploy and pair an empty managed orcad server over SSH (#16741 T6-5) (#24453)" This reverts commit8b76683b40. * Revert "fix(ssh): orcad GC honors the activation journal; readiness requires proven daemon coverage (#16741 T6 follow-up) (#24451)" This reverts commitd3f8c5063b. * Revert "feat(ssh): remote orcad stop by request file and journaled decommission (#16741 T6-4) (#24449)" This reverts commit43d9b43d3f. * Revert "feat(orcad): supervisable server: stop requests, managed stop receipts and a lifetime that keeps its lock on failed teardown (#16741 T6-3) (#24433)" This reverts commitb093d3ab20. * Revert "feat(ssh): crash-safe orcad activation, rollback and recovery (#16741 T6-2) (#24423)" This reverts commit1a9ac0e955. * Revert "feat(runtime): SSH access links for paired servers in a downgrade-safe sidecar (#16741 T5-1+T5-2) (#24420)" This reverts commit99db2bfae4. * Revert "feat(relay): capability-gated owner reset with a durable preparation journal (#16741 T3 R1) (#24418)" This reverts commit34a582bd39. * Revert "feat(ssh): track connection-manager drains, test probes and provider continuations (#16741 T2 P3+P8a) (#24407)" This reverts commitd53063d2b1. * Revert "feat(daemon): idle retirement, session census and recovery-only provider (#16741 T2 P4b) (#24409)" This reverts commitff212dbbef. * Revert "feat(ssh): add pty.resumeClient and split SSH PTY process listing (#16741 T2 P5+P6) (#24414)" This reverts commit92cb71765e. * Revert "feat(relay): await owned watcher and agent children on shutdown (#16741 T2 P1) (#24400)" This reverts commit6b36e4f85b. * Revert "feat(session): retry failed renderer session writes and verify local folder PTYs (#16741 T2 P9) (#24406)" This reverts commitd23ecef301. * Revert "feat(ssh): remote orcad primitives on the pinned Node runtime (#16741 T6-1) (#24419)" This reverts commitdd87ae578d. * Revert "fix(runtime): fence runtime-environment subscriptions and status probes by identity (#16741 T5-3) (#24421)" This reverts commitece9e4d2e3. * Revert "feat(orcad): migration manifest and dormant-state contracts (#16741 T6-7) (#24422)" This reverts commit3fbdaba262. * Revert "feat(ssh): wire SshConnection through the work and transport close ledgers (#16741 T2 P2) (#24401)" This reverts commit4e8edc8872. * Revert "feat(profiles): carry markdown frontmatter visibility in project transfers (#16741 T2 P7) (#24405)" This reverts commit60c93263cc. * Revert "fix(runtime): project the PTY incarnation onto mobile session tabs (#24413)" This reverts commit99e0303572. * Revert "feat(daemon): tag daemon stream data with the PTY incarnation id (#16741 T2 P4a) (#24402)" This reverts commit817af768b0. * Revert "feat(ssh): port the SSH connection work ledger and transport close ledger (#16741 T2) (#24210)" This reverts commitc9918931c8. * Revert "feat(relay): fence and drain file and git response streams on shutdown (#24185)" This reverts commitdc08ffeba9. * Revert "refactor(runtime-rpc): extract the Node WebSocket lifecycle; opt-in pinned port (#24186)" This reverts commita789233bbb. * Revert "feat(relay): route relay handlers through work admission; producer publication drain (#24181)" This reverts commit0b812bd698. * Revert "feat(relay): land the #16741 T1 seam (work drain, publication drain, release gate) (#24156)" This reverts commit3aa2d3af7c. --------- Co-authored-by: m4air <m4air@Mac.localdomain>
174 lines
5.9 KiB
TypeScript
174 lines
5.9 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import type { Socket } from 'node:net'
|
|
import {
|
|
encodeStreamDataEvent,
|
|
splitStreamDataForNdjson,
|
|
writeStreamDataEvents
|
|
} from './daemon-stream-data-split'
|
|
import { encodeNdjson } from './ndjson'
|
|
|
|
vi.mock('./ndjson', async (importOriginal) => {
|
|
const actual = await importOriginal<{ encodeNdjson: typeof encodeNdjson }>()
|
|
return { ...actual, encodeNdjson: vi.fn(actual.encodeNdjson) }
|
|
})
|
|
|
|
function write(
|
|
data: string,
|
|
maxLineBytes: number,
|
|
rawLength = data.length,
|
|
seq?: number,
|
|
transformed = false,
|
|
sessionId = 'session-1'
|
|
): string[] {
|
|
const lines: string[] = []
|
|
const socket: Pick<Socket, 'write'> = {
|
|
write: vi.fn((line: string) => {
|
|
lines.push(line)
|
|
return true
|
|
})
|
|
}
|
|
writeStreamDataEvents(socket, sessionId, data, maxLineBytes, rawLength, seq, transformed)
|
|
return lines
|
|
}
|
|
|
|
// Preserve the pre-optimization writer as a byte-for-byte oracle.
|
|
function previousWrites(
|
|
data: string,
|
|
maxLineBytes: number,
|
|
rawLength = data.length,
|
|
seq?: number,
|
|
transformed = false,
|
|
sessionId = 'session-1'
|
|
): string[] {
|
|
const explicitRawLength = rawLength === data.length ? undefined : rawLength
|
|
if (transformed) {
|
|
return [encodeStreamDataEvent(sessionId, data, rawLength, seq, true)]
|
|
}
|
|
const carriesMetadata = explicitRawLength !== undefined || seq !== undefined
|
|
const chunks = splitStreamDataForNdjson(
|
|
sessionId,
|
|
data,
|
|
carriesMetadata ? Math.max(1, maxLineBytes - 96) : maxLineBytes,
|
|
explicitRawLength
|
|
)
|
|
let consumed = 0
|
|
return chunks.map((chunk) => {
|
|
consumed += chunk.length
|
|
const chunkEndSeq = seq === undefined ? undefined : seq - (data.length - consumed)
|
|
const chunkRawLength = explicitRawLength === 0 ? 0 : carriesMetadata ? chunk.length : undefined
|
|
return encodeStreamDataEvent(sessionId, chunk, chunkRawLength, chunkEndSeq)
|
|
})
|
|
}
|
|
|
|
beforeEach(() => {
|
|
vi.mocked(encodeNdjson).mockClear()
|
|
})
|
|
|
|
describe('writeStreamDataEvents serialization budget', () => {
|
|
it.each(['', 'x', '\x1b[2K\rredraw', '"\\\n\t\u0000', 'é中🐙', '\ud800x\udc00'])(
|
|
'encodes an unsplit metadata-free frame once: %j',
|
|
(data) => {
|
|
const expected = previousWrites(data, 4096)
|
|
expect(encodeNdjson).toHaveBeenCalledTimes(2)
|
|
vi.mocked(encodeNdjson).mockClear()
|
|
expect(write(data, 4096)).toEqual(expected)
|
|
expect(encodeNdjson).toHaveBeenCalledTimes(1)
|
|
}
|
|
)
|
|
|
|
it('reuses the encoded frame exactly at the inclusive byte cap', () => {
|
|
const data = 'é🐙\x1b[0m'
|
|
const line = encodeStreamDataEvent('session-1', data)
|
|
vi.mocked(encodeNdjson).mockClear()
|
|
expect(write(data, Buffer.byteLength(line))).toEqual([line])
|
|
expect(encodeNdjson).toHaveBeenCalledTimes(1)
|
|
})
|
|
|
|
it('does not add a duplicate full-data sizing probe to oversized writes', () => {
|
|
const data = '🐙\x1b[0m'.repeat(100)
|
|
const expected = previousWrites(data, 160)
|
|
const previousCount = vi.mocked(encodeNdjson).mock.calls.length
|
|
vi.mocked(encodeNdjson).mockClear()
|
|
expect(write(data, 160)).toEqual(expected)
|
|
expect(encodeNdjson).toHaveBeenCalledTimes(previousCount)
|
|
})
|
|
|
|
it('keeps transformed writes at one encode without applying the ordinary byte cap', () => {
|
|
const data = '🐙'.repeat(100)
|
|
const lines = write(data, 1, 1234, 5000, true)
|
|
expect(encodeNdjson).toHaveBeenCalledTimes(1)
|
|
expect(lines).toEqual([encodeStreamDataEvent('session-1', data, 1234, 5000, true)])
|
|
})
|
|
})
|
|
|
|
describe('writeStreamDataEvents wire parity', () => {
|
|
it('preserves exact frames, chunk boundaries and metadata across payloads and caps', () => {
|
|
const payloads = [
|
|
'',
|
|
'x',
|
|
'plain output\r\n'.repeat(24),
|
|
'"\\\n\t\u0000'.repeat(40),
|
|
'é中🐙'.repeat(40),
|
|
'\ud800x\udc00🐙'.repeat(20)
|
|
]
|
|
for (const sessionId of ['session-1', 'ssh/"中🐙']) {
|
|
for (const data of payloads) {
|
|
for (const maxLineBytes of [1, 96, 160, 256, 4096]) {
|
|
for (const [rawLength, seq, transformed] of [
|
|
[data.length, undefined, false],
|
|
[data.length, 0, false],
|
|
[data.length, 9000, false],
|
|
[0, 9000, false],
|
|
[7, undefined, false],
|
|
[data.length + 99, 9000, false],
|
|
[1234, 9000, true]
|
|
] as const) {
|
|
const expected = previousWrites(
|
|
data,
|
|
maxLineBytes,
|
|
rawLength,
|
|
seq,
|
|
transformed,
|
|
sessionId
|
|
)
|
|
expect(write(data, maxLineBytes, rawLength, seq, transformed, sessionId)).toEqual(
|
|
expected
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
it('keeps JSON escaping, Unicode and newline framing byte-for-byte', () => {
|
|
expect(write('"\\\n\t\u0000é中🐙', 4096)).toEqual([
|
|
'{"type":"event","event":"data","sessionId":"session-1","payload":{"data":"\\\"\\\\\\n\\t\\u0000é中🐙"}}\n'
|
|
])
|
|
})
|
|
|
|
it('keeps split frames within the byte cap and preserves code points and sequence spans', () => {
|
|
const data = '🐙é中\x1b[0m"\\\n'.repeat(100)
|
|
for (const seq of [undefined, 9000]) {
|
|
const lines = write(data, 256, data.length, seq)
|
|
expect(lines.length).toBeGreaterThan(1)
|
|
let consumed = 0
|
|
const chunks = lines.map((line) => {
|
|
expect(Buffer.byteLength(line, 'utf8')).toBeLessThanOrEqual(256)
|
|
expect(line.endsWith('\n')).toBe(true)
|
|
const { payload } = JSON.parse(line)
|
|
expect(payload.data).not.toMatch(/^[\udc00-\udfff]|[\ud800-\udbff]$/)
|
|
consumed += payload.data.length
|
|
if (seq !== undefined) {
|
|
expect(payload.seq).toBe(seq - data.length + consumed)
|
|
expect(payload.rawLength).toBe(payload.data.length)
|
|
expect(payload.sequenceChars).toBe(payload.data.length)
|
|
} else {
|
|
expect(Object.keys(payload)).toEqual(['data'])
|
|
}
|
|
return payload.data as string
|
|
})
|
|
expect(chunks.join('')).toBe(data)
|
|
}
|
|
})
|
|
})
|