Files
deepseek-harness/packages/ptc-runtime/ptc-runtime-node/tests/raw-peer.ts
T
_Kerman 427d62d4a7 fix(ptc-runtime-node): fail fast on mismatched bootstraps and late replies
- Reject a control line that does not start with "{", so another
  release's length-prefixed frame fails as a protocol error instead of
  waiting for a newline until the deadline.
- Bump SSH_PROTOCOL_VERSION to 3: executable helpers embed the PTC
  worker, so an older helper is now rejected while connecting.
- Send a small error instead of a late binding result from a finished
  persistent evaluation, so it cannot overflow the pipe shared with
  the next evaluation.
- Leave per-call binding waits pending after the result instead of
  rejecting them; unawaited calls crashed the child and leaked the
  trace into the result logs.
- Pin birpc to 4.2.0 so the host and the bundled child agree, and
  regenerate THIRD_PARTY_NOTICES.md.
- Update stale frame wording.
2026-10-20 16:06:50 +08:00

23 lines
1014 B
TypeScript

/** Raw newline JSON peer for testing hostile RPC traffic without birpc validation. */
import { createInterface } from 'node:readline'
import type { Duplex } from 'node:stream'
/**
* Observe and forge JSON messages over a test-owned stream.
* @param stream - Test endpoint.
* @param receive - Raw JSON message observer.
* @returns Write receipts and endpoint cleanup.
*/
export function rawPeer(stream: Duplex, receive: (message: unknown) => void) {
const lines = createInterface({ input: stream, crlfDelay: Infinity })
lines.on('line', (line) => { receive(JSON.parse(line)) })
// The endpoint under test can destroy the shared stream pair; it reports that failure itself.
lines.on('error', (error: Error) => { void error })
return {
send: (message: unknown): Promise<void> => new Promise((resolve, reject) => {
stream.write(`${JSON.stringify(message)}\n`, (error) => { if (error) reject(error); else resolve() })
}),
close: (): void => { lines.close(); stream.destroy() },
}
}