agent: Codex's proxy is worked out from the login shell's NO_PROXY and HTTP_PROXY and macOS' HTTP entry alone, as its reqwest reads them, so "Codex 经代理连 magpie" no longer shows while Codex goes direct (liu_dyj on X)
liu_dyj: with the VPN on, magpie said Codex reached magpie through a
proxy that didn't pass its requests on; versions before f156d9046 had
no such check, which is why upgrading brought it.
Cause: codexProxyFor didn't read the proxy the way Codex does.
- It read magpie's own environment. Codex in a terminal has the login
shell's, and the ChatGPT app's Codex too (ChatGPT.app 26.1007 runs
$SHELL -ilc at start and Object.assign()s its env into process.env).
magpie opened from the Dock has neither, so a NO_PROXY=127.0.0.1 in
.zshrc, which keeps Codex direct, wasn't seen, and magpie probed the
system proxy and warned.
- For the system proxy it took netproxy's one URL (HTTPS over HTTP over
SOCKS). hyper-util 0.1.20's Matcher::from_system, which reqwest
0.12.28 uses for Codex, takes only macOS' HTTP entry for an http://
URL; with only the HTTPS or SOCKS entry set (ShadowsocksX-NG's global
mode is SOCKS only) Codex goes direct and magpie warned. On Windows
it takes ProxyServer as one address, which a per-protocol list
("http=..;https=..") isn't (http's Authority::parse refuses two
colons), so Codex goes direct there too.
- With respect_system_proxy on macOS, CFNetwork's SOCKS entry is
UnsupportedProxyScheme, and Codex falls back to HTTP_PROXY/ALL_PROXY
with NO_PROXY (codex-rs outbound_proxy.rs resolve_env_proxy_route);
magpie used the SOCKS URL.
- The probe spoke real SOCKS5 to a socks5:// proxy. Codex's reqwest is
built without SOCKS (no tokio-socks in codex-rs Cargo.lock) and sends
an absolute-URI HTTP request to it, so the probe now does the same:
it passes a Clash mixed port as Codex does and fails a SOCKS-only
port as Codex does.
So netproxy.Proxy carries the HTTP and SOCKS entries alone beside URL
(parseScutil, parseWindows), proc asks the login shell for the
*_PROXY variables with agentenv.Vars in the same probe and only reads
them (proc.LoginEnv; never set in magpie's env, whose requests use
netproxy), and codexProxyFor uses both. Failover's gate
(codexProxyOK) and the drift share codexProxyFor and proxyProbe, so
both follow. The pill's How to fix now names the shell profile for
NO_PROXY. Clash/mihomo rule mode with a 127.0.0.0/8 DIRECT rule never
warned and still doesn't; global mode or a rule set without it still
warns, rightly (real codex 502s there). TUN mode sets no proxy and
never warned.
Run:
- real codex-cli 0.162.1 in a sandbox HOME/CODEX_HOME against a fake
gateway and mihomo v1.19.32 (rule, no-LAN-rule, global ports):
direct, rule, and ALL_PROXY=socks5:// on the rule port reach the
gateway; no-LAN-rule and global 502; global with NO_PROXY=127.0.0.1
reaches it. The Go probe agrees on every one.
- go test -tags nogui ./internal/agent, ./internal/netproxy,
./internal/proc; gofmt -l; GOOS=linux and GOOS=windows go vet
-tags nogui on the three packages.
- Broke each part by hand: sys.URL back in codexProxyFor (Windows per
protocol, macOS HTTPS/SOCKS alone red), the probe's socks->http
(TestRealProxyProbe red), codexEnv without the login shell
(TestCodexEnvTakesLoginShell red), the respect-path SOCKS fallback
(three respect cases red), setUnset of every shell var and the probe
without ProxyVars (TestLoginEnvProxyVarsNotSet red).
Not tried: the macOS system proxy cases with real Codex (changing the
system's proxy settings is off limits here; read from hyper-util,
reqwest and codex-rs sources), the Windows per-protocol ProxyServer
with real Codex (from the http crate's source; no Windows run), and
the reporter's own app and mode, which are asked on X.
This commit is contained in:
@@ -62,7 +62,7 @@ something else shows up as drift.
|
||||
- A value an agent spells as its own provider's model is never taken for one of magpie's, even when magpie has a provider of the same name (`Spelled`, #835).
|
||||
- `Reapply` on `unwired` sets again every field on one of magpie's models and every field set to magpie itself (`magpieID`, as `Wired` takes it): Claude Desktop's drift shows on a tier, and its `provider` field is what writes the gateway back (dumplings on Discord). Claude Desktop's `Check` judges only the set of folders whose Claude-3p it ran in last (`desktopRead`, by `desktopdir.LastRun`), every set when it ran in none: magpie writes both of an MSIX install's sets, and 2.31226 reads the real `%LOCALAPPDATA%\Claude-3p`, so the package's copy being emptied is not Desktop off magpie.
|
||||
- `unreachable` never sets anything: the config is right, and the page's pill only says what has to listen. The exception is an address a WSL distro reached Windows at before (`distro.Was`, kept in `wsl.json`) while it reaches Windows at another now: the pill offers that one, and `Reapply` moves the config there (`Agent.move`, Codex's `codexMoveGateway`). An address no distro was seen at is the user's own and is never moved. An unknown answer (no probe yet) and a gateway down on loopback too are not drift. Tests stub `reachProbe` in `TestMain`.
|
||||
- `proxied` (Muma102kMichael on X: every project and every new chat 502 after magpie took Codex over) is this machine's Codex sending its requests for the gateway through a proxy that doesn't pass them on, while the gateway answers here ([`codex_proxy.go`](../../internal/agent/codex_proxy.go)). Codex's reqwest takes `HTTP_PROXY`/`ALL_PROXY`, else the system's proxy, and lets only an exact IP or a CIDR in `NO_PROXY` (on Windows, with no `NO_PROXY`, the bypass list with `*.` taken out) keep 127.0.0.1 off it: `127.*` and `localhost` don't, and macOS' exceptions aren't read. With `[features] respect_system_proxy` it asks the system alone, matching its list itself, wildcards and `<local>` included, and goes direct when no proxy is set there (codex-rs `outbound_proxy`; tried with codex-cli 0.162.1). `codexProxyFor` works out that proxy the same way, and a `GET /` through it must come back as magpie's (`proxyProbe`), tried as `reachable` is. Its pill says how to fix it, as `unreachable`'s does, and the dialog has Disconnect from magpie. Account failover, which magpie writes uninvited, waits for that probe (`codexProxyOK`) and isn't written while the proxy doesn't pass Codex on, and one it wrote goes again. Tests stub the env, the system proxy and `proxyProbe` in `TestMain`.
|
||||
- `proxied` (Muma102kMichael on X: every project and every new chat 502 after magpie took Codex over) is this machine's Codex sending its requests for the gateway through a proxy that doesn't pass them on, while the gateway answers here ([`codex_proxy.go`](../../internal/agent/codex_proxy.go)). Codex's reqwest takes `HTTP_PROXY`, else the system's proxy for `http://` (macOS' HTTP entry alone, never its HTTPS or SOCKS one; Windows' `ProxyServer` only when it is one address for every protocol), else `ALL_PROXY`, and lets only an exact IP or a CIDR in `NO_PROXY` (on Windows, with no `NO_PROXY`, the bypass list with `*.` taken out) keep 127.0.0.1 off it: `127.*` and `localhost` don't, and macOS' exceptions aren't read. With `[features] respect_system_proxy` it asks the system alone, matching its list itself, wildcards and `<local>` included, and goes direct when no proxy is set there; a macOS SOCKS entry alone it can't use, and takes `HTTP_PROXY`/`ALL_PROXY` then (codex-rs `outbound_proxy`; tried with codex-cli 0.162.1). Its reqwest has no SOCKS, so a `socks5://` proxy is spoken to as an HTTP one, and the probe does the same. The environment is Codex's: the login shell's `*_PROXY` (`proc.LoginEnv`, which a terminal's Codex and the ChatGPT app's both have) over magpie's own, which a magpie opened from the Dock lacks (liu_dyj on X: a `NO_PROXY=127.0.0.1` in the profile, or a macOS proxy with no HTTP entry, warned while Codex went direct). `codexProxyFor` works out that proxy the same way, and a `GET /` through it must come back as magpie's (`proxyProbe`), tried as `reachable` is. Its pill says how to fix it, as `unreachable`'s does, and the dialog has Disconnect from magpie. Account failover, which magpie writes uninvited, waits for that probe (`codexProxyOK`) and isn't written while the proxy doesn't pass Codex on, and one it wrote goes again. Tests stub the env, the system proxy and `proxyProbe` in `TestMain`.
|
||||
- Listing never starts a stopped WSL distro. A stopped distro's agent shows what was last seen there (`asleep`, `wsl.json`); setting one of its fields writes its files, which starts the distro.
|
||||
- Codex's sign-in (`login`) is ChatGPT (`""`, the default), Always ChatGPT (`chatgpt`) or magpie API (`api`). With ChatGPT, magpie's models join Codex's own beside the sign-in (`openai_base_url`), and while the Codex app holds the ChatGPT account Codex is signed in to (`codexUsedUp`, `provider.CodexUsedUp`: OpenAI no longer allows the account and it has no credits left, a workspace still within its overage excepted), magpie is made Codex's provider (`codex.out`): the Codex app sends nothing at all on an account it holds, a magpie model's turn included (#540), and as a provider of its own magpie is past that. A window at 100% with credits left doesn't count, and Codex stays signed in. Sync puts it back beside the sign-in once the account has room. Always ChatGPT never does that: Codex stays in its ChatGPT state, and the Codex app may send nothing till the account has room, while Codex CLI's turns still reach magpie by the base URL, and its routing and other accounts serve them.
|
||||
- Codex signed in to ChatGPT and not connected still gets `openai_base_url` while more of its ChatGPT accounts are on in magpie (`failover`, stash `codex.failover`; with a CC Switch mirror as its provider, the mirror's `base_url` and `codex.mirror_failover`), so a turn its own account has no allowance for goes on to the next. That Codex is `FailingOver`: not `Wired`, yet its requests go through magpie. The Agents row says so and what turns it off (`FailoverSaid` in the CLI and TUI, `failover` in `/api/state`, a button to Providers › Codex in the GUI), and the gateway hands it only its own models from `/backend-api/codex/models` (`CodexOwnOnly`, set on `gateway.CodexOwnOnly` by main; its ETag carries `provider.CodexOwnListTag`, and Sync ages a `models_cache.json` without it). A connected WSL Codex shares the gateway path, so while one is connected every Codex gets magpie's models (#1385). A base URL the user wrote by hand (#856) isn't failover's and stays a plain not-connected row. A Codex the user disconnected gets no failover till they connect it again. The app serving the gateway takes failover out as it quits (`EndFailover`, `EndCodexFailover` in `OnShutdown`), so a Codex left on its own goes straight to OpenAI rather than retrying a gateway that's gone (Leon920717 on X); the next start's Sync writes it again. Codex's app-server read the old base URL as it started and keeps it, and `KeepCodexDaemonCurrent` ends with magpie, so `EndCodexFailover` restarts it there when no codex session is on it (`codexDaemonCheck`); with one on it, it stays on the gone gateway until the user restarts it (thisisvainxx on X: "several restarts"). A connected Codex keeps magpie as it quits: its model is one of magpie's, and Disconnect is what puts its own config back. A magpie that ends without quitting (killed, a crash, `magpie serve`) leaves failover in place.
|
||||
@@ -87,7 +87,7 @@ go test -tags nogui ./internal/agent -run '^TestAstrBot'
|
||||
go test -tags nogui ./internal/agent -run '^TestJcode'
|
||||
go test -tags nogui ./internal/agent -run '^TestGrokApp'
|
||||
go test -tags nogui ./internal/agent -run '^TestPlugged'
|
||||
go test -tags nogui ./internal/agent -run 'TestCodexFailoverOnlyKeepsOwnModels|TestCodexOwnModelThroughMagpieWhileAccountsOn|TestCodexHandWrittenBaseURLStays|TestCodexProxyFor|TestRealProxyProbe|TestCodexFailoverHeldWhileProxyDoesNotPassOn|TestCodexProxiedDrift|TestCodexFailoverEndsWithMagpie|TestCodexMirrorFailoverHeldAndEndsWithMagpie'
|
||||
go test -tags nogui ./internal/agent -run 'TestCodexFailoverOnlyKeepsOwnModels|TestCodexOwnModelThroughMagpieWhileAccountsOn|TestCodexHandWrittenBaseURLStays|TestCodexProxyFor|TestRealProxyProbe|TestCodexEnvTakesLoginShell|TestCodexFailoverHeldWhileProxyDoesNotPassOn|TestCodexProxiedDrift|TestCodexFailoverEndsWithMagpie|TestCodexMirrorFailoverHeldAndEndsWithMagpie'
|
||||
go test -tags nogui ./internal/agent -run 'TestDisconnectStaysThroughSync|TestCodexDisconnectStaysWithAccountsOn|TestCodexAPIDisconnectStays'
|
||||
go test -tags nogui ./internal/tune ./internal/agent -run 'TestCompact|TestCacheTTL|TestTune'
|
||||
node --test internal/gui/tests/context-tune.test.cjs
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/yetone/magpie/internal/edit"
|
||||
"github.com/yetone/magpie/internal/netproxy"
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
// Codex sends its requests to magpie's gateway, http://127.0.0.1:3425, the
|
||||
@@ -20,8 +21,10 @@ import (
|
||||
// on X: every project and every new chat 502, "a local gateway config and a
|
||||
// proxy switch, two pitfalls stacked"). Its HTTP client is reqwest with its
|
||||
// default features (codex-rs Cargo.toml), whose proxy is hyper-util's
|
||||
// Matcher::from_system: HTTP_PROXY/ALL_PROXY, else the system's proxy
|
||||
// (Windows' Internet Options, macOS' network settings), and nothing goes
|
||||
// Matcher::from_system: HTTP_PROXY, else the system's proxy for http://
|
||||
// (Windows' Internet Options when it names one proxy for all, macOS' "Web
|
||||
// proxy (HTTP)" entry alone: never its HTTPS or SOCKS one), else ALL_PROXY,
|
||||
// and nothing goes
|
||||
// around it but what NO_PROXY names — or, with no NO_PROXY, Windows'
|
||||
// ProxyOverride — as an IP, a CIDR or "*" for an address: "127.*" and
|
||||
// "localhost" there don't keep 127.0.0.1 off it, and macOS' exceptions
|
||||
@@ -31,7 +34,15 @@ import (
|
||||
// them. With [features] respect_system_proxy (codex-rs outbound_proxy),
|
||||
// Codex asks the system alone: Windows' bypass list is matched with its
|
||||
// wildcards and <local>, macOS' exceptions likewise, and with no proxy set
|
||||
// there it goes direct.
|
||||
// there it goes direct; a SOCKS one alone on macOS it can't use, and takes
|
||||
// HTTP_PROXY/ALL_PROXY then. reqwest is built without SOCKS (codex-rs'
|
||||
// Cargo.lock has no tokio-socks), so a socks5:// proxy in ALL_PROXY is
|
||||
// spoken to as an HTTP one.
|
||||
//
|
||||
// The environment is the one Codex runs with: a terminal's, or, for the
|
||||
// ChatGPT app's Codex, the login shell's, which the app takes as it opens.
|
||||
// magpie opened from the Dock has neither, so the login shell's are asked
|
||||
// (proc.LoginEnv), over magpie's own.
|
||||
//
|
||||
// So before magpie hands Codex's requests to the gateway uninvited (account
|
||||
// failover), and while it has them, it asks the way Codex would go: through
|
||||
@@ -39,13 +50,22 @@ import (
|
||||
// kind "proxied").
|
||||
|
||||
// codexProxyEnv, codexSystemProxy and codexProxyOS are what codexProxyFor
|
||||
// reads; vars so tests can say.
|
||||
// reads, and loginEnv what codexEnv does; vars so tests can say.
|
||||
var (
|
||||
codexProxyEnv = os.Getenv
|
||||
codexProxyEnv = codexEnv
|
||||
codexSystemProxy = netproxy.System
|
||||
codexProxyOS = runtime.GOOS
|
||||
loginEnv = proc.LoginEnv
|
||||
)
|
||||
|
||||
// codexEnv is k as Codex has it: the login shell's, else magpie's own.
|
||||
func codexEnv(k string) string {
|
||||
if v := loginEnv(k); v != "" {
|
||||
return v
|
||||
}
|
||||
return os.Getenv(k)
|
||||
}
|
||||
|
||||
// codexProxyFor is the proxy this machine's Codex, configured by the
|
||||
// config.toml at cfg, sends a request for base through, and where that
|
||||
// proxy is set ("HTTP_PROXY", "the system's proxy settings"); "" when it
|
||||
@@ -77,16 +97,36 @@ func codexProxyFor(cfg, base string) (proxy, from string) {
|
||||
if sys.URL == "" || systemBypassed(host, sys.Bypass) {
|
||||
return "", ""
|
||||
}
|
||||
return sys.URL, systemProxyName()
|
||||
if codexProxyOS != "darwin" {
|
||||
return sys.URL, systemProxyName()
|
||||
}
|
||||
// CFNetwork's answer for an http:// URL: the HTTP entry (the HTTPS
|
||||
// one is for https:// alone); a SOCKS one Codex can't use, and
|
||||
// takes HTTP_PROXY/ALL_PROXY instead (codex-rs outbound_proxy:
|
||||
// UnsupportedProxyScheme, then resolve_env_proxy_route)
|
||||
switch {
|
||||
case sys.HTTP != "":
|
||||
return sys.HTTP, systemProxyName()
|
||||
case sys.SOCKS == "":
|
||||
return "", ""
|
||||
}
|
||||
p, k := env(httpKeys...), httpKeys[0]
|
||||
if p == "" {
|
||||
p, k = env("ALL_PROXY", "all_proxy"), "ALL_PROXY"
|
||||
}
|
||||
if p == "" || reqwestNoProxy(host, env("NO_PROXY", "no_proxy")) {
|
||||
return "", ""
|
||||
}
|
||||
return p, k
|
||||
}
|
||||
// reqwest's: each of the environment's first, the system's where it
|
||||
// names none, then ALL_PROXY; NO_PROXY, or Windows' bypass list without
|
||||
// it, goes around them
|
||||
// reqwest's: each of the environment's first, the system's for
|
||||
// http:// where it names none, then ALL_PROXY; NO_PROXY, or Windows'
|
||||
// bypass list without it, goes around them
|
||||
p, k := env(httpKeys...), httpKeys[0]
|
||||
no := env("NO_PROXY", "no_proxy")
|
||||
sys := codexSystemProxy()
|
||||
if p == "" && sys.URL != "" {
|
||||
p, k = sys.URL, systemProxyName()
|
||||
if p == "" && sys.HTTP != "" {
|
||||
p, k = sys.HTTP, systemProxyName()
|
||||
}
|
||||
if p == "" {
|
||||
p, k = env("ALL_PROXY", "all_proxy"), "ALL_PROXY"
|
||||
@@ -170,7 +210,9 @@ func systemBypassed(host string, bypass []string) bool {
|
||||
|
||||
// proxyProbe says whether a request for base sent through proxy is answered
|
||||
// by magpie: its gateway's GET / names it. A proxy's own 502, or anything
|
||||
// else that isn't magpie, is not. A var for tests.
|
||||
// else that isn't magpie, is not. A socks proxy is asked as Codex asks it:
|
||||
// as an HTTP one at the same address, since its reqwest has no SOCKS. A var
|
||||
// for tests.
|
||||
var proxyProbe = realProxyProbe
|
||||
|
||||
func realProxyProbe(base, proxy string) bool {
|
||||
@@ -178,6 +220,9 @@ func realProxyProbe(base, proxy string) bool {
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
if strings.HasPrefix(strings.ToLower(p.Scheme), "socks") {
|
||||
p.Scheme = "http"
|
||||
}
|
||||
c := &http.Client{Timeout: 3 * time.Second, Transport: &http.Transport{Proxy: http.ProxyURL(p)}}
|
||||
res, err := c.Get(strings.TrimSuffix(base, "/") + "/")
|
||||
if err != nil {
|
||||
@@ -218,11 +263,11 @@ func codexProxiedDetail(base, proxy, from string) string {
|
||||
"Have the proxy send 127.0.0.1 direct (a DIRECT rule for 127.0.0.0/8, or rule mode rather than global), "
|
||||
switch {
|
||||
case strings.Contains(from, "PROXY"):
|
||||
d += "or add 127.0.0.1 to NO_PROXY, "
|
||||
d += "or add 127.0.0.1 to NO_PROXY where " + from + " is set (your shell profile, such as ~/.zshrc, if it's there), "
|
||||
case codexProxyOS == "windows":
|
||||
d += "or add 127.0.0.1 to \"Don't use the proxy server for addresses beginning with\" in Windows' proxy settings (127.* there is not enough for Codex), "
|
||||
default:
|
||||
d += "or set NO_PROXY=127.0.0.1 for Codex, "
|
||||
d += "or add export NO_PROXY=127.0.0.1 to your shell profile (~/.zshrc): Codex in a terminal and the ChatGPT app's Codex both read it, "
|
||||
}
|
||||
return d + "then quit and reopen Codex. Until then, Disconnect from magpie puts Codex's config back as it was."
|
||||
}
|
||||
|
||||
@@ -5,11 +5,13 @@ import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -46,7 +48,13 @@ func TestCodexProxyFor(t *testing.T) {
|
||||
os.WriteFile(plain, []byte("model = \"gpt-5.5\"\n"), 0o600)
|
||||
respect := filepath.Join(t.TempDir(), "config.toml")
|
||||
os.WriteFile(respect, []byte("model = \"gpt-5.5\"\n\n[features]\nrespect_system_proxy = true\n"), 0o600)
|
||||
win := netproxy.Proxy{URL: clash, Bypass: []string{"localhost", "127.*", "<local>"}}
|
||||
win := netproxy.Proxy{URL: clash, HTTP: clash, Bypass: []string{"localhost", "127.*", "<local>"}}
|
||||
socks := "socks5://127.0.0.1:7891"
|
||||
// macOS' entries as scutil reads them: "Web proxy (HTTP)" and "Secure
|
||||
// web proxy (HTTPS)" set, or only one of HTTPS and SOCKS
|
||||
mac := netproxy.Proxy{URL: "http://127.0.0.1:7892", HTTP: clash, Bypass: []string{"127.0.0.1", "localhost"}}
|
||||
macHTTPS := netproxy.Proxy{URL: clash, Bypass: []string{"127.0.0.1"}}
|
||||
macSOCKS := netproxy.Proxy{URL: socks, SOCKS: socks, Bypass: []string{"*.local"}}
|
||||
cases := []struct {
|
||||
name string
|
||||
cfg string
|
||||
@@ -66,11 +74,24 @@ func TestCodexProxyFor(t *testing.T) {
|
||||
// the reporter's: Windows' proxy on, with 127.* in its bypass list,
|
||||
// which reqwest doesn't read as 127.0.0.1
|
||||
{"Windows 127.*", plain, nil, win, "windows", clash},
|
||||
{"Windows 127.0.0.1", plain, nil, netproxy.Proxy{URL: clash, Bypass: []string{"127.0.0.1"}}, "windows", ""},
|
||||
{"Windows NO_PROXY wins over its list", plain, map[string]string{"NO_PROXY": "example.com"}, netproxy.Proxy{URL: clash, Bypass: []string{"127.0.0.1"}}, "windows", clash},
|
||||
{"macOS exceptions not read", plain, nil, netproxy.Proxy{URL: clash, Bypass: []string{"127.0.0.1"}}, "darwin", clash},
|
||||
{"Windows 127.0.0.1", plain, nil, netproxy.Proxy{URL: clash, HTTP: clash, Bypass: []string{"127.0.0.1"}}, "windows", ""},
|
||||
{"Windows NO_PROXY wins over its list", plain, map[string]string{"NO_PROXY": "example.com"}, netproxy.Proxy{URL: clash, HTTP: clash, Bypass: []string{"127.0.0.1"}}, "windows", clash},
|
||||
// a ProxyServer per protocol is no address to reqwest: direct
|
||||
{"Windows per protocol", plain, nil, netproxy.Proxy{URL: clash, SOCKS: socks}, "windows", ""},
|
||||
{"macOS exceptions not read", plain, nil, mac, "darwin", clash},
|
||||
// liu_dyj on X: reqwest takes macOS' HTTP entry alone for an
|
||||
// http:// URL; with only HTTPS or SOCKS set Codex goes direct
|
||||
{"macOS HTTPS entry alone", plain, nil, macHTTPS, "darwin", ""},
|
||||
{"macOS SOCKS entry alone", plain, nil, macSOCKS, "darwin", ""},
|
||||
{"macOS SOCKS entry, ALL_PROXY", plain, map[string]string{"ALL_PROXY": socks}, macSOCKS, "darwin", socks},
|
||||
{"respect: Windows 127.* goes around", respect, nil, win, "windows", ""},
|
||||
{"respect: system proxy", respect, nil, netproxy.Proxy{URL: clash, Bypass: []string{"*.local"}}, "darwin", clash},
|
||||
{"respect: system proxy", respect, nil, netproxy.Proxy{URL: clash, HTTP: clash, Bypass: []string{"*.local"}}, "darwin", clash},
|
||||
{"respect: macOS exceptions", respect, nil, mac, "darwin", ""},
|
||||
{"respect: macOS HTTPS entry alone", respect, map[string]string{"HTTP_PROXY": clash}, macHTTPS, "darwin", ""},
|
||||
// a SOCKS entry Codex can't use: the environment's then
|
||||
{"respect: macOS SOCKS entry, no env", respect, nil, macSOCKS, "darwin", ""},
|
||||
{"respect: macOS SOCKS entry, HTTP_PROXY", respect, map[string]string{"HTTP_PROXY": clash}, macSOCKS, "darwin", clash},
|
||||
{"respect: macOS SOCKS entry, NO_PROXY", respect, map[string]string{"ALL_PROXY": socks, "NO_PROXY": "127.0.0.1"}, macSOCKS, "darwin", ""},
|
||||
// the system says direct, and the environment isn't asked (codex-cli
|
||||
// 0.162.1 with HTTP_PROXY set sent nothing to it)
|
||||
{"respect: no system proxy, env not read", respect, map[string]string{"HTTP_PROXY": clash}, netproxy.Proxy{}, "darwin", ""},
|
||||
@@ -85,6 +106,31 @@ func TestCodexProxyFor(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// liu_dyj on X: magpie opened from the Dock lacks the NO_PROXY a shell
|
||||
// profile sets, which the Codex a terminal or the ChatGPT app runs has.
|
||||
// The login shell's value is Codex's; magpie's own only where the shell
|
||||
// has none.
|
||||
func TestCodexEnvTakesLoginShell(t *testing.T) {
|
||||
was := loginEnv
|
||||
t.Cleanup(func() { loginEnv = was })
|
||||
loginEnv = func(k string) string { return map[string]string{"NO_PROXY": "127.0.0.1"}[k] }
|
||||
t.Setenv("NO_PROXY", "")
|
||||
t.Setenv("HTTP_PROXY", "http://127.0.0.1:7890")
|
||||
if got := codexEnv("NO_PROXY"); got != "127.0.0.1" {
|
||||
t.Fatalf("NO_PROXY = %q, want the login shell's", got)
|
||||
}
|
||||
if got := codexEnv("HTTP_PROXY"); got != "http://127.0.0.1:7890" {
|
||||
t.Fatalf("HTTP_PROXY = %q, want magpie's own", got)
|
||||
}
|
||||
proxyAs(t, nil, netproxy.Proxy{URL: "http://127.0.0.1:7890", HTTP: "http://127.0.0.1:7890"}, "darwin", nil)
|
||||
codexProxyEnv = codexEnv
|
||||
cfg := filepath.Join(t.TempDir(), "config.toml")
|
||||
os.WriteFile(cfg, []byte("model = \"gpt-5.5\"\n"), 0o600)
|
||||
if p, from := codexProxyFor(cfg, "http://127.0.0.1:3425/v1"); p != "" {
|
||||
t.Fatalf("NO_PROXY=127.0.0.1 in the shell, still through %q from %q", p, from)
|
||||
}
|
||||
}
|
||||
|
||||
// A proxy's own 502 isn't magpie; a proxy that passes the request on is.
|
||||
func TestRealProxyProbe(t *testing.T) {
|
||||
gw := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -113,6 +159,63 @@ func TestRealProxyProbe(t *testing.T) {
|
||||
if !realProxyProbe(gw.URL+"/v1", pass.URL) {
|
||||
t.Fatal("a proxy passing the request on didn't count")
|
||||
}
|
||||
// Codex's reqwest has no SOCKS: a socks5:// proxy is asked as an HTTP
|
||||
// one at that address. Clash's mixed port passes it on; a SOCKS-only
|
||||
// port, which Go would speak SOCKS to, doesn't, and Codex 502s
|
||||
if !realProxyProbe(gw.URL+"/v1", "socks5://"+strings.TrimPrefix(pass.URL, "http://")) {
|
||||
t.Fatal("an HTTP proxy named socks5:// didn't count, though Codex gets through it")
|
||||
}
|
||||
if realProxyProbe(gw.URL+"/v1", "socks5://"+socksOnly(t)) {
|
||||
t.Fatal("a SOCKS-only proxy counted, though Codex can't speak SOCKS")
|
||||
}
|
||||
}
|
||||
|
||||
// socksOnly is the address of a SOCKS5 proxy that speaks nothing else: it
|
||||
// passes a CONNECT on and drops anything that isn't SOCKS5.
|
||||
func socksOnly(t *testing.T) string {
|
||||
t.Helper()
|
||||
ln, err := net.Listen("tcp", "127.0.0.1:0")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Cleanup(func() { ln.Close() })
|
||||
go func() {
|
||||
for {
|
||||
c, err := ln.Accept()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
go func() {
|
||||
defer c.Close()
|
||||
c.SetDeadline(time.Now().Add(5 * time.Second))
|
||||
b := make([]byte, 262)
|
||||
if _, err := io.ReadFull(c, b[:2]); err != nil || b[0] != 5 {
|
||||
return
|
||||
}
|
||||
if _, err := io.ReadFull(c, b[:b[1]]); err != nil {
|
||||
return
|
||||
}
|
||||
c.Write([]byte{5, 0})
|
||||
if _, err := io.ReadFull(c, b[:4]); err != nil || b[3] != 1 {
|
||||
return
|
||||
}
|
||||
if _, err := io.ReadFull(c, b[:6]); err != nil {
|
||||
return
|
||||
}
|
||||
to := net.JoinHostPort(net.IP(b[:4]).String(), strconv.Itoa(int(b[4])<<8|int(b[5])))
|
||||
up, err := net.Dial("tcp", to)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer up.Close()
|
||||
c.Write([]byte{5, 0, 0, 1, 0, 0, 0, 0, 0, 0})
|
||||
c.SetDeadline(time.Time{})
|
||||
go io.Copy(up, c)
|
||||
io.Copy(c, up)
|
||||
}()
|
||||
}
|
||||
}()
|
||||
return ln.Addr().String()
|
||||
}
|
||||
|
||||
// Muma102kMichael on X: Codex 502 on every project and every new chat once
|
||||
@@ -139,7 +242,7 @@ func TestCodexFailoverHeldWhileProxyDoesNotPassOn(t *testing.T) {
|
||||
os.WriteFile(filepath.Join(filepath.Dir(provider.Path()), "logins.json"), b, 0o600)
|
||||
|
||||
works := false
|
||||
proxyAs(t, nil, netproxy.Proxy{URL: "http://127.0.0.1:7890", Bypass: []string{"localhost", "127.*"}}, "windows", &works)
|
||||
proxyAs(t, nil, netproxy.Proxy{URL: "http://127.0.0.1:7890", HTTP: "http://127.0.0.1:7890", Bypass: []string{"localhost", "127.*"}}, "windows", &works)
|
||||
cx := codex(home)
|
||||
sync := func() string {
|
||||
t.Helper()
|
||||
|
||||
@@ -352,8 +352,13 @@ func noProxy(host, list string) bool {
|
||||
}
|
||||
|
||||
// Proxy is the system's proxy: one address, and the hosts that skip it.
|
||||
// HTTP and SOCKS are the system's entries for plain http:// requests and
|
||||
// for SOCKS, each alone, for a client that reads them so (Codex's reqwest
|
||||
// takes macOS' HTTP entry and nothing else for an http:// URL).
|
||||
type Proxy struct {
|
||||
URL string
|
||||
HTTP string
|
||||
SOCKS string
|
||||
Bypass []string
|
||||
}
|
||||
|
||||
|
||||
@@ -32,9 +32,17 @@ func TestParseScutil(t *testing.T) {
|
||||
if p.URL != "http://127.0.0.1:7891" || len(p.Bypass) != 2 || p.Bypass[1] != "*.local" {
|
||||
t.Fatalf("%+v", p)
|
||||
}
|
||||
if p := parseScutil("<dictionary> {\n SOCKSEnable : 1\n SOCKSPort : 1080\n SOCKSProxy : 10.0.0.2\n}"); p.URL != "socks5://10.0.0.2:1080" {
|
||||
// each entry alone, for Codex's reqwest, which takes the HTTP one for
|
||||
// an http:// URL and never the HTTPS or SOCKS one
|
||||
if p.HTTP != "http://127.0.0.1:7890" || p.SOCKS != "socks5://127.0.0.1:7892" {
|
||||
t.Fatalf("entries: %+v", p)
|
||||
}
|
||||
if p := parseScutil("<dictionary> {\n SOCKSEnable : 1\n SOCKSPort : 1080\n SOCKSProxy : 10.0.0.2\n}"); p.URL != "socks5://10.0.0.2:1080" || p.HTTP != "" || p.SOCKS != p.URL {
|
||||
t.Fatalf("socks: %+v", p)
|
||||
}
|
||||
if p := parseScutil("<dictionary> {\n HTTPSEnable : 1\n HTTPSPort : 7890\n HTTPSProxy : 127.0.0.1\n}"); p.URL != "http://127.0.0.1:7890" || p.HTTP != "" {
|
||||
t.Fatalf("https only: %+v", p)
|
||||
}
|
||||
if p := parseScutil("<dictionary> {\n HTTPEnable : 0\n HTTPProxy : x\n}"); p.URL != "" {
|
||||
t.Fatalf("off: %+v", p)
|
||||
}
|
||||
@@ -51,6 +59,13 @@ func TestParseWindows(t *testing.T) {
|
||||
t.Errorf("%q: %q, want %q", server, got, want)
|
||||
}
|
||||
}
|
||||
// reqwest reads ProxyServer as one address: a list per protocol isn't one
|
||||
if p := parseWindows("127.0.0.1:7890", ""); p.HTTP != "http://127.0.0.1:7890" {
|
||||
t.Fatalf("one for all: %+v", p)
|
||||
}
|
||||
if p := parseWindows("http=127.0.0.1:1;https=127.0.0.1:2;socks=127.0.0.1:3", ""); p.HTTP != "" || p.SOCKS != "socks5://127.0.0.1:3" {
|
||||
t.Fatalf("per protocol: %+v", p)
|
||||
}
|
||||
p := parseWindows("127.0.0.1:7890", "*.corp;<local>")
|
||||
if !bypassed("git.corp", p.Bypass) || !bypassed("intranet", p.Bypass) || bypassed("chatgpt.com", p.Bypass) {
|
||||
t.Fatalf("bypass: %+v", p.Bypass)
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// parseScutil reads `scutil --proxy`. HTTPS wins over HTTP over SOCKS.
|
||||
// parseScutil reads `scutil --proxy`. HTTPS wins over HTTP over SOCKS for
|
||||
// URL; HTTP and SOCKS are each entry alone.
|
||||
func parseScutil(out string) Proxy {
|
||||
kv := map[string]string{}
|
||||
var bypass []string
|
||||
@@ -30,13 +31,21 @@ func parseScutil(out string) Proxy {
|
||||
}
|
||||
kv[k] = v
|
||||
}
|
||||
for _, p := range []struct{ key, scheme string }{{"HTTPS", "http"}, {"HTTP", "http"}, {"SOCKS", "socks5"}} {
|
||||
if kv[p.key+"Enable"] == "1" && kv[p.key+"Proxy"] != "" {
|
||||
host := kv[p.key+"Proxy"]
|
||||
if port := kv[p.key+"Port"]; port != "" {
|
||||
host = net.JoinHostPort(host, port)
|
||||
}
|
||||
return Proxy{URL: p.scheme + "://" + host, Bypass: bypass}
|
||||
entry := func(key, scheme string) string {
|
||||
if kv[key+"Enable"] != "1" || kv[key+"Proxy"] == "" {
|
||||
return ""
|
||||
}
|
||||
host := kv[key+"Proxy"]
|
||||
if port := kv[key+"Port"]; port != "" {
|
||||
host = net.JoinHostPort(host, port)
|
||||
}
|
||||
return scheme + "://" + host
|
||||
}
|
||||
p := Proxy{HTTP: entry("HTTP", "http"), SOCKS: entry("SOCKS", "socks5")}
|
||||
for _, u := range []string{entry("HTTPS", "http"), p.HTTP, p.SOCKS} {
|
||||
if u != "" {
|
||||
p.URL, p.Bypass = u, bypass
|
||||
return p
|
||||
}
|
||||
}
|
||||
return Proxy{}
|
||||
|
||||
@@ -4,6 +4,8 @@ import "strings"
|
||||
|
||||
// parseWindows reads Internet Options' ProxyServer ("host:port", or
|
||||
// "http=h:p;https=h:p;socks=h:p") and ProxyOverride ("a;*.b;<local>").
|
||||
// HTTP is the server only when it is one for every protocol: reqwest
|
||||
// takes ProxyServer as one address and can't read a list per protocol.
|
||||
func parseWindows(server, override string) Proxy {
|
||||
server = strings.TrimSpace(server)
|
||||
if server == "" {
|
||||
@@ -14,7 +16,7 @@ func parseWindows(server, override string) Proxy {
|
||||
if !strings.Contains(server, "://") {
|
||||
server = "http://" + server
|
||||
}
|
||||
return Proxy{URL: server, Bypass: bypass}
|
||||
return Proxy{URL: server, HTTP: server, Bypass: bypass}
|
||||
}
|
||||
by := map[string]string{}
|
||||
for _, part := range strings.Split(server, ";") {
|
||||
@@ -22,12 +24,17 @@ func parseWindows(server, override string) Proxy {
|
||||
by[strings.ToLower(strings.TrimSpace(k))] = strings.TrimSpace(v)
|
||||
}
|
||||
}
|
||||
for _, p := range []struct{ key, scheme string }{{"https", "http"}, {"http", "http"}, {"socks", "socks5"}} {
|
||||
if v := by[p.key]; v != "" {
|
||||
if !strings.Contains(v, "://") {
|
||||
v = p.scheme + "://" + v
|
||||
}
|
||||
return Proxy{URL: v, Bypass: bypass}
|
||||
entry := func(key, scheme string) string {
|
||||
v := by[key]
|
||||
if v != "" && !strings.Contains(v, "://") {
|
||||
v = scheme + "://" + v
|
||||
}
|
||||
return v
|
||||
}
|
||||
socks := entry("socks", "socks5")
|
||||
for _, u := range []string{entry("https", "http"), entry("http", "http"), socks} {
|
||||
if u != "" {
|
||||
return Proxy{URL: u, SOCKS: socks, Bypass: bypass}
|
||||
}
|
||||
}
|
||||
return Proxy{}
|
||||
|
||||
+42
-12
@@ -43,11 +43,15 @@ func UserPath() {
|
||||
go func() {
|
||||
defer close(done)
|
||||
p, vars := shellEnv()
|
||||
setUnset(vars)
|
||||
agents := make(map[string]string, len(agentenv.Vars))
|
||||
for _, v := range agentenv.Vars {
|
||||
agents[v] = vars[v]
|
||||
}
|
||||
setUnset(agents)
|
||||
if p != "" {
|
||||
addPath(filepath.SplitList(p))
|
||||
login.Lock()
|
||||
login.dirs, login.at = filepath.SplitList(p), time.Now()
|
||||
login.dirs, login.vars, login.at = filepath.SplitList(p), vars, time.Now()
|
||||
login.Unlock()
|
||||
}
|
||||
}()
|
||||
@@ -74,6 +78,7 @@ func setUnset(vars map[string]string) {
|
||||
var login struct {
|
||||
sync.Mutex
|
||||
dirs []string
|
||||
vars map[string]string
|
||||
at time.Time
|
||||
}
|
||||
|
||||
@@ -87,14 +92,38 @@ func LoginPath() []string {
|
||||
if login.dirs != nil && time.Since(login.at) < time.Minute {
|
||||
return login.dirs
|
||||
}
|
||||
p, _ := shellEnv()
|
||||
p, vars := shellEnv()
|
||||
if p == "" {
|
||||
return nil
|
||||
}
|
||||
login.dirs, login.at = filepath.SplitList(p), time.Now()
|
||||
login.dirs, login.vars, login.at = filepath.SplitList(p), vars, time.Now()
|
||||
return login.dirs
|
||||
}
|
||||
|
||||
// ProxyVars are the proxy variables the login shell is asked for beside
|
||||
// agentenv.Vars. An agent run in a terminal has the ones its profile sets,
|
||||
// and so does one the ChatGPT app starts (it takes the login shell's
|
||||
// environment as it opens), while magpie opened from the Dock doesn't: a
|
||||
// NO_PROXY=127.0.0.1 in .zshrc keeps Codex's requests for magpie off a
|
||||
// proxy that magpie, reading its own environment, thought they went
|
||||
// through (liu_dyj on X). They are only read (LoginEnv), never set in
|
||||
// magpie's environment: magpie's own requests take their proxy from
|
||||
// netproxy.
|
||||
var ProxyVars = []string{"HTTP_PROXY", "http_proxy", "HTTPS_PROXY", "https_proxy", "ALL_PROXY", "all_proxy", "NO_PROXY", "no_proxy"}
|
||||
|
||||
// shellVars are the variables shellProbe asks for, in its order.
|
||||
var shellVars = slices.Concat(agentenv.Vars, ProxyVars)
|
||||
|
||||
// LoginEnv is the value a terminal opened now has for k, one of
|
||||
// agentenv.Vars or ProxyVars: the login shell's, asked as LoginPath asks
|
||||
// and with it; "" when the shell has none for it or doesn't say.
|
||||
func LoginEnv(k string) string {
|
||||
LoginPath()
|
||||
login.Lock()
|
||||
defer login.Unlock()
|
||||
return login.vars[k]
|
||||
}
|
||||
|
||||
// UserBinDirs are the folders a user's command-line tools are installed in
|
||||
// that exist here — npm's prefixes, each Node version of nvm, fnm and mise,
|
||||
// bun, volta, pnpm, asdf, the standalone installers' ~/.local/bin,
|
||||
@@ -167,7 +196,7 @@ func npmPrefix(home string) string {
|
||||
}
|
||||
|
||||
// shellEnv asks the user's login shell for its PATH and the values it has
|
||||
// for agentenv.Vars ("" for one it hasn't); "" and nil when it can't say
|
||||
// for agentenv.Vars and ProxyVars ("" for one it hasn't); "" and nil when it can't say
|
||||
// within a few seconds.
|
||||
//
|
||||
// fish and nushell are asked too, when they are installed and set up here
|
||||
@@ -356,8 +385,9 @@ func ShellPath(sh string) []string {
|
||||
const shellMark = "__magpie_path__"
|
||||
|
||||
// shellProbe is the command the login shell sh runs to print its PATH and
|
||||
// agentenv.Vars, between two marks. A NUL (which no variable can hold)
|
||||
// parts the values: PATH first, then each of agentenv.Vars in order.
|
||||
// agentenv.Vars and ProxyVars (shellVars), between two marks. A NUL (which
|
||||
// no variable can hold) parts the values: PATH first, then each of
|
||||
// shellVars in order.
|
||||
//
|
||||
// A POSIX shell (zsh, bash) expands "$PATH" itself, and so does fish:
|
||||
// PATH, as each variable whose name ends in PATH, is a path variable there,
|
||||
@@ -375,7 +405,7 @@ const shellMark = "__magpie_path__"
|
||||
// where \0 reaches printf as it is.
|
||||
func shellProbe(sh string) string {
|
||||
format, args := shellMark+"%s", ` "$PATH"`
|
||||
for _, v := range agentenv.Vars {
|
||||
for _, v := range shellVars {
|
||||
format += `\0%s`
|
||||
args += ` "$` + v + `"`
|
||||
}
|
||||
@@ -386,7 +416,7 @@ func shellProbe(sh string) string {
|
||||
}
|
||||
|
||||
// parseShellEnv reads shellEnv's answer out of what the shell printed. The
|
||||
// variables are nil when their count isn't agentenv.Vars' (a printf that
|
||||
// variables are nil when their count isn't shellVars' (a printf that
|
||||
// doesn't know \0); PATH alone is still taken then. A value that is the
|
||||
// variable's own reference ("$CODEX_HOME") is a shell that printed the
|
||||
// text instead of expanding it (nushell before shellProbe knew it; a shell
|
||||
@@ -406,14 +436,14 @@ func parseShellEnv(s, mark string) (string, map[string]string) {
|
||||
if f[0] == "$PATH" {
|
||||
f[0] = ""
|
||||
}
|
||||
if len(f) != len(agentenv.Vars)+1 {
|
||||
if len(f) != len(shellVars)+1 {
|
||||
if len(f) == 1 {
|
||||
return f[0], nil
|
||||
}
|
||||
return "", nil
|
||||
}
|
||||
vars := make(map[string]string, len(agentenv.Vars))
|
||||
for k, v := range agentenv.Vars {
|
||||
vars := make(map[string]string, len(shellVars))
|
||||
for k, v := range shellVars {
|
||||
if f[k+1] == "$"+v {
|
||||
f[k+1] = ""
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/agentenv"
|
||||
"github.com/yetone/magpie/internal/testenv"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
@@ -90,21 +89,66 @@ func TestUserPathTakesAgentVars(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// liu_dyj on X: a NO_PROXY=127.0.0.1 in .zshrc keeps the Codex a terminal
|
||||
// or the ChatGPT app runs off the proxy, while magpie, opened from the Dock
|
||||
// without it, warned that Codex went through the proxy. The login shell's
|
||||
// proxy variables are read (LoginEnv) but never set in magpie's own
|
||||
// environment, whose requests take their proxy from netproxy.
|
||||
func TestLoginEnvProxyVarsNotSet(t *testing.T) {
|
||||
home := t.TempDir()
|
||||
t.Setenv("HOME", home)
|
||||
sh := filepath.Join(home, "sh")
|
||||
testenv.Program(t, sh, "#!/bin/sh\necho 'a profile that talks'\n"+
|
||||
"export HTTP_PROXY=http://127.0.0.1:7890 no_proxy=localhost,127.0.0.1\neval \"$2\"\n")
|
||||
t.Setenv("SHELL", sh)
|
||||
t.Setenv("PATH", "/usr/bin:/bin")
|
||||
for _, v := range ProxyVars {
|
||||
t.Setenv(v, "")
|
||||
os.Unsetenv(v)
|
||||
}
|
||||
exec.Command(sh, "-c", ":").Run()
|
||||
login.Lock()
|
||||
dirs, vars, at := login.dirs, login.vars, login.at
|
||||
login.dirs, login.vars, login.at = nil, nil, time.Time{}
|
||||
login.Unlock()
|
||||
t.Cleanup(func() {
|
||||
login.Lock()
|
||||
login.dirs, login.vars, login.at = dirs, vars, at
|
||||
login.Unlock()
|
||||
})
|
||||
|
||||
UserPath()
|
||||
for _, v := range ProxyVars {
|
||||
if _, set := os.LookupEnv(v); set {
|
||||
t.Fatalf("%s set in magpie's own environment", v)
|
||||
}
|
||||
}
|
||||
if got := LoginEnv("HTTP_PROXY"); got != "http://127.0.0.1:7890" {
|
||||
t.Fatalf("HTTP_PROXY = %q, want the profile's", got)
|
||||
}
|
||||
if got := LoginEnv("no_proxy"); got != "localhost,127.0.0.1" {
|
||||
t.Fatalf("no_proxy = %q, want the profile's", got)
|
||||
}
|
||||
if got := LoginEnv("ALL_PROXY"); got != "" {
|
||||
t.Fatalf("ALL_PROXY = %q, want none", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A login shell that doesn't expand "$CLAUDE_CONFIG_DIR" prints the
|
||||
// reference itself. That is no folder: the variable counts as unset,
|
||||
// rather than magpie setting CLAUDE_CONFIG_DIR to "$CLAUDE_CONFIG_DIR" and
|
||||
// then looking for Claude Code's sign-in under it (#738).
|
||||
func TestParseShellEnvUnexpanded(t *testing.T) {
|
||||
s := shellMark + "$PATH"
|
||||
for _, v := range agentenv.Vars {
|
||||
for _, v := range shellVars {
|
||||
s += "\x00$" + v
|
||||
}
|
||||
p, vars := parseShellEnv("hello from the profile\n"+s+shellMark, shellMark)
|
||||
if p != "" {
|
||||
t.Fatalf("PATH = %q, want none", p)
|
||||
}
|
||||
if len(vars) != len(agentenv.Vars) {
|
||||
t.Fatalf("%d variables, want %d", len(vars), len(agentenv.Vars))
|
||||
if len(vars) != len(shellVars) {
|
||||
t.Fatalf("%d variables, want %d", len(vars), len(shellVars))
|
||||
}
|
||||
for v, got := range vars {
|
||||
if got != "" {
|
||||
@@ -118,7 +162,7 @@ func TestParseShellEnvUnexpanded(t *testing.T) {
|
||||
// installed, the command's shape is all that can be checked.
|
||||
func TestShellEnvNushell(t *testing.T) {
|
||||
probe := shellProbe("/opt/homebrew/bin/nu")
|
||||
if !strings.HasPrefix(probe, "^/bin/sh -c 'printf \""+shellMark+"%s") || !strings.HasSuffix(probe, `"$`+agentenv.Vars[len(agentenv.Vars)-1]+`"'`) {
|
||||
if !strings.HasPrefix(probe, "^/bin/sh -c 'printf \""+shellMark+"%s") || !strings.HasSuffix(probe, `"$`+shellVars[len(shellVars)-1]+`"'`) {
|
||||
t.Fatalf("nushell's probe: %q", probe)
|
||||
}
|
||||
if strings.Contains(probe, `'`+shellMark) || strings.Count(probe, "'") != 2 {
|
||||
@@ -183,12 +227,13 @@ func TestAskShellOwnSession(t *testing.T) {
|
||||
// config.fish that echoes a line, puts /Users/john/.fishbin first on PATH
|
||||
// and sets CODEX_HOME: PATH joined with ':' (a path variable), then each of
|
||||
// agentenv.Vars. The captured tail after CODEX_HOME was all empty values;
|
||||
// it is padded to agentenv.Vars' count as it is now.
|
||||
// it is padded to shellVars' count (agentenv.Vars, then ProxyVars) as it is
|
||||
// now.
|
||||
func fishProbeOutput() string {
|
||||
s := "hello from config.fish\n" + shellMark +
|
||||
"/Users/john/.fishbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin" +
|
||||
"\x00\x00/Users/john/codex"
|
||||
return s + strings.Repeat("\x00", len(agentenv.Vars)-2) + shellMark
|
||||
return s + strings.Repeat("\x00", len(shellVars)-2) + shellMark
|
||||
}
|
||||
|
||||
// fakeShells makes HOME a temp folder with a login shell (SHELL) whose
|
||||
|
||||
@@ -78,6 +78,11 @@ func LoginPath() []string {
|
||||
return dirs
|
||||
}
|
||||
|
||||
// LoginEnv is "" on Windows: an app started from the Start menu gets the
|
||||
// user's variables from the registry, as a terminal does, so magpie's own
|
||||
// environment has them.
|
||||
func LoginEnv(string) string { return "" }
|
||||
|
||||
// ShellPath is LoginPath on Windows: PowerShell and cmd both take the
|
||||
// registry's PATH.
|
||||
func ShellPath(string) []string { return LoginPath() }
|
||||
|
||||
Reference in New Issue
Block a user