feat(companion): add idle observability alias

This commit is contained in:
William Valentin
2026-02-16 22:00:08 -08:00
parent 699f848fc5
commit 45ea084cf0
6 changed files with 49 additions and 2 deletions
+13
View File
@@ -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' });
+12
View File
@@ -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();
}
+3
View File
@@ -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 () => {
+4
View File
@@ -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,