feat(companion): add platform stream passthrough helpers
This commit is contained in:
@@ -25,6 +25,8 @@ function createRuntimeMock(): {
|
||||
listCanvasArtifacts: ReturnType<typeof vi.fn>;
|
||||
deleteCanvasArtifact: ReturnType<typeof vi.fn>;
|
||||
clearCanvasArtifacts: ReturnType<typeof vi.fn>;
|
||||
subscribeAgentStream: ReturnType<typeof vi.fn>;
|
||||
waitForAgentStream: ReturnType<typeof vi.fn>;
|
||||
} {
|
||||
const connect = vi.fn(async () => undefined);
|
||||
const disconnect = vi.fn(() => undefined);
|
||||
@@ -50,6 +52,8 @@ function createRuntimeMock(): {
|
||||
const listCanvasArtifacts = vi.fn(async () => ({ artifacts: [{ id: 'a1' }] }));
|
||||
const deleteCanvasArtifact = vi.fn(async () => ({ deleted: true }));
|
||||
const clearCanvasArtifacts = vi.fn(async () => ({ cleared: 1 }));
|
||||
const subscribeAgentStream = vi.fn(() => () => undefined);
|
||||
const waitForAgentStream = vi.fn(async () => ({ token: 'streamed' }));
|
||||
|
||||
const runtime = {
|
||||
connect,
|
||||
@@ -69,6 +73,8 @@ function createRuntimeMock(): {
|
||||
listCanvasArtifacts,
|
||||
deleteCanvasArtifact,
|
||||
clearCanvasArtifacts,
|
||||
subscribeAgentStream,
|
||||
waitForAgentStream,
|
||||
} as unknown as CompanionRuntimeClient;
|
||||
|
||||
return {
|
||||
@@ -90,6 +96,8 @@ function createRuntimeMock(): {
|
||||
listCanvasArtifacts,
|
||||
deleteCanvasArtifact,
|
||||
clearCanvasArtifacts,
|
||||
subscribeAgentStream,
|
||||
waitForAgentStream,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -150,6 +158,20 @@ describe('platform companion clients', () => {
|
||||
expect(mock.dispose).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('platform stream helper methods forward to runtime client', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new AndroidCompanionClient({ runtime: mock.runtime, nodeId: 'android-node' });
|
||||
const streamHandler = vi.fn();
|
||||
|
||||
const unsubscribe = client.subscribeAgentStream(streamHandler);
|
||||
const awaited = await client.waitForAgentStream<{ token: string }>({ timeoutMs: 500 });
|
||||
|
||||
expect(mock.subscribeAgentStream).toHaveBeenCalledWith(streamHandler);
|
||||
expect(mock.waitForAgentStream).toHaveBeenCalledWith({ timeoutMs: 500 });
|
||||
expect(awaited).toEqual({ token: 'streamed' });
|
||||
unsubscribe();
|
||||
});
|
||||
|
||||
it('macOS client forwards canvas methods to runtime client', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new MacOSCompanionClient({ runtime: mock.runtime, nodeId: 'mac-node' });
|
||||
|
||||
Reference in New Issue
Block a user