Files
orca/src/shared/agent-hook-request-body-memory.test.ts
T
NeilandOrca 879aad7dd6 oom(foundation): bound shared readers/limits + add BoundedMap primitive (#10299)
* oom(01): A1-shared-readers — reintroduce #10179 subset

Files: 18 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(02): A2-shared-image-media — reintroduce #10179 subset

Files: 7 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(03): A3-shared-fs-listing — reintroduce #10179 subset

Files: 21 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(04): A4-shared-remote-relay — reintroduce #10179 subset

Files: 8 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(05): A5-shared-misc — reintroduce #10179 subset

Files: 28 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

* oom(06): B-shared-wiring — reintroduce #10179 subset

Files: 81 applied, 0 deleted (from 6eb70d8370)

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-07-24 21:36:57 -07:00

33 lines
1.1 KiB
TypeScript

import { EventEmitter } from 'node:events'
import type { IncomingHttpHeaders, IncomingMessage } from 'node:http'
import { describe, expect, it, vi } from 'vitest'
import { readRequestBody } from './agent-hook-listener'
type FakeIncomingMessage = EventEmitter & {
headers: IncomingHttpHeaders
destroy: ReturnType<typeof vi.fn>
}
function createReadableRequest(): FakeIncomingMessage {
const request = new EventEmitter() as FakeIncomingMessage
request.headers = { 'content-type': 'application/json' }
request.destroy = vi.fn(() => request.emit('close'))
return request
}
describe('agent hook request body retention', () => {
it('accepts adversarial one-byte events without per-event retained buffers', async () => {
const request = createReadableRequest()
const reading = readRequestBody(request as unknown as IncomingMessage)
const value = 'x'.repeat(100_000)
const body = Buffer.from(JSON.stringify({ value }))
for (let index = 0; index < body.length; index += 1) {
request.emit('data', body.subarray(index, index + 1))
}
request.emit('end')
await expect(reading).resolves.toEqual({ value })
})
})