| 32 | } |
| 33 | |
| 34 | function fakeRes() { |
| 35 | const listeners = new Map(); |
| 36 | return { |
| 37 | body: '', |
| 38 | writableEnded: false, |
| 39 | write(chunk) { this.body += String(chunk); return true; }, |
| 40 | end(chunk) { |
| 41 | if (chunk) this.write(chunk); |
| 42 | this.writableEnded = true; |
| 43 | for (const cb of listeners.get('close') || []) cb(); |
| 44 | }, |
| 45 | on(event, cb) { |
| 46 | if (!listeners.has(event)) listeners.set(event, []); |
| 47 | listeners.get(event).push(cb); |
| 48 | return this; |
| 49 | }, |
| 50 | }; |
| 51 | } |
| 52 | |
| 53 | describe('stream error protocol', () => { |
| 54 | it('creates OpenAI-style structured stream errors', () => { |