feat(companion): add pending work snapshot helper

This commit is contained in:
William Valentin
2026-02-16 21:57:34 -08:00
parent c5bc2c1754
commit b4cef5235e
7 changed files with 95 additions and 2 deletions
+27
View File
@@ -643,6 +643,33 @@ describe('CompanionRuntimeClient', () => {
expect(client.hasPendingWork).toBe(false);
});
it('returns pending work snapshot', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
expect(client.getPendingWorkSnapshot()).toEqual({
pendingRequestCount: 0,
pendingEventWaitCount: 0,
hasPendingWork: false,
});
const pendingWait = client.waitForEvent('agent.stream', { timeoutMs: 10_000 }).catch(() => undefined);
expect(client.getPendingWorkSnapshot()).toEqual({
pendingRequestCount: 0,
pendingEventWaitCount: 1,
hasPendingWork: true,
});
client.clearEventSubscriptions();
await pendingWait;
expect(client.getPendingWorkSnapshot()).toEqual({
pendingRequestCount: 0,
pendingEventWaitCount: 0,
hasPendingWork: false,
});
});
it('waitForIdle resolves immediately when no work is pending', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',