Files
magpie/internal/gui/update_quiet_test.go
T
yetone 3f09b9ffc6 update: the header's Update pill shows a waiting update at once; only its x holds it, for 3 days (visamzh, normalcoder_ on X)
visamzh (0.1.4174, 0.1.4176 downloaded, Update button and Automatic
updates on) and normalcoder_ (0.1.4079) saw no Update pill for about two
days. Cause: 36eebea13 (v0.1.3879, 11-12) set /api/update's quiet until
this version had been behind for update.Quiet (3 days), counted from the
first newer version seen and kept per running version. With a release
every few minutes, every update starts that clock over, so on any version
a user updates within 3 days the pill never lit, whether a download was
waiting (ready) or one was found with downloads off (found), on every OS.
The Version row and the tray's Restart to update still offered it.

Now being behind holds nothing: ready, found and available light the
pill at once. Only the pill's x (or right-click) holds it, for
update.Quiet across the releases out meanwhile (Behind.Hushed), which
keeps 36eebea13's answer to "always lit" (the x used to hold only until
the next release, minutes later). An urgent release still lights it
through that. The old notes' "since" is never read as a dismissal.
Settings > Update button says "Hidden for 3 days" whenever the x holds
(it said "Hidden for <v> until a newer version is out" only while that
exact version was latest), and Show again lifts the hold
(update.Unhush, an empty update-skip). The x's label and toast say
3 days instead of "until the next version" (en, zh, zh-TW, ja, de).

Users on 0.1.3879 to 0.1.4179 get it with their next update: Settings >
About > Restart to update, the tray's Restart to update, or quitting.
0.1.4079 still checks, downloads and verifies the newest release: its
updater code (LatestEvery + Stage, sandbox HOME on mica) fetched
0.1.4178, passed download, verify (SHA256SUMS signature, attestation)
and unpack, and stopped only at the Team ID check because the probe
binary is unsigned.

Run (mica/mote, macOS, Go 1.26.8), at this tree:
- go test -count=1 ./internal/update ./internal/gui: ok, before and
  after the rebase onto 0b8c4bfc3 (also i18n-keys, i18n-en-no-cjk, update-quiet, update-hide there: 118/118). go vet darwin, GOOS=linux -tags
  nogui, GOOS=windows: clean. gofmt -l clean.
- Broken by hand (old semantics: first-seen sets the clock, Lit needs it
  past Quiet): TestPillLightsWhenANewerVersionIsOut,
  TestDismissalHoldsForTheQuiet and TestUpdateQuietUntilBehindAWhile
  (ready, found, available: quiet true, want false) red.
- GUI, Chromium + WebKit: update-quiet.test.cjs (en, zh, zh-TW, ja, de;
  panel 420, narrow window 400, window 900; ready and found show the
  pill, quiet hides it and Settings says Hidden for 3 days with Show
  again) and update-hide.test.cjs pass; update-quiet red on the old
  app.js (Settings row). 52 GUI files touching Settings, updates, i18n
  and menus: 882/935; the reds (menu-scroll, settings-hints,
  settings-search, settings-lines-wrap, settings-groups warm-ups) are
  the same 50 at origin/main aa358555f run alone (54 pass / 50 fail
  both), filed as #1550, #5982, #6133, #6353, #6597. plugin-card-update
  webkit was red only under --test-concurrency=3 and passes alone.
Not run: the full go test ./... and the whole GUI suite (mote over its
load, mica running another session's GUI suite); not tried in the real
app with a real download waiting.
2026-11-14 23:47:47 +08:00

48 lines
1.9 KiB
Go

package gui
import (
"path/filepath"
"testing"
"time"
"github.com/yetone/magpie/internal/update"
)
// /api/update says quiet only while the pill's dismissal holds ("红点都快
// 焊死了", certhon520 and others on X: its x hid it only until the next
// release, minutes later), and never for an urgent release. A version
// that is only behind, a download waiting or one found, is not quiet: the
// pill shows (visamzh and normalcoder_ on X, 11-14: it never came while a
// quiet counted from the first newer version started over on each update).
func TestUpdateQuietUntilBehindAWhile(t *testing.T) {
h := t.TempDir()
t.Setenv("HOME", h)
t.Setenv("USERPROFILE", h)
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
t.Setenv("APPDATA", filepath.Join(h, "AppData"))
was := Version
Version = "0.1.100"
t.Cleanup(func() { Version = was })
now := time.Now()
for _, c := range []struct {
name string
b update.Behind
state string
quiet bool
}{
{"downloaded, waiting", update.Behind{Base: "0.1.100"}, "ready", false},
{"found, downloads off", update.Behind{Base: "0.1.100"}, "found", false},
{"out, no download here", update.Behind{Base: "0.1.100"}, "available", false},
{"dismissed an hour ago", update.Behind{Base: "0.1.100", Hushed: now.Add(-time.Hour)}, "ready", true},
{"dismissed, found", update.Behind{Base: "0.1.100", Hushed: now.Add(-time.Hour)}, "found", true},
{"dismissed days ago", update.Behind{Base: "0.1.100", Hushed: now.Add(-update.Quiet - time.Minute)}, "ready", false},
{"urgent through a dismissal", update.Behind{Base: "0.1.100", Hushed: now, Urgent: "0.1.104"}, "ready", false},
{"up to date says nothing", update.Behind{Base: "0.1.100", Hushed: now}, "latest", false},
} {
u := &updater{state: c.state, behind: c.b, latest: &update.Release{Version: "0.1.105"}}
if got := u.json().Quiet; got != c.quiet {
t.Errorf("%s: quiet %v, want %v", c.name, got, c.quiet)
}
}
}