Files
magpie/internal/testenv
yetone 93e118a578 testenv: a test that runs plugins on a bun older than 1.4.2 is skipped, saying which bun and to install 1.4.2 or newer, not failed on Bun's own differences (#1600, justrun1983)
justrun1983 saw TestPluginModelListThroughAccountProxy fail on main with
"fake-not the list: http://models.invalid:80/list" among the models. The
plugin tests run the bun on PATH (testenv.Bun), and Bun 1.3 names the
default port in a proxy's request line: GET http://models.invalid:80/list,
which Go reads as r.URL.Host "models.invalid:80", so the test's proxy
answered 400 and the fake plugin took the error text as a model. Bun 1.4
sends GET http://models.invalid/list. It wasn't the offline environment:
the test already clears every *_PROXY variable and reaches nothing real.

magpie itself never runs plugins on a Bun older than plugin.BunVersion
(1.4.2, the one it downloads and the floor CheckBun keeps), and CI pins
1.4.2, so an older bun on a developer's PATH tests something no user runs.
On Bun 1.3.0 internal/plugin's TestPluginSOCKSProxy ("vendor
vendor.invalid:80"), TestPluginProxy (the proxy saw
http://vendor.invalid:80/...) and TestPluginHTTP2TakesTheProxy (Bun 1.3's
node:http2 answers status 0, and the host quits) failed the same way.

testenv.Bun now runs `bun --version` once (it already ran it to warm the
binary) and skips with a message naming the bun when it is older than
testenv.MinBun. testenv can't import internal/plugin (whose own tests use
it), so MinBun is a copy, and TestMinBunIsBunVersion fails when it and
plugin.BunVersion differ; BunVersion's comment names it and test.yml's
bun-version.

Run (bun 1.3.0 from npm's @oven/bun-darwin-aarch64 first on PATH, temp
HOME):
- before: gateway TestPluginModelListThroughAccountProxy FAIL with the
  reporter's exact text; plugin TestPluginSOCKSProxy, TestPluginProxy,
  TestPluginHTTP2TakesTheProxy FAIL.
- after: all skipped, packages ok.
A probe of the request line a proxy receives: 1.3.0 sends
http://models.invalid:80/list, 1.4.2 and 1.4.3 http://models.invalid/list.
TestBunOlderThanMinSkips (fake bun printing 1.3.0, 1.4.1, 0.9.9, 1.4.2,
1.4.3-canary, 1.10.0, 2.0.0, nothing) goes red with the skip removed by
hand. With bun 1.4.2: go test -tags nogui ./internal/testenv,
./internal/plugin, ./internal/gateway pass; gofmt -l clean; go vet,
GOOS=linux and GOOS=windows go vet -tags nogui on testenv and plugin pass.
Not run: the full ./... suite, nor the fake-bun test on Windows (it skips
there: the fake is a shell script).
2026-10-11 20:44:39 +08:00
..
gateway, provider tests: the tests stay off the network (testenv.Offline in their TestMains) — after 555f5706 (#1016) routing reads a plan key's quota windows, and a test whose provider has a vendor's real base URL and a made-up key would ask the vendor in the background. Routing's own read (keyAllowance, allowances) was already stubbed in routing_test.go's init, and a survey with a dial guard found no plan-key dial, but it found others: every plugin host's first start fetched models.dev's catalog (65 dials in the gateway's plugin tests), and provider tests asked api.github.com (TestSubscriptionUsageEachAccount, TestSubscriptionUsageServesStale), chatgpt.com (TestCopilotQuotaWithoutEditorsSignIn), server.codeium.com (TestDevinSignedInOnlyInMagpie) and decide.test (TestModelTest) with made-up accounts; each passed whether the vendor answered or not. internal/testenv's Offline wraps http.DefaultTransport's DialContext (so http.DefaultClient and every transport cloned from it later): localhost, *.localhost, loopback and unspecified addresses are dialled, anything else is refused before it is looked up, said once per address on stderr ("testenv: a test asked models.dev:443, refused: tests stay off the network"). internal/gateway's TestMain and internal/provider's (kiro_main_test.go, in RunIn's setup) call it before the tests run. TestLocal (the address table) and TestOffline (a loopback httptest server answers through DefaultClient; models.dev is refused through it and through a Clone made after the call) pass -race -count=3. go test -race -tags nogui -timeout 30m ./internal/testenv ./internal/provider ./internal/gateway passes under a temp HOME (gateway 516 s). The gateway and provider test binaries were then run under sandbox-exec with every non-loopback network-outbound denied, with the kernel's Sandbox reports streamed: both PASS, Offline refused only the six addresses above, and the kernel reported no denial, so no transport outside DefaultTransport reaches the network either. go vet, gofmt -l, linux and windows (nogui) builds pass. Tests only.
2026-10-06 21:08:57 +08:00
gateway, provider tests: the tests stay off the network (testenv.Offline in their TestMains) — after 555f5706 (#1016) routing reads a plan key's quota windows, and a test whose provider has a vendor's real base URL and a made-up key would ask the vendor in the background. Routing's own read (keyAllowance, allowances) was already stubbed in routing_test.go's init, and a survey with a dial guard found no plan-key dial, but it found others: every plugin host's first start fetched models.dev's catalog (65 dials in the gateway's plugin tests), and provider tests asked api.github.com (TestSubscriptionUsageEachAccount, TestSubscriptionUsageServesStale), chatgpt.com (TestCopilotQuotaWithoutEditorsSignIn), server.codeium.com (TestDevinSignedInOnlyInMagpie) and decide.test (TestModelTest) with made-up accounts; each passed whether the vendor answered or not. internal/testenv's Offline wraps http.DefaultTransport's DialContext (so http.DefaultClient and every transport cloned from it later): localhost, *.localhost, loopback and unspecified addresses are dialled, anything else is refused before it is looked up, said once per address on stderr ("testenv: a test asked models.dev:443, refused: tests stay off the network"). internal/gateway's TestMain and internal/provider's (kiro_main_test.go, in RunIn's setup) call it before the tests run. TestLocal (the address table) and TestOffline (a loopback httptest server answers through DefaultClient; models.dev is refused through it and through a Clone made after the call) pass -race -count=3. go test -race -tags nogui -timeout 30m ./internal/testenv ./internal/provider ./internal/gateway passes under a temp HOME (gateway 516 s). The gateway and provider test binaries were then run under sandbox-exec with every non-loopback network-outbound denied, with the kernel's Sandbox reports streamed: both PASS, Offline refused only the six addresses above, and the kernel reported no denial, so no transport outside DefaultTransport reaches the network either. go vet, gofmt -l, linux and windows (nogui) builds pass. Tests only.
2026-10-06 21:08:57 +08:00