JonahFu on X: GitHub is unreachable without a proxy, while API requests may go direct, so plugin downloads' proxy should be set apart from the one model requests take. Before: plugin downloads already followed the global proxy (fetches through http.DefaultClient and netproxy.Func, bun add and git through netproxy.Env), so nothing ignored it; there was only no way to give them a different one. Now Settings › Network has a Plugin downloads row under Proxy: Same as above (the default, unset: downloads follow the global proxy as before), Direct, or Custom with its login, remembered as pluginProxyCustom as Proxy's Custom is. The CLI takes it as `magpie settings set pluginProxy <url|direct|"">`. It covers the plugins list and Discover's lists (fetchJSONFrom), a user's own npm registry (fetchRegistry), Bun's download (getURLFrom), bun add/update/remove and the git commands of GitHub-installed plugins (dlEnv). The plugin host (bun run) keeps the global proxy: its requests are the vendors'. Both fields belong to this computer (KeepOwn) and are left out of auto-backups, since a proxy URL may hold a password. Settings' Proxy row and the new one are drawn by one helper (proxyRow); the core's script budget is met by cutting the proxy rows' comments, no raise. Run (mote, through mote-run): gofmt -l clean; go vet of the touched packages (darwin), GOOS=linux -tags nogui ./..., GOOS=windows of the touched packages; go test -count=1 internal/settings, settingsapi, backup, netproxy, plugin, gui, cli all ok (gui after the comment cut; its first run had TestCoreScriptBudget 1,352 bytes over). GUI, chromium and webkit: settings-plugin-proxy (new, 5 languages x 2 widths), settings-proxy-remember, settings-proxy-auth, proxy-test, settings-sections, proxy-login-fields and the i18n files: 102 pass, 0 fail. plugin-proxy-page, proxy-own-wording, account-proxy, provider-proxy, routing-proxy, provider-many-keys-proxy and signin-proxy: 104 pass, 2 fail, both signin-proxy's "a subscription with no proxy offers the global one" at 380px in Chromium, red the same way on origin/mainb596da773(filed #5866). Again at this commit, rebased onb596da773: gofmt, the three go vets, the seven packages' go test (all ok, TestCoreScriptBudget included) and settings-plugin-proxy, -remember and -auth (50 pass, 0 fail). Broken by hand: fetchJSONFrom without netproxy.Downloads -> TestPluginDownloadsTakeTheirOwnProxy red (the list went direct and hit testenv's offline guard); bunCommand always taking env() -> red (bun add's HTTPS_PROXY ""); the GUI row saving key "proxy" -> settings-plugin-proxy 10 of 10 red in chromium. Not tried: a real install behind a real proxy with GitHub blocked; the Library's (skills, MCP) downloads and plugin icons (loaded by the webview through usemagpie.ai) still follow the global proxy; Windows.
57 lines
2.2 KiB
Go
57 lines
2.2 KiB
Go
package settings
|
|
|
|
import "testing"
|
|
|
|
// The remembered custom proxy holds the proxy's login, so it is this
|
|
// computer's own as the proxy is: a sync or a restored backup keeps the
|
|
// one here and never brings another computer's.
|
|
func TestProxyCustomOwn(t *testing.T) {
|
|
from := Settings{Theme: "dark", Proxy: "direct", ProxyCustom: "socks5://a:b@there:1080"}
|
|
from.KeepOwn(Settings{ProxyCustom: "socks5://c:d@here:1080"})
|
|
if from.ProxyCustom != "socks5://c:d@here:1080" || from.Theme != "dark" {
|
|
t.Fatalf("KeepOwn: %+v", from)
|
|
}
|
|
from.KeepOwn(Settings{})
|
|
if from.ProxyCustom != "" {
|
|
t.Fatal("another computer's proxy login taken here")
|
|
}
|
|
}
|
|
|
|
// Plugin downloads' proxy, and the one remembered for its Custom, are
|
|
// this computer's own as the proxy is.
|
|
func TestPluginProxyOwn(t *testing.T) {
|
|
from := Settings{Theme: "dark", PluginProxy: "socks5://a:b@there:1080", PluginProxyCustom: "socks5://a:b@there:1080"}
|
|
from.KeepOwn(Settings{PluginProxy: "direct", PluginProxyCustom: "http://c:d@here:8080"})
|
|
if from.PluginProxy != "direct" || from.PluginProxyCustom != "http://c:d@here:8080" || from.Theme != "dark" {
|
|
t.Fatalf("KeepOwn: %+v", from)
|
|
}
|
|
from.KeepOwn(Settings{})
|
|
if from.PluginProxy != "" || from.PluginProxyCustom != "" {
|
|
t.Fatal("another computer's plugin proxy taken here")
|
|
}
|
|
}
|
|
|
|
// Plugin downloads' proxy is checked as the proxy is, and the last of the
|
|
// user's own is remembered for Custom while it follows or goes direct.
|
|
func TestPluginProxySaved(t *testing.T) {
|
|
t.Setenv("XDG_CONFIG_HOME", t.TempDir())
|
|
if err := Save(Settings{PluginProxy: " socks5://u:p@127.0.0.1:1080 "}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s := Load(); s.PluginProxy != "socks5://u:p@127.0.0.1:1080" || s.PluginProxyCustom != s.PluginProxy || s.Proxy != "" {
|
|
t.Fatalf("%+v", s)
|
|
}
|
|
if err := Save(Settings{PluginProxy: "direct", PluginProxyCustom: Load().PluginProxyCustom}); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if s := Load(); s.PluginProxy != "direct" || s.PluginProxyCustom != "socks5://u:p@127.0.0.1:1080" {
|
|
t.Fatalf("%+v", s)
|
|
}
|
|
if Save(Settings{PluginProxy: "ftp://x:21"}) == nil {
|
|
t.Fatal("an ftp proxy accepted")
|
|
}
|
|
if Load().PluginProxy != "direct" {
|
|
t.Fatal("a refused value overwrote the saved one")
|
|
}
|
|
}
|