Skip to content

[Bug]: Offline smoke tests fail when ambient proxy environment variables are set #154

Description

@jimpablo

Product or interface

Source build or repository tooling

Version

Source commit 17b8ded (main, 2026-09-18). Node.js v24.19.0, pnpm 9.12.0 (via Corepack).

Platform

macOS

OS version and architecture

macOS 26.6.2 (build 25G83), arm64

Issue area

Build / CI / source distribution

Desktop log upload ID (optional)

No response

Steps to reproduce

Summary: on machines where any proxy environment variable is set (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, or lowercase variants — common for local/corporate proxies), 3 of 7 pnpm test:smoke tests fail with false "Unexpected outbound network attempt" reports, and pnpm verify therefore stops at the test:smoke gate. CI is unaffected because GitHub runners have no proxy variables. Full root cause analysis and a suggested fix direction are in "Expected and actual behavior" below.

Steps (no real proxy needed — an unreachable synthetic address is enough, the harness flags the connection attempt itself):

  1. Fresh clone of main at 17b8ded; pnpm install --frozen-lockfile and pnpm build both succeed.
  2. Set one synthetic proxy variable (nothing listens on this port):
    export HTTPS_PROXY=http://127.0.0.1:9
  3. Run pnpm test:smoke.

Result: 3 tests fail — "provider configuration loads from an isolated data directory", "ACP starts the real runtime and answers initialize over stdio", "local plugin browsing remains available with managed services offline". Each fails the same way: the audit file written by test/network-deny.mjs exists, containing a network-attempt stack from Socket.connect through minified undici dispatcher frames in dist/chunks/.

  1. Unset and re-run: env -u HTTPS_PROXY pnpm test:smoke → all 7 tests pass. A full pnpm verify with proxy variables unset passes all 14 gates on the same machine, so this is isolated to the interaction between ambient proxy configuration and the offline harness.

Lowercase variants (https_proxy etc.) trigger the same failure — verified with only https_proxy=http://127.0.0.1:9 set.

Expected and actual behavior

Expected: pnpm verify / pnpm test:smoke results are independent of ambient proxy environment variables. test/byok.test.mjs already neutralizes this by blanking HTTP_PROXY / HTTPS_PROXY / ALL_PROXY in its child environment (test/byok.test.mjs:156-158), which suggests the smoke fixture was intended to do the same.

Actual: with any proxy variable set, the three tests above fail solely because the network-audit file exists.

Root cause analysis (from reading the source; happy to be corrected):

  1. The smoke fixture spreads ...process.env, so proxy variables are inherited by every CLI child (test/smoke.test.mjs:33-40).
  2. Every CLI invocation calls configureTuiNetworkProxy before subcommand dispatch (packages/tui/src/cli/main.ts:97-99).
  3. When resolveTuiProxyConfiguration() detects a proxy variable (packages/tui/src/cli/network-proxy.ts:31-49, case-insensitive), configureTuiNetworkProxy() sets a global undici dispatcher wrapping a ProxyAgent and then calls undici.install() (network-proxy.ts:51-67, 105-107), which replaces globalThis.fetch — removing the fetch-level offline mock that test/network-deny.mjs installed via NODE_OPTIONS --import.
  4. All three commands construct the TUI runtime, whose ProviderPresetCatalog constructor starts a background models.dev catalog refresh using the global fetch (packages/local-runtime-v2/src/service/model-system/, provider-presets.service.ts:58-66 → provider-presets.client.ts:25-63 → https://models.dev/api.json). models.dev is on the managed-offline allowlist, so without proxy variables this fetch receives the local 503 fixture and the failure is swallowed.
  5. With proxy variables set, the same fetch dispatches through the ProxyAgent and reaches net.Socket.connect toward the proxy address; the prototype-level hook (network-deny.mjs:37-43) records the attempt and throws, and the fixture's after-hook (smoke.test.mjs:18-30) fails because the audit file exists.

Suggested fix direction: mirror test/byok.test.mjs:156-158 by blanking HTTP_PROXY / HTTPS_PROXY / ALL_PROXY (and the lowercase variants) in the smoke fixture's child env. A belt-and-braces alternative is to neutralize proxy dispatch for all harness children (clear the variables in network-deny.mjs or guard undici.install() when MCODE_TEST_NETWORK_AUDIT is set), which would also protect future fixtures. Per the contribution policy I'm not attaching a PR as a non-collaborator; happy to test any direction you prefer. If a docs-first approach is preferred, documenting the env -u workaround in docs/installation.md or CONTRIBUTING.md would already unblock affected developers.

Related: #82 concerns runtime proxy detection (PAC/SOCKS5) in the product; this report is only about the offline test harness interaction.

Redacted error summary

✖ provider configuration loads from an isolated data directory (1062ms)
  AssertionError [ERR_ASSERTION]: Error: network-attempt
      at denied (file:///…/test/network-deny.mjs:19:56)
      at Socket.connect (file:///…/test/network-deny.mjs:42:10)
      at Object.connect (node:net:254:17)
      … minified undici dispatcher frames in dist/chunks/
  true !== false  (test/smoke.test.mjs:20:14 — after-hook asserts the audit file does not exist)

# Synthetic address 127.0.0.1:9 used; no real proxy, credential, or private data involved.

Screenshots

No response

Before submitting

  • I have searched existing issues.
  • I have included my version and removed sensitive information.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions