From b005d1a473a0e6863647cfea54f755f5a78b4255 Mon Sep 17 00:00:00 2001 From: yetone Date: Sat, 14 Nov 2026 12:17:33 +0800 Subject: [PATCH] update: a fresh install of Stable's version stays on Stable (fishmagic80 on X) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The site now offers Stable's downloads, but the app's Update channel is Every version until changed, so a Stable install was offered the newest at its first check. Before that check, a fresh install (no version run before and magpie's folder new, from whatsNew.start) asks the feed for Stable's version and the newest; when it is Stable's and a newer one is out, settings take "updateChannel": "stable" (settings.TakeStable, under the file lock, keeping a channel already set). A feed that can't be read is unknown and asked again at the next check. A version that is both Stable's and the newest stays on Every version: its download can't be told apart. update.LatestStable never falls back to GitHub. docs/reference.md and the privacy pages (en, zh, ja, llms-full.txt) say a fresh install asks ?channel=stable once. Old installs: nothing changes for them. Until a release with this becomes Stable, a Stable download (0.1.3078 today) is still offered the newest unless Settings → Update channel is set to Stable. Run at 936c70756, on mote: gofmt -l internal/ clean; go vet (darwin), GOOS=linux and GOOS=windows go vet of internal/gui, update, settings ok; go test -count=1 ./internal/update ./internal/settings ./internal/gui ok (gui 99.9s). TestFreshStableInstallStaysOnStable goes red (2 subtests) with the takeStable call removed (broken by hand, on mica). llms-full.txt regenerated and current. Not run: the full go test ./... (mote and mica each had several suites queued on the lock); not tried with a real Stable install. --- docs/reference.md | 8 ++ internal/gui/stable_install.go | 64 +++++++++++++++ internal/gui/stable_install_test.go | 122 ++++++++++++++++++++++++++++ internal/gui/update.go | 1 + internal/gui/whatsnew.go | 4 +- internal/settings/settings.go | 18 ++++ internal/update/update.go | 15 ++++ site/public/docs/ja/privacy.html | 2 +- site/public/docs/privacy.html | 2 +- site/public/docs/zh/privacy.html | 2 +- site/public/llms-full.txt | 2 +- 11 files changed, 235 insertions(+), 5 deletions(-) create mode 100644 internal/gui/stable_install.go create mode 100644 internal/gui/stable_install_test.go diff --git a/docs/reference.md b/docs/reference.md index d3ea6fef0..940e26b4f 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -3513,6 +3513,14 @@ keeps it and waits until Stable passes it. While it waits, the Version row says *Up to date on Stable*, names the newest version out on Every version, and offers to switch to Every version. +The site's downloads offer Stable's version beside the newest +(`usemagpie.ai/download/stable/`). A fresh install of it (no +magpie run on this computer before) takes Stable before its first update +check, so it isn't offered the newest at once: it asks the feed for +Stable's version and the newest, and when it is Stable's and a newer one +is out, sets `"updateChannel": "stable"`. A channel you set is kept, and a +version that is both Stable's and the newest stays on Every version. + The update feed works this out from the release list (`https://usemagpie.ai/api/latest?channel=stable`); nothing is promoted by hand. A release is urgent when its notes have a line that starts with diff --git a/internal/gui/stable_install.go b/internal/gui/stable_install.go new file mode 100644 index 000000000..d04202306 --- /dev/null +++ b/internal/gui/stable_install.go @@ -0,0 +1,64 @@ +package gui + +import ( + "context" + "log" + "sync/atomic" + + "github.com/yetone/magpie/internal/settings" + "github.com/yetone/magpie/internal/update" +) + +// A fresh install of the Stable channel's version stays on Stable +// (fishmagic80 on X). usemagpie.ai offers Stable's downloads beside the +// newest's, and Settings' Update channel is every version until changed, +// so an app put in from a Stable download was offered the newest at its +// first check. Before that check, a fresh install (whatsNew.start: no +// version run before, and magpie's folder new) asks the feed for Stable's +// version; when it is this one and a newer one is out, the channel becomes +// Stable. A channel already set is kept, and so is every version when +// this one is also the newest, where the download can't be told apart. + +// freshInstall: this run is magpie's first here, and the channel isn't +// settled yet. A feed that can't be read leaves it for the next check. +var freshInstall atomic.Bool + +// latestStable and latestEvery are update's; tests stand in for them. +var ( + latestStable = update.LatestStable + latestEvery = func(ctx context.Context) (*update.Release, error) { return update.LatestEvery(ctx, "") } +) + +// takeStable runs before an update check reads the channel. +func takeStable(ctx context.Context) { + if !freshInstall.Load() { + return + } + if !update.Released(Version) || settings.Load().UpdateChannel != "" { + freshInstall.Store(false) + return + } + st, err := latestStable(ctx) + if err != nil { + log.Println("stable on a fresh install:", err) // unknown: asked again next check + return + } + if st.Version != Version { + freshInstall.Store(false) + return + } + every, err := latestEvery(ctx) + if err != nil { + log.Println("stable on a fresh install:", err) + return + } + freshInstall.Store(false) + if !update.Newer(every.Version, Version) { + return + } + if took, err := settings.TakeStable(); err != nil { + log.Println("stable on a fresh install:", err) + } else if took { + log.Printf("a fresh install of Stable's %s: the update channel is Stable", Version) + } +} diff --git a/internal/gui/stable_install_test.go b/internal/gui/stable_install_test.go new file mode 100644 index 000000000..d1dd9cca4 --- /dev/null +++ b/internal/gui/stable_install_test.go @@ -0,0 +1,122 @@ +package gui + +import ( + "encoding/json" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "sync/atomic" + "testing" + "time" + + "github.com/yetone/magpie/internal/settings" + "github.com/yetone/magpie/internal/update" +) + +// A fresh install of Stable's version stays on Stable (fishmagic80 on X): +// usemagpie.ai's Stable download, 0.1.11, put in where magpie never ran, +// takes Settings' Update channel Stable before its first check, so that +// check finds nothing newer and 0.1.12 isn't offered. The newest's +// download, an install magpie ran in before, a version that is both +// Stable's and the newest, and a feed that can't be read leave the +// channel on every version. +func TestFreshStableInstallStaysOnStable(t *testing.T) { + stableV, newest := "0.1.11", "0.1.12" + var down atomic.Bool + var asked atomic.Int32 + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + asked.Add(1) + if down.Load() { + http.Error(w, "down", 502) + return + } + v := newest + if r.URL.Query().Get("channel") == "stable" { + v = stableV + } + json.NewEncoder(w).Encode(update.Release{Version: v}) + })) + defer srv.Close() + t.Setenv("MAGPIE_UPDATE_FEED", srv.URL) + oldV := Version + defer func() { Version = oldV }() + o := updates + defer func() { updates = o }() + defer freshInstall.Store(false) + + // start is a first run of version in a new magpie folder, or (used) + // one that held settings before this run; then the first check + run := func(t *testing.T, version string, used bool) updateJSON { + t.Helper() + sandboxHome(t) + Version = version + if used { + s := settings.Load() + s.Theme = "dark" + if err := settings.Save(s); err != nil { + t.Fatal(err) + } + old := started.Add(-time.Hour) + if err := os.Chtimes(filepath.Join(settings.Dir(), "settings.json"), old, old); err != nil { + t.Fatal(err) + } + } + (&whatsNew{}).start() + updates = &updater{} + updates.check() + return updates.json() + } + + t.Run("the Stable download", func(t *testing.T) { + j := run(t, "0.1.11", false) + if got := settings.Load().UpdateChannel; got != settings.UpdateStable { + t.Fatalf("channel %q", got) + } + if j.State != "latest" || j.Latest == newest { + t.Fatalf("offered the newest: %+v", j) + } + if freshInstall.Load() { + t.Fatal("still asks at the next check") + } + }) + t.Run("the newest's download", func(t *testing.T) { + run(t, "0.1.12", false) + if got := settings.Load().UpdateChannel; got != "" { + t.Fatalf("channel %q", got) + } + }) + t.Run("magpie ran here before", func(t *testing.T) { + before := asked.Load() + run(t, "0.1.11", true) + if got := settings.Load().UpdateChannel; got != "" { + t.Fatalf("channel %q", got) + } + if n := asked.Load() - before; n != 1 { + t.Fatalf("the feed was asked %d times, not once for the check itself", n) + } + }) + t.Run("Stable's is the newest too", func(t *testing.T) { + stableV = newest + defer func() { stableV = "0.1.11" }() + run(t, newest, false) + if got := settings.Load().UpdateChannel; got != "" { + t.Fatalf("channel %q", got) + } + }) + t.Run("the feed down is unknown, asked again", func(t *testing.T) { + down.Store(true) + run(t, "0.1.11", false) + if got := settings.Load().UpdateChannel; got != "" { + t.Fatalf("channel %q on a failed read", got) + } + if !freshInstall.Load() { + t.Fatal("a failed read settled it") + } + down.Store(false) + updates.check() + if got := settings.Load().UpdateChannel; got != settings.UpdateStable { + t.Fatalf("the next check: channel %q", got) + } + }) +} diff --git a/internal/gui/update.go b/internal/gui/update.go index 8e373ae41..286e23565 100644 --- a/internal/gui/update.go +++ b/internal/gui/update.go @@ -491,6 +491,7 @@ func (u *updater) run() { ctx := context.Background() cctx, cancel := context.WithTimeout(ctx, checkWait) defer cancel() + takeStable(cctx) // a fresh install of Stable's version stays on Stable s := settings.Load() u.mu.Lock() lang := u.lang diff --git a/internal/gui/whatsnew.go b/internal/gui/whatsnew.go index 1615c903e..5c13fef46 100644 --- a/internal/gui/whatsnew.go +++ b/internal/gui/whatsnew.go @@ -154,7 +154,9 @@ func (n *whatsNew) start() { dir := settings.Dir() b, _ := os.ReadFile(filepath.Join(dir, lastRunFile)) last := strings.TrimSpace(string(b)) - after, show := update.ShowNotes(last, Version, last == "" && usedBefore(dir)) + used := usedBefore(dir) + after, show := update.ShowNotes(last, Version, last == "" && used) + freshInstall.Store(last == "" && !used) // takeStable // a restart to update into this version: its notes wait in Settings mark := filepath.Join(dir, updatedInAppFile) m, err := os.ReadFile(mark) diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 0cf792e49..ddc0a06e6 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -2360,6 +2360,24 @@ func SetRouterAllTools(on bool) error { return save(s, true) } +// TakeStable puts UpdateChannel on Stable when no channel is set, from +// what the file holds now: a fresh install of the Stable version (the +// site's Stable download) stays on Stable. A channel already set is the +// user's, and is kept. It says whether it changed the channel. A settings +// file that can't be read is left as it is, with the error. +func TakeStable() (bool, error) { + defer lockFile()() + s, err := loadChecked() + if err != nil { + return false, err + } + if s.UpdateChannel != "" { + return false, nil + } + s.UpdateChannel = UpdateStable + return true, save(s, false) +} + // EditCheckinOff changes CheckinOff alone, as edit returns it from what the // file holds now, so a save elsewhere from an older snapshot isn't undone. // A settings file that can't be read is left as it is, with the error. diff --git a/internal/update/update.go b/internal/update/update.go index 8e57c3c9a..fb230992e 100644 --- a/internal/update/update.go +++ b/internal/update/update.go @@ -143,6 +143,21 @@ func LatestEvery(ctx context.Context, lang string) (*Release, error) { return latestAt(ctx, withLang(Feed(), lang), lang) } +// LatestStable is the Stable channel's release, whatever Settings' +// channel: what a fresh install compares itself with, to stay on Stable +// when it is Stable's version (the site's Stable download). Only the site +// knows it, so a failed feed is never answered from GitHub. +func LatestStable(ctx context.Context) (*Release, error) { + u, err := url.Parse(Feed()) + if err != nil { + return nil, err + } + q := u.Query() + q.Set("channel", settings.UpdateStable) + u.RawQuery = q.Encode() + return latestFrom(ctx, u.String(), "") +} + func latestAt(ctx context.Context, feed, lang string) (*Release, error) { if githubOnly() { return githubLatest(ctx, lang) diff --git a/site/public/docs/ja/privacy.html b/site/public/docs/ja/privacy.html index 9b7575a3d..4980c0221 100644 --- a/site/public/docs/ja/privacy.html +++ b/site/public/docs/ja/privacy.html @@ -234,7 +234,7 @@

usemagpie.ai に見えるもの

magpie はプライバシー設定にかかわらず、どのアプリも自分の更新サーバーに尋ねるのと同じように、自分のサイトにいくつか尋ねます。どのリクエストにもインストール ID やアカウントは付きません。