feat(companion): add idle observability alias
This commit is contained in:
@@ -43,6 +43,7 @@ function createRuntimeMock(): {
|
||||
pendingRequestCount: number;
|
||||
pendingEventWaitCount: number;
|
||||
hasPendingWork: boolean;
|
||||
idle: boolean;
|
||||
connected: boolean;
|
||||
} {
|
||||
const connect = vi.fn(async () => undefined);
|
||||
@@ -91,6 +92,7 @@ function createRuntimeMock(): {
|
||||
const pendingRequestCount = 2;
|
||||
const pendingEventWaitCount = 1;
|
||||
const hasPendingWork = true;
|
||||
const idle = false;
|
||||
const connected = true;
|
||||
|
||||
const runtime = {
|
||||
@@ -137,6 +139,9 @@ function createRuntimeMock(): {
|
||||
get hasPendingWork() {
|
||||
return hasPendingWork;
|
||||
},
|
||||
get idle() {
|
||||
return idle;
|
||||
},
|
||||
get connected() {
|
||||
return connected;
|
||||
},
|
||||
@@ -179,6 +184,7 @@ function createRuntimeMock(): {
|
||||
pendingRequestCount,
|
||||
pendingEventWaitCount,
|
||||
hasPendingWork,
|
||||
idle,
|
||||
connected,
|
||||
};
|
||||
}
|
||||
@@ -345,6 +351,13 @@ describe('platform companion clients', () => {
|
||||
expect(client.hasPendingWork).toBe(mock.hasPendingWork);
|
||||
});
|
||||
|
||||
it('platform idle forwards runtime getter value', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new IOSCompanionClient({ runtime: mock.runtime, nodeId: 'ios-node' });
|
||||
|
||||
expect(client.idle).toBe(mock.idle);
|
||||
});
|
||||
|
||||
it('platform waitForIdle forwards options to runtime client', async () => {
|
||||
const mock = createRuntimeMock();
|
||||
const client = new IOSCompanionClient({ runtime: mock.runtime, nodeId: 'ios-node' });
|
||||
|
||||
@@ -289,6 +289,10 @@ export class MacOSCompanionClient {
|
||||
return this.runtime.hasPendingWork;
|
||||
}
|
||||
|
||||
get idle(): boolean {
|
||||
return this.runtime.idle;
|
||||
}
|
||||
|
||||
getPendingWorkSnapshot(): PendingWorkSnapshot {
|
||||
return this.runtime.getPendingWorkSnapshot();
|
||||
}
|
||||
@@ -551,6 +555,10 @@ export class IOSCompanionClient {
|
||||
return this.runtime.hasPendingWork;
|
||||
}
|
||||
|
||||
get idle(): boolean {
|
||||
return this.runtime.idle;
|
||||
}
|
||||
|
||||
getPendingWorkSnapshot(): PendingWorkSnapshot {
|
||||
return this.runtime.getPendingWorkSnapshot();
|
||||
}
|
||||
@@ -811,6 +819,10 @@ export class AndroidCompanionClient {
|
||||
return this.runtime.hasPendingWork;
|
||||
}
|
||||
|
||||
get idle(): boolean {
|
||||
return this.runtime.idle;
|
||||
}
|
||||
|
||||
getPendingWorkSnapshot(): PendingWorkSnapshot {
|
||||
return this.runtime.getPendingWorkSnapshot();
|
||||
}
|
||||
|
||||
@@ -632,15 +632,18 @@ describe('CompanionRuntimeClient', () => {
|
||||
await client.connect();
|
||||
expect(client.pendingRequestCount).toBe(0);
|
||||
expect(client.hasPendingWork).toBe(false);
|
||||
expect(client.idle).toBe(true);
|
||||
|
||||
const pending = client.call('system.capabilities');
|
||||
expect(client.pendingRequestCount).toBe(1);
|
||||
expect(client.hasPendingWork).toBe(true);
|
||||
expect(client.idle).toBe(false);
|
||||
|
||||
client.disconnect();
|
||||
await expect(pending).rejects.toThrow('Disconnected');
|
||||
expect(client.pendingRequestCount).toBe(0);
|
||||
expect(client.hasPendingWork).toBe(false);
|
||||
expect(client.idle).toBe(true);
|
||||
});
|
||||
|
||||
it('returns pending work snapshot', async () => {
|
||||
|
||||
@@ -326,6 +326,10 @@ export class CompanionRuntimeClient {
|
||||
return this.pendingRequestCount > 0 || this.pendingEventWaitCount > 0;
|
||||
}
|
||||
|
||||
get idle(): boolean {
|
||||
return !this.hasPendingWork;
|
||||
}
|
||||
|
||||
getPendingWorkSnapshot(): PendingWorkSnapshot {
|
||||
return {
|
||||
pendingRequestCount: this.pendingRequestCount,
|
||||
|
||||
Reference in New Issue
Block a user