11import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
22
3- const { fetchWithSsrFGuardMock, hasEnvHttpProxyConfiguredMock, matchesNoProxyMock } = vi . hoisted (
4- ( ) => ( {
5- fetchWithSsrFGuardMock : vi . fn ( ) ,
6- hasEnvHttpProxyConfiguredMock : vi . fn ( ( ) => false ) ,
7- matchesNoProxyMock : vi . fn ( ( ) => false ) ,
8- } ) ,
9- ) ;
3+ const { fetchWithSsrFGuardMock, shouldUseEnvHttpProxyForUrlMock } = vi . hoisted ( ( ) => ( {
4+ fetchWithSsrFGuardMock : vi . fn ( ) ,
5+ shouldUseEnvHttpProxyForUrlMock : vi . fn ( ( ) => false ) ,
6+ } ) ) ;
107
118vi . mock ( "../infra/net/fetch-guard.js" , async ( ) => {
129 const actual = await vi . importActual < typeof import ( "../infra/net/fetch-guard.js" ) > (
@@ -24,8 +21,7 @@ vi.mock("../infra/net/proxy-env.js", async () => {
2421 ) ;
2522 return {
2623 ...actual ,
27- hasEnvHttpProxyConfigured : hasEnvHttpProxyConfiguredMock ,
28- matchesNoProxy : matchesNoProxyMock ,
24+ shouldUseEnvHttpProxyForUrl : shouldUseEnvHttpProxyForUrlMock ,
2925 } ;
3026} ) ;
3127
@@ -42,8 +38,7 @@ import {
4238} from "./shared.js" ;
4339
4440beforeEach ( ( ) => {
45- hasEnvHttpProxyConfiguredMock . mockReturnValue ( false ) ;
46- matchesNoProxyMock . mockReturnValue ( false ) ;
41+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( false ) ;
4742} ) ;
4843
4944afterEach ( ( ) => {
@@ -417,7 +412,7 @@ describe("fetchWithTimeoutGuarded", () => {
417412 } ) ;
418413
419414 it ( "does not set a guarded fetch mode when no HTTP proxy env is configured" , async ( ) => {
420- hasEnvHttpProxyConfiguredMock . mockReturnValue ( false ) ;
415+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( false ) ;
421416 fetchWithSsrFGuardMock . mockResolvedValue ( {
422417 response : new Response ( null , { status : 200 } ) ,
423418 finalUrl : "https://example.com" ,
@@ -432,7 +427,7 @@ describe("fetchWithTimeoutGuarded", () => {
432427 } ) ;
433428
434429 it ( "auto-selects trusted env proxy mode when HTTP proxy env is configured" , async ( ) => {
435- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
430+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
436431 fetchWithSsrFGuardMock . mockResolvedValue ( {
437432 response : new Response ( null , { status : 200 } ) ,
438433 finalUrl : "https://api.minimax.io" ,
@@ -454,7 +449,7 @@ describe("fetchWithTimeoutGuarded", () => {
454449 } ) ;
455450
456451 it ( "respects an explicit mode from the caller when HTTP proxy env is configured" , async ( ) => {
457- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
452+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
458453 fetchWithSsrFGuardMock . mockResolvedValue ( {
459454 response : new Response ( null , { status : 200 } ) ,
460455 finalUrl : "https://api.example.com" ,
@@ -473,7 +468,7 @@ describe("fetchWithTimeoutGuarded", () => {
473468 } ) ;
474469
475470 it ( "auto-upgrades transcription requests to trusted env proxy when proxy env is configured" , async ( ) => {
476- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
471+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
477472 fetchWithSsrFGuardMock . mockResolvedValue ( {
478473 response : new Response ( null , { status : 200 } ) ,
479474 finalUrl : "https://api.openai.com" ,
@@ -495,7 +490,7 @@ describe("fetchWithTimeoutGuarded", () => {
495490 } ) ;
496491
497492 it ( "forwards an explicit mode override through postJsonRequest even when proxy env is configured" , async ( ) => {
498- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
493+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
499494 fetchWithSsrFGuardMock . mockResolvedValue ( {
500495 response : new Response ( null , { status : 200 } ) ,
501496 finalUrl : "https://api.example.com" ,
@@ -518,7 +513,7 @@ describe("fetchWithTimeoutGuarded", () => {
518513 } ) ;
519514
520515 it ( "forwards an explicit mode override through postTranscriptionRequest even when proxy env is configured" , async ( ) => {
521- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
516+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
522517 fetchWithSsrFGuardMock . mockResolvedValue ( {
523518 response : new Response ( null , { status : 200 } ) ,
524519 finalUrl : "https://api.example.com" ,
@@ -541,11 +536,11 @@ describe("fetchWithTimeoutGuarded", () => {
541536 } ) ;
542537
543538 it ( "does not auto-upgrade when only ALL_PROXY is configured (HTTP(S) proxy gate)" , async ( ) => {
544- // ALL_PROXY is ignored by EnvHttpProxyAgent; `hasEnvHttpProxyConfigured`
539+ // ALL_PROXY is ignored by EnvHttpProxyAgent; the shared proxy URL helper
545540 // reflects that by returning false when only ALL_PROXY is set. Auto-upgrade
546541 // must NOT fire, otherwise the request would skip pinned-DNS/SSRF checks
547542 // and then be dispatched directly.
548- hasEnvHttpProxyConfiguredMock . mockReturnValue ( false ) ;
543+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( false ) ;
549544 fetchWithSsrFGuardMock . mockResolvedValue ( {
550545 response : new Response ( null , { status : 200 } ) ,
551546 finalUrl : "https://api.example.com" ,
@@ -568,7 +563,7 @@ describe("fetchWithTimeoutGuarded", () => {
568563 // Callers with custom proxy URL / proxyTls / connect options must keep
569564 // control over the dispatcher. Auto-upgrade would build an
570565 // EnvHttpProxyAgent that silently drops those overrides.
571- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
566+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( true ) ;
572567 fetchWithSsrFGuardMock . mockResolvedValue ( {
573568 response : new Response ( null , { status : 200 } ) ,
574569 finalUrl : "https://api.example.com" ,
@@ -595,8 +590,7 @@ describe("fetchWithTimeoutGuarded", () => {
595590 // for NO_PROXY matches, but in TRUSTED_ENV_PROXY mode fetchWithSsrFGuard
596591 // skips pinned-DNS checks — so auto-upgrading those targets would bypass
597592 // SSRF protection. Keep strict mode for NO_PROXY matches.
598- hasEnvHttpProxyConfiguredMock . mockReturnValue ( true ) ;
599- matchesNoProxyMock . mockReturnValue ( true ) ;
593+ shouldUseEnvHttpProxyForUrlMock . mockReturnValue ( false ) ;
600594 fetchWithSsrFGuardMock . mockResolvedValue ( {
601595 response : new Response ( null , { status : 200 } ) ,
602596 finalUrl : "https://internal.corp.example" ,
0 commit comments