@@ -15,6 +15,7 @@ import path from "node:path";
1515import { fileURLToPath } from "node:url" ;
1616import Database from "better-sqlite3" ;
1717import { parse as parseYaml } from "yaml" ;
18+ import { withoutProxyEnvironment } from "./offline-environment.mjs" ;
1819
1920const cli = fileURLToPath ( new URL ( "../dist/cli.js" , import . meta. url ) ) ;
2021// This fixture validates BYOK transport and real Runtime persistence, not model quality.
@@ -152,7 +153,6 @@ test(
152153 } ) ;
153154 const baseUrl = `http://127.0.0.1:${ server . address ( ) . port } /v1` ;
154155 const env = {
155- ...process . env ,
156156 MINIMAX_DATA_DIR : dataDir ,
157157 MAVIS_DATA_DIR : dataDir ,
158158 MCODE_PROVIDER_API_KEY : "fixture-only-key" ,
@@ -161,12 +161,9 @@ test(
161161 MCODE_TEST_MANAGED_OFFLINE : "1" ,
162162 MCODE_TEST_PROCESS_PROBE : "1" ,
163163 NODE_OPTIONS : `--import=${ new URL ( "./network-deny.mjs" , import . meta. url ) . href } ` ,
164- HTTP_PROXY : "" ,
165- HTTPS_PROXY : "" ,
166- ALL_PROXY : "" ,
167164 } ;
168165 let commandSequence = 0 ;
169- async function run ( args ) {
166+ async function run ( args , environment = process . env ) {
170167 const startedAt = Date . now ( ) ;
171168 const label = args . slice ( 0 , 2 ) . join ( " " ) ;
172169 const requestCountAtStart = requests . length ;
@@ -177,7 +174,7 @@ test(
177174 return new Promise ( ( resolve , reject ) => {
178175 const child = spawn ( process . execPath , [ cli , ...commandArgs ] , {
179176 cwd : dataDir ,
180- env,
177+ env : { ... withoutProxyEnvironment ( environment ) , ... env } ,
181178 stdio : [ "ignore" , "pipe" , "pipe" ] ,
182179 } ) ;
183180 let stdout = "" ,
@@ -247,13 +244,45 @@ test(
247244 ( p ) => p . kind === "custom" && p . name === "Fixture" ,
248245 ) ;
249246 assert . ok ( selected ?. hasApiKey ) ;
250- await run ( [
251- "provider" ,
252- "test" ,
253- selected . providerId ,
254- "--model" ,
255- "fixture-model" ,
256- ] ) ;
247+ const proxyNames = [
248+ "HTTP_PROXY" , "HTTPS_PROXY" , "ALL_PROXY" , "NO_PROXY" ,
249+ "http_proxy" , "https_proxy" , "all_proxy" , "no_proxy" ,
250+ ] ;
251+ const cleanEnvironment = Object . fromEntries (
252+ Object . entries ( process . env ) . filter ( ( [ name ] ) => ! proxyNames . includes ( name ) ) ,
253+ ) ;
254+ const proxyValue = ( name ) => name . toLowerCase ( ) === "no_proxy"
255+ ? "*"
256+ : "http://127.0.0.1:9" ;
257+ for ( const [ label , proxies ] of [
258+ [ "no proxy" , { } ] ,
259+ ...proxyNames . map ( ( name ) => [ name , { [ name ] : proxyValue ( name ) } ] ) ,
260+ [ "uppercase and lowercase together" , Object . fromEntries (
261+ proxyNames . map ( ( name ) => [ name , proxyValue ( name ) ] ) ,
262+ ) ] ,
263+ ] ) {
264+ await t . test ( `offline BYOK ignores ambient proxies: ${ label } ` , async ( ) => {
265+ const environment = Object . freeze ( { ...cleanEnvironment , ...proxies } ) ;
266+ // NO_PROXY alone does not enable proxy mode, so check its isolation explicitly.
267+ const isolated = withoutProxyEnvironment ( environment ) ;
268+ for ( const name of proxyNames ) assert . equal ( isolated [ name ] , "" ) ;
269+ assert . equal ( isolated . PATH , environment . PATH ) ;
270+ const beforeRequests = requests . length ;
271+ const managedAudit = `${ networkAudit } .managed` ;
272+ const beforeManaged = readFileSync ( managedAudit , "utf8" ) . length ;
273+ await run ( [
274+ "provider" , "test" , selected . providerId , "--model" , "fixture-model" ,
275+ ] , environment ) ;
276+ assert . ok ( requests . length > beforeRequests , "The local provider must receive the request" ) ;
277+ assert . equal ( requests [ beforeRequests ] . body . model , "fixture-model" ) ;
278+ assert . match (
279+ readFileSync ( managedAudit , "utf8" ) . slice ( beforeManaged ) ,
280+ / h t t p s : \/ \/ m o d e l s \. d e v \/ a p i \. j s o n | \/ m a v i s \/ a p i \/ v 1 \/ m o d e l s - d e v \/ c a t a l o g / ,
281+ ) ;
282+ assert . equal ( existsSync ( networkAudit ) , false , "No outbound network attempt is allowed" ) ;
283+ for ( const [ name , value ] of Object . entries ( proxies ) ) assert . equal ( environment [ name ] , value ) ;
284+ } ) ;
285+ }
257286 const configPath = path . join ( dataDir , "config.yaml" ) ;
258287 const savedConfig = ( ) => parseYaml ( readFileSync ( configPath , "utf8" ) ) ;
259288 assert . equal ( savedConfig ( ) . defaultModel , "minimax/MiniMax-M3" ) ;
0 commit comments