With only a SOCKS system proxy on macOS (127.0.0.1:4401), every plugin
install failed: netproxy.Env put socks5://… in bun add's *_PROXY, and Bun
takes only http:// and https:// proxies, so it stopped with
"UnsupportedProxyProtocol downloading package manifest". The plugin
host's own fetches already went through netproxy.Bridge (hostEnv), but
bunCommand, which runs bun add, update and remove, did not.
- netproxy.EnvForBun rewrites a SOCKS5 HTTPS_PROXY/HTTP_PROXY/ALL_PROXY
(any case) to the loopback HTTP bridge in front of it; others as they are.
- bunCommand uses it, so add, update, remove and the host's run all get it.
- Sibling: an agent CLI installed with bun is updated by `bun add -g`
with the same env (updateEnv in cliupdate.go); npm is left as it is.
- provider-plugins.md says so.
Run:
- TestInstallThroughSOCKSProxy (real bun 1.4.2, fake registry, SOCKS
proxy only): on the old bunCommand it fails with the reporter's exact
"error: UnsupportedProxyProtocol downloading package manifest"; passes
with the fix, through the SOCKS proxy.
- TestEnvForBunBridgesSystemSOCKS (system SOCKS proxy via Env) and
TestUpdateWithBunBridgesSOCKS fail with EnvForBun / the bun branch
broken ("bun is given …socks5://…"), pass with it.
- Real use: a throwaway test with a real SOCKS5 server and only
*_PROXY=socks5://… installed @magpie-community/opencode-cursor-auth
0.2.2 from registry.npmjs.org through it; on the old code the same
failed as UnsupportedProxyProtocol. Scratch HOME, not committed.
- gofmt -l clean; go vet ./...; GOOS=linux go vet -tags nogui ./...;
GOOS=windows go vet ./...; go build; GOOS=linux go build -tags nogui;
GOOS=windows go build; go test -tags nogui ./... (scratch HOME) all ok.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
// With only a SOCKS5 proxy, which a Mac's system SOCKS proxy hands bun
|
|
// through netproxy.Env, a plugin still installs (#1409): bun takes only
|
|
// http:// and https:// proxies, and every registry fetch failed as
|
|
// UnsupportedProxyProtocol. bunCommand bridges it, for add, update and
|
|
// remove alike, and the install goes through the SOCKS proxy.
|
|
func TestInstallThroughSOCKSProxy(t *testing.T) {
|
|
sandbox(t)
|
|
const pkg = "@magpie-community/opencode-socks-auth"
|
|
heldRegistry(t, pkg, map[string]time.Time{"0.1.0": time.Now().Add(-72 * time.Hour)}, "0.1.0")
|
|
reg, _ := url.Parse(npmRegistry)
|
|
socks, carried := socksTo(t, reg.Host)
|
|
for _, k := range []string{"HTTPS_PROXY", "https_proxy", "HTTP_PROXY", "http_proxy", "ALL_PROXY", "all_proxy"} {
|
|
t.Setenv(k, socks)
|
|
}
|
|
t.Setenv("NO_PROXY", "")
|
|
t.Setenv("no_proxy", "")
|
|
|
|
for _, kv := range bunCommand(context.Background(), "bun", t.TempDir(), "add", "x").Env {
|
|
if k, v, _ := strings.Cut(kv, "="); strings.HasSuffix(strings.ToUpper(k), "_PROXY") && strings.HasPrefix(v, "socks") {
|
|
t.Fatalf("bun is given %s", kv)
|
|
}
|
|
}
|
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
|
defer cancel()
|
|
e, err := Add(ctx, pkg)
|
|
if err != nil {
|
|
t.Fatalf("add: %v", err)
|
|
}
|
|
if v := Version(e.Spec); v != "0.1.0" {
|
|
t.Fatalf("installed %q", v)
|
|
}
|
|
if carried.Load() == 0 {
|
|
t.Fatal("the install didn't go through the SOCKS proxy")
|
|
}
|
|
}
|