fix(companion): validate event wait timeout options

This commit is contained in:
William Valentin
2026-02-16 22:17:14 -08:00
parent 45ea084cf0
commit c41332a643
4 changed files with 26 additions and 1 deletions
+6
View File
@@ -359,6 +359,9 @@ describe('CompanionRuntimeClient', () => {
expect(() => client.waitForEvent(123 as unknown as string)).toThrow(
'eventName must be a non-empty string',
);
expect(() => client.waitForEvent('agent.stream', { timeoutMs: 0 })).toThrow(
'timeoutMs must be a positive number',
);
});
it('waitForEvent supports AbortSignal cancellation', async () => {
@@ -600,6 +603,9 @@ describe('CompanionRuntimeClient', () => {
expect(() => client.waitForAnyEvent(['agent.stream', 123 as unknown as string])).toThrow(
'eventNames must not contain empty values',
);
expect(() => client.waitForAnyEvent(['agent.stream'], { timeoutMs: 0 })).toThrow(
'timeoutMs must be a positive number',
);
});
it('tracks pendingRequestCount for in-flight RPCs', async () => {
+6
View File
@@ -477,6 +477,9 @@ export class CompanionRuntimeClient {
throw new Error('eventName must be a non-empty string');
}
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
throw new Error('timeoutMs must be a positive number');
}
const predicate = options?.predicate;
const signal = options?.signal;
@@ -550,6 +553,9 @@ export class CompanionRuntimeClient {
}
const eventNameSet = new Set(eventNames);
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
throw new Error('timeoutMs must be a positive number');
}
const predicate = options?.predicate;
const signal = options?.signal;