fix(companion): validate waitForIdle timeout option

This commit is contained in:
William Valentin
2026-02-16 20:57:34 -08:00
parent 1a46b122e0
commit 239d9f93ff
3 changed files with 26 additions and 1 deletions
+10
View File
@@ -661,6 +661,16 @@ describe('CompanionRuntimeClient', () => {
);
});
it('waitForIdle validates timeoutMs option', () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
expect(() => client.waitForIdle({ timeoutMs: 0 })).toThrow(
'timeoutMs must be a positive number',
);
});
it('waitForIdle resolves after pending event waiters are cleared', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
+4 -1
View File
@@ -614,6 +614,10 @@ export class CompanionRuntimeClient {
}
waitForIdle(options?: WaitForIdleOptions): Promise<void> {
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
if (!Number.isFinite(timeoutMs) || timeoutMs <= 0) {
throw new Error('timeoutMs must be a positive number');
}
const pollIntervalMs = options?.pollIntervalMs ?? 25;
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs <= 0) {
throw new Error('pollIntervalMs must be a positive number');
@@ -621,7 +625,6 @@ export class CompanionRuntimeClient {
if (!this.hasPendingWork) {
return Promise.resolve();
}
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
const signal = options?.signal;
return new Promise<void>((resolve, reject) => {