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.
116 lines
3.3 KiB
Go
116 lines
3.3 KiB
Go
package update
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// stableFor saves Settings' Update channel for one test and puts the one
|
|
// before back after it.
|
|
func stableFor(t *testing.T, channel string) {
|
|
t.Helper()
|
|
before := settings.Load()
|
|
s := before
|
|
s.UpdateChannel = channel
|
|
if err := settings.Save(s); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Cleanup(func() { settings.Save(before) })
|
|
}
|
|
|
|
// The Stable channel (ssharpcc on X): the feed is asked with
|
|
// channel=stable, and only then; every version asks it as before. The
|
|
// language goes with it either way.
|
|
func TestLatestAsksTheChannel(t *testing.T) {
|
|
var (
|
|
mu sync.Mutex
|
|
asked []string
|
|
)
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
asked = append(asked, r.URL.RawQuery)
|
|
mu.Unlock()
|
|
v := "0.1.1600"
|
|
if r.URL.Query().Get("channel") == "stable" {
|
|
v = "0.1.1550"
|
|
}
|
|
json.NewEncoder(w).Encode(Release{Version: v})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_UPDATE_FEED", srv.URL+"/api/latest")
|
|
ctx := context.Background()
|
|
|
|
for _, c := range []struct{ channel, lang, query, version string }{
|
|
{"", "zh", "lang=zh", "0.1.1600"},
|
|
{"", "", "", "0.1.1600"},
|
|
{settings.UpdateStable, "zh", "channel=stable&lang=zh", "0.1.1550"},
|
|
{settings.UpdateStable, "", "channel=stable", "0.1.1550"},
|
|
} {
|
|
t.Run(fmt.Sprintf("%q %q", c.channel, c.lang), func(t *testing.T) {
|
|
stableFor(t, c.channel)
|
|
mu.Lock()
|
|
asked = nil
|
|
mu.Unlock()
|
|
rel, err := LatestIn(ctx, c.lang)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
if len(asked) != 1 || asked[0] != c.query {
|
|
t.Fatalf("asked %q, want %q", asked, c.query)
|
|
}
|
|
if rel.Version != c.version {
|
|
t.Fatalf("got %s, want %s", rel.Version, c.version)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// What's new after a Stable update is every release since the one
|
|
// installed, read as one list: the cap of 40 is every version's only.
|
|
func TestStableNotesAreAll(t *testing.T) {
|
|
var notes []Note
|
|
for i := 1; i <= 120; i++ {
|
|
notes = append(notes, Note{Version: fmt.Sprintf("0.1.%d", 1000+i), Notes: fmt.Sprintf("- change %d", i)})
|
|
}
|
|
stableFor(t, "")
|
|
if got := Between(notes, "0.1.1000", "0.1.1120"); len(got) != MaxNotes || got[0].Version != "0.1.1120" {
|
|
t.Fatalf("every version: %d notes, first %s", len(got), got[0].Version)
|
|
}
|
|
stableFor(t, settings.UpdateStable)
|
|
got := Between(notes, "0.1.1000", "0.1.1120")
|
|
if len(got) != 120 || got[0].Version != "0.1.1120" || got[119].Version != "0.1.1001" {
|
|
t.Fatalf("stable: %d notes", len(got))
|
|
}
|
|
if MostNotes() != StableMaxNotes {
|
|
t.Fatalf("MostNotes on stable: %d", MostNotes())
|
|
}
|
|
}
|
|
|
|
// Settings take "stable" or nothing; anything else is refused, and the
|
|
// value is kept as saved.
|
|
func TestUpdateChannelSaved(t *testing.T) {
|
|
stableFor(t, settings.UpdateStable)
|
|
if got := settings.Load().UpdateChannel; got != "stable" || !Stable() {
|
|
t.Fatalf("saved stable, read %q", got)
|
|
}
|
|
for _, bad := range []string{"Stable", "beta", "every", " stable"} {
|
|
s := settings.Load()
|
|
s.UpdateChannel = bad
|
|
if err := settings.Save(s); err == nil {
|
|
t.Errorf("%q was saved", bad)
|
|
}
|
|
}
|
|
if got := settings.Load().UpdateChannel; got != "stable" {
|
|
t.Fatalf("a refused save changed it: %q", got)
|
|
}
|
|
}
|