ssharpcc on X reads every changelog before updating, for fear of a ban
when behind, and with many releases a day that is a lot of reading.
Settings → About → Update channel (zh: 更新渠道, 稳定版 / 每个版本) picks
Every version, the default and today's behaviour, or Stable: one version
a week, the newest that had been out three days as the week began
(Monday 00:00 UTC), and an urgent release at once. usemagpie.ai chooses
it from the release list (the previous commit); a release is urgent when
a line of its notes starts with "**Urgent release:**", which
magpie-releases' release run writes from an `Urgent: <why>` trailer
(magpie-releases 73f6cff).
- settings: updateChannel, "" or "stable"; anything else is refused.
- update: on Stable the feed is asked with channel=stable; What's new
shows every release since the installed one (up to 1500) instead of
the newest 40, so a week's notes read as one list.
- gui: the row is segs, never a <select>; a save that doesn't send the
channel keeps it; switching asks the feed again at once, and a
download from every version newer than Stable's pick is dropped,
never restarted into. What's new's notes are kept per channel.
- cli: magpie update channel [stable|every] ("all" too), and it says
which with nothing after it.
- docs: reference.md's Update channel (the rule and the marker); the
privacy pages (en, zh, ja) name ?channel=stable on /api/latest.
The full Go and GUI suites were not run: the disk was at 3 GB free and
other sessions had GUI suites and a 45-minute gateway run going the
whole time.
Run, at this tree before the rebase:
- gofmt -l (clean); go vet on darwin, GOOS=linux -tags nogui and
GOOS=windows for ./internal/update/... ./internal/cli/...
./internal/settings/... ./internal/gui/.
- go test -count=1 ./internal/update/... ./internal/cli/...
./internal/settings/...: ok. ./internal/gui -run
'TestUpdateChannelSwitch|TestWhatsNewKeyedByChannel|TestCoreScriptBudget':
ok (the app.js budget passes).
- GUI, chromium and webkit: update-channel (22: en, zh, zh-TW, ja, de at
900 and 420 wide: default lit, Stable saved, kept by another save,
kept over a reload, Every saved back, no click scrolls, no sideways
scroll at 420), i18n-keys, gui-ja, gui-de, gui-zh-tw and every
update-*.test.cjs: 253 of 253 pass.
- The live feed: /api/latest?channel=stable answers 0.1.1327 (out
2026-10-22 21:55 UTC, the last before Friday 10-23 00:00) with 15
assets after the first real cron run filled the ledger (400 releases
back to 10-10); /api/notes 0.1.1200..0.1.1327 gives 124 notes, none
empty (1213 and 1218 were never published).
After rebasing on afc99490f: TestCoreScriptBudget, the channel Go tests
(update, cli, gui) and GUI i18n-keys + update-channel (both engines,
26 of 26) pass again.
Broken by hand, each red: the feed asked without channel=stable
(TestLatestAsksTheChannel); Stable capped at 40 (TestStableNotesAreAll);
any channel saved (TestUpdateChannelSaved); "all" dropped
(TestUpdateChannelCmd); a save without the field clearing it, no new ask
on a switch, the newer download kept (TestUpdateChannelSwitch); one
notes key for both channels, What's new capped at 40 on Stable
(TestWhatsNewKeyedByChannel); app.js's other saves dropping the channel,
Stable's click saving "" (update-channel 11 of 11 red); the zh label or
a de subtitle taken out (update-channel and i18n-keys red).
Not tried: the full go test ./... and the whole GUI suite (above); a
real app switching channel against the live feed; Windows and Linux
runs (vet only); a real urgent release.
Requested by ssharpcc on X.
161 lines
4.9 KiB
Go
161 lines
4.9 KiB
Go
package gui
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"strings"
|
|
"sync/atomic"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
"github.com/yetone/magpie/internal/update"
|
|
)
|
|
|
|
// Settings' Update channel (ssharpcc on X). Every version found 0.1.12
|
|
// and downloaded it; Stable's version is 0.1.11. Turning Stable on asks
|
|
// the feed again on it at once, and what was downloaded from every
|
|
// version is dropped for Stable's, never restarted into. A save from a
|
|
// page that doesn't send the channel keeps it.
|
|
func TestUpdateChannelSwitch(t *testing.T) {
|
|
sandboxHome(t)
|
|
body := []byte("new magpie")
|
|
sum := sha256.Sum256(body)
|
|
var downloads atomic.Int32
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.URL.Path == "/asset" {
|
|
downloads.Add(1)
|
|
w.Write(body)
|
|
return
|
|
}
|
|
v := "0.1.12"
|
|
if r.URL.Query().Get("channel") == "stable" {
|
|
v = "0.1.11"
|
|
}
|
|
json.NewEncoder(w).Encode(update.Release{Version: v, Notes: "- faster", Assets: map[string]update.Asset{
|
|
update.BinaryAsset(): {URL: "http://" + r.Host + "/asset", Size: int64(len(body)), SHA256: hex.EncodeToString(sum[:])},
|
|
}})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_UPDATE_FEED", srv.URL)
|
|
oldV := Version
|
|
Version = "0.1.10"
|
|
defer func() { Version = oldV }()
|
|
exe, err := update.Executable()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(exe + ".new")
|
|
|
|
o := updates
|
|
u := &updater{exe: exe}
|
|
u.self, _ = os.Stat(exe)
|
|
updates = u
|
|
defer func() { updates = o }()
|
|
settle := func() updateJSON {
|
|
t.Helper()
|
|
for range 1000 {
|
|
if j := u.json(); j.State != "checking" && j.State != "downloading" {
|
|
return j
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
t.Fatalf("still %s", u.json().State)
|
|
return updateJSON{}
|
|
}
|
|
save := func(in string) {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings", strings.NewReader(in)))
|
|
if rec.Code != 200 {
|
|
t.Fatalf("%s: %d %s", in, rec.Code, rec.Body)
|
|
}
|
|
}
|
|
|
|
// every version: 0.1.12, downloaded
|
|
u.check()
|
|
if j := settle(); j.State != "ready" || j.Latest != "0.1.12" || downloads.Load() != 1 {
|
|
t.Fatalf("every version: %+v, %d downloads", j, downloads.Load())
|
|
}
|
|
|
|
// Stable: asked again at once, 0.1.12's download dropped for 0.1.11's
|
|
save(`{"theme":"light","updateChannel":"stable"}`)
|
|
if settings.Load().UpdateChannel != settings.UpdateStable {
|
|
t.Fatal("stable wasn't saved")
|
|
}
|
|
for range 500 {
|
|
if downloads.Load() == 2 {
|
|
break
|
|
}
|
|
time.Sleep(10 * time.Millisecond)
|
|
}
|
|
if j := settle(); j.State != "ready" || j.Latest != "0.1.11" || downloads.Load() != 2 {
|
|
t.Fatalf("on stable: %+v, %d downloads", j, downloads.Load())
|
|
}
|
|
u.mu.Lock()
|
|
staged, latest := u.staged, u.latest.Version
|
|
u.mu.Unlock()
|
|
if staged == "" || latest != "0.1.11" {
|
|
t.Fatalf("staged %q for %s", staged, latest)
|
|
}
|
|
|
|
// a save without the channel keeps it
|
|
save(`{"theme":"dark"}`)
|
|
if got := settings.Load().UpdateChannel; got != settings.UpdateStable {
|
|
t.Fatalf("a save without updateChannel set it to %q", got)
|
|
}
|
|
// a check on Stable keeps the download
|
|
u.check()
|
|
if j := settle(); j.State != "ready" || j.Latest != "0.1.11" || downloads.Load() != 2 {
|
|
t.Fatalf("checked again on stable: %+v, %d downloads", j, downloads.Load())
|
|
}
|
|
// a value the channel doesn't have is refused
|
|
rec := httptest.NewRecorder()
|
|
Handler(nil, nil).ServeHTTP(rec, httptest.NewRequest("POST", "/api/settings", strings.NewReader(`{"updateChannel":"beta"}`)))
|
|
if rec.Code == 200 || settings.Load().UpdateChannel != settings.UpdateStable {
|
|
t.Fatalf("beta: %d, saved %q", rec.Code, settings.Load().UpdateChannel)
|
|
}
|
|
}
|
|
|
|
// What's new's notes are kept by language and channel: Stable shows every
|
|
// release since the one installed, every version at most 40, and the list
|
|
// asked on one isn't the other's.
|
|
func TestWhatsNewKeyedByChannel(t *testing.T) {
|
|
sandboxHome(t)
|
|
if got := notesKey("zh"); got != "zh" {
|
|
t.Fatalf("every version: %q", got)
|
|
}
|
|
s := settings.Load()
|
|
s.UpdateChannel = settings.UpdateStable
|
|
if err := settings.Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := notesKey("zh"); got != "zh|stable" {
|
|
t.Fatalf("stable: %q", got)
|
|
}
|
|
t.Setenv("MAGPIE_NOTES_FEED", "http://127.0.0.1:1/") // never the real one
|
|
oldV := Version
|
|
Version = "0.1.100"
|
|
defer func() { Version = oldV }()
|
|
var list []update.Note
|
|
for i := range 100 {
|
|
list = append(list, update.Note{Version: fmt.Sprintf("0.1.%d", 100-i), Notes: "- x"})
|
|
}
|
|
waiting := updateJSON{State: "available", Latest: "0.1.200", Notes: "- the next one"}
|
|
if got := withWaiting(t.Context(), list, waiting, "en"); len(got) != 101 || got[0].Version != "0.1.200" {
|
|
t.Fatalf("stable keeps %d of 101", len(got))
|
|
}
|
|
s.UpdateChannel = ""
|
|
if err := settings.Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got := withWaiting(t.Context(), list, waiting, "en"); len(got) != update.MaxNotes {
|
|
t.Fatalf("every version keeps %d", len(got))
|
|
}
|
|
}
|