test(companion): cover pending event wait count lifecycle

This commit is contained in:
William Valentin
2026-02-16 20:53:27 -08:00
parent 21a57c88b9
commit 7e556c5815
3 changed files with 34 additions and 0 deletions
+12
View File
@@ -873,6 +873,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-pending-event-wait-count-lifecycle-coverage": {
"status": "completed",
"date": "2026-02-17",
"updated": "2026-02-17",
"summary": "Added lifecycle coverage for `pendingEventWaitCount` across runtime and platform wait flows, including `waitForAnyEvent()` increment/decrement and clear-subscription rejection teardown.",
"files_modified": [
"src/companion/runtimeClient.test.ts",
"src/companion/platformClients.integration.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",
@@ -131,6 +131,25 @@ describe('platform clients integration', () => {
expect(client.eventSubscriptionCount).toBe(0); expect(client.eventSubscriptionCount).toBe(0);
}); });
it('platform pendingEventWaitCount tracks waitForAnyEvent lifecycle', async () => {
if (!LISTEN_ALLOWED) {
return;
}
const runtime = createRuntime();
const client = new IOSCompanionClient({ runtime, nodeId: 'ios-wait-count-e2e' });
expect(client.pendingEventWaitCount).toBe(0);
const awaited = expect(
client.waitForAnyEvent(['agent.stream'], { timeoutMs: 10_000 }),
).rejects.toThrow('Event subscriptions cleared');
expect(client.pendingEventWaitCount).toBe(1);
client.clearEventSubscriptions();
await awaited;
expect(client.pendingEventWaitCount).toBe(0);
});
it('platform connected reflects runtime connection lifecycle', async () => { it('platform connected reflects runtime connection lifecycle', async () => {
if (!LISTEN_ALLOWED) { if (!LISTEN_ALLOWED) {
return; return;
+3
View File
@@ -528,10 +528,12 @@ describe('CompanionRuntimeClient', () => {
const client = new CompanionRuntimeClient({ const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1', url: 'ws://127.0.0.1:1',
}); });
expect(client.pendingEventWaitCount).toBe(0);
const awaited = client.waitForAnyEvent<{ active?: boolean; token?: string }>( const awaited = client.waitForAnyEvent<{ active?: boolean; token?: string }>(
['agent.typing', 'agent.stream'], ['agent.typing', 'agent.stream'],
{ timeoutMs: 2000 }, { timeoutMs: 2000 },
); );
expect(client.pendingEventWaitCount).toBe(1);
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage( (client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
JSON.stringify({ JSON.stringify({
@@ -545,6 +547,7 @@ describe('CompanionRuntimeClient', () => {
event: 'agent.typing', event: 'agent.typing',
data: { active: true }, data: { active: true },
}); });
expect(client.pendingEventWaitCount).toBe(0);
}); });
it('waitForAnyEvent supports per-event predicate filtering', async () => { it('waitForAnyEvent supports per-event predicate filtering', async () => {