feat(companion): add typed wait helpers for stream events

This commit is contained in:
William Valentin
2026-02-16 19:11:10 -08:00
parent 1b69970065
commit 43968f830a
4 changed files with 64 additions and 1 deletions
+34
View File
@@ -321,6 +321,40 @@ describe('CompanionRuntimeClient', () => {
await awaited;
});
it('waitForAgentStream resolves on agent.stream events', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const awaited = client.waitForAgentStream<{ token: string }>({ timeoutMs: 2000 });
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
JSON.stringify({
id: 54,
event: 'agent.stream',
data: { token: 'typed-stream' },
}),
);
await expect(awaited).resolves.toEqual({ token: 'typed-stream' });
});
it('waitForAgentTyping resolves on agent.typing events', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
});
const awaited = client.waitForAgentTyping<{ active: boolean }>({ timeoutMs: 2000 });
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
JSON.stringify({
id: 55,
event: 'agent.typing',
data: { active: true },
}),
);
await expect(awaited).resolves.toEqual({ active: true });
});
it('connects and performs node registration + capability discovery', async () => {
if (!LISTEN_ALLOWED) {
return;