fix(tools): make js_execution fetch honor proxy env vars (#3273) - #3577
Conversation
Node's built-in fetch (undici) ignores HTTP_PROXY/HTTPS_PROXY env vars unless NODE_USE_ENV_PROXY is set (Node >= 24), so js_execution could not reach the network through a local proxy/VPN even though CodeWhale and the shell had the proxy variables set — fetch() timed out with an Undici connect error. The js_execution child already inherits CodeWhale's environment, so default NODE_USE_ENV_PROXY=1 to switch Node's built-in proxy handling on; this makes fetch() use the same HTTP(S)_PROXY and honor NO_PROXY as the rest of the app. Only defaulted when unset so an explicit NODE_USE_ENV_PROXY=0 opt-out still wins; no-op on Node < 24.
|
Thanks @LeoLin990405 for taking the time to contribute. This repository is observing a maintainer-managed PR intake gate in dry-run mode, so this pull request is staying open. This note helps maintainers prepare the allowlist before any enforcement is considered. Please read |
This is awesome - thank you so much. I'm working on adding Tailscale comparability so things like this are increasing in value for the project in real time!! |
Problem
Fixes #3273 — on a host with a local proxy/VPN,
js_executioncan't reach the network even though CodeWhale config and the shell both haveHTTP_PROXY/HTTPS_PROXYset.fetch()times out with an Undici connect error, while the shell tools reach the same URL fine.Root cause
Node's built-in
fetch(undici) ignoresHTTP_PROXY/HTTPS_PROXYenvironment variables by default. It only honors them whenNODE_USE_ENV_PROXYis set (equivalent to--use-env-proxy, Node ≥ 24).js_executionspawnsnode script.jsinheriting CodeWhale's environment — so the proxy variables are present in the child, but Node'sfetchnever consults them.Verified locally (Node 26):
Fix
Default
NODE_USE_ENV_PROXY=1on thejs_executionNode child so itsfetch()uses the sameHTTP(S)_PROXY(and honorsNO_PROXY) as the rest of CodeWhale. Only defaulted when the variable is unset, so an explicitNODE_USE_ENV_PROXY=0opt-out still wins. It's a no-op on Node < 24 (the variable is simply ignored), so it's safe across versions — the proper fix for the reporter's Node 22 would be upgrading to Node ≥ 24, but this removes the CodeWhale-side gap for every Node that supports it.Testing
execute_js_enables_env_proxy_so_fetch_honors_proxy_varsspawns the Node child and asserts it seesNODE_USE_ENV_PROXY=1(skipped when Node is absent or the caller already set the variable).cargo clippy -p codewhale-tui --all-featuresclean;cargo test -p codewhale-tui --all-features js_executiongreen.