fix(companion): reject pending event waits on teardown

This commit is contained in:
William Valentin
2026-02-16 19:26:04 -08:00
parent a76e3e03dc
commit f7c6947d22
4 changed files with 56 additions and 2 deletions
+24
View File
@@ -339,6 +339,30 @@ describe('CompanionRuntimeClient', () => {
await awaited;
});
it('waitForEvent rejects immediately when event subscriptions are cleared', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const awaited = expect(
client.waitForEvent('agent.stream', { timeoutMs: 10_000 }),
).rejects.toThrow('Event subscriptions cleared');
client.clearEventSubscriptions();
await awaited;
});
it('waitForEvent rejects immediately on disconnect', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const awaited = expect(
client.waitForEvent('agent.stream', { timeoutMs: 10_000 }),
).rejects.toThrow('Disconnected');
client.disconnect();
await awaited;
});
it('waitForAgentStream resolves on agent.stream events', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',