(
port: number,
body: string,
token?: string
)
| 3 | import { startOpencodeHookServer } from './startOpencodeHookServer' |
| 4 | |
| 5 | const sendHookRequest = async ( |
| 6 | port: number, |
| 7 | body: string, |
| 8 | token?: string |
| 9 | ): Promise<{ statusCode?: number; body: string }> => { |
| 10 | return await new Promise((resolve, reject) => { |
| 11 | const headers: Record<string, string | number> = { |
| 12 | 'Content-Type': 'application/json', |
| 13 | 'Content-Length': Buffer.byteLength(body) |
| 14 | } |
| 15 | if (token) { |
| 16 | headers['x-hapi-hook-token'] = token |
| 17 | } |
| 18 | |
| 19 | const req = request({ |
| 20 | host: '127.0.0.1', |
| 21 | port, |
| 22 | path: '/hook/opencode', |
| 23 | method: 'POST', |
| 24 | headers |
| 25 | }, (res) => { |
| 26 | const chunks: Buffer[] = [] |
| 27 | res.on('data', (chunk) => chunks.push(chunk as Buffer)) |
| 28 | res.on('error', reject) |
| 29 | res.on('end', () => { |
| 30 | resolve({ |
| 31 | statusCode: res.statusCode, |
| 32 | body: Buffer.concat(chunks).toString('utf-8') |
| 33 | }) |
| 34 | }) |
| 35 | }) |
| 36 | |
| 37 | req.on('error', reject) |
| 38 | req.end(body) |
| 39 | }) |
| 40 | } |
| 41 | |
| 42 | describe('startOpencodeHookServer', () => { |
| 43 | it('forwards hook payload to callback', async () => { |
no test coverage detected