Linka (linkaww, Discord, 10-25): 希望「关于 - 更新内容」加个可选项,查看
「上次更新以来 / 当前版本前 10 / 20 / 50 / 100 个版本」的更新说明.
Settings › About › What's new now has a pill in its head (the app's
menu, sess-pick, never a native select): "Since the last update", the
default and what it showed before, or "This version and {n} before" for
10, 20, 50 and 100. The dialog shown by itself after an update has no
pill and is unchanged.
- site/worker.js: /api/notes takes limit=, the newest that many after
upto, so a request for 11 isn't answered with 100.
- internal/update: NotesBack(ctx, upto, n, lang) asks upto and limit
n+1; Back(notes, upto, n) keeps upto and the n releases before it,
newest first, Install sections stripped, empties dropped. It is not
capped at MaxNotes (40), which only Between keeps.
- internal/gui/whatsnew.go: /api/whatsnew?all=1&last=N, for N in
10/20/50/100 only (anything else is the default). Cached per language,
the longest range asked kept, and a shorter one cut from it, so
picking 10 after 100 asks nothing and a reopen asks nothing. A failed
fetch is unknown: the reply carries error and whatever range was had
before.
- app.js: openWhatsNew(b, last) and wnRange. A pick that fails keeps
the notes last shown, says "Couldn't load the release notes" with Try
again above them, and Try again asks the same range.
- The archive helpers (archivedCalls, headersPanel, downloadArchive,
archiveBodyPanel), used only by the Usage page, moved to
plugins/usage/page.js as d08b6118b did, so app.js stays under its
budget (1,319,177 of 1,321,336); no budget raised.
- i18n: three strings in zh, zh-TW, ja and de.
Run at the pushed head (rebased on origin/main 0d2a10116):
- go test -count=1 -tags nogui ./internal/update/ ./internal/gui/ in a
sandbox HOME: ok (TestNotesBack, TestWhatsNewBackRanges,
TestCoreScriptBudget among them).
- gofmt -l: none. go build ./...; go vet ./...; GOOS=linux go vet -tags
nogui ./...; GOOS=windows go vet ./...: ok.
- node --test site/worker.test.mjs: 21 pass (new: limit keeps the
newest that many up to upto; "", 0, x and -1 mean no limit).
- GUI at this head, both engines: whats-new-range (new), whats-new,
whats-new-failed, i18n-keys, ledger-cache-unknown, request-archive and
request-archive-usage (the Usage page holds the moved helpers): 50 of
50. whats-new-range.test.cjs alone is 12 of 12: five languages x two
engines plus the post-update dialog in both. Covers the default label
and no last= asked, the menu's head and five items, 10 then 100,
the same pick asking nothing, a failed 50 keeping the 100 shown with
the error above, Try again, no scroll, no left-border accent, and a
440px window with the pill inside the dialog.
- Whole GUI suite (869 files), chromium then webkit, concurrency 4:
still running at push time, started at 1f156ba40 (the same change on
e57e78563); the tree was rebased under it at 01:45. Chromium at 01:46:
1725 top-level tests passed, 7 red, none in a What's new or Usage file:
agents' sign-ins, Plugins › Built-in, zh-TW 420px context map, gateway
mode, an MCP server out of the library, and "a menu opened from a long
text box's rule stays open" (en, zh). They will be checked against
origin/main and filed or fixed when the run ends. Before the rebase,
usage-ledger's "newest live route needs no return-to-live button" was
red here and on an origin/main e57e78563 copy alike (#3104, #3001).
Broken by hand, each red, then restored:
- the pill not added to the head: whats-new-range red.
- the kept notes not used on a failure: red at "the notes shown before
are kept".
- the ?last= route skipped: TestWhatsNewBackRanges red.
- Back not cutting to n+1: TestNotesBack red.
Not tried:
- the real site: the test fakes /api/notes and /api/whatsnew. The site
holds GitHub's newest 100 releases, so "100 before" on the newest
version can show at most 100. An undeployed site ignores limit; the
app cuts the list itself.
- the real app window (Wails/WebKitGTK); only Playwright's engines.
- go test ./... in full was not run: the machine had a queue of other
sessions' full suites, and the owner's rule is not to hold a verified
commit behind one.
Known limits: a range view carries no pending (waiting update) notes;
if a longer cached range dropped an Install-only release, a range cut
from it can reach one release further back than a fresh ask would.
175 lines
5.7 KiB
Go
175 lines
5.7 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"slices"
|
|
"strconv"
|
|
"sync"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/update"
|
|
)
|
|
|
|
// Settings' What's new offers, besides the notes since the last update,
|
|
// this version and the 10, 20, 50 or 100 before it (Linka on Discord). The
|
|
// site is asked for that many alone, once per language and longest range:
|
|
// a shorter range, or the same again, is cut from what was had. A failed
|
|
// ask is said, with the shorter range had before; a range magpie doesn't
|
|
// offer is the default. The site's list is magpie-releases' shape, with
|
|
// 0.1.1407 never released and each note's Install section.
|
|
func TestWhatsNewBackRanges(t *testing.T) {
|
|
home := t.TempDir()
|
|
t.Setenv("XDG_CONFIG_HOME", home)
|
|
var list []update.Note
|
|
for v := 1420; v >= 1290; v-- {
|
|
if v == 1407 {
|
|
continue
|
|
}
|
|
s := strconv.Itoa(v)
|
|
list = append(list, update.Note{
|
|
Version: "0.1." + s,
|
|
Notes: "## Bug Fixes\n\n- fix " + s + "\n\n## Install\n\n- macOS: [magpie-0.1." + s + "-mac-arm64.dmg](https://github.com/yetone/magpie-releases/releases/download/v0.1." + s + "/magpie-0.1." + s + "-mac-arm64.dmg)",
|
|
})
|
|
}
|
|
var mu sync.Mutex
|
|
var asked []string
|
|
down := false
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
mu.Lock()
|
|
asked = append(asked, r.URL.RawQuery)
|
|
failing := down
|
|
mu.Unlock()
|
|
if failing {
|
|
http.Error(w, `{"error":"no releases"}`, http.StatusServiceUnavailable)
|
|
return
|
|
}
|
|
// as the site answers: up to upto, newest first, at most limit
|
|
var out []update.Note
|
|
upto := r.URL.Query().Get("upto")
|
|
limit, _ := strconv.Atoi(r.URL.Query().Get("limit"))
|
|
for _, n := range list {
|
|
if !update.Newer(n.Version, upto) && (limit <= 0 || len(out) < limit) {
|
|
out = append(out, n)
|
|
}
|
|
}
|
|
json.NewEncoder(w).Encode(map[string]any{"releases": out})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_NOTES_FEED", srv.URL)
|
|
t.Setenv("MAGPIE_UPDATE_FEED", "http://127.0.0.1:1/")
|
|
oldV, oldNews, oldUp := Version, news, updates
|
|
t.Cleanup(func() { Version, news, updates = oldV, oldNews, oldUp })
|
|
Version = "0.1.1410"
|
|
news = &whatsNew{after: "0.1.1408", pending: true, shown: true}
|
|
updates = &updater{state: "latest", notesIn: "en"}
|
|
mux := http.NewServeMux()
|
|
whatsNewRoutes(mux)
|
|
ask := func(q string) (whatsNewJSON, []string) {
|
|
mu.Lock()
|
|
asked = nil
|
|
mu.Unlock()
|
|
rec := httptest.NewRecorder()
|
|
mux.ServeHTTP(rec, httptest.NewRequest("GET", "/api/whatsnew?all=1&lang=en"+q, nil))
|
|
var j whatsNewJSON
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &j); err != nil {
|
|
t.Fatal(rec.Code, rec.Body.String(), err)
|
|
}
|
|
mu.Lock()
|
|
defer mu.Unlock()
|
|
return j, slices.Clone(asked)
|
|
}
|
|
versions := func(j whatsNewJSON) []string {
|
|
out := []string{}
|
|
for _, r := range j.Releases {
|
|
out = append(out, r.Version)
|
|
}
|
|
return out
|
|
}
|
|
// the n releases before 0.1.1410, newest first, 0.1.1407 skipped
|
|
before := func(n int) []string {
|
|
out := []string{}
|
|
for _, r := range list {
|
|
if !update.Newer(r.Version, Version) && len(out) < n+1 {
|
|
out = append(out, r.Version)
|
|
}
|
|
}
|
|
return out
|
|
}
|
|
|
|
// the default is as it was: the notes since the last update
|
|
j, _ := ask("")
|
|
if got := versions(j); !slices.Equal(got, []string{"0.1.1410", "0.1.1409"}) {
|
|
t.Fatalf("default: %v", got)
|
|
}
|
|
// 10 before: eleven releases, from the site's 11 alone, Install out
|
|
j, got := ask("&last=10")
|
|
if !slices.Equal(got, []string{"lang=en&limit=11&upto=0.1.1410"}) {
|
|
t.Fatalf("10 asked the site %q", got)
|
|
}
|
|
if !slices.Equal(versions(j), before(10)) || j.Error != "" {
|
|
t.Fatalf("10: %v (%q), want %v", versions(j), j.Error, before(10))
|
|
}
|
|
if j.Releases[0].Notes != "## Bug Fixes\n\n- fix 1410" {
|
|
t.Fatalf("10: Install kept: %q", j.Releases[0].Notes)
|
|
}
|
|
// the same again: not asked again
|
|
if j, got = ask("&last=10"); len(got) != 0 || len(j.Releases) != 11 {
|
|
t.Fatalf("10 again asked %q, %d releases", got, len(j.Releases))
|
|
}
|
|
// 100, past MaxNotes: asked once, 101 releases; then 20 and 50 are cut
|
|
// from it, without asking
|
|
if j, got = ask("&last=100"); len(got) != 1 || !slices.Equal(versions(j), before(100)) {
|
|
t.Fatalf("100 asked %q, got %v", got, versions(j))
|
|
}
|
|
for _, n := range []int{20, 50, 10} {
|
|
if j, got = ask("&last=" + strconv.Itoa(n)); len(got) != 0 || !slices.Equal(versions(j), before(n)) {
|
|
t.Fatalf("%d after 100 asked %q, got %v", n, got, versions(j))
|
|
}
|
|
}
|
|
// a range magpie doesn't offer: the default, the site not asked for it
|
|
for _, q := range []string{"&last=7", "&last=x", "&last=1000"} {
|
|
if j, _ = ask(q); !slices.Equal(versions(j), []string{"0.1.1410", "0.1.1409"}) {
|
|
t.Fatalf("%s: %v", q, versions(j))
|
|
}
|
|
}
|
|
|
|
// a fresh run: the site failing says so, keeping
|
|
// the shorter range had before
|
|
news = &whatsNew{}
|
|
if j, _ = ask("&last=20"); len(j.Releases) != 21 {
|
|
t.Fatalf("fresh 20: %d", len(j.Releases))
|
|
}
|
|
mu.Lock()
|
|
down = true
|
|
mu.Unlock()
|
|
j, got = ask("&last=50")
|
|
if len(got) != 1 || j.Error == "" {
|
|
t.Fatalf("50 with the site down: asked %q, error %q", got, j.Error)
|
|
}
|
|
if !slices.Equal(versions(j), before(20)) {
|
|
t.Fatalf("50 with the site down: %v, want the 20 had", versions(j))
|
|
}
|
|
// and once it answers, asked again: the 50
|
|
mu.Lock()
|
|
down = false
|
|
mu.Unlock()
|
|
if j, got = ask("&last=50"); len(got) != 1 || j.Error != "" || !slices.Equal(versions(j), before(50)) {
|
|
t.Fatalf("50 back: asked %q, error %q, %v", got, j.Error, versions(j))
|
|
}
|
|
// nothing had at all and the site failing: an error, no notes
|
|
news = &whatsNew{}
|
|
mu.Lock()
|
|
down = true
|
|
mu.Unlock()
|
|
if j, _ = ask("&last=10"); j.Error == "" || len(j.Releases) != 0 || j.URL == "" {
|
|
t.Fatalf("down from the start: %+v", j)
|
|
}
|
|
// a build from source has no releases to list
|
|
Version = "dev"
|
|
if j, got = ask("&last=10"); len(got) != 0 || len(j.Releases) != 0 {
|
|
t.Fatalf("dev: asked %q, %v", got, versions(j))
|
|
}
|
|
}
|