fix(companion): preserve manual disconnect snapshot metadata

This commit is contained in:
William Valentin
2026-02-16 23:29:40 -08:00
parent 95df7cd445
commit 6821e3779f
3 changed files with 59 additions and 5 deletions
+42
View File
@@ -842,6 +842,48 @@ describe('CompanionRuntimeClient', () => {
});
});
it('manual disconnect metadata is not overwritten by local close event', async () => {
class FakeWebSocket extends EventEmitter {
readyState: number = WebSocket.CONNECTING;
constructor() {
super();
queueMicrotask(() => {
this.readyState = WebSocket.OPEN;
this.emit('open');
});
}
send(_payload: string, callback?: (error?: Error) => void): void {
callback?.();
}
close(): void {
this.readyState = WebSocket.CLOSED;
this.emit('close');
}
}
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',
websocketFactory: () => new FakeWebSocket() as unknown as WebSocket,
});
await client.connect();
client.disconnect(4100, 'manual stop');
expect(client.getConnectionSnapshot()).toEqual({
connected: false,
eventSubscriptionCount: 0,
pendingRequestCount: 0,
pendingEventWaitCount: 0,
hasPendingWork: false,
idle: true,
lastDisconnectCode: 4100,
lastDisconnectReason: 'manual stop',
});
});
it('waitForIdle resolves immediately when no work is pending', async () => {
const client = new CompanionRuntimeClient({
url: 'ws://127.0.0.1:1',