fix(companion): validate waitForIdle timeout option
This commit is contained in:
@@ -938,6 +938,18 @@
|
|||||||
],
|
],
|
||||||
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
|
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
|
||||||
},
|
},
|
||||||
|
"companion-runtime-wait-for-idle-timeout-validation": {
|
||||||
|
"status": "completed",
|
||||||
|
"date": "2026-02-17",
|
||||||
|
"updated": "2026-02-17",
|
||||||
|
"summary": "Added `waitForIdle()` timeout validation guardrails (`timeoutMs > 0`) with regression tests for deterministic option validation behavior.",
|
||||||
|
"files_modified": [
|
||||||
|
"src/companion/runtimeClient.ts",
|
||||||
|
"src/companion/runtimeClient.test.ts",
|
||||||
|
"docs/plans/state.json"
|
||||||
|
],
|
||||||
|
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
|
||||||
|
},
|
||||||
"browser-tools-activation-clarity": {
|
"browser-tools-activation-clarity": {
|
||||||
"status": "completed",
|
"status": "completed",
|
||||||
"date": "2026-02-17",
|
"date": "2026-02-17",
|
||||||
|
|||||||
@@ -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 () => {
|
it('waitForIdle resolves after pending event waiters are cleared', async () => {
|
||||||
const client = new CompanionRuntimeClient({
|
const client = new CompanionRuntimeClient({
|
||||||
url: 'ws://127.0.0.1:1',
|
url: 'ws://127.0.0.1:1',
|
||||||
|
|||||||
@@ -614,6 +614,10 @@ export class CompanionRuntimeClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
waitForIdle(options?: WaitForIdleOptions): Promise<void> {
|
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;
|
const pollIntervalMs = options?.pollIntervalMs ?? 25;
|
||||||
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs <= 0) {
|
if (!Number.isFinite(pollIntervalMs) || pollIntervalMs <= 0) {
|
||||||
throw new Error('pollIntervalMs must be a positive number');
|
throw new Error('pollIntervalMs must be a positive number');
|
||||||
@@ -621,7 +625,6 @@ export class CompanionRuntimeClient {
|
|||||||
if (!this.hasPendingWork) {
|
if (!this.hasPendingWork) {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
const timeoutMs = options?.timeoutMs ?? this.requestTimeoutMs;
|
|
||||||
const signal = options?.signal;
|
const signal = options?.signal;
|
||||||
|
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user