feat(companion): add platform bootstrap helper
This commit is contained in:
@@ -41,4 +41,5 @@ export type {
|
||||
PlatformClientOptions,
|
||||
RegisterPushTokenInput,
|
||||
SharedStatusInput,
|
||||
PlatformBootstrapResult,
|
||||
} from './platformClients.js';
|
||||
|
||||
@@ -118,7 +118,9 @@ describe('platform clients integration', () => {
|
||||
await client.connect();
|
||||
|
||||
try {
|
||||
await client.register();
|
||||
const boot = await client.bootstrap();
|
||||
expect(boot.register.registered).toBe(true);
|
||||
expect(boot.capabilities.node.id).toBe('macos-e2e');
|
||||
const status = await client.setStatus({
|
||||
appVersion: '1.0.0',
|
||||
statusText: 'menu-bar-active',
|
||||
|
||||
@@ -151,4 +151,21 @@ describe('platform companion clients', () => {
|
||||
expect(mock.deleteCanvasArtifact).toHaveBeenCalledWith({ sessionId: 'ws:test-canvas', artifactId: 'a1' });
|
||||
expect(mock.clearCanvasArtifacts).toHaveBeenCalledWith('ws:test-canvas');
|
||||
});
|
||||
|
||||
it('bootstrap registers node and then fetches capabilities', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new IOSCompanionClient({ runtime: mock.runtime, nodeId: 'ios-node' });
|
||||
|
||||
const result = await client.bootstrap();
|
||||
|
||||
expect(mock.registerNode).toHaveBeenCalledOnce();
|
||||
expect(mock.getNodeCapabilities).toHaveBeenCalledOnce();
|
||||
expect(mock.registerNode.mock.invocationCallOrder[0]).toBeLessThan(
|
||||
mock.getNodeCapabilities.mock.invocationCallOrder[0],
|
||||
);
|
||||
expect(result).toEqual({
|
||||
register: { registered: true },
|
||||
capabilities: expect.any(Object),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,6 +38,11 @@ export type SharedStatusInput = Omit<
|
||||
'platform'
|
||||
>;
|
||||
|
||||
export interface PlatformBootstrapResult {
|
||||
register: NodeRegisterResult;
|
||||
capabilities: NodeCapabilitiesResult;
|
||||
}
|
||||
|
||||
export class MacOSCompanionClient {
|
||||
private readonly runtime: CompanionRuntimeClient;
|
||||
private readonly nodeId: string;
|
||||
@@ -70,6 +75,12 @@ export class MacOSCompanionClient {
|
||||
});
|
||||
}
|
||||
|
||||
async bootstrap(): Promise<PlatformBootstrapResult> {
|
||||
const register = await this.register();
|
||||
const capabilities = await this.getCapabilities();
|
||||
return { register, capabilities };
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
@@ -163,6 +174,12 @@ export class IOSCompanionClient {
|
||||
});
|
||||
}
|
||||
|
||||
async bootstrap(): Promise<PlatformBootstrapResult> {
|
||||
const register = await this.register();
|
||||
const capabilities = await this.getCapabilities();
|
||||
return { register, capabilities };
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
@@ -256,6 +273,12 @@ export class AndroidCompanionClient {
|
||||
});
|
||||
}
|
||||
|
||||
async bootstrap(): Promise<PlatformBootstrapResult> {
|
||||
const register = await this.register();
|
||||
const capabilities = await this.getCapabilities();
|
||||
return { register, capabilities };
|
||||
}
|
||||
|
||||
getCapabilities(): Promise<NodeCapabilitiesResult> {
|
||||
return this.runtime.getNodeCapabilities();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user