feat(companion): add connection snapshot helper

This commit is contained in:
William Valentin
2026-02-16 22:24:16 -08:00
parent 965267d67e
commit c8f6d76638
7 changed files with 107 additions and 2 deletions
+27
View File
@@ -721,6 +721,33 @@ describe('CompanionRuntimeClient', () => {
await pendingWait;
});
it('returns connection snapshot', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const pendingWait = client.waitForEvent('agent.stream', { timeoutMs: 10_000 }).catch(() => undefined);
expect(client.getConnectionSnapshot()).toEqual({
connected: false,
eventSubscriptionCount: 1,
pendingRequestCount: 0,
pendingEventWaitCount: 1,
hasPendingWork: true,
idle: false,
});
client.clearEventSubscriptions();
await pendingWait;
expect(client.getConnectionSnapshot()).toEqual({
connected: false,
eventSubscriptionCount: 0,
pendingRequestCount: 0,
pendingEventWaitCount: 0,
hasPendingWork: false,
idle: true,
});
});
it('waitForIdle resolves immediately when no work is pending', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',