gui: the tray panel keeps the latest height it asked for, its fits sent one at a time (robot_yz on X)
robot_yz on X (11-05, v0.1.3005): the menu-bar panel had become short, and the Allowances tab's one card, Zhipu GLM (max, rings 5h 7%, 7d 18%, MCP 1%, a curve), was cut off by the foot. Cause: Wails v3 serves each request from the page on a goroutine of its own (application.go, `go a.handleWebViewRequest(request)`), so two window/fit requests sent together reach fitPanel in either order. In a real WKWebView under Wails on mote, 69 of 400 pairs of fetches sent together reached the handler the wrong way round. When an older, smaller height lands last, it stays: fit.last in app.js and the panel's own panelHeight both take the newer height as done, so nothing asks again until the content's height changes. Since2ba044aa6(v0.1.2913) every Mac panel open runs load(true), and renderAgents and renderPanelQuota each fit in the same task. A boot asks 122, 306, 566 and 291 within about 120ms (setPanelTab, renderAgentsLoading, the routing panel, its poll), which is likely why it showed after the update. fit(), panelFrame, panelRoom and fitPanel haven't changed since 10-20/10-26, and go.mod's Wails hasn't changed either. Fix: fit() sends through fitSend. A fit asked while one is on its way waits for it, and only the latest of those goes next, so the panel always ends at the height asked last. Test: panel-fit-order.test.cjs sets up panel mode with the reporter's case: one Zhipu GLM allowance with its 5h, 7d and MCP windows and the 5h curve, 15 agents, and the Allowances tab. The fake panel holds the first fit until the page has drawn the card and stopped asking. The test asserts that the panel ends at the last height asked, that the card's bottom is inside the view, and that the tab doesn't overflow. Chromium and WebKit, en, zh, zh-TW, ja and de. Rebased on4e85cac01and run again on mote at this head: go test ./internal/gui -run Budget ok; panel-fit-order, account-models-available and i18n-keys, 94 pass, 0 fail (onea3d1c62e: every panel-* file too, 300 pass). First run on mote (mote-run), at base0e55a7593: - panel-fit-order.test.cjs: 10 of 10 pass. - Every panel-*.test.cjs and quota-*.test.cjs file plus i18n-keys.test.cjs (47 files, --test-concurrency=2): 534 tests, 534 pass, 0 fail. - go test -timeout 45m ./internal/gui: FAIL, one red, TestMainWindowCorners/macOS_26_SDK ("a toolbar doesn't change the corners in this design, yet the main window's was taken off"). The same test alone on origin/main2260390a0(fetched just before) fails the same way. It is #3949 (macOS 27 on mote), and this change touches no Go. Every other test in the package passed. Broken by hand: the new test run against origin/main's assets (git archive of internal/gui/assets) is 0 of 10, each one "the panel ended at an older height than the page asked for last (asked 122 306 566 291, applied 306 566 291 122)". The panel was left at 220 and the card was cut off. Not tried: the real tray panel by hand on a Mac with this build. The reporter's own overlapping fits weren't seen either; the reorder was measured with Wails and WKWebView on mote, not on their machine.
This commit is contained in:
@@ -4320,7 +4320,24 @@ function fit(extra = 0, glide) {
|
||||
if (h === fit.last) return;
|
||||
fit.last = h;
|
||||
const still = !glide || calm();
|
||||
api("window/fit?h=" + h + (still ? "" : "&ms=" + glide.ms + "&ease=" + glide.ease), {});
|
||||
fitSend("window/fit?h=" + h + (still ? "" : "&ms=" + glide.ms + "&ease=" + glide.ease));
|
||||
}
|
||||
// fitSend asks for one height at a time. Wails serves each of the page's
|
||||
// requests on a goroutine of its own, so two fits asked together reached
|
||||
// the panel in either order (69 of 400 pairs the wrong way round in a real
|
||||
// WKWebView), and the older one landing last kept the panel at its height:
|
||||
// fit.last and the panel's own height then took the newer as done, and the
|
||||
// Allowances tab's card was cut off by the foot (robot_yz on X). A fit
|
||||
// asked while one is on its way waits for it, and only the latest goes.
|
||||
function fitSend(path) {
|
||||
if (fitSend.busy) { fitSend.next = path; return; }
|
||||
fitSend.busy = true;
|
||||
api(path, {}).catch(() => {}).finally(() => {
|
||||
fitSend.busy = false;
|
||||
const next = fitSend.next;
|
||||
fitSend.next = null;
|
||||
if (next) fitSend(next);
|
||||
});
|
||||
}
|
||||
|
||||
// the panel brought up on its Allowances tab is the reader opening them
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// The tray panel keeps the height it asked for last (robot_yz on X, on
|
||||
// v0.1.3005: the panel had become short, and the Allowances tab's one card,
|
||||
// Zhipu GLM with its 5h, 7d and MCP rings and its curve, was cut off by the
|
||||
// foot). Wails serves each of the page's requests on a goroutine of its own,
|
||||
// so two window/fit requests on their way together reach the panel in either
|
||||
// order; in a real WKWebView 69 of 400 pairs sent together landed the wrong
|
||||
// way round. The fake here does what Wails can: the panel's first fit is
|
||||
// answered, and so applied, only after the page has drawn the card and
|
||||
// asked for whatever else it would. The panel must end at the latest
|
||||
// height asked, with the card whole. Chromium and WebKit, every language;
|
||||
// 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(process.env.MAGPIE_PANEL_FIT_ORDER_ASSETS || path.join(__dirname, "../assets"));
|
||||
const H = 3600e3;
|
||||
const iso = (ms) => new Date(ms).toISOString();
|
||||
|
||||
// the reporter's allowance: Zhipu GLM's Max plan, renewed, its 5-hour and
|
||||
// weekly windows and the MCP month aside (planquota.go's names), and the
|
||||
// 5-hour window's readings this cycle for the curve
|
||||
function zhipu(now) {
|
||||
const s5 = now - 2 * H, r5 = now + 3 * H;
|
||||
const quota = {
|
||||
provider: "zhipu", name: "Zhipu GLM", icon: "zhipu-color", plan: "max", until: iso(now + 99 * 24 * H), renew: "auto",
|
||||
windows: [
|
||||
{ name: "5 hours", used: 7, span: 5 * H * 1e6, startsAt: iso(s5), resetsAt: iso(r5) },
|
||||
{ name: "7 days", used: 18, span: 7 * 24 * H * 1e6, startsAt: iso(now - 2 * 24 * H), resetsAt: iso(now + 5 * 24 * H) },
|
||||
{ name: "MCP · Month", used: 1, aside: true, resetsAt: iso(now + 20 * 24 * H) },
|
||||
],
|
||||
};
|
||||
const points = [];
|
||||
for (let m = 0; m <= 120; m += 10) points.push({ at: iso(s5 + m * 60e3), left: 100 - (7 * m) / 120, start: iso(s5), resetsAt: iso(r5) });
|
||||
return { quotas: [quota], history: [{ provider: "zhipu", user: "", lines: [{ name: "5 hours", points }] }] };
|
||||
}
|
||||
|
||||
// fifteen agents (the reporter's tab says 15), two of them set up
|
||||
function serve(page, lang, panel) {
|
||||
const data = zhipu(Date.now());
|
||||
const ids = Array.from({ length: 15 }, (_, i) => "agent" + i);
|
||||
const state = {
|
||||
agents: ids.map((id, i) => ({ id, name: id, path: "/test/" + id, fields: [], wired: i < 2, added: i < 2 })),
|
||||
profiles: [], settings: { lang, theme: "light", tray: "panel", guideHidden: true },
|
||||
};
|
||||
return async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const json = (body) => route.fulfill({ json: body });
|
||||
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light"};` });
|
||||
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||||
if (url.pathname === "/api/window/fit") return panel.fit(route, Number(url.searchParams.get("h")));
|
||||
if (url.pathname === "/api/state") return json(state);
|
||||
if (url.pathname === "/api/settings") return json(state.settings);
|
||||
if (url.pathname === "/api/usage/quotas") return json(data.quotas);
|
||||
if (url.pathname === "/api/usage/quotas/history") return json(data.history);
|
||||
if (url.pathname === "/api/gateway/trace") {
|
||||
if (url.searchParams.get("wait")) await new Promise((r) => setTimeout(r, 20e3));
|
||||
return json({ mine: true, now: iso(Date.now()), seq: 0, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], gateway: { running: true, window: true } });
|
||||
if (url.pathname === "/api/groups") return json({ groups: [], models: [] });
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
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)];
|
||||
try { await route.fulfill({ body: await fs.readFile(file), contentType }); } catch { await route.fulfill({ status: 404, body: "" }); }
|
||||
};
|
||||
}
|
||||
|
||||
// the panel: it takes a height when its fit request is served, no shorter
|
||||
// than panelMin (textsize.go), and its first fit is served only on release
|
||||
function trayPanel(page) {
|
||||
const asked = [], applied = [];
|
||||
let release, first = true;
|
||||
const held = new Promise((r) => { release = r; });
|
||||
const take = async (route, h) => {
|
||||
applied.push(h);
|
||||
await page.setViewportSize({ width: 440, height: Math.min(560, Math.max(220, h)) }).catch(() => {});
|
||||
await route.fulfill({ status: 204 }).catch(() => {});
|
||||
};
|
||||
return {
|
||||
asked, applied, release: () => release(),
|
||||
async fit(route, h) {
|
||||
asked.push(h);
|
||||
if (first) { first = false; await held; }
|
||||
return take(route, h);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
// no new height asked for, or served, for a while
|
||||
async function quiet(page, panel) {
|
||||
let n = -1;
|
||||
while (n !== panel.asked.length + panel.applied.length) {
|
||||
n = panel.asked.length + panel.applied.length;
|
||||
await page.waitForTimeout(400);
|
||||
}
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
test(`${engine} ${lang}: the panel keeps the latest height asked, and the Zhipu GLM card shows whole`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
const page = await (await browser.newContext({ viewport: { width: 440, height: 220 }, reducedMotion: "reduce" })).newPage();
|
||||
page.setDefaultTimeout(10000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(e.message));
|
||||
await page.addInitScript(() => { try { localStorage.setItem("magpie.panelTab", "usage"); } catch {} });
|
||||
const panel = trayPanel(page);
|
||||
await page.route("**/*", serve(page, lang, panel));
|
||||
await page.goto("http://magpie.test/?mode=panel");
|
||||
|
||||
// the card drawn with its rings and curve, and the page done asking
|
||||
// while its first fit is still on its way
|
||||
await page.locator("#panelQuota .pq-card .pq-spark").waitFor();
|
||||
assert.equal(await page.locator("#panelQuota .pq-card").count(), 1, "one card, Zhipu GLM's");
|
||||
await page.locator("#agents .row.agent").first().waitFor({ state: "attached" });
|
||||
await quiet(page, panel);
|
||||
panel.release();
|
||||
await quiet(page, panel);
|
||||
|
||||
const last = panel.asked[panel.asked.length - 1];
|
||||
assert.equal(panel.applied[panel.applied.length - 1], last,
|
||||
`the panel ended at an older height than the page asked for last (asked ${panel.asked.join(" ")}, applied ${panel.applied.join(" ")})`);
|
||||
const seen = await page.evaluate(() => {
|
||||
const v = document.querySelector("#view-agents"), card = document.querySelector("#panelQuota .pq-card");
|
||||
return { over: v.scrollHeight - v.clientHeight, cardBottom: card.getBoundingClientRect().bottom, viewBottom: v.getBoundingClientRect().bottom, tab: document.body.dataset.ptab };
|
||||
});
|
||||
assert.equal(seen.tab, "usage");
|
||||
assert(seen.cardBottom <= seen.viewBottom + 0.5,
|
||||
`the Zhipu GLM card is cut off: its bottom at ${seen.cardBottom}, the view's at ${seen.viewBottom} (asked ${panel.asked.join(" ")}, applied ${panel.applied.join(" ")})`);
|
||||
assert(seen.over <= 0, `the Allowances tab overflows the panel by ${seen.over}px`);
|
||||
assert.deepEqual(errors, []);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user