From 71c4b184f9fad612f3a133b67cd9d7dec895c855 Mon Sep 17 00:00:00 2001 From: Tam Nhu Tran Date: Fri, 3 Apr 2026 19:51:29 -0400 Subject: [PATCH] test(cliproxy): stabilize tunnel localhost binding check --- .../unit/cliproxy/https-tunnel-proxy.test.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/unit/cliproxy/https-tunnel-proxy.test.ts b/tests/unit/cliproxy/https-tunnel-proxy.test.ts index 522b6ab4..81e85324 100644 --- a/tests/unit/cliproxy/https-tunnel-proxy.test.ts +++ b/tests/unit/cliproxy/https-tunnel-proxy.test.ts @@ -116,17 +116,18 @@ describe('HttpsTunnelProxy', () => { }); const port = await tunnel.start(); + const net = await import('net'); + const socket = new net.Socket(); - // Try to connect - should work on localhost - const response = await new Promise((resolve, reject) => { - const req = http.get(`http://127.0.0.1:${port}/test`, resolve); - req.on('error', reject); - req.setTimeout(1000); - }).catch((err) => err); + await new Promise((resolve, reject) => { + socket.once('error', reject); + socket.connect(port, '127.0.0.1', () => { + socket.end(); + resolve(); + }); + }); - // We expect an error because there's no upstream, but connection should be accepted - // If binding failed, we'd get ECONNREFUSED before any response - expect(response).toBeDefined(); + expect(tunnel.getPort()).toBe(port); }); });