@@ -59,4 +59,40 @@ describe("GatewayClientTransport", () => {
|
59 | 59 | await expect(transport.connect()).rejects.toThrow("gateway transport is closed"); |
60 | 60 | expect(gatewayClientMocks.instances).toHaveLength(0); |
61 | 61 | }); |
| 62 | + |
| 63 | +it("resolves connect when a hello observer throws", async () => { |
| 64 | +const onHelloOk = vi.fn(() => { |
| 65 | +throw new Error("hello observer failed"); |
| 66 | +}); |
| 67 | +const transport = new GatewayClientTransport({ onHelloOk }); |
| 68 | + |
| 69 | +const connect = transport.connect(); |
| 70 | +const client = gatewayClientMocks.instances[0]; |
| 71 | + |
| 72 | +expect(() => client?.opts.onHelloOk?.({ sessionId: "session-1" })).toThrow( |
| 73 | +"hello observer failed", |
| 74 | +); |
| 75 | + |
| 76 | +await expect(connect).resolves.toBeUndefined(); |
| 77 | +expect(onHelloOk).toHaveBeenCalledWith({ sessionId: "session-1" }); |
| 78 | +}); |
| 79 | + |
| 80 | +it("rejects connect when a connect-error observer throws", async () => { |
| 81 | +const onConnectError = vi.fn(() => { |
| 82 | +throw new Error("connect observer failed"); |
| 83 | +}); |
| 84 | +const transport = new GatewayClientTransport({ onConnectError }); |
| 85 | + |
| 86 | +const connect = transport.connect(); |
| 87 | +const connectExpectation = expect(connect).rejects.toThrow("gateway rejected"); |
| 88 | +const client = gatewayClientMocks.instances[0]; |
| 89 | + |
| 90 | +expect(() => client?.opts.onConnectError?.(new Error("gateway rejected"))).toThrow( |
| 91 | +"connect observer failed", |
| 92 | +); |
| 93 | + |
| 94 | +await connectExpectation; |
| 95 | +expect(onConnectError).toHaveBeenCalledOnce(); |
| 96 | +expect(client?.stopAndWait).toHaveBeenCalledTimes(1); |
| 97 | +}); |
62 | 98 | }); |