The owner asked for the groups to leave the Routing page (11-06): under the live stage and every request they were a long scroll down, and New group with them. The design was reviewed before this was built. - New page, Routing groups (#view-groups), drawn by the routing plugin's same script (routingPage), so the editor, its dirty/discard and every group action are unchanged. Toolbar: filter, "N groups · M on", Templates, Import, Select, and New group as the filled button. The list is right under it, and a Settings section under the list holds Found groups (with Exclude providers…) and Names in agents' lists. - No Export button: each group already has its own Copy to share. - Routing keeps the live stage and the requests. A request's group opens the groups page at its row. - The sidebar has a Routing groups tab right after Routing (from 1024 points). The header's row has no room for one: at 860px the extra tab pushed the logo out (brand.test). There the tab is hidden, Routing's tab is lit for both pages (markNav), and Routing's head has a "Routing groups ›" button, hidden beside the sidebar. - Every way in now goes to the groups page: the guide's Open routing groups, the panel's and the provider editor's Make a routing group (window/main?view=groups&newgroup=…). mainView still takes view=routing&newgroup from an older panel. - Words: "Routing groups", "Open routing groups", "Once saved, make a group of them in Routing groups.", and the editor's names note now says the setting is under the list, in zh, zh-TW, ja and de. "Open Routing" stays for the Agents page's button. - Docs: providers-accounts, gateway-routing, plugin-runtime, gui-shell and reference say "Routing groups page" where they mean the groups. - Core budget: the core's scripts are 1,533,774 of 1,533,802, paid for by three show()/setGatewayMode comments cut in app.js. No raise. Tests: routing-groups-page.test.cjs (new) covers the page in Chromium and WebKit, en/zh/zh-TW/ja/de, at 1280, 640 (window) and 420 (web): no groups on Routing, the tab or the head's button by width, the lit tab, toolbar order, New group primary and in sight, list then Settings, no sideways scroll, no native select, no left-border accent; a request's group to its row; quotas redrawn with an open editor left alone. The trace tests (routing-compact, -pause-folder, -rule-models, -folder) open Routing, then show the groups; routing-editor-foot and name-suffix-where-named scroll by wheel, as the scroll guard lets a reader; builtins expects the groups tab beside the sidebar only. Removed: routing-groups-jump (the head's "Routing groups ↓" that scrolled down to them, gone with them), routing-pointer-pin and routing-steady (the groups kept in place under requests streaming in above them: no request is above them now). Their guarantee that what redraws leaves an open editor and its typing alone is routing-groups-page's quotas case; Routing's own lists keep their keepInView. The groups page's jump: a request's group, or a pool's "Several keys" chip, opened the groups page and scrolled the row to the centre, and the next frame show()'s backAfterLoad put the page back where the reader last left it, then brought the focused segment in by "nearest": in WebKit the pool sat half under the window's foot (routing-mode-goes, 9 of its 10 WebKit cases). goRouting now jumps at once on a page it opens and marks it arrived(). The wheel in routing-many-keys turns over the keys: at the page's foot, now shorter, the mouse rested over the requests list (.rt-reqs, overscroll-behavior: contain), which took every wheel up, and the test stopped with 2 keys in sight. That is #4082's cause. routing-days-fit's fixture has 12 requests, a day that fills the window, since the day bar held needs room under it. Run on mote (macOS 27, load 25 to 65), Playwright 1.62.0: - Go: go vet, gofmt -l and go test ./... at the rebased head (650bf8412base) ok except TestMainWindowCorners (#3949); internal/gui again after the last edits: the same, TestCoreScriptBudget ok (1,533,773 of 1,533,802, no raise). - GUI, the 262 files a change here can reach, at the head and at the base: the reds at the head are the base's, with their issues: menu-input-scroll #3402, provider-mask #5109, context-fold and order-unknown (webkit) #3479, header-centre #3479, i18n-keys #5332/#5426/#5482, account-eye #5052/#4244, call-headers webkit de #5045, codex-predictions #2624, codex-auto-reset webkit de #4790, routing-* under load #5088, and zero-priced-free, last-page, reasoning-speed, routing-row-swap/-tag-whole/-story-shrinks/-steps-cap and routing-intent-entry, red at the base the same way. - After the last edits: the 11 files with a way to the groups page or its scroll (group-*, routing-groups-page, routing-mode-goes, routing-groups-off, routing-provider-off, routing-many-keys, click-scroll), 175 of 176; the one red is routing-many-keys webkit's wire at the foot, red at the base in 8 of 12 (#5543). brand, gateway-mode-sessions, header-zoom-fit, header-centre, inner-scroll-contain and mobile-web: the same 11 reds at the head and the base (mobile-web compares with origin/main through git, which a mote-run copy hasn't). - Rebased onecc26a339, again: gofmt -l, go vet ./internal/gui and TestCoreScriptBudget ok; 10 GUI files (i18n-keys, routing-groups-page, routing-mode-goes, sidebar, brand, menu-first-second, library-bar-more, click-scroll, name-suffix-saved, unlisted-models) 211 of 212, the one red i18n-keys' "a plugin's words are its own", red the same atecc26a339(#5332/#5426/#5482). - Broken by hand: without the groups page's CSS rule, brand and routing-groups-page go red (32 fails); with the old goRouting, routing-mode-goes is red in 9 of its 10 WebKit cases. Not tried: the whole GUI suite on Linux (WSL magpie-desktop) at this head; a run at an earlier head is under way and has the Linux reds #4120/#4121 name. Not tried in the real macOS app, only Playwright's WebKit.
211 lines
12 KiB
JavaScript
211 lines
12 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// real-jacket, #1581: on the Usage page a card's grip (drawn on hover by its
|
|
// logo) stood on the card's left border, while the Agents row's grip sits
|
|
// 4px inside the list's. Each grip had its own `left`, copied from the
|
|
// Agents row while the box around it had its own padding. Every kind of
|
|
// grip that is drawn in a row's left margin now stands at least 4px inside
|
|
// the edge the reader sees (the card's or the list's border, or the edge
|
|
// its shadow draws): the Agents, Providers, Usage and Routing pages, a
|
|
// group's members in its editor, an agent's model order, and the tray
|
|
// panel's agents and Arrange rows. The grips still show only on hover (the
|
|
// owner: 一直出现太丑了). Chromium and WebKit, every language, a wide window
|
|
// and a narrow one; no backend, the API is faked here.
|
|
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");
|
|
const prov = (id) => ({
|
|
id, name: id.toUpperCase(), icon: "generic", host: id + ".example.com", chat: "https://" + id + ".example.com/v1", responses: "", anthropic: "", catalog: "",
|
|
models: [{ id: "m", name: "M", on: true }], agents: [], fallback: [], headers: {},
|
|
key: { set: true, masked: "sk-…" + id }, keyList: [], balanceToken: { takes: false, set: false }, proxy: "",
|
|
});
|
|
const quotas = [
|
|
{ provider: "codex", name: "Codex", icon: "codex-color", user: "x@y.z", windows: [{ name: "5-hour", used: 8 }, { name: "Weekly", used: 40 }] },
|
|
{ provider: "kimi", name: "Kimi", icon: "kimi-color", windows: [{ name: "Weekly", used: 30 }] },
|
|
{ provider: "deepseek", name: "DeepSeek", icon: "deepseek-color", windows: [], balance: "¥12.30" },
|
|
];
|
|
const models = [
|
|
{ id: "a/one", name: "one", providerName: "A", icon: "generic" },
|
|
{ id: "a/two", name: "two", providerName: "A", icon: "generic" },
|
|
{ id: "b/three", name: "three", providerName: "B", icon: "generic" },
|
|
];
|
|
const members = ["a/one", "a/two", "b/three"];
|
|
const groups = {
|
|
models, pools: [], deciders: [], found: true,
|
|
groups: [
|
|
{ id: "g", name: "G", members, ready: true, routing: "order", memberInfo: members.map((id) => ({ id, ready: true })) },
|
|
{ id: "h", name: "H", members: ["b/three"], ready: true, memberInfo: [{ id: "b/three", ready: true }] },
|
|
],
|
|
};
|
|
const agentModels = [
|
|
{ id: "relay/m1", name: "m1", group: "Relay", icon: "generic" },
|
|
{ id: "relay/m2", name: "m2", group: "Relay", icon: "generic" },
|
|
{ id: "relay/m3", name: "m3", group: "Relay", icon: "generic" },
|
|
];
|
|
|
|
function serve(lang, web) {
|
|
const settings = { lang, theme: "light", tray: "panel", usageOrder: [], panelUsageHidden: [] };
|
|
const agent = (id, name) => ({
|
|
id, name, icon: "generic", path: "/fixture/" + id, wired: true,
|
|
fields: [{ key: "model", label: "model", value: "m1", options: [{ value: "m1", label: "m1", ref: "relay/m1" }] }],
|
|
models: { shown: 3, listed: 3, by: [{ name: "Relay", icon: "generic", n: 3 }] },
|
|
});
|
|
const state = { agents: [agent("codex", "Codex"), agent("beta", "Beta"), agent("gamma", "Gamma")], profiles: [], settings };
|
|
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:${web}};` });
|
|
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/settings") return json(settings);
|
|
if (url.pathname === "/api/providers") return json({ providers: [prov("a"), prov("b")], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
|
if (url.pathname === "/api/usage/quotas") return json(quotas);
|
|
if (url.pathname === "/api/usage") return json({ calls: 0, cost: 0, days: [], agents: [], models: [], keys: [] });
|
|
if (url.pathname === "/api/groups") return json(groups);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname === "/api/agents/cli") return json({ agents: {}, pending: false });
|
|
if (url.pathname.startsWith("/api/agent-models/")) return json({ models: agentModels, ordered: false });
|
|
if (url.pathname === "/api/gateway/trace") {
|
|
if (url.searchParams.get("wait")) return new Promise(() => {}); // nothing more comes
|
|
return json({ mine: true, now: new Date().toISOString(), seq: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
|
}
|
|
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
|
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 grip under the pointer and the edge the reader sees left of it: the
|
|
// inner side of the first box out from the row that draws a border or a
|
|
// shadow. A grip drawn as ::before is read from its handle's box and its
|
|
// own left; one drawn as an element, from its box. `shown` is its opacity:
|
|
// the measure is taken with the pointer on the row, where it is drawn.
|
|
const measure = (page, row, grip) => page.evaluate(([row, grip]) => {
|
|
const r = document.querySelector(row);
|
|
if (!r) return null;
|
|
const g = r.querySelector(grip);
|
|
let left, width, opacity;
|
|
if (g.classList.contains("grip")) {
|
|
const b = g.getBoundingClientRect(), s = getComputedStyle(g);
|
|
left = b.left; width = b.width; opacity = s.opacity;
|
|
} else {
|
|
const s = getComputedStyle(g, "::before");
|
|
left = g.getBoundingClientRect().left + parseFloat(s.left); width = parseFloat(s.width); opacity = s.opacity;
|
|
}
|
|
let box = r;
|
|
for (; box && box !== document.body; box = box.parentElement) {
|
|
const s = getComputedStyle(box);
|
|
if (parseFloat(s.borderLeftWidth) > 0 || s.boxShadow !== "none") break;
|
|
}
|
|
const edge = box.getBoundingClientRect().left + box.clientLeft;
|
|
return { inset: +(left - edge).toFixed(2), left, width, opacity, box: box.tagName.toLowerCase() + "." + [...box.classList].join(".") };
|
|
}, [row, grip]);
|
|
|
|
// each kind of grip: where it is, how to bring it up, and its row
|
|
const kinds = [
|
|
{ name: "Agents", mode: "window", view: "agents", row: '#agents > .row.agent[data-id="beta"]', grip: ".ag-handle" },
|
|
{ name: "Providers", mode: "window", view: "providers", row: "#providers > .row.provider", grip: ".pv-handle" },
|
|
{ name: "Usage", mode: "window", view: "usage", row: ".subscription-card", grip: ".us-handle" },
|
|
{ name: "Routing groups", mode: "window", view: "groups", row: '.rt-groups > .rt-group[data-id="g"]', grip: ".rt-ghandle" },
|
|
{
|
|
name: "a group's members", mode: "window", view: "groups", row: ".rt-gedit .fbrow:has(.rt-mhandle)", grip: ".rt-mhandle",
|
|
open: async (page) => {
|
|
await page.locator('.rt-groups > .rt-group[data-id="g"]').waitFor();
|
|
await page.evaluate(() => document.querySelector('.rt-groups > .rt-group[data-id="g"]').click());
|
|
await page.locator(".rt-gedit .fbrow .rt-mhandle").first().waitFor();
|
|
},
|
|
},
|
|
{
|
|
name: "an agent's model order", mode: "window", view: "agents", row: ".am-pop:not(.leaving) .am-or", grip: ".grip",
|
|
open: async (page) => {
|
|
const row = page.locator('.row.agent[data-id="codex"]');
|
|
await row.locator(".ag-link").click();
|
|
await row.locator(".ag-exp .ag-chips .ag-quiet").click();
|
|
const pop = page.locator(".am-pop:not(.leaving)");
|
|
await pop.locator(".am-seg button").last().click();
|
|
await pop.locator(".am-or").first().waitFor();
|
|
},
|
|
},
|
|
{ name: "the panel's agents", mode: "panel", view: "agents", row: '#agents > .row.agent[data-id="beta"]', grip: ".ag-handle" },
|
|
{
|
|
name: "the panel's Arrange", mode: "panel", row: "#panelQuota .pq-arow", grip: ".pq-ahandle", tab: "usage",
|
|
open: async (page) => {
|
|
await page.locator("#panelQuota .pq-arrange").click();
|
|
await page.locator("#panelQuota .pq-arow").first().waitFor();
|
|
},
|
|
},
|
|
];
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: every row's grip stands inside its card's edge`, { timeout: 600000 }, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) for (const width of [980, 420]) for (const k of kinds) {
|
|
await t.test(`${lang} ${width}px: ${k.name}`, async () => {
|
|
// the window is no narrower than 560px (windowMinW); narrower, it
|
|
// is the browser page (magpie web, a phone)
|
|
const web = k.mode === "window" && width < 560;
|
|
const viewport = k.mode === "panel" ? { width: Math.min(width, 440), height: 640 } : { width, height: 760 };
|
|
const ctx = await browser.newContext({ viewport, reducedMotion: "reduce" });
|
|
if (k.tab) await ctx.addInitScript((tab) => { try { localStorage.setItem("magpie.panelTab", tab); } catch {} }, k.tab);
|
|
const page = await ctx.newPage(), errors = [];
|
|
page.setDefaultTimeout(8000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
try {
|
|
await page.route("**/*", serve(lang, web));
|
|
await page.goto("http://magpie.test/?" + (web ? "" : `mode=${k.mode}&`) + (k.view ? `view=${k.view}` : ""));
|
|
if (k.open) await k.open(page);
|
|
const row = page.locator(k.row).first();
|
|
await row.waitFor();
|
|
await page.evaluate(() => Promise.all(document.getAnimations().map((a) => a.finished.catch(() => {}))));
|
|
// drawn only on hover: away, it is not there
|
|
await page.mouse.move(viewport.width - 2, viewport.height - 2);
|
|
await page.waitForFunction(([r, g]) => {
|
|
const e = document.querySelector(r)?.querySelector(g);
|
|
return e && getComputedStyle(e, e.classList.contains("grip") ? null : "::before").opacity === "0";
|
|
}, [k.row, k.grip]);
|
|
// on the row's left padding, by the grip, which no other element
|
|
// covers; the page brought to it by the test, as the reader would
|
|
// the row brought into sight with the wheel, as the reader would (a
|
|
// scroll by code the page puts back); its box taken once it holds
|
|
// still
|
|
const still = () => row.evaluate((r) => new Promise((done) => {
|
|
let last = "", same = 0;
|
|
const look = () => {
|
|
const x = r.getBoundingClientRect(), now = [x.x, x.y, x.width, x.height].join();
|
|
same = now === last ? same + 1 : 0;
|
|
last = now;
|
|
if (same >= 5) return done({ x: x.x, y: x.y, width: x.width, height: x.height });
|
|
requestAnimationFrame(look);
|
|
};
|
|
look();
|
|
}));
|
|
let b = await still();
|
|
for (let i = 0; i < 6 && (b.y < 60 || b.y + b.height > viewport.height - 20); i++) {
|
|
await page.mouse.move(viewport.width / 2, viewport.height / 2);
|
|
await page.mouse.wheel(0, b.y + b.height / 2 - viewport.height / 2);
|
|
b = await still();
|
|
}
|
|
await page.mouse.move(b.x + 6, b.y + b.height / 2);
|
|
await page.waitForFunction(([r, g]) => {
|
|
const e = document.querySelector(r)?.querySelector(g);
|
|
return e && getComputedStyle(e, e.classList.contains("grip") ? null : "::before").opacity === "1";
|
|
}, [k.row, k.grip]);
|
|
const m = await measure(page, k.row, k.grip);
|
|
if (process.env.GRIP_LOG) console.log(engine, lang, width, k.name, JSON.stringify(m));
|
|
assert(m.inset >= 4, `${k.name}'s grip is ${m.inset}px from its edge (${m.box}), not 4px inside it: ${JSON.stringify(m)}`);
|
|
assert.deepEqual(errors, []);
|
|
} finally {
|
|
await ctx.close();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|