@@ -31,4 +31,29 @@ describe('maybeInstallProxyAgent', () => {
3131 expect ( maybeInstallProxyAgent ( { env : { HTTPS_PROXY : '' } , install } ) ) . toBe ( false ) ;
3232 expect ( install ) . not . toHaveBeenCalled ( ) ;
3333 } ) ;
34+
35+ it ( 'falls back (returns false, warns, never throws) when installing the agent fails' , ( ) => {
36+ // A malformed/unsupported proxy value makes the agent throw at startup; the
37+ // CLI must degrade to a proxy-less dispatcher, not crash every command.
38+ const errs : string [ ] = [ ] ;
39+ const installed = maybeInstallProxyAgent ( {
40+ env : { HTTPS_PROXY : 'http://proxy.corp.example.com:8080' } ,
41+ install : ( ) => {
42+ throw new Error ( 'unsupported proxy scheme' ) ;
43+ } ,
44+ stderr : line => errs . push ( line ) ,
45+ } ) ;
46+ expect ( installed ) . toBe ( false ) ;
47+ expect ( errs . join ( '\n' ) ) . toContain ( 'ignoring proxy environment' ) ;
48+ } ) ;
49+
50+ it ( 'still installs when NO_PROXY is set (exemptions are applied per request by undici)' , ( ) => {
51+ const install = vi . fn ( ) ;
52+ const installed = maybeInstallProxyAgent ( {
53+ env : { HTTPS_PROXY : 'http://proxy.corp.example.com:8080' , NO_PROXY : 'localhost,127.0.0.1' } ,
54+ install,
55+ } ) ;
56+ expect ( installed ) . toBe ( true ) ;
57+ expect ( install ) . toHaveBeenCalledTimes ( 1 ) ;
58+ } ) ;
3459} ) ;
0 commit comments