@@ -10,6 +10,11 @@ const AgentCtor = vi.hoisted(() =>
1010 this . options = options ;
1111 } ) ,
1212) ;
13+ const EnvHttpProxyAgentCtor = vi . hoisted ( ( ) =>
14+ vi . fn ( function MockEnvHttpProxyAgent ( this : { options : unknown } , options : unknown ) {
15+ this . options = options ;
16+ } ) ,
17+ ) ;
1318
1419vi . mock ( "node:net" , async ( ) => {
1520 const actual = await vi . importActual < typeof import ( "node:net" ) > ( "node:net" ) ;
@@ -29,6 +34,7 @@ vi.mock("node:dns", async () => {
2934
3035vi . mock ( "undici" , ( ) => ( {
3136 Agent : AgentCtor ,
37+ EnvHttpProxyAgent : EnvHttpProxyAgentCtor ,
3238 setGlobalDispatcher,
3339} ) ) ;
3440
@@ -40,6 +46,7 @@ afterEach(() => {
4046 setDefaultResultOrder . mockReset ( ) ;
4147 setGlobalDispatcher . mockReset ( ) ;
4248 AgentCtor . mockClear ( ) ;
49+ EnvHttpProxyAgentCtor . mockClear ( ) ;
4350 vi . unstubAllEnvs ( ) ;
4451 vi . clearAllMocks ( ) ;
4552 if ( originalFetch ) {
@@ -147,12 +154,12 @@ describe("resolveTelegramFetch", () => {
147154 expect ( setDefaultResultOrder ) . toHaveBeenCalledTimes ( 2 ) ;
148155 } ) ;
149156
150- it ( "replaces global undici dispatcher with autoSelectFamily-enabled agent" , async ( ) => {
157+ it ( "replaces global undici dispatcher with proxy-aware autoSelectFamily-enabled agent" , async ( ) => {
151158 globalThis . fetch = vi . fn ( async ( ) => ( { } ) ) as unknown as typeof fetch ;
152159 resolveTelegramFetch ( undefined , { network : { autoSelectFamily : true } } ) ;
153160
154161 expect ( setGlobalDispatcher ) . toHaveBeenCalledTimes ( 1 ) ;
155- expect ( AgentCtor ) . toHaveBeenCalledWith ( {
162+ expect ( EnvHttpProxyAgentCtor ) . toHaveBeenCalledWith ( {
156163 connect : {
157164 autoSelectFamily : true ,
158165 autoSelectFamilyAttemptTimeout : 300 ,
@@ -174,13 +181,13 @@ describe("resolveTelegramFetch", () => {
174181 resolveTelegramFetch ( undefined , { network : { autoSelectFamily : false } } ) ;
175182
176183 expect ( setGlobalDispatcher ) . toHaveBeenCalledTimes ( 2 ) ;
177- expect ( AgentCtor ) . toHaveBeenNthCalledWith ( 1 , {
184+ expect ( EnvHttpProxyAgentCtor ) . toHaveBeenNthCalledWith ( 1 , {
178185 connect : {
179186 autoSelectFamily : true ,
180187 autoSelectFamilyAttemptTimeout : 300 ,
181188 } ,
182189 } ) ;
183- expect ( AgentCtor ) . toHaveBeenNthCalledWith ( 2 , {
190+ expect ( EnvHttpProxyAgentCtor ) . toHaveBeenNthCalledWith ( 2 , {
184191 connect : {
185192 autoSelectFamily : false ,
186193 autoSelectFamilyAttemptTimeout : 300 ,
0 commit comments