Files
magpie/internal/gui/tests/update-quiet.test.cjs
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

90 lines
5.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Run with Node's test runner and Playwright on the module path; see README.md.
// "右上角的更新按钮不见了" (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");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const assets = path.resolve(__dirname, "../assets");
function server(lang, ctl) {
return async (route) => {
const url = new URL(route.request().url());
const json = (data) => route.fulfill({ json: data });
const settings = {
theme: "light", lang, tray: "panel", currency: "usd", redactWords: [], trayUsageEvery: 3,
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:false};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
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: [] });
if (url.pathname.startsWith("/api/")) return json({});
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
await route.fulfill({ body: await fs.readFile(file), contentType });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
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 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); });
await page.route("**/*", server(lang, ctl));
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 [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 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], []);
});
}
}
});
}