feat(companion): expose pending request observability

This commit is contained in:
William Valentin
2026-02-16 20:51:57 -08:00
parent 5277fed220
commit df86fbd08e
6 changed files with 84 additions and 1 deletions
+38
View File
@@ -593,6 +593,44 @@ describe('CompanionRuntimeClient', () => {
);
});
it('tracks pendingRequestCount for in-flight RPCs', 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();
expect(client.pendingRequestCount).toBe(0);
const pending = client.call('system.capabilities');
expect(client.pendingRequestCount).toBe(1);
client.disconnect();
await expect(pending).rejects.toThrow('Disconnected');
expect(client.pendingRequestCount).toBe(0);
});
it('connects and performs node registration + capability discovery', async () => {
if (!LISTEN_ALLOWED) {
return;