Skip to content

Commit 640a40f

Browse files
authored
test(claude): make CONNECT upstream failure deterministic (lidge-jun#7929)
Co-authored-by: JUN <[email protected]>
1 parent e7b8cdf commit 640a40f

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

‎tests/claude-integration/claude-intercept-proxy.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { afterAll, expect, test } from "bun:test";
2-
import { connect, createServer, type Socket } from "node:net";
2+
import { connect, createServer, Socket } from "node:net";
33
import { CLAUDE_INTERCEPT_HOSTS, isLoopbackTarget, parseConnectRequestLine, startConnectProxy, type ConnectProxyHandle } from "../../src/claude/intercept/connect-proxy";
44
import { startClaudeInterceptListener, rewriteInterceptedRequest } from "../../src/claude/intercept/listener";
55
import { createLocalInterceptCa, issueLocalInterceptLeaf } from "../../src/claude/intercept/local-ca";
@@ -326,12 +326,12 @@ test("isLoopbackTarget covers mapped, unspecified and shorthand loopback literal
326326
});
327327

328328
test("a dead upstream yields 502 instead of a hung tunnel", async () => {
329-
const dead = await startEchoUpstream();
330-
await dead.close();
331329
const proxy = await startConnectProxy(0, {
332330
interceptPort: 1,
333331
authToken: AUTH_TOKEN,
334-
dialUpstream: () => connect({ host: "127.0.0.1", port: dead.port }),
332+
// A closed listener's port can be reassigned, even to this proxy. Fail a real socket
333+
// asynchronously instead, so this always exercises dial failure before establishment.
334+
dialUpstream: () => new Socket().destroy(new Error("connect ECONNREFUSED")),
335335
});
336336
cleanups.push(proxy.close);
337337
expect(await rawRequest(proxy.port, `CONNECT gone.example:443 HTTP/1.1\r\n${AUTH_HEADER}\r\n`)).toStartWith("HTTP/1.1 502");

0 commit comments

Comments
 (0)