|
1 | 1 | import { describe, expect, test } from "bun:test"; |
2 | 2 | import { EventEmitter } from "node:events"; |
| 3 | +import { createServer } from "node:net"; |
3 | 4 | import { join } from "node:path"; |
4 | 5 | import { |
5 | 6 | ClientPathError, |
@@ -90,6 +91,45 @@ describe("MiniMax Code client config", () => { |
90 | 91 | }); |
91 | 92 |
|
92 | 93 | describe("MiniMax CLI wrapper", () => { |
| 94 | + test("keeps the bridge's upstream hop direct when the parent has a proxy", async () => { |
| 95 | + const reservation = createServer(); |
| 96 | + const proxyPort = await new Promise<number>((resolve, reject) => { |
| 97 | + reservation.once("error", reject); |
| 98 | + reservation.listen(0, "127.0.0.1", () => { |
| 99 | + const address = reservation.address(); |
| 100 | + if (!address || typeof address === "string") reject(new Error("proxy port reservation failed")); |
| 101 | + else resolve(address.port); |
| 102 | + }); |
| 103 | + }); |
| 104 | + await new Promise<void>((resolve, reject) => reservation.close(error => error ? reject(error) : resolve())); |
| 105 | + |
| 106 | + const child = Bun.spawn([process.execPath, join(import.meta.dir, "fixtures/minimax-bridge-direct.ts")], { |
| 107 | + env: { |
| 108 | + ...process.env, |
| 109 | + HTTP_PROXY: `http://127.0.0.1:${proxyPort}`, |
| 110 | + HTTPS_PROXY: `http://127.0.0.1:${proxyPort}`, |
| 111 | + ALL_PROXY: `http://127.0.0.1:${proxyPort}`, |
| 112 | + NO_PROXY: "", |
| 113 | + no_proxy: "", |
| 114 | + TEST_PROXY_PORT: String(proxyPort), |
| 115 | + }, |
| 116 | + stdout: "pipe", |
| 117 | + stderr: "pipe", |
| 118 | + }); |
| 119 | + const [stdout, stderr, exitCode] = await Promise.all([ |
| 120 | + new Response(child.stdout).text(), |
| 121 | + new Response(child.stderr).text(), |
| 122 | + child.exited, |
| 123 | + ]); |
| 124 | + expect(exitCode, stderr).toBe(0); |
| 125 | + expect(JSON.parse(stdout.trim())).toEqual({ |
| 126 | + responseStatus: 200, |
| 127 | + responseText: JSON.stringify({ source: "upstream" }), |
| 128 | + proxyRequests: 0, |
| 129 | + upstreamBody: JSON.stringify({ prompt: "private bridge payload" }), |
| 130 | + }); |
| 131 | + }); |
| 132 | + |
93 | 133 | test("passes through only standalone help and officially supported version invocations", () => { |
94 | 134 | expect(isStandaloneInformationalInvocation(["--help"], "mmx")).toBeTrue(); |
95 | 135 | expect(isStandaloneInformationalInvocation(["--version"], "mmx")).toBeTrue(); |
|
0 commit comments