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.
123 lines
3.4 KiB
Go
123 lines
3.4 KiB
Go
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)
|
|
}
|
|
})
|
|
}
|