Repository navigation
fix(core): normalize proxy-agent esbuild interop for environment proxy resolution - #29401
DavidAPierce merged 12 commits into
Conversation
…y 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 google-gemini#26533
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses issues with CJS/ESM interop for proxy agents within the esbuild bundle pipeline. By normalizing how these modules are exported and consumed, it ensures that developers can reliably use both named and default imports without encountering runtime resolution errors. The changes also centralize the patch configuration to maintain consistency across various build targets. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
|
📊 PR Size: size/L
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the http-proxy-agent and https-proxy-agent patches to improve CJS/ESM interop, moves their aliases to common aliases in esbuild.config.js, and expands the test suite to verify static/dynamic imports and proxy environment variables. The review feedback identifies a potential runtime TypeError in strict mode caused by directly mutating the imported constructor functions. To prevent crashes, it is recommended to use Object.defineProperty wrapped in a try-catch block to safely assign the self-referential properties.
There was a problem hiding this comment.
Code Review
This pull request refactors the proxy agent aliases in esbuild.config.js to be shared under commonAliases, updates the http-proxy-agent and https-proxy-agent patches to support robust ESM/CJS interop, and expands the test suite to verify static/dynamic imports and environment-based proxy instantiation. The review feedback suggests further strengthening the interop resolution in both patches to handle cases where mod.default is an object containing the named exports rather than the constructor function itself.
…roperty 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 google-gemini#26533
|
Applied requested review updates:
|
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the proxy agent patches for http-proxy-agent and https-proxy-agent to improve ESM/CJS interop handling during bundling, moving their aliases to commonAliases in esbuild.config.js and adding comprehensive tests. The feedback highlights a potential runtime safety issue in both patches where resolvedCtor is initialized with the raw namespace object, which could lead to a TypeError if none of the interop conditions match. It is recommended to initialize the constructor as undefined and fall back to a dummy class that throws a clear error upon instantiation.
…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 google-gemini#26533
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the http-proxy-agent and https-proxy-agent patches to improve ESM/CJS interop and robustly resolve constructors under different import styles. It also updates the esbuild configuration to apply these aliases globally and expands the test suite to verify static/dynamic imports and proxy environment variables. Feedback on the PR suggests using a Proxy object instead of mutating the resolved constructor directly to avoid side-effects and handle potentially frozen constructors more safely.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the http-proxy-agent and https-proxy-agent patches to use a Proxy-based wrapper, ensuring robust CommonJS/ESM interop and self-referential property support. It also moves these aliases to the common configuration in esbuild.config.js and expands the test suite to cover static/dynamic imports and proxy environment variables. The review feedback recommends omitting the receiver argument from Reflect.get in both proxy patches to avoid potential this-binding issues or runtime errors with private static members.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the http-proxy-agent and https-proxy-agent patches to improve CommonJS/ESM interop and adds comprehensive bundling tests. Specifically, it moves the proxy agent aliases to commonAliases in esbuild.config.js, wraps the resolved constructors in a Proxy to support both default and named exports, and expands the test suite to verify these behaviors under various import styles and environment configurations. The feedback recommends passing the receiver argument to Reflect.get in the Proxy get traps of both patch files to ensure the correct this context is preserved during property access.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the 'http-proxy-agent' and 'https-proxy-agent' patches to improve ESM/CJS interop and adds comprehensive bundling and environment variable tests. Feedback highlights a potential issue in both patches where using 'Reflect.get' with the proxy as the receiver can break static getters or methods on the class constructor; the reviewer suggests binding retrieved functions to the target constructor instead.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the http-proxy-agent and https-proxy-agent patches to improve ESM/CJS interop by dynamically resolving constructors and wrapping them in a Proxy, alongside updating the esbuild configuration and expanding bundle tests. However, the Proxy implementation in both patches binds all retrieved functions to the target, which strips their prototype property and breaks subclassing. It is recommended to use standard receiver-forwarding with Reflect.get(target, prop, receiver) instead.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the esbuild configuration to use custom patches for http-proxy-agent and https-proxy-agent to improve ESM/CJS interop. It also enhances the corresponding test suite to verify both static and dynamic imports, as well as proxy agent instantiation when environment variables are set. There are no review comments to address.
Summary
Normalizes the CJS/ESM interop handling and export structures for
https-proxy-agentandhttp-proxy-agentwithin the esbuild bundle pipeline to ensure consistent constructor resolution across static, dynamic, named, and default imports.Details
packages/cli/src/patches/https-proxy-agent.tsandhttp-proxy-agent.tsto safely normalize constructor resolution (raw.HttpsProxyAgent || raw.default || raw), export both named and default constructors, and attach self-referential properties on the constructor function (HttpsProxyAgent.HttpsProxyAgentandHttpsProxyAgent.default) for full cross-module compatibility.https-proxy-agentandhttp-proxy-agentpatch aliases intocommonAliasesinesbuild.config.jsso that all build configurations (cliConfig,workerConfig,a2aServerConfig) resolve proxy modules consistently.scripts/tests/proxy-agent-bundle.test.tsto validate named and default export resolution, constructability, and instantiation withHTTP_PROXY/HTTPS_PROXYenvironment variables set.Type of Change
Related Issues
Closes #26533
How to Validate
npm test -w @google/gemini-cli-core -- src/core/contentGenerator.test.tsPre-Merge Checklist