feat(companion): add filtered runtime event subscription helper
This commit is contained in:
@@ -151,6 +151,42 @@ describe('CompanionRuntimeClient', () => {
|
||||
expect(goodHandler).toHaveBeenCalledWith('agent.stream', { token: 'safe' });
|
||||
});
|
||||
|
||||
it('supports filtered subscribeEvent helper', () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
});
|
||||
const streamHandler = vi.fn();
|
||||
const unsubscribe = client.subscribeEvent<{ token: string }>('agent.stream', streamHandler);
|
||||
|
||||
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
|
||||
JSON.stringify({
|
||||
id: 45,
|
||||
event: 'agent.stream',
|
||||
data: { token: 'first' },
|
||||
}),
|
||||
);
|
||||
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
|
||||
JSON.stringify({
|
||||
id: 46,
|
||||
event: 'agent.typing',
|
||||
data: { active: true },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(streamHandler).toHaveBeenCalledTimes(1);
|
||||
expect(streamHandler).toHaveBeenCalledWith({ token: 'first' });
|
||||
|
||||
unsubscribe();
|
||||
(client as unknown as { handleMessage: (raw: string) => void }).handleMessage(
|
||||
JSON.stringify({
|
||||
id: 47,
|
||||
event: 'agent.stream',
|
||||
data: { token: 'second' },
|
||||
}),
|
||||
);
|
||||
expect(streamHandler).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('connects and performs node registration + capability discovery', async () => {
|
||||
if (!LISTEN_ALLOWED) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user