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.
182 lines
6.8 KiB
Go
182 lines
6.8 KiB
Go
package update
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"reflect"
|
|
"testing"
|
|
)
|
|
|
|
// What changed is shown after an upgrade between releases only.
|
|
func TestShowNotes(t *testing.T) {
|
|
for _, c := range []struct {
|
|
name, last, current string
|
|
existed bool
|
|
after string
|
|
show bool
|
|
}{
|
|
{"upgrade", "0.1.600", "0.1.604", true, "0.1.600", true},
|
|
{"upgrade, v kept", "v0.1.600", "0.1.604", true, "0.1.600", true},
|
|
{"minor upgrade", "0.1.604", "0.2.0", true, "0.1.604", true},
|
|
{"fresh install", "", "0.1.604", false, "", false},
|
|
{"from before versions were kept", "", "0.1.604", true, "", true},
|
|
{"same version", "0.1.604", "0.1.604", true, "", false},
|
|
{"downgrade", "0.1.604", "0.1.600", true, "", false},
|
|
{"source build", "0.1.600", "dev", true, "", false},
|
|
{"source build after a release", "0.1.600", "v0.1.604-3-g0bcb2cc", true, "", false},
|
|
{"last unreadable", "dev", "0.1.604", true, "", false},
|
|
} {
|
|
after, show := ShowNotes(c.last, c.current, c.existed)
|
|
if after != c.after || show != c.show {
|
|
t.Errorf("%s: ShowNotes(%q, %q, %v) = %q, %v; want %q, %v", c.name, c.last, c.current, c.existed, after, show, c.after, c.show)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestStripInstall(t *testing.T) {
|
|
md := "## Bug Fixes\n\n- Fixed a thing. (#464)\n\n### Install\n\nDownload from [usemagpie.ai](https://usemagpie.ai).\n\n- **macOS:** `magpie.dmg`\n"
|
|
if got, want := StripInstall(md), "## Bug Fixes\n\n- Fixed a thing. (#464)"; got != want {
|
|
t.Errorf("got %q, want %q", got, want)
|
|
}
|
|
// a section after it at its level or above stays
|
|
md = "## Install\n\nlinks\n\n### more links\n\n## New Features\n\n- A feature. (#1)"
|
|
if got, want := StripInstall(md), "## New Features\n\n- A feature. (#1)"; got != want {
|
|
t.Errorf("got %q, want %q", got, want)
|
|
}
|
|
if got := StripInstall("- Install the CLI faster. (#2)"); got != "- Install the CLI faster. (#2)" {
|
|
t.Errorf("a bullet naming Install was taken: %q", got)
|
|
}
|
|
// the Chinese notes' section is 安装 (#649), Japanese ones' インストール
|
|
for _, h := range []string{"安装", "インストール"} {
|
|
md = "## Bug Fixes\n\n- 修复了一件事。\n\n### " + h + "\n\n从 [usemagpie.ai](https://usemagpie.ai) 下载。"
|
|
if got, want := StripInstall(md), "## Bug Fixes\n\n- 修复了一件事。"; got != want {
|
|
t.Errorf("%s: got %q, want %q", h, got, want)
|
|
}
|
|
}
|
|
if got := StripInstall("- 安装更快了。"); got != "- 安装更快了。" {
|
|
t.Errorf("a bullet naming 安装 was taken: %q", got)
|
|
}
|
|
}
|
|
|
|
func TestBetween(t *testing.T) {
|
|
notes := []Note{
|
|
{Version: "0.1.598", Notes: "- old"},
|
|
{Version: "v0.1.604", Notes: "- four\n\n### Install\n\nlinks"},
|
|
{Version: "0.1.605", Notes: "- not out here yet"},
|
|
{Version: "0.1.601", Notes: "- one"},
|
|
{Version: "0.1.600", Notes: "- zero"},
|
|
{Version: "0.1.602", Notes: "### Install\n\nlinks"}, // nothing left
|
|
{Version: "0.1.603", Notes: "- three"},
|
|
}
|
|
vs := func(ns []Note) (out []string) {
|
|
for _, n := range ns {
|
|
out = append(out, n.Version)
|
|
}
|
|
return out
|
|
}
|
|
got := Between(notes, "0.1.600", "0.1.604")
|
|
if want := []string{"0.1.604", "0.1.603", "0.1.601"}; !reflect.DeepEqual(vs(got), want) {
|
|
t.Fatalf("got %v, want %v", vs(got), want)
|
|
}
|
|
if got[0].Notes != "- four" {
|
|
t.Errorf("Install kept: %q", got[0].Notes)
|
|
}
|
|
if got := Between(notes, "", "0.1.604"); !reflect.DeepEqual(vs(got), []string{"0.1.604"}) {
|
|
t.Errorf("current alone: %v", vs(got))
|
|
}
|
|
if got := Between(notes, "0.1.604", "0.1.604"); len(got) != 0 {
|
|
t.Errorf("nothing between: %v", vs(got))
|
|
}
|
|
}
|
|
|
|
func TestNotesBetween(t *testing.T) {
|
|
var asked string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
asked = r.URL.RawQuery
|
|
json.NewEncoder(w).Encode(map[string]any{"releases": []Note{
|
|
{Version: "0.1.604", Notes: "- four", URL: "https://example.com/4"},
|
|
{Version: "0.1.600", Notes: "- zero"},
|
|
{Version: "0.1.602", Notes: "- two"},
|
|
}})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_NOTES_FEED", srv.URL)
|
|
got, err := NotesBetween(context.Background(), "0.1.600", "0.1.604", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if asked != "after=0.1.600&upto=0.1.604" {
|
|
t.Errorf("asked %q", asked)
|
|
}
|
|
if len(got) != 2 || got[0].Version != "0.1.604" || got[1].Version != "0.1.602" || got[0].URL != "https://example.com/4" {
|
|
t.Errorf("%+v", got)
|
|
}
|
|
srv.Close()
|
|
if _, err := NotesBetween(context.Background(), "0.1.600", "0.1.604", ""); err == nil {
|
|
t.Error("no error offline")
|
|
}
|
|
}
|
|
|
|
// Settings' What's new can show this version and the 10, 20, 50 or 100
|
|
// before it (Linka on Discord): the site is asked for that many alone, and
|
|
// a site that sends more (from before it took a limit) is cut to them.
|
|
func TestNotesBack(t *testing.T) {
|
|
versions := func(ns []Note) []string {
|
|
out := []string{}
|
|
for _, n := range ns {
|
|
out = append(out, n.Version)
|
|
}
|
|
return out
|
|
}
|
|
var asked []string
|
|
var list []Note
|
|
for v := 660; v >= 590; v-- {
|
|
if v == 607 {
|
|
continue // never released
|
|
}
|
|
list = append(list, Note{Version: fmt.Sprintf("0.1.%d", v), Notes: fmt.Sprintf("- %d\n\n## Install\n\nDownload it.", v)})
|
|
}
|
|
list[660-617].Notes = "## Install\n\nonly links" // 0.1.617: nothing left once Install is out
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
asked = append(asked, r.URL.RawQuery)
|
|
// a site from before limit: every release, whatever was asked
|
|
json.NewEncoder(w).Encode(map[string]any{"releases": list})
|
|
}))
|
|
defer srv.Close()
|
|
t.Setenv("MAGPIE_NOTES_FEED", srv.URL)
|
|
got, err := NotesBack(context.Background(), "0.1.612", 10, "zh")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if want := []string{"lang=zh&limit=11&upto=0.1.612"}; !reflect.DeepEqual(asked, want) {
|
|
t.Errorf("asked %q, want %q", asked, want)
|
|
}
|
|
// 0.1.612 and the ten before it, 0.1.607 never released
|
|
want := []string{"0.1.612", "0.1.611", "0.1.610", "0.1.609", "0.1.608", "0.1.606", "0.1.605", "0.1.604", "0.1.603", "0.1.602", "0.1.601"}
|
|
if !reflect.DeepEqual(versions(got), want) {
|
|
t.Errorf("got %v, want %v", versions(got), want)
|
|
}
|
|
if got[0].Notes != "- 612" {
|
|
t.Errorf("Install kept: %q", got[0].Notes)
|
|
}
|
|
// newer than upto isn't counted; an empty one counts but isn't shown
|
|
if got, want := versions(Back(list, "0.1.619", 3)), []string{"0.1.619", "0.1.618", "0.1.616"}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("back 3 from 0.1.619: %v, want %v", got, want)
|
|
}
|
|
// fewer than asked: what there is
|
|
if got, want := versions(Back(list, "0.1.592", 10)), []string{"0.1.592", "0.1.591", "0.1.590"}; !reflect.DeepEqual(got, want) {
|
|
t.Errorf("short list: %v, want %v", got, want)
|
|
}
|
|
// more than MaxNotes: the 100 asked for are all kept
|
|
if got := Back(list, "0.1.660", 100); len(got) != len(list)-1 {
|
|
t.Errorf("back 100: %d releases, want %d", len(got), len(list)-1)
|
|
}
|
|
srv.Close()
|
|
if _, err := NotesBack(context.Background(), "0.1.612", 10, ""); err == nil {
|
|
t.Error("no error offline")
|
|
}
|
|
}
|