test(companion): cover waitForIdle pending RPC lifecycle
This commit is contained in:
@@ -990,6 +990,17 @@
|
|||||||
],
|
],
|
||||||
"test_status": "pnpm test:run src/companion/platformClients.integration.test.ts src/companion/platformClients.test.ts src/companion/runtimeClient.test.ts src/companion/heartbeatLoop.test.ts + pnpm typecheck passing"
|
"test_status": "pnpm test:run src/companion/platformClients.integration.test.ts src/companion/platformClients.test.ts src/companion/runtimeClient.test.ts src/companion/heartbeatLoop.test.ts + pnpm typecheck passing"
|
||||||
},
|
},
|
||||||
|
"companion-runtime-wait-for-idle-pending-rpc-coverage": {
|
||||||
|
"status": "completed",
|
||||||
|
"date": "2026-02-17",
|
||||||
|
"updated": "2026-02-17",
|
||||||
|
"summary": "Added runtime regression coverage for `waitForIdle()` pending-RPC behavior, verifying idle resolution after pending requests are rejected on teardown.",
|
||||||
|
"files_modified": [
|
||||||
|
"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",
|
||||||
|
|||||||
@@ -730,6 +730,49 @@ describe('CompanionRuntimeClient', () => {
|
|||||||
await pendingWait;
|
await pendingWait;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('waitForIdle resolves after pending RPC requests are rejected', async () => {
|
||||||
|
class FakeWebSocket extends EventEmitter {
|
||||||
|
readyState: number = WebSocket.CONNECTING;
|
||||||
|
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
queueMicrotask(() => {
|
||||||
|
this.readyState = WebSocket.OPEN;
|
||||||
|
this.emit('open');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
send(_payload: string, callback?: (error?: Error) => void): void {
|
||||||
|
callback?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
close(_code?: number, _reason?: string): void {
|
||||||
|
this.readyState = WebSocket.CLOSED;
|
||||||
|
this.emit('close');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new CompanionRuntimeClient({
|
||||||
|
url: 'ws://127.0.0.1:1',
|
||||||
|
websocketFactory: () => new FakeWebSocket() as unknown as WebSocket,
|
||||||
|
requestTimeoutMs: 10_000,
|
||||||
|
});
|
||||||
|
await client.connect();
|
||||||
|
|
||||||
|
const pendingCall = client.call('system.capabilities').catch(() => undefined);
|
||||||
|
expect(client.pendingRequestCount).toBe(1);
|
||||||
|
|
||||||
|
const idle = client.waitForIdle({ timeoutMs: 1_000, pollIntervalMs: 5 });
|
||||||
|
setTimeout(() => {
|
||||||
|
client.disconnect();
|
||||||
|
}, 20);
|
||||||
|
|
||||||
|
await expect(idle).resolves.toBeUndefined();
|
||||||
|
await pendingCall;
|
||||||
|
expect(client.pendingRequestCount).toBe(0);
|
||||||
|
expect(client.hasPendingWork).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
it('waitForIdle supports AbortSignal cancellation', async () => {
|
it('waitForIdle supports AbortSignal cancellation', async () => {
|
||||||
const client = new CompanionRuntimeClient({
|
const client = new CompanionRuntimeClient({
|
||||||
url: 'ws://127.0.0.1:1',
|
url: 'ws://127.0.0.1:1',
|
||||||
|
|||||||
Reference in New Issue
Block a user