From ce2736d4ae764aa72b6708bcd86ccc21745dbb4a Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Fri, 18 Sep 2026 14:17:12 -0600 Subject: [PATCH 01/10] fix(core): normalize proxy-agent esbuild interop for environment proxy resolution Normalizes the CJS/ESM interop handling and export structures for https-proxy-agent and http-proxy-agent within the esbuild bundle pipeline. - Export both named and default constructors from the patch shims. - Attach self-referential constructor properties for cross-module compatibility. - Share proxy-agent patch aliases across all bundle configurations in commonAliases. - Add test coverage in scripts/tests/proxy-agent-bundle.test.ts for proxy resolution. Closes #26533 --- esbuild.config.js | 16 +-- packages/cli/src/patches/http-proxy-agent.ts | 29 +++- packages/cli/src/patches/https-proxy-agent.ts | 29 +++- scripts/tests/proxy-agent-bundle.test.ts | 134 ++++++++++++++++-- 4 files changed, 184 insertions(+), 24 deletions(-) diff --git a/esbuild.config.js b/esbuild.config.js index 85e2402961f..c18f288a36c 100644 --- a/esbuild.config.js +++ b/esbuild.config.js @@ -76,6 +76,14 @@ const baseConfig = { const commonAliases = { punycode: 'punycode/', + 'https-proxy-agent': path.resolve( + __dirname, + 'packages/cli/src/patches/https-proxy-agent.ts', + ), + 'http-proxy-agent': path.resolve( + __dirname, + 'packages/cli/src/patches/http-proxy-agent.ts', + ), }; const cliConfig = { @@ -101,14 +109,6 @@ const cliConfig = { plugins: createWasmPlugins(), alias: { 'is-in-ci': path.resolve(__dirname, 'packages/cli/src/patches/is-in-ci.ts'), - 'https-proxy-agent': path.resolve( - __dirname, - 'packages/cli/src/patches/https-proxy-agent.ts', - ), - 'http-proxy-agent': path.resolve( - __dirname, - 'packages/cli/src/patches/http-proxy-agent.ts', - ), '@google/gemini-cli-devtools': path.resolve( __dirname, 'packages/devtools/src/index.ts', diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 1f13f9bb98e..0570854e74d 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -4,5 +4,30 @@ * SPDX-License-Identifier: Apache-2.0 */ -// eslint-disable-next-line import/no-relative-packages -export { HttpProxyAgent } from '../../../../node_modules/http-proxy-agent/dist/index.js'; +/* eslint-disable @typescript-eslint/no-unsafe-type-assertion */ +/* eslint-disable import/no-relative-packages */ + +import * as rawProxyAgent from '../../../../node_modules/http-proxy-agent/dist/index.js'; + +type HttpProxyAgentCtor = typeof rawProxyAgent.HttpProxyAgent; + +interface InteropShape { + HttpProxyAgent?: HttpProxyAgentCtor; + default?: HttpProxyAgentCtor; +} + +const mod = rawProxyAgent as unknown as InteropShape; +const HttpProxyAgent: HttpProxyAgentCtor = + mod.HttpProxyAgent || + mod.default || + (rawProxyAgent as unknown as HttpProxyAgentCtor); + +if (typeof HttpProxyAgent === 'function') { + const ctorRecord = HttpProxyAgent as unknown as Record; + ctorRecord['HttpProxyAgent'] = HttpProxyAgent; + ctorRecord['default'] = HttpProxyAgent; +} + +export { HttpProxyAgent }; +// eslint-disable-next-line import/no-default-export +export default HttpProxyAgent; diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index a7c16557979..7ed02729bcb 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -4,5 +4,30 @@ * SPDX-License-Identifier: Apache-2.0 */ -// eslint-disable-next-line import/no-relative-packages -export { HttpsProxyAgent } from '../../../../node_modules/https-proxy-agent/dist/index.js'; +/* eslint-disable @typescript-eslint/no-unsafe-type-assertion */ +/* eslint-disable import/no-relative-packages */ + +import * as rawProxyAgent from '../../../../node_modules/https-proxy-agent/dist/index.js'; + +type HttpsProxyAgentCtor = typeof rawProxyAgent.HttpsProxyAgent; + +interface InteropShape { + HttpsProxyAgent?: HttpsProxyAgentCtor; + default?: HttpsProxyAgentCtor; +} + +const mod = rawProxyAgent as unknown as InteropShape; +const HttpsProxyAgent: HttpsProxyAgentCtor = + mod.HttpsProxyAgent || + mod.default || + (rawProxyAgent as unknown as HttpsProxyAgentCtor); + +if (typeof HttpsProxyAgent === 'function') { + const ctorRecord = HttpsProxyAgent as unknown as Record; + ctorRecord['HttpsProxyAgent'] = HttpsProxyAgent; + ctorRecord['default'] = HttpsProxyAgent; +} + +export { HttpsProxyAgent }; +// eslint-disable-next-line import/no-default-export +export default HttpsProxyAgent; diff --git a/scripts/tests/proxy-agent-bundle.test.ts b/scripts/tests/proxy-agent-bundle.test.ts index 605c45275b0..7ff8976f13f 100644 --- a/scripts/tests/proxy-agent-bundle.test.ts +++ b/scripts/tests/proxy-agent-bundle.test.ts @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; vi.unmock('fs'); vi.unmock('node:fs'); import * as esbuild from 'esbuild'; @@ -17,21 +17,42 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); const projectRoot = path.resolve(__dirname, '../../'); -describe('proxy-agent bundle shape', () => { - it('preserves named constructors after ESM splitting', async () => { - const tmpDir = mkdtempSync(path.join(tmpdir(), 'gemini-proxy-test-')); +describe('proxy-agent bundle shape and interop', () => { + let tmpDir: string; + + beforeEach(() => { + tmpDir = mkdtempSync(path.join(tmpdir(), 'gemini-proxy-test-')); + }); + + afterEach(() => { + vi.unstubAllEnvs(); + if (tmpDir) { + rmSync(tmpDir, { recursive: true, force: true }); + } + }); + + it('preserves named and default constructors after ESM splitting', async () => { const entryFile = path.join(tmpDir, 'entry.ts'); - // Create a minimal entry file that dynamically imports the proxy agents + // Create an entry file that tests both static and dynamic imports writeFileSync( entryFile, ` + import StaticHttpsDefault from 'https-proxy-agent'; + import { HttpsProxyAgent as StaticHttpsNamed } from 'https-proxy-agent'; + import StaticHttpDefault from 'http-proxy-agent'; + import { HttpProxyAgent as StaticHttpNamed } from 'http-proxy-agent'; + export async function getAgents() { const httpsMod = await import('https-proxy-agent'); const httpMod = await import('http-proxy-agent'); return { https: httpsMod, http: httpMod, + staticHttpsDefault: StaticHttpsDefault, + staticHttpsNamed: StaticHttpsNamed, + staticHttpDefault: StaticHttpDefault, + staticHttpNamed: StaticHttpNamed, }; } `, @@ -64,17 +85,106 @@ describe('proxy-agent bundle shape', () => { ).href; const { getAgents } = await import(bundledEntryUrl); - const { https, http } = await getAgents(); + const { + https, + http, + staticHttpsDefault, + staticHttpsNamed, + staticHttpDefault, + staticHttpNamed, + } = await getAgents(); - // Verify named exports exist + // Verify named exports exist and are functions expect(typeof https.HttpsProxyAgent).toBe('function'); expect(typeof http.HttpProxyAgent).toBe('function'); - // Verify they are constructable - expect(() => new https.HttpsProxyAgent('http://127.0.0.1:9')).not.toThrow(); - expect(() => new http.HttpProxyAgent('http://127.0.0.1:9')).not.toThrow(); + // Verify default exports exist and are functions + expect(typeof https.default).toBe('function'); + expect(typeof http.default).toBe('function'); + + // Verify static imports work + expect(typeof staticHttpsDefault).toBe('function'); + expect(typeof staticHttpsNamed).toBe('function'); + expect(typeof staticHttpDefault).toBe('function'); + expect(typeof staticHttpNamed).toBe('function'); + + // Verify self-referential properties for CJS/ESM interop fallback + expect(https.HttpsProxyAgent.HttpsProxyAgent).toBe(https.HttpsProxyAgent); + expect(https.HttpsProxyAgent.default).toBe(https.HttpsProxyAgent); + expect(http.HttpProxyAgent.HttpProxyAgent).toBe(http.HttpProxyAgent); + expect(http.HttpProxyAgent.default).toBe(http.HttpProxyAgent); + + // Verify they are constructable with proxy URLs + expect( + () => new https.HttpsProxyAgent('http://127.0.0.1:7897'), + ).not.toThrow(); + expect(() => new https.default('http://127.0.0.1:7897')).not.toThrow(); + expect(() => new staticHttpsDefault('http://127.0.0.1:7897')).not.toThrow(); + expect(() => new staticHttpsNamed('http://127.0.0.1:7897')).not.toThrow(); + + expect( + () => new http.HttpProxyAgent('http://127.0.0.1:7897'), + ).not.toThrow(); + expect(() => new http.default('http://127.0.0.1:7897')).not.toThrow(); + expect(() => new staticHttpDefault('http://127.0.0.1:7897')).not.toThrow(); + expect(() => new staticHttpNamed('http://127.0.0.1:7897')).not.toThrow(); + }); + + it('instantiates proxy agents when HTTP_PROXY and HTTPS_PROXY are set', async () => { + vi.stubEnv('HTTP_PROXY', 'http://127.0.0.1:7897'); + vi.stubEnv('HTTPS_PROXY', 'http://127.0.0.1:7897'); + + const entryFile = path.join(tmpDir, 'proxy-env-entry.ts'); + writeFileSync( + entryFile, + ` + export async function testEnvProxy() { + const httpsMod = await import('https-proxy-agent'); + const httpMod = await import('http-proxy-agent'); + + const httpsProxyUrl = process.env.HTTPS_PROXY || process.env.https_proxy; + const httpProxyUrl = process.env.HTTP_PROXY || process.env.http_proxy; + + const httpsConstructor = httpsMod.HttpsProxyAgent || httpsMod.default || httpsMod; + const httpConstructor = httpMod.HttpProxyAgent || httpMod.default || httpMod; + + const httpsAgent = new httpsConstructor(httpsProxyUrl); + const httpAgent = new httpConstructor(httpProxyUrl); + + return { httpsAgent, httpAgent }; + } + `, + ); + + await esbuild.build({ + entryPoints: { gemini: entryFile }, + outdir: path.join(tmpDir, 'bundle'), + bundle: true, + splitting: true, + format: 'esm', + platform: 'node', + outExtension: { '.js': '.mjs' }, + alias: { + 'https-proxy-agent': path.resolve( + projectRoot, + 'packages/cli/src/patches/https-proxy-agent.ts', + ), + 'http-proxy-agent': path.resolve( + projectRoot, + 'packages/cli/src/patches/http-proxy-agent.ts', + ), + }, + }); + + const bundledEntryUrl = pathToFileURL( + path.join(tmpDir, 'bundle/gemini.mjs'), + ).href; + const { testEnvProxy } = await import(bundledEntryUrl); - // Cleanup - rmSync(tmpDir, { recursive: true, force: true }); + const { httpsAgent, httpAgent } = await testEnvProxy(); + expect(httpsAgent).toBeDefined(); + expect(httpAgent).toBeDefined(); + expect(httpsAgent.proxy?.href).toBe('http://127.0.0.1:7897/'); + expect(httpAgent.proxy?.href).toBe('http://127.0.0.1:7897/'); }); }); From e18bda5730b32c2421b07a1c4e4f2f94234f4eb5 Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Fri, 18 Sep 2026 14:50:05 -0600 Subject: [PATCH 02/10] fix(cli): add robust namespace constructor resolution and defensive property definitions in proxy patches Address review feedback: - Handle edge cases where default export is a module namespace containing named proxy agent constructors. - Use Object.defineProperty with try-catch to defensively define self-referential properties without mutating frozen objects. Related to #26533 --- packages/cli/src/patches/http-proxy-agent.ts | 37 +++++++++++++++---- packages/cli/src/patches/https-proxy-agent.ts | 37 +++++++++++++++---- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 0570854e74d..2ed7ad66cb5 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -13,19 +13,40 @@ type HttpProxyAgentCtor = typeof rawProxyAgent.HttpProxyAgent; interface InteropShape { HttpProxyAgent?: HttpProxyAgentCtor; - default?: HttpProxyAgentCtor; + default?: HttpProxyAgentCtor | InteropShape; } const mod = rawProxyAgent as unknown as InteropShape; -const HttpProxyAgent: HttpProxyAgentCtor = - mod.HttpProxyAgent || - mod.default || - (rawProxyAgent as unknown as HttpProxyAgentCtor); +const defaultMod = mod.default as InteropShape | undefined; +const defaultNamedCtor = defaultMod?.HttpProxyAgent; + +let resolvedCtor = rawProxyAgent as unknown as HttpProxyAgentCtor; +if (typeof mod.HttpProxyAgent === 'function') { + resolvedCtor = mod.HttpProxyAgent; +} else if (typeof mod.default === 'function') { + resolvedCtor = mod.default; +} else if (typeof defaultNamedCtor === 'function') { + resolvedCtor = defaultNamedCtor; +} +const HttpProxyAgent = resolvedCtor; if (typeof HttpProxyAgent === 'function') { - const ctorRecord = HttpProxyAgent as unknown as Record; - ctorRecord['HttpProxyAgent'] = HttpProxyAgent; - ctorRecord['default'] = HttpProxyAgent; + try { + Object.defineProperty(HttpProxyAgent, 'HttpProxyAgent', { + value: HttpProxyAgent, + configurable: true, + writable: true, + enumerable: true, + }); + Object.defineProperty(HttpProxyAgent, 'default', { + value: HttpProxyAgent, + configurable: true, + writable: true, + enumerable: true, + }); + } catch { + // Safely ignore if the constructor is frozen or properties are non-configurable + } } export { HttpProxyAgent }; diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index 7ed02729bcb..f2e5323d6b8 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -13,19 +13,40 @@ type HttpsProxyAgentCtor = typeof rawProxyAgent.HttpsProxyAgent; interface InteropShape { HttpsProxyAgent?: HttpsProxyAgentCtor; - default?: HttpsProxyAgentCtor; + default?: HttpsProxyAgentCtor | InteropShape; } const mod = rawProxyAgent as unknown as InteropShape; -const HttpsProxyAgent: HttpsProxyAgentCtor = - mod.HttpsProxyAgent || - mod.default || - (rawProxyAgent as unknown as HttpsProxyAgentCtor); +const defaultMod = mod.default as InteropShape | undefined; +const defaultNamedCtor = defaultMod?.HttpsProxyAgent; + +let resolvedCtor = rawProxyAgent as unknown as HttpsProxyAgentCtor; +if (typeof mod.HttpsProxyAgent === 'function') { + resolvedCtor = mod.HttpsProxyAgent; +} else if (typeof mod.default === 'function') { + resolvedCtor = mod.default; +} else if (typeof defaultNamedCtor === 'function') { + resolvedCtor = defaultNamedCtor; +} +const HttpsProxyAgent = resolvedCtor; if (typeof HttpsProxyAgent === 'function') { - const ctorRecord = HttpsProxyAgent as unknown as Record; - ctorRecord['HttpsProxyAgent'] = HttpsProxyAgent; - ctorRecord['default'] = HttpsProxyAgent; + try { + Object.defineProperty(HttpsProxyAgent, 'HttpsProxyAgent', { + value: HttpsProxyAgent, + configurable: true, + writable: true, + enumerable: true, + }); + Object.defineProperty(HttpsProxyAgent, 'default', { + value: HttpsProxyAgent, + configurable: true, + writable: true, + enumerable: true, + }); + } catch { + // Safely ignore if the constructor is frozen or properties are non-configurable + } } export { HttpsProxyAgent }; From aa6116560a8d8baaa890b9879fa9d2ea1cdccdc4 Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Fri, 18 Sep 2026 15:01:19 -0600 Subject: [PATCH 03/10] fix(cli): add fallback error class if proxy agent constructor cannot be resolved Address follow-up review feedback: - Initialize resolvedCtor as undefined rather than prematurely casting rawProxyAgent. - Fallback to a stub class that throws an informative Error on instantiation if no constructor can be resolved. Related to #26533 --- packages/cli/src/patches/http-proxy-agent.ts | 15 +++++++++++++-- packages/cli/src/patches/https-proxy-agent.ts | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 2ed7ad66cb5..973f1ce1ab2 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -20,15 +20,26 @@ const mod = rawProxyAgent as unknown as InteropShape; const defaultMod = mod.default as InteropShape | undefined; const defaultNamedCtor = defaultMod?.HttpProxyAgent; -let resolvedCtor = rawProxyAgent as unknown as HttpProxyAgentCtor; +let resolvedCtor: HttpProxyAgentCtor | undefined; if (typeof mod.HttpProxyAgent === 'function') { resolvedCtor = mod.HttpProxyAgent; } else if (typeof mod.default === 'function') { resolvedCtor = mod.default; } else if (typeof defaultNamedCtor === 'function') { resolvedCtor = defaultNamedCtor; +} else if (typeof rawProxyAgent === 'function') { + resolvedCtor = rawProxyAgent as unknown as HttpProxyAgentCtor; } -const HttpProxyAgent = resolvedCtor; + +const HttpProxyAgent = + resolvedCtor ?? + (class { + constructor() { + throw new Error( + 'HttpProxyAgent constructor could not be resolved from http-proxy-agent', + ); + } + } as unknown as HttpProxyAgentCtor); if (typeof HttpProxyAgent === 'function') { try { diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index f2e5323d6b8..4002bdc46ea 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -20,15 +20,26 @@ const mod = rawProxyAgent as unknown as InteropShape; const defaultMod = mod.default as InteropShape | undefined; const defaultNamedCtor = defaultMod?.HttpsProxyAgent; -let resolvedCtor = rawProxyAgent as unknown as HttpsProxyAgentCtor; +let resolvedCtor: HttpsProxyAgentCtor | undefined; if (typeof mod.HttpsProxyAgent === 'function') { resolvedCtor = mod.HttpsProxyAgent; } else if (typeof mod.default === 'function') { resolvedCtor = mod.default; } else if (typeof defaultNamedCtor === 'function') { resolvedCtor = defaultNamedCtor; +} else if (typeof rawProxyAgent === 'function') { + resolvedCtor = rawProxyAgent as unknown as HttpsProxyAgentCtor; } -const HttpsProxyAgent = resolvedCtor; + +const HttpsProxyAgent = + resolvedCtor ?? + (class { + constructor() { + throw new Error( + 'HttpsProxyAgent constructor could not be resolved from https-proxy-agent', + ); + } + } as unknown as HttpsProxyAgentCtor); if (typeof HttpsProxyAgent === 'function') { try { From b8b16fc8ca24dc029af6e449c73b873bc4189ab8 Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Mon, 21 Sep 2026 10:38:39 -0600 Subject: [PATCH 04/10] fix(cli): use Proxy wrapper for non-mutating proxy agent constructor interop --- packages/cli/src/patches/http-proxy-agent.ts | 30 +++++++------------ packages/cli/src/patches/https-proxy-agent.ts | 30 +++++++------------ 2 files changed, 22 insertions(+), 38 deletions(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 973f1ce1ab2..c15049289c0 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -6,6 +6,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-type-assertion */ /* eslint-disable import/no-relative-packages */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* eslint-disable no-restricted-syntax */ import * as rawProxyAgent from '../../../../node_modules/http-proxy-agent/dist/index.js'; @@ -31,7 +33,7 @@ if (typeof mod.HttpProxyAgent === 'function') { resolvedCtor = rawProxyAgent as unknown as HttpProxyAgentCtor; } -const HttpProxyAgent = +const baseCtor = resolvedCtor ?? (class { constructor() { @@ -41,24 +43,14 @@ const HttpProxyAgent = } } as unknown as HttpProxyAgentCtor); -if (typeof HttpProxyAgent === 'function') { - try { - Object.defineProperty(HttpProxyAgent, 'HttpProxyAgent', { - value: HttpProxyAgent, - configurable: true, - writable: true, - enumerable: true, - }); - Object.defineProperty(HttpProxyAgent, 'default', { - value: HttpProxyAgent, - configurable: true, - writable: true, - enumerable: true, - }); - } catch { - // Safely ignore if the constructor is frozen or properties are non-configurable - } -} +const HttpProxyAgent = new Proxy(baseCtor, { + get(target, prop, receiver) { + if (prop === 'HttpProxyAgent' || prop === 'default') { + return receiver; + } + return Reflect.get(target, prop, receiver); + }, +}); export { HttpProxyAgent }; // eslint-disable-next-line import/no-default-export diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index 4002bdc46ea..77468729f7a 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -6,6 +6,8 @@ /* eslint-disable @typescript-eslint/no-unsafe-type-assertion */ /* eslint-disable import/no-relative-packages */ +/* eslint-disable @typescript-eslint/no-unsafe-return */ +/* eslint-disable no-restricted-syntax */ import * as rawProxyAgent from '../../../../node_modules/https-proxy-agent/dist/index.js'; @@ -31,7 +33,7 @@ if (typeof mod.HttpsProxyAgent === 'function') { resolvedCtor = rawProxyAgent as unknown as HttpsProxyAgentCtor; } -const HttpsProxyAgent = +const baseCtor = resolvedCtor ?? (class { constructor() { @@ -41,24 +43,14 @@ const HttpsProxyAgent = } } as unknown as HttpsProxyAgentCtor); -if (typeof HttpsProxyAgent === 'function') { - try { - Object.defineProperty(HttpsProxyAgent, 'HttpsProxyAgent', { - value: HttpsProxyAgent, - configurable: true, - writable: true, - enumerable: true, - }); - Object.defineProperty(HttpsProxyAgent, 'default', { - value: HttpsProxyAgent, - configurable: true, - writable: true, - enumerable: true, - }); - } catch { - // Safely ignore if the constructor is frozen or properties are non-configurable - } -} +const HttpsProxyAgent = new Proxy(baseCtor, { + get(target, prop, receiver) { + if (prop === 'HttpsProxyAgent' || prop === 'default') { + return receiver; + } + return Reflect.get(target, prop, receiver); + }, +}); export { HttpsProxyAgent }; // eslint-disable-next-line import/no-default-export From b01ec5725666b5ac0cab45136b7c298a6a5987c3 Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Mon, 21 Sep 2026 10:55:57 -0600 Subject: [PATCH 05/10] fix(cli): omit receiver in Reflect.get proxy traps to preserve class target context --- packages/cli/src/patches/http-proxy-agent.ts | 2 +- packages/cli/src/patches/https-proxy-agent.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index c15049289c0..0a588985759 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -48,7 +48,7 @@ const HttpProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop, receiver); + return Reflect.get(target, prop); }, }); diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index 77468729f7a..0c6fc183cee 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -48,7 +48,7 @@ const HttpsProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpsProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop, receiver); + return Reflect.get(target, prop); }, }); From 1b6e0fd7e1bed9a70c55efa363d39e26fd73d187 Mon Sep 17 00:00:00 2001 From: Diego Godinez <119542009+diegogodinezr@users.noreply.github.com> Date: Mon, 21 Sep 2026 10:59:00 -0600 Subject: [PATCH 06/10] Update packages/cli/src/patches/http-proxy-agent.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/patches/http-proxy-agent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 0a588985759..c15049289c0 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -48,7 +48,7 @@ const HttpProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop); + return Reflect.get(target, prop, receiver); }, }); From 19f88e74cd548d66a74c8bdef246b88133efdba7 Mon Sep 17 00:00:00 2001 From: Diego Godinez <119542009+diegogodinezr@users.noreply.github.com> Date: Mon, 21 Sep 2026 10:59:11 -0600 Subject: [PATCH 07/10] Update packages/cli/src/patches/https-proxy-agent.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/patches/https-proxy-agent.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index 0c6fc183cee..77468729f7a 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -48,7 +48,7 @@ const HttpsProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpsProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop); + return Reflect.get(target, prop, receiver); }, }); From 0882f895ab577296b95f3df8e937935053b090ab Mon Sep 17 00:00:00 2001 From: Diego Godinez <119542009+diegogodinezr@users.noreply.github.com> Date: Mon, 21 Sep 2026 11:02:45 -0600 Subject: [PATCH 08/10] Update packages/cli/src/patches/http-proxy-agent.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/patches/http-proxy-agent.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index c15049289c0..1089e787caa 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -48,7 +48,11 @@ const HttpProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop, receiver); + const value = Reflect.get(target, prop); + if (typeof value === 'function') { + return value.bind(target); + } + return value; }, }); From f992a43f0add7a28d690d5dc85eee311c1574c45 Mon Sep 17 00:00:00 2001 From: Diego Godinez <119542009+diegogodinezr@users.noreply.github.com> Date: Mon, 21 Sep 2026 11:02:53 -0600 Subject: [PATCH 09/10] Update packages/cli/src/patches/https-proxy-agent.ts Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> --- packages/cli/src/patches/https-proxy-agent.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index 77468729f7a..eb5f552ae97 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -48,7 +48,11 @@ const HttpsProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpsProxyAgent' || prop === 'default') { return receiver; } - return Reflect.get(target, prop, receiver); + const value = Reflect.get(target, prop); + if (typeof value === 'function') { + return value.bind(target); + } + return value; }, }); From 8b617e973ba94221d549e13734e28a2920fa4e20 Mon Sep 17 00:00:00 2001 From: Diego Godinez Robles Date: Mon, 21 Sep 2026 11:11:48 -0600 Subject: [PATCH 10/10] fix(cli): use standard receiver forwarding in proxy agent get traps --- packages/cli/src/patches/http-proxy-agent.ts | 6 +----- packages/cli/src/patches/https-proxy-agent.ts | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/patches/http-proxy-agent.ts b/packages/cli/src/patches/http-proxy-agent.ts index 1089e787caa..c15049289c0 100644 --- a/packages/cli/src/patches/http-proxy-agent.ts +++ b/packages/cli/src/patches/http-proxy-agent.ts @@ -48,11 +48,7 @@ const HttpProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpProxyAgent' || prop === 'default') { return receiver; } - const value = Reflect.get(target, prop); - if (typeof value === 'function') { - return value.bind(target); - } - return value; + return Reflect.get(target, prop, receiver); }, }); diff --git a/packages/cli/src/patches/https-proxy-agent.ts b/packages/cli/src/patches/https-proxy-agent.ts index eb5f552ae97..77468729f7a 100644 --- a/packages/cli/src/patches/https-proxy-agent.ts +++ b/packages/cli/src/patches/https-proxy-agent.ts @@ -48,11 +48,7 @@ const HttpsProxyAgent = new Proxy(baseCtor, { if (prop === 'HttpsProxyAgent' || prop === 'default') { return receiver; } - const value = Reflect.get(target, prop); - if (typeof value === 'function') { - return value.bind(target); - } - return value; + return Reflect.get(target, prop, receiver); }, });