Files
magpie/update_flags_test.go
yetone bc141ad834 update: install.sh and magpie update take --proxy and --mirror, and magpie update mirror keeps one for the app's updates too (akic404 on Discord: 安装和update如果没有梯子也是麻烦事,能否在install.sh和magpie update后加子选项?--proxy等可自定义或默认ghproxy) — install.sh had no options and fetched with curl alone, and magpie update took none; without a way out to GitHub both failed. Now both take --proxy <url> (http, https, socks5, socks5h; install.sh also MAGPIE_PROXY=) for the feed and the download, and --mirror <prefix> (or MAGPIE_MIRROR=), a GitHub download mirror the release file is fetched from as <prefix>https://github.com/…; only github.com / githubusercontent.com URLs are put through it. No mirror is used unless one is given: magpie names none and has none by default. The feed with each file's SHA-256 is always fetched from usemagpie.ai, never through the mirror, so a file the mirror changed is refused and deleted ("… from the mirror X does not match its checksum from https://usemagpie.ai; not installed"); macOS still checks the app's signing team. magpie update mirror <prefix>|off saves Settings' updateMirror (http(s) only), which the app's own background update follows too; magpie update --mirror off skips it once; the Settings page's save keeps it. The app's update already followed Settings → Proxy (#294); magpie update --proxy overrides it for one run. The environment's ALL_PROXY / all_proxy is now honoured when HTTPS_PROXY / HTTP_PROXY are unset (Go's ProxyFromEnvironment ignores it), with NO_PROXY as curl reads it. magpie update takes --flag value or --flag=value, and an unknown word is an error instead of an update. The help, README and the docs' FAQ (en/zh/ja) say how. install.test.mjs's proxy, mirror and tampered-mirror tests, TestAllProxyFromTheEnvironment, TestUpdateThroughAMirror, TestUpdateThroughAProxyGiven and TestUpdateFlags fail on the old code and pass; TestSettingsSaveKeepsWhatItDoesNotSend covers updateMirror. A dry run of install.sh as Linux amd64 into a temp HOME installed the real 0.1.773 with its SHA-256 checked, refused a local mirror serving a wrong file, and with --proxy to a closed port failed reaching the site through it. go vet, builds (darwin, GOOS=linux, GOOS=windows), sh -n, node --test site/install.test.mjs and go test -tags nogui -count=1 ./... under a temp HOME pass but TestClaudeIdentityServedWhileAsked, a timing test that passes alone. Not tried through a real proxy server or a real public mirror; no install.ps1 exists for Windows, and the app has no field for the mirror.
2026-10-04 00:19:47 +08:00

45 lines
1.6 KiB
Go

package main
import (
"slices"
"testing"
"github.com/yetone/magpie/internal/settings"
)
// magpie update takes --proxy and --mirror, as --flag value or
// --flag=value, before or after check; magpie update mirror keeps one for
// every update, the app's too, and off clears it.
func TestUpdateFlags(t *testing.T) {
rest, proxy, mirror, err := updateFlags([]string{"update", "--proxy", "socks5://127.0.0.1:1080", "check", "--mirror=https://mirror.example/"})
if err != nil || !slices.Equal(rest, []string{"update", "check"}) || proxy != "socks5://127.0.0.1:1080" || mirror != "https://mirror.example/" {
t.Fatalf("%v %q %q %v", rest, proxy, mirror, err)
}
for _, bad := range [][]string{
{"update", "--proxy"},
{"update", "--proxy", "ftp://x:1"},
{"update", "--mirror", "mirror.example"},
} {
if _, _, _, err := updateFlags(bad); err == nil {
t.Errorf("%v taken", bad)
}
}
if err := updateCmd([]string{"update", "chek"}); err == nil {
t.Error("magpie update chek ran an update")
}
groupsHome(t)
if err := updateCmd([]string{"update", "mirror", "https://mirror.example/"}); err != nil {
t.Fatal(err)
}
if got := settings.Load().UpdateMirror; got != "https://mirror.example/" {
t.Fatalf("saved %q", got)
}
if err := updateCmd([]string{"update", "mirror", "nope"}); err == nil || settings.Load().UpdateMirror != "https://mirror.example/" {
t.Fatalf("a bad mirror: %v, kept %q", err, settings.Load().UpdateMirror)
}
if err := updateCmd([]string{"update", "mirror", "off"}); err != nil || settings.Load().UpdateMirror != "" {
t.Fatalf("off: %v, kept %q", err, settings.Load().UpdateMirror)
}
}