feat(companion): add platform single-event passthrough helpers

This commit is contained in:
William Valentin
2026-02-16 19:35:08 -08:00
parent 6a9796066b
commit 78466c7e71
4 changed files with 83 additions and 1 deletions
+15
View File
@@ -29,8 +29,10 @@ function createRuntimeMock(): {
subscribeAgentTyping: ReturnType<typeof vi.fn>;
subscribeContextWarning: ReturnType<typeof vi.fn>;
subscribeEvents: ReturnType<typeof vi.fn>;
subscribeEvent: ReturnType<typeof vi.fn>;
clearEventSubscriptions: ReturnType<typeof vi.fn>;
listKnownEventNames: ReturnType<typeof vi.fn>;
waitForEvent: ReturnType<typeof vi.fn>;
waitForAgentStream: ReturnType<typeof vi.fn>;
waitForAgentTyping: ReturnType<typeof vi.fn>;
waitForContextWarning: ReturnType<typeof vi.fn>;
@@ -65,8 +67,10 @@ function createRuntimeMock(): {
const subscribeAgentTyping = vi.fn(() => () => undefined);
const subscribeContextWarning = vi.fn(() => () => undefined);
const subscribeEvents = vi.fn(() => () => undefined);
const subscribeEvent = vi.fn(() => () => undefined);
const clearEventSubscriptions = vi.fn(() => undefined);
const listKnownEventNames = vi.fn(() => ['agent.stream', 'agent.typing', 'context_warning']);
const waitForEvent = vi.fn(async () => ({ token: 'evented' }));
const waitForAgentStream = vi.fn(async () => ({ token: 'streamed' }));
const waitForAgentTyping = vi.fn(async () => ({ active: true }));
const waitForContextWarning = vi.fn(async () => ({ thresholdPct: 75, estimatedPct: 90 }));
@@ -95,8 +99,10 @@ function createRuntimeMock(): {
subscribeAgentTyping,
subscribeContextWarning,
subscribeEvents,
subscribeEvent,
clearEventSubscriptions,
listKnownEventNames,
waitForEvent,
waitForAgentStream,
waitForAgentTyping,
waitForContextWarning,
@@ -129,8 +135,10 @@ function createRuntimeMock(): {
subscribeAgentTyping,
subscribeContextWarning,
subscribeEvents,
subscribeEvent,
clearEventSubscriptions,
listKnownEventNames,
waitForEvent,
waitForAgentStream,
waitForAgentTyping,
waitForContextWarning,
@@ -203,11 +211,14 @@ describe('platform companion clients', () => {
const typingHandler = vi.fn();
const warningHandler = vi.fn();
const eventHandler = vi.fn();
const streamEventHandler = vi.fn();
const unsubscribeStream = client.subscribeAgentStream(streamHandler);
const unsubscribeTyping = client.subscribeAgentTyping(typingHandler);
const unsubscribeWarning = client.subscribeContextWarning(warningHandler);
const unsubscribeEvents = client.subscribeEvents(eventHandler);
const unsubscribeEvent = client.subscribeEvent('agent.stream', streamEventHandler);
const waitedEvent = await client.waitForEvent<{ token: string }>('agent.stream', { timeoutMs: 500 });
const awaited = await client.waitForAgentStream<{ token: string }>({ timeoutMs: 500 });
const waitedTyping = await client.waitForAgentTyping<{ active: boolean }>({ timeoutMs: 500 });
const waitedWarning = await client.waitForContextWarning<{ thresholdPct: number; estimatedPct: number }>({ timeoutMs: 500 });
@@ -217,10 +228,13 @@ describe('platform companion clients', () => {
expect(mock.subscribeAgentTyping).toHaveBeenCalledWith(typingHandler);
expect(mock.subscribeContextWarning).toHaveBeenCalledWith(warningHandler);
expect(mock.subscribeEvents).toHaveBeenCalledWith(eventHandler);
expect(mock.subscribeEvent).toHaveBeenCalledWith('agent.stream', streamEventHandler);
expect(mock.waitForEvent).toHaveBeenCalledWith('agent.stream', { timeoutMs: 500 });
expect(mock.waitForAgentStream).toHaveBeenCalledWith({ timeoutMs: 500 });
expect(mock.waitForAgentTyping).toHaveBeenCalledWith({ timeoutMs: 500 });
expect(mock.waitForContextWarning).toHaveBeenCalledWith({ timeoutMs: 500 });
expect(mock.waitForAnyEvent).toHaveBeenCalledWith(['agent.stream'], { timeoutMs: 500 });
expect(waitedEvent).toEqual({ token: 'evented' });
expect(awaited).toEqual({ token: 'streamed' });
expect(waitedTyping).toEqual({ active: true });
expect(waitedWarning).toEqual({ thresholdPct: 75, estimatedPct: 90 });
@@ -229,6 +243,7 @@ describe('platform companion clients', () => {
unsubscribeTyping();
unsubscribeWarning();
unsubscribeEvents();
unsubscribeEvent();
});
it('platform clearEventSubscriptions forwards to runtime client', async () => {