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.
This commit is contained in:
yetone
2026-11-14 23:47:47 +08:00
parent 1106a33a89
commit 3f09b9ffc6
11 changed files with 221 additions and 147 deletions
+27 -19
View File
@@ -894,26 +894,34 @@ See `TestGatewayPauseAndResume`, `TestGatewayPauseRollsBack`,
`TestGatewayResumesOnWire`, `TestGatewayPauseFileUnreadable`,
`TestTrayMenuLabels` and `gateway-pause.test.cjs`.
### The Update pill waits until it is news
### The Update pill and its 3-day ×
A release comes every few minutes, so a newer one is nearly always out and
downloaded, and a pill lit for each was never out (certhon520, jkd6688,
Yuyuaneth and milianxinqi on X, 11-12). The header's Update pill (window and
tray panel alike) lights only when `/api/update` has no `quiet`:
this version has been behind for `update.Quiet` (3 days, the Stable
channel's soak), counted from the first newer version seen and kept across
restarts in `update-behind.json` (`update.Behind`, for the version running,
so an update starts it over), or an urgent release is out (a line starting
"**Urgent release:**" in the latest's notes, or in any release between this
one and it, `urgentBetween`). An urgent release lights the pill at once and
a dismissal does not hide it. Dismissing with the × hides that version and
starts the quiet over (`quietAgain`), so the pill is not back with the next
release. The pill waiting changes nothing else: Settings › Version, the
tray's Restart to update, quitting and Restart automatically work at any
time. Plugin updates have their own dot on Plugins, which lights only for
a plugin that does not update by itself. See `TestPillWaitsForTheQuiet`,
`TestUrgentLightsThePillAtOnce`, `TestDismissalStartsTheQuietOver`,
`TestUpdateQuietUntilBehindAWhile` and `update-quiet.test.cjs`.
The header's Update pill (window and tray panel alike) lights as soon as a
newer version is downloaded and waiting (`ready`), found with downloads off
(`found`) or out where magpie can't download it (`available`), unless
`/api/update` says `quiet`. A release comes every few minutes, so the ×
(or a right-click) that hid the pill only until the next version had it
back within minutes (certhon520, jkd6688, Yuyuaneth and milianxinqi on X,
11-12): it now also hushes it for `update.Quiet` (3 days, the Stable
channel's soak) across the releases out meanwhile (`quietAgain`,
`update.QuietAgain`), kept across restarts in `update-behind.json`
(`update.Behind.Hushed`, for the version running, so an update starts
afresh). Settings › Update button says "Hidden for 3 days" while it holds,
with Show again (`unhush`, `update.Unhush`, an empty `update-skip`).
Nothing else holds the pill. From 0.1.3879 to 0.1.4179 a quiet was also
counted from the first newer version seen; with a release every few
minutes it started over on each update, so a downloaded update waited
with no pill for days (visamzh and normalcoder_ on X, 11-14). Those
versions' notes keep that time as `since`, which is never read as a
dismissal. An urgent release (a line starting "**Urgent release:**" in the
latest's notes, or in any release between this one and it,
`urgentBetween`) lights the pill through a dismissal. Settings › Version,
the tray's Restart to update, quitting and Restart automatically work at
any time. Plugin updates have their own dot on Plugins, which lights only
for a plugin that does not update by itself. See
`TestPillLightsWhenANewerVersionIsOut`, `TestUrgentLightsThePillAtOnce`,
`TestDismissalHoldsForTheQuiet`, `TestUpdateQuietUntilBehindAWhile`,
`update-quiet.test.cjs` and `update-hide.test.cjs`.
### A restart to update hands the gateway over
+2
View File
@@ -1890,6 +1890,8 @@ func Handler(w Windows, gw *gateway.Server) http.Handler {
s.UpdateSkip = strings.TrimSpace(in.Version)
if s.UpdateSkip != "" {
updates.quietAgain() // a dismissal holds for the quiet, not only the next release
} else {
updates.unhush() // Show again
}
if err := settings.Save(s); err != nil {
fail(rw, err)
+9 -8
View File
@@ -4414,9 +4414,9 @@ for (const k of "pointerdown keydown input wheel".split(" ")) addEventListener(k
}, true);
// renderUpdateBadge shows the header's Update pill once a newer magpie is
// downloaded or out and has been for a while (u.quiet: releases come every
// few minutes, so a pill lit for each is never out; an urgent one lights it
// at once); Settings or its × keeps it away.
// downloaded or out; Settings or its × keeps it away (u.quiet: the × holds
// for 3 days, not only until the next release, minutes later; an urgent
// release lights it through that).
async function renderUpdateBadge() {
const b = $("#update"), label = b.querySelector("span");
@@ -4434,7 +4434,7 @@ async function renderUpdateBadge() {
if (b.hidden !== !on) b.hidden = !on;
if (!on) return;
const hide = $("#updateHide");
hide.setAttribute("aria-label", t("Hide until the next version"));
hide.setAttribute("aria-label", t("Hide for 3 days"));
hide.onclick = b.oncontextmenu = (e) => {
e.preventDefault();
skipUpdate(u.latest);
@@ -4532,7 +4532,7 @@ async function skipUpdate(v) {
const ns = await writingPrefs(api("settings/update-skip", { version: v }));
prefs = ns;
if (state) state.settings = ns;
if (v) status(t("Update hidden until the next version; Settings still has it"), "ok", 3000);
if (v) status(t("Update hidden for 3 days; Settings still has it"), "ok", 3000);
} catch (e) {
statusErr(e);
}
@@ -20231,10 +20231,11 @@ function renderSettings() {
const pill = row(t("Update button"), t("Shows in the header when a newer magpie is out"),
"", segs([["off", t("Off")], ["on", t("On")]], s.noUpdatePill ? "off" : "on", (v) => savePrefs({ ...keep, noUpdatePill: v === "off" }).then(renderUpdateBadge)));
pill.classList.add("update-pill-row");
if (s.updateSkip && !s.noUpdatePill) {
// hidden by its × for 3 days, across the releases out meanwhile (u.quiet)
if (!s.noUpdatePill) {
api(updatePath("update")).then((u) => {
if (!pill.isConnected || !u || u.latest !== s.updateSkip) return;
pill.querySelector(".sub").textContent = t("Hidden for {v} until a newer version is out", { v: u.latest });
if (!pill.isConnected || !u?.quiet) return;
pill.querySelector(".sub").textContent = t("Hidden for 3 days");
const back = el("button", "text", t("Show again"));
back.onclick = () => skipUpdate("");
pill.querySelector(".val").prepend(back);
+12 -8
View File
@@ -4034,14 +4034,15 @@ const I18N = {
"Update": "更新",
"Update failed": "更新失败",
"Hide until the next version": "隐藏,直到下一个版本",
"Update hidden until the next version; Settings still has it": "已隐藏更新按钮,下一个版本发布时再显示;设置里仍可更新",
"Hide for 3 days": "隐藏 3 天",
"Update hidden for 3 days; Settings still has it": "已隐藏更新按钮 3 天;设置里仍可更新",
"The `magpie` command is a copy": "终端里的 `magpie` 命令是一份拷贝",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup of {time}. A change made after that may be missing; the damaged file is kept beside it.": "{file} 已损坏(多半是电脑在写入途中停机),magpie 已从 {time} 的备份恢复。之后的改动可能缺失;损坏的文件保留在旁边。",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup. A change made after that may be missing; the damaged file is kept beside it.": "{file} 已损坏(多半是电脑在写入途中停机),magpie 已从备份恢复。之后的改动可能缺失;损坏的文件保留在旁边。",
"The `magpie` command at {path} is a copied file, not the installer's link to the app: it won't follow the app's updates, and an old copy can break what a new one fixed. Re-run the installer, or link it by hand.": "`magpie` 命令({path})是拷贝的文件,不是安装脚本建立的应用链接:不会随应用更新,旧拷贝可能使新版的修复失效。请重新运行安装脚本,或手动建立链接。",
"Update button": "更新按钮",
"Shows in the header when a newer magpie is out": "magpie 有新版本时显示在顶栏",
"Hidden for {v} until a newer version is out": "{v} 已隐藏,更新的版本发布时再显示",
"Hidden for 3 days": "已隐藏 3 天",
"Show again": "重新显示",
"Automatic updates": "自动更新",
"Checks for a newer magpie by itself": "自动检查 magpie 新版本",
@@ -9298,14 +9299,15 @@ const I18N = {
"Update": "更新",
"Update failed": "更新失敗",
"Hide until the next version": "隱藏,直到下一個版本",
"Update hidden until the next version; Settings still has it": "已隱藏更新按鈕,下一個版本釋出時再顯示;設定裡仍可更新",
"Hide for 3 days": "隱藏 3 天",
"Update hidden for 3 days; Settings still has it": "已隱藏更新按鈕 3 天;設定裡仍可更新",
"The `magpie` command is a copy": "終端機裡的 `magpie` 命令是一份複製",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup of {time}. A change made after that may be missing; the damaged file is kept beside it.": "{file} 已損壞(多半是電腦在寫入途中停機),magpie 已從 {time} 的備份還原。之後的變更可能缺失;損壞的檔案保留在旁邊。",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup. A change made after that may be missing; the damaged file is kept beside it.": "{file} 已損壞(多半是電腦在寫入途中停機),magpie 已從備份還原。之後的變更可能缺失;損壞的檔案保留在旁邊。",
"The `magpie` command at {path} is a copied file, not the installer's link to the app: it won't follow the app's updates, and an old copy can break what a new one fixed. Re-run the installer, or link it by hand.": "`magpie` 命令({path})是複製的檔案,不是安裝指令碼建立的應用連結:不會隨應用更新,舊複製可能使新版的修復失效。請重新執行安裝指令碼,或手動建立連結。",
"Update button": "更新按鈕",
"Shows in the header when a newer magpie is out": "magpie 有新版本時顯示在頂欄",
"Hidden for {v} until a newer version is out": "{v} 已隱藏,更新的版本釋出時再顯示",
"Hidden for 3 days": "已隱藏 3 天",
"Show again": "重新顯示",
"Automatic updates": "自動更新",
"Checks for a newer magpie by itself": "自動檢查 magpie 新版本",
@@ -14577,14 +14579,15 @@ const I18N = {
"Update": "アップデート",
"Update failed": "アップデートに失敗しました",
"Hide until the next version": "次のバージョンまで非表示",
"Update hidden until the next version; Settings still has it": "次のバージョンまでアップデートを非表示にしました。設定からは引き続きアップデートできます",
"Hide for 3 days": "3 日間非表示",
"Update hidden for 3 days; Settings still has it": "アップデートを 3 日間非表示にしました。設定からは引き続きアップデートできます",
"The `magpie` command is a copy": "`magpie` コマンドはコピーです",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup of {time}. A change made after that may be missing; the damaged file is kept beside it.": "{file} が破損していました(書き込み中にコンピューターが停止した可能性があります)。magpie は {time} のバックアップから復元しました。それ以降の変更は失われている可能性があります。破損したファイルはそのそばに残してあります。",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup. A change made after that may be missing; the damaged file is kept beside it.": "{file} が破損していました(書き込み中にコンピューターが停止した可能性があります)。magpie はバックアップから復元しました。それ以降の変更は失われている可能性があります。破損したファイルはそのそばに残してあります。",
"The `magpie` command at {path} is a copied file, not the installer's link to the app: it won't follow the app's updates, and an old copy can break what a new one fixed. Re-run the installer, or link it by hand.": "{path} にある `magpie` コマンドはコピーされたファイルで、インストーラーが作成したアプリへのリンクではありません。アプリのアップデートに追従せず、古いコピーは新しいバージョンで修正された内容を壊すことがあります。インストーラーを再実行するか、手動でリンクを作成してください。",
"Update button": "アップデートボタン",
"Shows in the header when a newer magpie is out": "新しい magpie が出たときにヘッダーに表示します",
"Hidden for {v} until a newer version is out": "新しいバージョンが出るまで {v} を非表示にしています",
"Hidden for 3 days": "3 日間非表示にしています",
"Show again": "再表示",
"Automatic updates": "自動アップデート",
"Checks for a newer magpie by itself": "新しい magpie を自動で確認します",
@@ -19865,14 +19868,15 @@ const I18N = {
"Update": "Aktualisieren",
"Update failed": "Update fehlgeschlagen",
"Hide until the next version": "Bis zur nächsten Version ausblenden",
"Update hidden until the next version; Settings still has it": "Update bis zur nächsten Version ausgeblendet; in den Einstellungen weiterhin verfügbar",
"Hide for 3 days": "3 Tage ausblenden",
"Update hidden for 3 days; Settings still has it": "Update für 3 Tage ausgeblendet; in den Einstellungen weiterhin verfügbar",
"The `magpie` command is a copy": "Der Befehl `magpie` ist eine Kopie",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup of {time}. A change made after that may be missing; the damaged file is kept beside it.": "{file} war beschädigt (der Computer ist wohl mitten im Schreiben ausgefallen), daher hat magpie die Datei aus ihrer Sicherung vom {time} wiederhergestellt. Spätere Änderungen fehlen eventuell; die beschädigte Datei liegt daneben.",
"{file} was damaged (the computer likely stopped mid-write), so magpie restored it from its backup. A change made after that may be missing; the damaged file is kept beside it.": "{file} war beschädigt (der Computer ist wohl mitten im Schreiben ausgefallen), daher hat magpie die Datei aus ihrer Sicherung wiederhergestellt. Spätere Änderungen fehlen eventuell; die beschädigte Datei liegt daneben.",
"The `magpie` command at {path} is a copied file, not the installer's link to the app: it won't follow the app's updates, and an old copy can break what a new one fixed. Re-run the installer, or link it by hand.": "Der Befehl `magpie` unter {path} ist eine kopierte Datei, nicht die Verknüpfung des Installers zur App: Er folgt den Updates der App nicht, und eine alte Kopie kann kaputt machen, was eine neue behoben hat. Führen Sie den Installer erneut aus oder verknüpfen Sie ihn von Hand.",
"Update button": "Update-Button",
"Shows in the header when a newer magpie is out": "Erscheint in der Kopfzeile, wenn eine neuere magpie-Version verfügbar ist",
"Hidden for {v} until a newer version is out": "Für {v} ausgeblendet, bis eine neuere Version erscheint",
"Hidden for 3 days": "Für 3 Tage ausgeblendet",
"Show again": "Wieder anzeigen",
"Automatic updates": "Automatische Updates",
"Checks for a newer magpie by itself": "Sucht selbst nach einer neueren magpie-Version",
+1 -1
View File
@@ -92,7 +92,7 @@
<svg viewBox="0 0 16 16" width="11" height="11"><path d="M8 13V3.5M3.75 7.5 8 3.25l4.25 4.25" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/></svg>
<span>Update</span>
</button>
<button class="update-hide" id="updateHide" title="Hide until the next version" data-tt>
<button class="update-hide" id="updateHide" title="Hide for 3 days" data-tt>
<svg viewBox="0 0 10 10" width="8" height="8"><path d="M2.5 2.5l5 5M7.5 2.5l-5 5" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"/></svg>
</button>
</span>
+20 -12
View File
@@ -1,10 +1,11 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// The header's Update pill can be kept away (Wang Hsiaohi on Discord). Its ×,
// shown with the pointer over it, hides it for that version: it stays away
// after a reload and comes back once a newer version is out; a right-click
// shown with the pointer over it, hides it for 3 days: it stays away after a
// reload and through the releases out meanwhile (a release comes every few
// minutes), and comes back once the 3 days are over; a right-click
// does the same, and the × sits off the pill, so a click meant for Update
// never lands on it (#2291). Settings → Update button turns it off for good, and says
// which version it is hidden for with a way to show it again. The version
// that it is hidden for 3 days, with a way to show it again. The version
// row still offers the restart. No click moves the page. English and
// Chinese, in the tray panel and the window; no backend, the API is faked.
const assert = require("node:assert/strict");
@@ -17,10 +18,10 @@ const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const words = {
en: { update: "Update", hide: "Hide until the next version", pill: "Update button", off: "Off", on: "On",
hidden: "Hidden for 0.1.401 until a newer version is out", again: "Show again", restart: "Restart to update", version: "Version" },
zh: { update: "更新", hide: "隐藏,直到下一个版本", pill: "更新按钮", off: "关闭", on: "开启",
hidden: "0.1.401 已隐藏,更新的版本发布时再显示", again: "重新显示", restart: "重启以更新", version: "版本" },
en: { update: "Update", hide: "Hide for 3 days", pill: "Update button", off: "Off", on: "On",
hidden: "Hidden for 3 days", again: "Show again", restart: "Restart to update", version: "Version" },
zh: { update: "更新", hide: "隐藏 3 天", pill: "更新按钮", off: "关闭", on: "开启",
hidden: "已隐藏 3 天", again: "重新显示", restart: "重启以更新", version: "版本" },
};
function settingsPayload(lang, ctl) {
@@ -37,7 +38,8 @@ function settingsPayload(lang, ctl) {
};
}
// ctl holds what the backend would: the version out, and the two settings
// ctl holds what the backend would: the version out, the two settings, and
// whether the × still holds (hushed: /api/update's quiet)
function server(lang, ctl) {
return async (route) => {
const req = route.request(), url = new URL(req.url());
@@ -48,6 +50,7 @@ function server(lang, ctl) {
if (url.pathname === "/api/settings/update-skip") {
ctl.skips.push(req.postDataJSON().version);
ctl.skip = req.postDataJSON().version;
ctl.hushed = !!ctl.skip;
return json(settingsPayload(lang, ctl));
}
if (url.pathname === "/api/settings") {
@@ -58,7 +61,7 @@ function server(lang, ctl) {
}
return json(settingsPayload(lang, ctl));
}
if (url.pathname === "/api/update") return json({ state: "ready", current: "0.1.400", latest: ctl.latest });
if (url.pathname === "/api/update") return json({ state: "ready", current: "0.1.400", latest: ctl.latest, ...(ctl.hushed ? { quiet: true } : {}) });
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
@@ -69,7 +72,7 @@ function server(lang, ctl) {
};
}
const fresh = (over) => ({ latest: "0.1.401", off: false, skip: "", skips: [], saves: [], ...over });
const fresh = (over) => ({ latest: "0.1.401", off: false, skip: "", hushed: false, skips: [], saves: [], ...over });
// wheel a row into sight, as a user would; a click must then not move the page
async function showRow(page, row) {
await page.locator("#view-settings").hover();
@@ -103,7 +106,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
};
for (const lang of ["en", "zh"]) {
const w = words[lang];
await t.test(lang + ": the × hides it for this version, a newer one brings it back", async () => {
await t.test(lang + ": the × hides it for 3 days, through newer versions", async () => {
const ctl = fresh();
const { page, errors } = await open(lang, ctl, "?mode=panel");
const pill = page.locator("#update"), x = page.locator("#updateHide");
@@ -127,6 +130,11 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await pill.isHidden(), true, "still hidden for 0.1.401");
ctl.latest = "0.1.402";
await page.reload();
await page.locator("#sync").waitFor();
await page.waitForTimeout(400);
assert.equal(await pill.isHidden(), true, "a release minutes later brought it back");
ctl.hushed = false; // the 3 days are over
await page.reload();
await pill.waitFor({ state: "visible" });
// and a right-click hides it as well
await pill.click({ button: "right" });
@@ -175,7 +183,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
}
await t.test(lang + ": Settings turns it off, and shows it again", async () => {
const ctl = fresh({ skip: "0.1.401" });
const ctl = fresh({ skip: "0.1.400", hushed: true, latest: "0.1.402" });
const { page, errors } = await open(lang, ctl, "?view=settings&tab=about");
const row = page.locator("#about .row.pref", { has: page.locator(".name", { hasText: w.pill }) });
await row.locator(".sub", { hasText: w.hidden }).waitFor();
+31 -18
View File
@@ -1,11 +1,13 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// "红点都快焊死了" (certhon520, jkd6688, Yuyuaneth, milianxinqi on X): a release
// comes every few minutes, so a downloaded update was always waiting and the
// header's Update pill was always lit. /api/update says quiet for a version
// not behind for long and with no urgent release out: the pill stays away,
// while Settings' version row still offers the restart. Not quiet (behind
// for days, or urgent), it shows. Every language, tray panel and
// window; no backend, the API is faked.
// "右上角的更新按钮不见了" (visamzh, normalcoder_ on X, 11-14): a download
// waiting (ready) or a newer version found with downloads off (found)
// lights the header's Update pill at once. /api/update says quiet only
// while the pill's × holds (3 days, "红点都快焊死了", certhon520 and others
// on X: it used to hold only until the next release, minutes later): the
// pill stays away, Settings' Update button row says it is hidden for 3 days
// with Show again, and the version row still offers the restart. Every
// language, tray panel, a narrow window and a wide one; no backend, the API
// is faked.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -29,6 +31,7 @@ function server(lang, ctl) {
if (url.pathname === "/api/state") return json({ agents: [], profiles: [], settings, fx: settings.fx });
if (url.pathname === "/api/settings") return json(settings);
if (url.pathname === "/api/update") return json({ state: "ready", current: "0.1.400", latest: "0.1.401", ...ctl });
if (url.pathname === "/api/settings/update-skip") return json(settings);
if (url.pathname === "/api/plugins") return json({ plugins: [] });
if (url.pathname === "/api/usage/quotas") return json([]);
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
@@ -40,12 +43,13 @@ function server(lang, ctl) {
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Update pill waits until the update has been out a while", async (t) => {
test(engine + ": the Update pill shows a waiting update, and keeps away while its × holds", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
t.after(() => browser.close());
const open = async (lang, ctl, query) => {
const errors = [];
const page = await (await browser.newContext({ viewport: { width: query.includes("panel") ? 420 : 900, height: 560 }, reducedMotion: "reduce" })).newPage();
const width = query.includes("panel") ? 420 : query.includes("narrow") ? 400 : 900;
const page = await (await browser.newContext({ viewport: { width, height: 560 }, reducedMotion: "reduce" })).newPage();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
page.on("pageerror", (e) => { if (!/^ResizeObserver loop completed with undelivered notifications/.test(e.message)) errors.push(e.message); });
@@ -53,23 +57,32 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.goto("http://magpie.test/" + query);
return { page, errors };
};
const hidden = { en: "Hidden for 3 days", zh: "已隐藏 3 天", "zh-TW": "已隱藏 3 天", ja: "3 日間非表示にしています", de: "Für 3 Tage ausgeblendet" };
const again = { en: "Show again", zh: "重新显示", "zh-TW": "重新顯示", ja: "再表示", de: "Wieder anzeigen" };
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
for (const mode of ["?mode=panel", ""]) {
await t.test(lang + (mode ? " panel" : " window") + ": quiet keeps the pill away, and its version row still restarts", async () => {
for (const [where, mode] of [["panel", "?mode=panel"], ["narrow window", "?narrow"], ["window", ""]]) {
for (const state of ["ready", "found"]) {
await t.test(lang + " " + where + ": " + state + ", just out, shows the pill at once", async () => {
const { page, errors } = await open(lang, { state, latest: "0.1.402" }, mode);
await page.locator("#update").waitFor({ state: "visible" });
const box = await page.locator("#update").boundingBox();
assert(box && box.x >= 0 && box.x + box.width <= (where === "panel" ? 420 : where === "narrow window" ? 400 : 900), "the pill is on screen");
assert.deepEqual(errors, []);
});
}
await t.test(lang + " " + where + ": quiet (the × holds) keeps the pill away, and Settings says so", async () => {
const { page, errors } = await open(lang, { quiet: true }, mode);
await page.locator("#sync").waitFor();
await page.waitForTimeout(500);
assert.equal(await page.locator("#update").isHidden(), true, "a fresh update lit the pill");
const v = await open(lang, { quiet: true }, "?view=settings&tab=about");
assert.equal(await page.locator("#update").isHidden(), true, "a dismissed pill came back");
const v = await open(lang, { quiet: true }, "?view=settings&tab=about" + (mode ? "&narrow" : ""));
await v.page.locator("#about .row.pref .val button.text").first().waitFor(); // the version row's restart
const row = v.page.locator("#about .row.pref.update-pill-row");
await row.locator(".sub", { hasText: hidden[lang] }).waitFor();
await row.locator("button", { hasText: again[lang] }).waitFor();
assert.equal(await v.page.locator("#update").isHidden(), true);
assert.deepEqual([...errors, ...v.errors], []);
});
await t.test(lang + (mode ? " panel" : " window") + ": not quiet (days behind, or urgent) shows the pill", async () => {
const { page, errors } = await open(lang, {}, mode);
await page.locator("#update").waitFor({ state: "visible" });
assert.deepEqual(errors, []);
});
}
}
});
+15 -7
View File
@@ -33,8 +33,8 @@ type updater struct {
mu sync.Mutex
state string // checking | latest | found | downloading | ready | available | source | error | blocked
latest *update.Release
// behind: since when a newer version has been out for this one, and
// whether it is urgent; the pill waits for it (update.Behind)
// behind: when the pill was dismissed, and whether a newer version is
// urgent; a dismissed pill waits for it (update.Behind)
behind update.Behind
err string
bundle string // the .app to replace, "" when not in one or stuck
@@ -145,9 +145,9 @@ type updateJSON struct {
// blocked: the version this computer wouldn't start, and why (#894)
Blocked *update.Blocked `json:"blocked,omitempty"`
// Quiet: a newer version is out but this one has not been behind long
// enough, and none is urgent, so the header's pill stays out (the
// Version row and Restart to update still offer it)
// Quiet: a newer version is out but the header's pill was dismissed
// less than update.Quiet ago, and none is urgent, so the pill stays out
// (the Version row and Restart to update still offer it)
Quiet bool `json:"quiet,omitempty"`
Total int64 `json:"total,omitempty"`
// found: the size of the file Download update would fetch, in bytes
@@ -550,7 +550,7 @@ func (u *updater) run() {
}
u.latest, u.notesIn, u.stable = rel, lang, stable
if update.Released(Version) && update.Newer(rel.Version, Version) {
u.behind = update.NoteBehind(Version, rel.Version, update.UrgentIn(rel.Notes), time.Now())
u.behind = update.NoteBehind(Version, rel.Version, update.UrgentIn(rel.Notes))
if u.behind.Urgent == "" {
// an urgent release between this one and the latest: its
// notes aren't the latest's
@@ -784,7 +784,7 @@ func (u *updater) urgentBetween(latest, lang string) {
}
for _, n := range notes {
if update.UrgentIn(n.Notes) {
b := update.NoteUrgent(Version, n.Version, time.Now())
b := update.NoteUrgent(Version, n.Version)
u.mu.Lock()
u.behind = b
u.mu.Unlock()
@@ -801,6 +801,14 @@ func (u *updater) quietAgain() {
u.mu.Unlock()
}
// unhush lifts the pill's dismissal: Settings' Show again.
func (u *updater) unhush() {
b := update.Unhush(Version)
u.mu.Lock()
u.behind = b
u.mu.Unlock()
}
// inLang has the next checks ask for the notes in lang ("" leaves it).
func (u *updater) inLang(lang string) {
if lang == "" {
+14 -9
View File
@@ -8,10 +8,12 @@ import (
"github.com/yetone/magpie/internal/update"
)
// "红点都快焊死了" (certhon520 and others on X): with a release every few
// minutes, a downloaded update was always there and the header's pill was
// always lit. /api/update says quiet for a version not behind for long,
// and not quiet for an urgent one.
// /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)
@@ -28,11 +30,14 @@ func TestUpdateQuietUntilBehindAWhile(t *testing.T) {
state string
quiet bool
}{
{"just found", update.Behind{Base: "0.1.100", Since: now.Add(-time.Hour)}, "ready", true},
{"behind for days", update.Behind{Base: "0.1.100", Since: now.Add(-update.Quiet - time.Minute)}, "ready", false},
{"urgent at once", update.Behind{Base: "0.1.100", Since: now, Urgent: "0.1.104"}, "ready", false},
{"found, held download", update.Behind{Base: "0.1.100", Since: now}, "found", true},
{"up to date says nothing", update.Behind{Base: "0.1.100", Since: now}, "latest", false},
{"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 {
+44 -28
View File
@@ -1,13 +1,16 @@
package update
// How long this version has been behind (users on X, 11-12: the header's
// Update pill was "always lit"). A release comes every few minutes, so a
// newer one is nearly always out, downloaded and ready; lighting the pill
// for each of them is a pill that never goes out. The pill lights once this
// version has been behind for Quiet, or at once for an urgent release (a
// security hole, a ban risk, lost data: the notes' "**Urgent release:**"
// line, see Stable). The Version row in Settings, Restart to update in the
// tray's menu and a restart or quit all work at any time.
// When the header's Update pill is hushed. A release comes every few
// minutes, so a newer one is nearly always out (users on X, 11-12: the pill
// was "always lit", and its x hid it only until the next release, minutes
// later). The x hushes it for Quiet; nothing else does. A newer version that
// was only seen, not dismissed, lights it at once (visamzh, normalcoder_ on
// X, 11-14): a quiet counted from the first newer version seen started over
// with every update, so on a version that updates within days the pill
// never came. An urgent release (a security hole, a ban risk, lost data:
// the notes' "**Urgent release:**" line, see Stable) lights it through a
// hush too. The Version row in Settings, Restart to update in the tray's
// menu and a restart or quit all work at any time.
import (
"encoding/json"
@@ -20,16 +23,18 @@ import (
"github.com/yetone/magpie/internal/lazyre"
)
// Quiet is how long a version has to be behind before the pill lights, and
// how long a dismissal holds: the Stable channel's soak.
// Quiet is how long a dismissal of the pill holds: the Stable channel's
// soak.
const Quiet = 72 * time.Hour
// Behind is what is kept of being behind, for the version running (Base).
type Behind struct {
Base string `json:"base"`
// Since is when a newer version was first seen, or when the pill was
// last dismissed: the quiet runs from it.
Since time.Time `json:"since"`
// Hushed is when the pill was last dismissed: the quiet runs from it.
// (0.1.3879 to 0.1.4179 kept "since", the first newer version seen,
// and held the pill for it; a note of theirs is for their own version,
// so it is never read as a dismissal.)
Hushed time.Time `json:"hushed,omitempty"`
// Urgent is the newest version known to be urgent, "" for none.
Urgent string `json:"urgent,omitempty"`
}
@@ -77,27 +82,25 @@ func ReadBehind(current string) Behind {
return readBehind(current)
}
// NoteBehind notes that latest is out while current runs: the quiet starts
// at the first time, and an urgent latest is kept until current has
// caught up with it. A note that can't be read starts the quiet again, but
// the urgent one is read again from the next check's notes.
func NoteBehind(current, latest string, urgent bool, now time.Time) Behind {
// NoteBehind notes that latest is out while current runs: an urgent latest
// is kept until current has caught up with it. Being behind starts no
// quiet; only a dismissal does. A note that can't be read loses a
// dismissal (the pill shows), and the urgent one is read again from the
// next check's notes.
func NoteBehind(current, latest string, urgent bool) Behind {
behindMu.Lock()
defer behindMu.Unlock()
b := readBehind(current)
if b.Since.IsZero() {
b.Since = now
}
if urgent && (b.Urgent == "" || Newer(latest, b.Urgent)) {
b.Urgent = latest
writeBehind(b)
}
writeBehind(b)
return b
}
// NoteUrgent notes that version, newer than current, is urgent.
func NoteUrgent(current, version string, now time.Time) Behind {
return NoteBehind(current, version, true, now)
func NoteUrgent(current, version string) Behind {
return NoteBehind(current, version, true)
}
// QuietAgain starts the quiet over: the pill was dismissed.
@@ -105,18 +108,31 @@ func QuietAgain(current string, now time.Time) Behind {
behindMu.Lock()
defer behindMu.Unlock()
b := readBehind(current)
b.Since = now
b.Hushed = now
writeBehind(b)
return b
}
// Lit is whether the pill may light at now: an urgent release newer than
// current is out, or the quiet has passed.
// Unhush lifts a dismissal: Settings' Show again.
func Unhush(current string) Behind {
behindMu.Lock()
defer behindMu.Unlock()
b := readBehind(current)
if !b.Hushed.IsZero() {
b.Hushed = time.Time{}
writeBehind(b)
}
return b
}
// Lit is whether the pill may light at now: it was never dismissed, the
// quiet after a dismissal has passed, or an urgent release newer than
// current is out.
func (b Behind) Lit(current string, now time.Time) bool {
if b.Urgent != "" && Newer(b.Urgent, current) {
return true
}
return !b.Since.IsZero() && now.Sub(b.Since) >= Quiet
return b.Hushed.IsZero() || now.Sub(b.Hushed) >= Quiet
}
var urgentLine = lazyre.New(`(?im)^[ \t]*(?:>[ \t]*)?\*\*urgent release:\*\*`)
+46 -37
View File
@@ -2,6 +2,7 @@ package update
import (
"os"
"path/filepath"
"testing"
"time"
)
@@ -15,32 +16,34 @@ func behindHome(t *testing.T) {
t.Setenv("APPDATA", h+"/AppData")
}
// Releases come every few minutes, so the header's pill (users on X,
// 11-12: "always lit") waits until this version has been behind for Quiet.
func TestPillWaitsForTheQuiet(t *testing.T) {
// "右上角的更新按钮不见了" (visamzh, normalcoder_ on X, 11-14): the pill
// waited for this version to be behind for Quiet, counted from the first
// newer version seen. With a release every few minutes that clock started
// over on each update, so a downloaded update waited with no pill for days.
// Being behind lights it at once; only a dismissal holds it, for Quiet.
func TestPillLightsWhenANewerVersionIsOut(t *testing.T) {
behindHome(t)
t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
b := NoteBehind("0.1.100", "0.1.101", false, t0)
if b.Lit("0.1.100", t0.Add(time.Minute)) {
t.Error("lit a minute after the first newer version")
t0 := time.Date(2026, 11, 14, 9, 0, 0, 0, time.UTC)
b := NoteBehind("0.1.4174", "0.1.4176", false)
if !b.Lit("0.1.4174", t0) {
t.Fatal("not lit when a newer version is out")
}
// ten newer versions later, the clock still runs from the first
for i := 2; i < 12; i++ {
b = NoteBehind("0.1.100", "0.1.1"+string(rune('0'+i%10))+"0", false, t0.Add(time.Duration(i)*time.Hour))
for i := 0; i < 10; i++ {
b = NoteBehind("0.1.4174", "0.1.4180", false)
}
if b.Lit("0.1.100", t0.Add(Quiet-time.Minute)) {
t.Error("lit before the quiet passed")
if !b.Lit("0.1.4174", t0.Add(time.Minute)) || !ReadBehind("0.1.4174").Lit("0.1.4174", t0.Add(time.Minute)) {
t.Error("newer versions seen again put the pill out")
}
if !b.Lit("0.1.100", t0.Add(Quiet)) {
t.Error("not lit once the quiet passed")
// a note an older magpie (0.1.3879 to 0.1.4179) kept, "since" the first
// newer version: it was never a dismissal
if err := os.MkdirAll(filepath.Dir(behindFile()), 0o755); err != nil {
t.Fatal(err)
}
// the clock is kept across a restart without an update
if !ReadBehind("0.1.100").Lit("0.1.100", t0.Add(Quiet)) {
t.Error("the note was not kept")
if err := writeFileForTest(behindFile(), `{"base":"0.1.4174","since":"`+t0.Format(time.RFC3339)+`"}`); err != nil {
t.Fatal(err)
}
// updated: the note is for the version it was
if ReadBehind("0.1.200").Lit("0.1.200", t0.Add(10*Quiet)) {
t.Error("a note for another version counted")
if !ReadBehind("0.1.4174").Lit("0.1.4174", t0.Add(time.Hour)) {
t.Error("an old first-seen note held the pill")
}
}
@@ -49,11 +52,11 @@ func TestPillWaitsForTheQuiet(t *testing.T) {
func TestUrgentLightsThePillAtOnce(t *testing.T) {
behindHome(t)
t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
b := NoteBehind("0.1.100", "0.1.105", true, t0)
b := NoteBehind("0.1.100", "0.1.105", true)
if !b.Lit("0.1.100", t0) {
t.Fatal("an urgent release did not light the pill")
}
b = NoteBehind("0.1.100", "0.1.106", false, t0.Add(time.Hour))
b = NoteBehind("0.1.100", "0.1.106", false)
if !b.Lit("0.1.100", t0.Add(time.Hour)) {
t.Error("a later plain release put out the urgent one's pill")
}
@@ -64,39 +67,45 @@ func TestUrgentLightsThePillAtOnce(t *testing.T) {
if b.Lit("0.1.105", t0) && b.Urgent != "0.1.105" {
t.Error("urgent not kept")
}
if (Behind{Base: "0.1.105", Urgent: "0.1.105", Since: t0}).Lit("0.1.105", t0) {
if (Behind{Base: "0.1.105", Urgent: "0.1.105", Hushed: t0}).Lit("0.1.105", t0) {
t.Error("lit for an urgent release already running")
}
}
// A dismissal holds for the quiet, not only until the next release.
func TestDismissalStartsTheQuietOver(t *testing.T) {
// A dismissal holds for the quiet, not only until the next release, and is
// kept across a restart; Show again lifts it; an update starts afresh.
func TestDismissalHoldsForTheQuiet(t *testing.T) {
behindHome(t)
t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
NoteBehind("0.1.100", "0.1.101", false, t0)
later := t0.Add(Quiet + time.Hour)
if !ReadBehind("0.1.100").Lit("0.1.100", later) {
t.Fatal("not lit after the quiet")
}
b := QuietAgain("0.1.100", later)
if b.Lit("0.1.100", later.Add(Quiet-time.Minute)) {
NoteBehind("0.1.100", "0.1.101", false)
b := QuietAgain("0.1.100", t0)
NoteBehind("0.1.100", "0.1.102", false)
if b.Lit("0.1.100", t0.Add(Quiet-time.Minute)) || ReadBehind("0.1.100").Lit("0.1.100", t0.Add(Quiet-time.Minute)) {
t.Error("lit again before the quiet passed after a dismissal")
}
if !b.Lit("0.1.100", later.Add(Quiet)) {
if !ReadBehind("0.1.100").Lit("0.1.100", t0.Add(Quiet)) {
t.Error("never lit again")
}
if !Unhush("0.1.100").Lit("0.1.100", t0.Add(time.Minute)) || !ReadBehind("0.1.100").Lit("0.1.100", t0.Add(time.Minute)) {
t.Error("Show again did not bring it back")
}
QuietAgain("0.1.100", t0)
if !ReadBehind("0.1.102").Lit("0.1.102", t0.Add(time.Minute)) {
t.Error("a dismissal on another version counted")
}
}
// An unreadable note is unknown: it starts the quiet, it doesn't light.
// An unreadable note is unknown: a dismissal it held is lost, and the pill
// shows (Settings > Version offers the update either way).
func TestUnreadableBehindNoteIsNone(t *testing.T) {
behindHome(t)
t0 := time.Date(2026, 11, 12, 9, 0, 0, 0, time.UTC)
writeBehind(Behind{Base: "0.1.100", Since: t0})
writeBehind(Behind{Base: "0.1.100", Hushed: t0})
if err := writeFileForTest(behindFile(), "{half"); err != nil {
t.Fatal(err)
}
if ReadBehind("0.1.100").Lit("0.1.100", t0.Add(10*Quiet)) {
t.Error("a half-written note lit the pill")
if b := ReadBehind("0.1.100"); !b.Hushed.IsZero() || b.Urgent != "" {
t.Errorf("a half-written note read as %+v", b)
}
}