feat(companion): add cancellable pending event wait helper
This commit is contained in:
@@ -389,6 +389,29 @@ describe('CompanionRuntimeClient', () => {
|
||||
await awaited;
|
||||
});
|
||||
|
||||
it('cancelPendingEventWaits rejects waiters without clearing subscriptions', async () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
});
|
||||
const handler = vi.fn();
|
||||
client.subscribeEvents(handler);
|
||||
|
||||
const awaited = expect(
|
||||
client.waitForEvent('agent.stream', { timeoutMs: 10_000 }),
|
||||
).rejects.toThrow('manually cancelled');
|
||||
client.cancelPendingEventWaits('manually cancelled');
|
||||
await awaited;
|
||||
|
||||
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
|
||||
JSON.stringify({
|
||||
id: 99,
|
||||
event: 'agent.stream',
|
||||
data: { token: 'still-subscribed' },
|
||||
}),
|
||||
);
|
||||
expect(handler).toHaveBeenCalledWith('agent.stream', { token: 'still-subscribed' });
|
||||
});
|
||||
|
||||
it('waitForEvent rejects immediately on disconnect', async () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
|
||||
Reference in New Issue
Block a user