Files
magpie/internal/testenv/main_test.go
T
ggbdpqandfactory-droid[bot] 1c746a7e85 testenv: the machine's proxy variables no longer stand in a test binary's first routed request (#1570, ggbdpq)
What changed:
- net/http reads HTTPS_PROXY and its siblings once per process, at its
  first routed request. A test binary that lets the machine's stand froze
  that read with the developer's shell: on a machine with https_proxy set,
  whichever test reached net/http first (a plugin host's catalog read was
  the earliest single one) fixed the machine's proxy into every later
  route, and a test that set its own afterwards read the machine's —
  TestSearchFollowsTheSearchersProxy's Auto ask follows ALL_PROXY alone
  for exactly that reason, and its searcher went to a proxy that cannot
  reach the test's servers (red in the full package run, green alone).
  Offline's refused hosts were carried for real by the machine's proxy on
  loopback, red-lining TestOffline the same way.
- testenv.ClearProxy unsets the eight variables. Isolate calls it, and so
  does the gateway's own TestMain (the package isolates itself) and this
  package's new TestMain. TestIsolate now sets a proxy variable and holds
  Isolate to having cleared it.

Run: TestSearchFollowsTheSearchersProxy alone green, red with
TestClinePluginPinsDeepSeek run before it, green again with the fix
(TestClinePluginPinsDeepSeek|TestSearchFollowsTheSearchersProxy); without
ClearProxy the pair is red, TestOffline fails with "models.dev: <nil>"
(the request went through the machine's proxy) and TestIsolate fails with
"HTTPS_PROXY is still set"; both green with it. go test -tags nogui
./internal/testenv ./internal/gateway (the gateway package whole) green.

Review: reproduced on main (3f5702421) with https_proxy, http_proxy and
HTTPS_PROXY set to http://127.0.0.1:1 for the test run: the pair above
fails with "proxyconnect tcp: dial tcp 127.0.0.1:1" (CONNECTs []), and
TestOffline fails the same way, i.e. a vendor host went to the machine's
proxy instead of Offline's refusal. With the change both packages are ok
under the same variables; taking ClearProxy out of Isolate turns
TestIsolate red ("HTTPS_PROXY is still set"), and out of the gateway's
TestMain turns the pair red again. The gateway's is the only TestMain
that isolates itself without testenv.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
2026-10-11 12:00:41 +08:00

16 lines
345 B
Go

package testenv
import (
"os"
"testing"
)
// This package's tests run without the machine's proxy variables too:
// Offline's guard sits below the proxy hop, so one standing on loopback
// carries a refused host for real, and TestOffline then answers
// models.dev through it.
func TestMain(m *testing.M) {
ClearProxy()
os.Exit(m.Run())
}