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

219 lines
12 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.
// The header's Update pill can be kept away (Wang Hsiaohi on Discord). Its ×,
// 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
// 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");
const fs = require("node:fs/promises");
const path = require("node:path");
const { test } = require("node:test");
const { chromium, webkit } = require("playwright");
const { watchSettingsReads, settingsDrawn } = require("./reader.cjs");
const assets = path.resolve(__dirname, "../assets");
const words = {
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) {
return {
theme: "light", lang, tray: "panel", quotaLeft: false, currency: "usd",
dock: false, dockWindow: false, proxy: "", redact: false, redactPersonal: false, redactWords: [],
codexWarmup: "", claudeWarmup: "", codexWarmAt: "", claudeWarmAt: "", workbuddyCheckin: false, noStats: false,
trayUsage: "", trayUsageEvery: 3, vision: "", imageGen: "",
noUpdatePill: ctl.off, updateSkip: ctl.skip,
version: "0.1.400", dir: "~/.config/magpie", gateway: "http://127.0.0.1:3425",
proxyNow: "none", proxySource: "none", login: false,
visionModels: [], imageGenModels: [], workbuddyCheckins: [], lanURLs: [],
fx: { rate: 7.2, at: new Date().toISOString(), stale: false },
};
}
// 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());
const json = (data) => route.fulfill({ json: data });
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: settingsPayload(lang, ctl), fx: settingsPayload(lang, ctl).fx });
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") {
if (req.method() === "POST") {
const body = req.postDataJSON();
ctl.off = !!body.noUpdatePill;
ctl.saves.push(body);
}
return json(settingsPayload(lang, ctl));
}
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: [] });
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 });
};
}
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();
for (let i = 0; i < 40; i++) {
const box = await row.boundingBox();
const view = await page.locator("#view-settings").boundingBox();
if (box && view && box.y >= view.y + 4 && box.y + box.height <= view.y + view.height - 4) break;
await page.mouse.wheel(0, 180);
await page.waitForTimeout(16);
}
await page.waitForTimeout(250);
}
const scrolls = (page) => page.evaluate(() => [window.scrollY, document.scrollingElement.scrollTop, ...[...document.querySelectorAll(".view")].map((v) => v.scrollTop)].join(","));
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": the Update pill can be hidden", 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();
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
// WebKit's notice when a layout outruns its observers, not a fault
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 watchSettingsReads(page);
await page.goto("http://magpie.test/" + query);
await settingsDrawn(page); // rows found are the ones that stay (#1659)
return { page, errors };
};
for (const lang of ["en", "zh"]) {
const w = words[lang];
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");
await pill.waitFor({ state: "visible" });
assert.equal((await pill.innerText()).trim(), w.update);
assert.equal(await x.getAttribute("aria-label"), w.hide);
assert.equal(await x.getAttribute("title"), w.hide);
// out of sight until the pointer is over the pill
assert.equal(await x.evaluate((e) => getComputedStyle(e).opacity), "0");
await pill.hover();
await page.waitForFunction(() => getComputedStyle(document.querySelector("#updateHide")).opacity === "1");
const before = await scrolls(page);
await x.click();
await pill.waitFor({ state: "hidden" });
assert.deepEqual(ctl.skips, ["0.1.401"]);
assert.equal(await scrolls(page), before, "the click must not scroll the page");
assert.equal(await x.isVisible(), false);
await page.reload();
await page.locator("#sync").waitFor();
await page.waitForTimeout(400);
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" });
await pill.waitFor({ state: "hidden" });
assert.deepEqual(ctl.skips, ["0.1.401", "0.1.402"]);
assert.deepEqual(errors, []);
});
// #2291 (MuiseDestiny): the × sat over the pill's top right, a fifth
// of the round arrow in a narrow header, and a click meant for Update
// hid it. It sits off the pill now: no point of the pill is the ×'s.
for (const tight of [false, true]) {
await t.test(lang + (tight ? ": in a narrow header" : ": in the panel") + ", the × covers no part of the pill", async () => {
const ctl = fresh();
const { page, errors } = await open(lang, ctl, "?mode=panel");
const pill = page.locator("#update"), x = page.locator("#updateHide");
await pill.waitFor({ state: "visible" });
if (tight) {
// the header as fitTop leaves it when the tabs don't fit (#442)
await page.evaluate(() => { topFit.disconnect(); document.querySelector(".top").classList.add("tight"); });
assert.equal(await pill.locator("span").evaluate((e) => getComputedStyle(e).display), "none", "the pill is its round arrow");
}
await pill.hover();
await page.waitForFunction(() => getComputedStyle(document.querySelector("#updateHide")).opacity === "1");
const seen = await page.evaluate(() => {
const p = document.querySelector("#update"), x = document.querySelector("#updateHide");
const a = p.getBoundingClientRect(), c = x.getBoundingClientRect();
const rad = Math.min(a.height / 2, parseFloat(getComputedStyle(p).borderTopLeftRadius));
const taken = [];
for (let i = 1; i < a.width; i += 0.5) for (let j = 1; j < a.height; j += 0.5) {
const px = a.left + i, py = a.top + j;
const cx = Math.min(Math.max(px, a.left + rad), a.right - rad), cy = Math.min(Math.max(py, a.top + rad), a.bottom - rad);
if (Math.hypot(px - cx, py - cy) > rad - 0.5) continue; // outside the pill's round
if (!p.contains(document.elementFromPoint(px, py))) taken.push([i, j]);
}
const mid = document.elementFromPoint(c.left + c.width / 2, c.top + c.height / 2);
return { taken, own: x.contains(mid), inside: c.top >= 0 && c.left >= 0 && c.right <= innerWidth };
});
assert.deepEqual(seen.taken, [], "the × takes clicks meant for the pill");
assert(seen.own && seen.inside, "the × itself can still be clicked, in the window");
await x.click();
await pill.waitFor({ state: "hidden" });
assert.deepEqual(ctl.skips, ["0.1.401"]);
assert.deepEqual(errors, []);
});
}
await t.test(lang + ": Settings turns it off, and shows it again", async () => {
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();
// the version row still offers the update
await page.locator("#about .row.pref", { has: page.locator(".name", { hasText: w.version }) }).locator("button", { hasText: w.restart }).waitFor();
assert.equal(await page.locator("#update").isHidden(), true);
await showRow(page, row);
await row.locator("button", { hasText: w.again }).click();
await page.locator("#update").waitFor({ state: "visible" });
assert.deepEqual(ctl.skips, [""]);
await row.locator(".sub", { hasText: w.hidden }).waitFor({ state: "detached" });
// off for good: no pill, whatever version is out
await showRow(page, row);
const before = await scrolls(page);
await row.locator("button", { hasText: w.off }).click();
await page.locator("#update").waitFor({ state: "hidden" });
assert.equal(ctl.saves.at(-1).noUpdatePill, true);
assert.equal(await scrolls(page), before, "the click must not scroll the page");
ctl.latest = "0.1.402";
await page.reload();
await page.locator("#sync").waitFor();
await page.waitForTimeout(400);
assert.equal(await page.locator("#update").isHidden(), true);
await showRow(page, row);
await page.locator("#about .row.pref", { has: page.locator(".name", { hasText: w.pill }) }).locator("button", { hasText: w.on }).click();
await page.locator("#update").waitFor({ state: "visible" });
assert.equal(ctl.saves.at(-1).noUpdatePill, false);
assert.deepEqual(errors, []);
});
}
});
}