feat(companion): add platform dispose lifecycle helper
This commit is contained in:
@@ -10,6 +10,7 @@ function createRuntimeMock(): {
|
||||
runtime: CompanionRuntimeClient;
|
||||
connect: ReturnType<typeof vi.fn>;
|
||||
disconnect: ReturnType<typeof vi.fn>;
|
||||
dispose: ReturnType<typeof vi.fn>;
|
||||
registerNode: ReturnType<typeof vi.fn>;
|
||||
getNodeCapabilities: ReturnType<typeof vi.fn>;
|
||||
setNodeStatus: ReturnType<typeof vi.fn>;
|
||||
@@ -26,6 +27,7 @@ function createRuntimeMock(): {
|
||||
} {
|
||||
const connect = vi.fn(async () => undefined);
|
||||
const disconnect = vi.fn(() => undefined);
|
||||
const dispose = vi.fn(() => undefined);
|
||||
const registerNode = vi.fn(async () => ({ registered: true }));
|
||||
const getNodeCapabilities = vi.fn(async () => ({ node: { id: 'n1', role: 'companion', registeredAt: Date.now() }, protocol: { serverVersion: 1, nodeVersion: 1, negotiatedVersion: 1 }, capabilities: { declared: [], enabled: [], featureGates: {} } }));
|
||||
const setNodeStatus = vi.fn(async () => ({ updated: true }));
|
||||
@@ -43,6 +45,7 @@ function createRuntimeMock(): {
|
||||
const runtime = {
|
||||
connect,
|
||||
disconnect,
|
||||
dispose,
|
||||
registerNode,
|
||||
getNodeCapabilities,
|
||||
setNodeStatus,
|
||||
@@ -62,6 +65,7 @@ function createRuntimeMock(): {
|
||||
runtime,
|
||||
connect,
|
||||
disconnect,
|
||||
dispose,
|
||||
registerNode,
|
||||
getNodeCapabilities,
|
||||
setNodeStatus,
|
||||
@@ -127,6 +131,14 @@ describe('platform companion clients', () => {
|
||||
expect(mock.listSystemNodes).toHaveBeenCalledWith({ platform: 'android', role: 'companion' });
|
||||
});
|
||||
|
||||
it('platform dispose forwards to runtime dispose', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new MacOSCompanionClient({ runtime: mock.runtime, nodeId: 'mac-node' });
|
||||
|
||||
client.dispose();
|
||||
expect(mock.dispose).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it('macOS client forwards canvas methods to runtime client', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new MacOSCompanionClient({ runtime: mock.runtime, nodeId: 'mac-node' });
|
||||
|
||||
@@ -95,6 +95,10 @@ export class MacOSCompanionClient {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.runtime.dispose();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
@@ -231,6 +235,10 @@ export class IOSCompanionClient {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.runtime.dispose();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
@@ -367,6 +375,10 @@ export class AndroidCompanionClient {
|
||||
this.runtime.disconnect();
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.runtime.dispose();
|
||||
}
|
||||
|
||||
register(): Promise<NodeRegisterResult> {
|
||||
return this.runtime.registerNode({
|
||||
nodeId: this.nodeId,
|
||||
|
||||
Reference in New Issue
Block a user