test(companion): cover waitForAnyEvent socket-close rejection
This commit is contained in:
@@ -785,6 +785,17 @@
|
||||
],
|
||||
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
|
||||
},
|
||||
"companion-runtime-wait-for-any-close-rejection-coverage": {
|
||||
"status": "completed",
|
||||
"date": "2026-02-17",
|
||||
"updated": "2026-02-17",
|
||||
"summary": "Added regression coverage proving `waitForAnyEvent()` rejects with `WebSocket closed` when the runtime socket closes unexpectedly.",
|
||||
"files_modified": [
|
||||
"src/companion/runtimeClient.test.ts",
|
||||
"docs/plans/state.json"
|
||||
],
|
||||
"test_status": "pnpm test:run src/companion/runtimeClient.test.ts src/companion/platformClients.test.ts src/companion/heartbeatLoop.test.ts src/companion/platformClients.integration.test.ts + pnpm typecheck passing"
|
||||
},
|
||||
"browser-tools-activation-clarity": {
|
||||
"status": "completed",
|
||||
"date": "2026-02-17",
|
||||
|
||||
@@ -418,6 +418,44 @@ describe('CompanionRuntimeClient', () => {
|
||||
expect(client.connected).toBe(false);
|
||||
});
|
||||
|
||||
it('waitForAnyEvent rejects when websocket closes unexpectedly', 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(_code?: number, _reason?: string): 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();
|
||||
|
||||
const awaited = expect(
|
||||
client.waitForAnyEvent(['agent.stream', 'agent.typing'], { timeoutMs: 10_000 }),
|
||||
).rejects.toThrow('WebSocket closed');
|
||||
|
||||
const ws = (client as unknown as { ws: WebSocket | null }).ws;
|
||||
ws?.close();
|
||||
await awaited;
|
||||
expect(client.connected).toBe(false);
|
||||
});
|
||||
|
||||
it('waitForAgentStream resolves on agent.stream events', async () => {
|
||||
const client = new CompanionRuntimeClient({
|
||||
url: 'ws://127.0.0.1:1',
|
||||
|
||||
Reference in New Issue
Block a user