From 8097860ab14a264d8d4755fdcfe7a2a5fa3c6b40 Mon Sep 17 00:00:00 2001 From: yetone Date: Fri, 13 Nov 2026 01:01:27 +0800 Subject: [PATCH] gui: put back what 76ceff87c took out of main by mistake 76ceff87c was built on an older base and its tree dropped the Linux backdrop-blur rule (7c37424fc) and Codex seats change (d6b5f24db) with their tests, docs and history.go edits. This restores those files from d6b5f24db; the diff against d6b5f24db is now only the hours feature. Run: git diff d6b5f24db --stat lists the usage files alone. --- docs/subsystems/gui-shell.md | 1 + internal/gateway/history.go | 11 ++- internal/gateway/history_tallies_test.go | 18 +++++ internal/gui/assets/app.css | 8 ++ internal/gui/assets/plugins/routing/client.js | 3 +- .../gui/tests/linux-no-backdrop-blur.test.cjs | 35 +++++++++ .../gui/tests/routing-codex-seats.test.cjs | 73 +++++++++++++++++++ 7 files changed, 145 insertions(+), 4 deletions(-) create mode 100644 internal/gui/tests/linux-no-backdrop-blur.test.cjs create mode 100644 internal/gui/tests/routing-codex-seats.test.cjs diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 5f5f0bbb8..59e3717a5 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -692,6 +692,7 @@ covers it in both engines, every language and a narrow window. - On Linux the panel is a solid window, as the main window is, and its page paints `--bg` whole (`panelOptions`, `body.linux.panel` in `app.css`). The Mac's and Windows' panels stay translucent. A see-through panel is an RGBA, app-paintable GTK window under a transparent webview, and on KDE Plasma 6 its page, painted at 93%, left a fainter copy of the old scroll position as it scrolled (Wayland and XWayland, compositing mode on or off) while the main window never did (#1803, `TestPanelSolidOnLinux`, `panel-linux-opaque.test.cjs`). Xvfb with picom on WebKitGTK 2.54 doesn't show the ghost either way, so the fix rests on the reporter's machine. - A Wayland window can't place itself, so under Hyprland and niri the compositor is asked to put the panel under the bar. Under Hyprland `placePanel` gives it a window rule at the cursor (`omarchy.PlacePanel`) and closes it on a click outside (`omarchy.ReportClicks`). The rule names the monitor under the cursor and moves the panel to x, y from that monitor's corner (`omarchy.PanelAt`): Hyprland adds the window's monitor's place to a `move`, so a position across the whole layout put the panel off a monitor not at 0,0 (#1785, `TestPanelAtMonitorOffScreenOrigin`). The cursor and the clients' places that `omarchy.ClickedOutside` compares are both across the layout. niri (`omarchy.Niri`, `NIRI_SOCKET` set) takes no rules at runtime and doesn't report the cursor. There `omarchy.NiriPanel` watches niri's event stream and moves the panel each time it opens: the window of magpie's pid titled `panelTitle`, moved with `MoveFloatingWindow` (after `MoveWindowToFloating` if it was tiled). It goes 6 px under the working area's top, centred on the x the tray host passed to `Activate(x, y)`. Wails keeps that x in its Linux tray (`trayClick`, `TestTrayClickIsWails`), and it is taken across the bar, since that's all a Wayland bar knows. With no click (`magpie panel`), or with one off the output, it goes top right. Wails' `HideOnFocusLost` closes it, since a click on another window takes niri's focus. It still opens in the middle and slides up, and a bar at the bottom or the side isn't accounted for (#1670). - Wails calls the tray's click handler both for the icon's click (`Activate`) and when the tray host opens the icon's menu (dbusmenu's "opened" event). KDE opens the menu on a right-click, and the panel that click opened took the focus and shut the menu on Wayland. On Linux the handler ignores the call when it comes from the menu opening (`menuOpening` in [`trayclick.go`](../../internal/gui/trayclick.go), which looks for Wails' `(*linuxSystemTray).Event` among its callers; `TestTrayMenuOpenFrameIsWails` fails if Wails renames it or stops calling the handler there) (#1430). +- On Linux the app draws without backdrop blur (`body.linux` rules at the end of `app.css`; `linux-no-backdrop-blur.test.cjs`): `webkit_linux.go` turns accelerated compositing off under Wayland and without a GPU, and there a blur is repainted by the CPU on every frame (a full-window modal took 25ms a frame against 16ms with none, in WebKitGTK 2.52 on Xvfb). The modal, pickers and Settings' sticky head are 92% or more opaque, so the blur is barely seen. Not reproduced on NVIDIA under Wayland (no such machine), so a report of lag there may have another part (#3150). - On GTK 3 builds, the app gives GDK a font DPI before the first webview when it has none (`fontDPI`, [`fontdpi_gtk3.h`](../../internal/gui/fontdpi_gtk3.h)). GDK's unset value is -1, and WebKitGTK 2.54's GTK 3 settings reader multiplies it by 1024 unchecked, so every page lays out at a negative width with a 9000000px font (#1371). An unset DPI takes `gtk-xft-dpi`, or 96, times a valid `GDK_DPI_SCALE`; a positive one is left alone. Wails initialises GTK (its GtkApplication) only inside `Run` and makes each window from a default-idle-priority callback on the main loop, so `fontDPI`, called just before `Run`, queues the check as a `G_PRIORITY_HIGH` idle: it runs on the main thread after GTK's own start, before the first window. `TestFontDPIUnset` opens a real WebKitGTK page through `magpie_font_dpi` and needs a display (Xvfb). - Tests never touch a live agent config. The package's `TestMain` runs under `testenv`'s home of its own. A macOS test that shows windows runs them in a process of its own through `runAppKit` ([`appkit_darwin_test.go`](../../internal/gui/appkit_darwin_test.go)). AppKit and WebKit take their home from the account, not from HOME, so `runAppKit` gives them a temporary one with `CFFIXED_USER_HOME`; appearance, contrast and languages still come from the account. The test fails when that process leaves a folder in the real `~/Library/WebKit` or `~/Library/Caches`. Playwright tests serve `assets/` with isolated `/api` fixtures. - `POST /api/settings/codex-auto-review` accepts an empty value (Codex's own choice, or the session's model when Codex's sign-in is on a Free plan), `session` (the session's own model when it is one of magpie's; "Same as the session" in the picker), or an exact model/group ID in `provider.Served`, including unlisted providers. A known provider with an unknown or empty model name is rejected without changing the saved reviewer or catalog tag. Generic gateway request resolution remains permissive; it is not the validator for this setting. See `Handler` in [`api.go`](../../internal/gui/api.go) and `TestCodexAutoReviewSetting` in [`codex_auto_review_test.go`](../../internal/gui/codex_auto_review_test.go). diff --git a/internal/gateway/history.go b/internal/gateway/history.go index 743fb6dd4..c138de401 100644 --- a/internal/gateway/history.go +++ b/internal/gateway/history.go @@ -533,12 +533,17 @@ type tallied struct { Tries []Try `json:"tries"` } -// tallyKey is what the page groups an account by: its provider and its -// user, however it is weighed into a request (its sign-in may move); a +// tallyKey is what the page groups an account by: its provider, its user +// and its plan (two seats of one email on different plans are two +// accounts, not one), however it is weighed into a request (its sign-in may move); a // key or a provider by its own id. func tallyKey(w Weighed) string { if w.Kind == "account" && w.Who != "" { - b, _ := json.Marshal([]string{w.Provider, strings.ToLower(strings.TrimSpace(w.Who))}) + k := []string{w.Provider, strings.ToLower(strings.TrimSpace(w.Who))} + if plan := strings.ToLower(strings.TrimSpace(w.Plan)); plan != "" { + k = append(k, plan) // a plan-less seat keeps the two-part key + } + b, _ := json.Marshal(k) return string(b) } return w.ID diff --git a/internal/gateway/history_tallies_test.go b/internal/gateway/history_tallies_test.go index 0c07bafa9..7479ed4eb 100644 --- a/internal/gateway/history_tallies_test.go +++ b/internal/gateway/history_tallies_test.go @@ -144,3 +144,21 @@ func TestDayTalliesCountARateLimitAsOne(t *testing.T) { t.Errorf("tallied %v, want 1 rate and 2 quota", a.Fails) } } + +// Two seats of one email on different plans are two accounts in the day's +// tallies, as the Routing page's list keys them (RayYanOnline on X); a +// seat with no plan keeps the two-part key. +func TestTallyKeyTellsPlansApart(t *testing.T) { + seat := func(plan string) Weighed { + return Weighed{ID: "codex", Provider: "codex", Kind: "account", Who: "Jd@Example.com", Plan: plan} + } + if a, b := tallyKey(seat("team")), tallyKey(seat("prolite")); a == b { + t.Errorf("a Team seat and a Pro Lite login share the key %s", a) + } + if got, want := tallyKey(seat("")), `["codex","jd@example.com"]`; got != want { + t.Errorf("a seat with no plan: %s, want %s", got, want) + } + if got, want := tallyKey(seat(" Team ")), `["codex","jd@example.com","team"]`; got != want { + t.Errorf("a plan: %s, want %s", got, want) + } +} diff --git a/internal/gui/assets/app.css b/internal/gui/assets/app.css index d46aaad80..25ceee610 100644 --- a/internal/gui/assets/app.css +++ b/internal/gui/assets/app.css @@ -5290,3 +5290,11 @@ body .row.agent .ag-prefs .row.pref .who { display: block; } .server-pin .hint.err { color: var(--red); overflow-wrap: anywhere; } .server-pin .pin-acts { display: flex; flex-wrap: wrap; gap: 12px; } .server-pin .pin-peek.busy { pointer-events: none; opacity: .6; } +/* WebKitGTK draws without accelerated compositing (webkit_linux.go), so a + backdrop blur is redone by the CPU for its whole box on every frame: a + full-window modal took 25ms a frame where the same page took 16ms with none + (lagging scroll, Lsheng2012 on X, KDE). Each of these grounds is 92% opaque + or a dim, so the blur is barely seen; the Linux app draws without it. */ +body.linux .modal, body.linux .pop, body.linux.panel .profiles.open, +body.linux:not(.side-nav) #view-settings .set-head::before, +body.linux .action-confirm::backdrop { -webkit-backdrop-filter: none; backdrop-filter: none; } diff --git a/internal/gui/assets/plugins/routing/client.js b/internal/gui/assets/plugins/routing/client.js index d6f4451a8..5fb361d6e 100644 --- a/internal/gui/assets/plugins/routing/client.js +++ b/internal/gui/assets/plugins/routing/client.js @@ -4744,7 +4744,8 @@ function routingPage(part) { // that same account uses provider@user and the base ID names another. // Group accounts by their identity, resolving each try in its own route. const keyOf = (w) => w.kind === "account" && w.who - ? JSON.stringify([w.provider, w.who.trim().toLowerCase()]) : w.id; + ? JSON.stringify(w.plan && String(w.plan).trim() + ? [w.provider, w.who.trim().toLowerCase(), String(w.plan).trim().toLowerCase()] : [w.provider, w.who.trim().toLowerCase()]) : w.id; // Live: the day's counts come with the history read the page already // asks for (#3351) — the Usage page's own reading of the day, not the // last few requests the gateway keeps. What that read cannot say (the diff --git a/internal/gui/tests/linux-no-backdrop-blur.test.cjs b/internal/gui/tests/linux-no-backdrop-blur.test.cjs new file mode 100644 index 000000000..2081513e6 --- /dev/null +++ b/internal/gui/tests/linux-no-backdrop-blur.test.cjs @@ -0,0 +1,35 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// The Linux app's WebKitGTK draws without accelerated compositing, where a +// backdrop blur is repainted by the CPU on every frame (a full-window modal +// cost 25ms a frame against 16ms with none). On Linux the app's modals, +// pickers and sticky Settings head draw without the blur; elsewhere they keep it. +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 css = path.resolve(__dirname, "../assets/app.css"); +const probe = `
+
x
`; + +for (const [name, engine] of [["chromium", chromium], ["webkit", webkit]]) { + test(`${name}: backdrop blur is off on Linux only`, async () => { + const b = await engine.launch(); + try { + const out = {}; + for (const cls of ["linux", ""]) { + const page = await b.newPage(); + await page.setContent(`${probe}`); + await page.addStyleTag({ content: await fs.readFile(css, "utf8") }); + out[cls || "other"] = await page.evaluate(() => { + const bf = (el, pseudo) => { const s = getComputedStyle(el, pseudo); return s.backdropFilter || s.webkitBackdropFilter || "none"; }; + return [bf(m), bf(p), bf(h, "::before")]; + }); + await page.close(); + } + assert.deepEqual(out.linux, ["none", "none", "none"]); + for (const v of out.other) assert.notEqual(v, "none"); + } finally { await b.close(); } + }); +} diff --git a/internal/gui/tests/routing-codex-seats.test.cjs b/internal/gui/tests/routing-codex-seats.test.cjs new file mode 100644 index 000000000..d90c2f514 --- /dev/null +++ b/internal/gui/tests/routing-codex-seats.test.cjs @@ -0,0 +1,73 @@ +// Codex accounts in one group on the Routing page (RayYanOnline on X): seats +// that share a name (a Team seat and a Pro Lite login of one email) were +// folded into one card in the accounts list, so several accounts read as +// one. An account is told apart by its plan as well as its name. +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"); + + +function routes(now) { + const reset = new Date(now.getTime() + 4 * 3600e3).toISOString(); + const kiro = { provider: "codex", name: "Codex", kind: "account", icon: "codex-color", agent: "codex", plan: "team", model: "gpt-6.1-sol", known: true, used: 10, renews: [reset] }; + const named = { ...kiro, id: "codex", who: "jd@example.com" }; + const other = { ...kiro, id: "codex@jd@example.com", who: "jd@example.com", plan: "prolite", used: 20 }; + const key = { ...kiro, id: "codex@jd@example.com#2", who: "jd@example.com", plan: "plus", used: 30 }; + return Array.from({ length: 4 }, (_, i) => { + const time = new Date(now.getTime() - (4 - i) * 1000).toISOString(); + const id = ["codex", other.id, key.id][i % 3]; + return { id: i + 1, seq: i + 1, time, agent: "claude", model: "kiro/claude-sonnet-4.5", provider: "kiro", order: [named, other, key], done: true, + status: 200, ms: 20, tries: [{ id, model: "gpt-6.1-sol", start: time, done: true, status: 200, ms: 20 }] }; + }).reverse(); +} + +function serve(lang, now, names, users = () => ({})) { + const assets = path.resolve(__dirname, "../assets"); + return async (route) => { + const url = new URL(route.request().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:true};` }); + 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: { lang, theme: "light" } }); + if (url.pathname === "/api/gateway/trace") { + if (url.searchParams.has("wait")) return; + return json({ mine: true, now: now.toISOString(), seq: 4, totals: { requests: 4, rerouted: 0, errors: 0 }, routes: routes(now) }); + } + if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] }); + if (url.pathname === "/api/groups") return json({ groups: [] }); + if (url.pathname === "/api/providers") return json({ providers: [{ + id: "codex", name: "Codex", icon: "codex-color", models: [{ id: "gpt-6.1-sol", on: true }], keyList: [], + account: { agent: "codex", user: "jd@example.com · Team", logins: [] }, + accountNames: names(), accountUsers: users(), + }], presets: [], excluded: [], gateway: { running: true, window: true } }); + 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" }[path.extname(file)]; + await route.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType }); + }; +} + + + +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}: Routing keeps Codex seats of one name apart`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + const page = await browser.newPage({ viewport: { width: 1100, height: 1000 } }); + page.setDefaultTimeout(5000); + page.setDefaultNavigationTimeout(60000); + const errors = []; + page.on("pageerror", (e) => errors.push(e.message)); + await page.route("**/*", serve(lang, new Date(), () => ({}), () => ({}))); + await page.goto("http://magpie.test/?view=routing"); + await page.locator(".rt-act").first().waitFor(); + assert.equal(await page.locator(".rt-act", { hasText: "jd@example.com" }).count(), 3, "three seats are three cards: " + (await page.locator(".rt-acts").innerText())); + const text = (await page.locator(".rt-act", { hasText: "jd@example.com" }).allInnerTexts()).join(" | ").toLowerCase(); + for (const plan of ["team", "plus"]) assert.ok(text.includes(plan), plan + " tells its seat apart: " + text); + assert.deepEqual(errors, []); + }); + } +}