fix(onebot): await malformed stream responses
Wait for asynchronous transports to flush bad-request frames before processStreamRequest returns. This prevents malformed Stream API requests from losing their terminal error response.
This commit is contained in:
2 files changed
+23
-5
No files matched your search
@@ -164,4 +164,20 @@ describe('Stream API plumbing', () => {
|
||||
expect(frames).toHaveLength(3);
|
||||
for (const f of parse(frames)) expect(f).toMatchObject({ status: 'failed' });
|
||||
});
|
||||
|
||||
it('waits for an async bad-request frame to flush', async () => {
|
||||
const h = newHandler();
|
||||
let release!: () => void;
|
||||
const flushed = new Promise<void>((resolve) => { release = resolve; });
|
||||
let completed = false;
|
||||
|
||||
const request = h.processStreamRequest('', async () => flushed);
|
||||
void request.then(() => { completed = true; });
|
||||
await Promise.resolve();
|
||||
expect(completed).toBe(false);
|
||||
|
||||
release();
|
||||
await request;
|
||||
expect(completed).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user