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.
262 lines
16 KiB
JavaScript
262 lines
16 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||
// Routing groups have a page of their own beside Routing (11-06): below the
|
||
// stage and every request they were a long scroll down, New group with
|
||
// them. The sidebar names the page under Models, after Routing; its
|
||
// toolbar is the filter, how many groups there are and how many are on,
|
||
// then Templates, Import, Select and New group, the one filled button;
|
||
// the list follows, then Settings (found groups, the names in agents'
|
||
// lists). The Routing page keeps the stage and the requests, and a
|
||
// request's group opens the groups page on its row. Every language,
|
||
// Chromium and WebKit, wide, a narrow window and a phone's width.
|
||
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_ROUTING_ASSETS || path.join(__dirname, "../assets"));
|
||
const models = [
|
||
{ id: "a/m", name: "m", providerName: "A", icon: "generic" },
|
||
{ id: "b/m", name: "m", providerName: "B", icon: "generic" },
|
||
{ id: "a/n", name: "n", providerName: "A", icon: "generic" },
|
||
];
|
||
const info = (ids) => ids.map((id) => ({ id, ready: true }));
|
||
const groups = [
|
||
{ id: "auto-m", name: "Model M", members: ["a/m", "b/m"], auto: true, ready: true, memberInfo: info(["a/m", "b/m"]) },
|
||
{ id: "mine", name: "Mine", members: ["a/n", "b/m"], ready: true, memberInfo: info(["a/n", "b/m"]) },
|
||
{ id: "off", name: "Off one", members: ["a/n"], disabled: true, ready: true, memberInfo: info(["a/n"]) },
|
||
];
|
||
|
||
const words = {
|
||
en: { nav: "Routing groups", count: "3 groups · 2 on", fresh: "New group", settings: "Settings" },
|
||
zh: { nav: "路由组", count: "3 个组 · 2 个开启", fresh: "新建组", settings: "设置" },
|
||
"zh-TW": { nav: "路由組", count: "3 個組 · 2 個開啟", fresh: "新增組", settings: "設定" },
|
||
ja: { nav: "ルーティンググループ", count: "3 個のグループ · 2 個がオン", fresh: "新しいグループ", settings: "設定" },
|
||
de: { nav: "Weiterleitungsgruppen", count: "3 Gruppen · 2 an", fresh: "Neue Gruppe", settings: "Einstellungen" },
|
||
};
|
||
|
||
// enough requests that the Routing page scrolls
|
||
const now = Date.now();
|
||
const routes = Array.from({ length: 30 }, (_, i) => ({
|
||
id: "r" + i, seq: i + 1, at: new Date(now - i * 60000).toISOString(), agent: "claude", asked: "group/mine",
|
||
model: "a/n", provider: "a", status: 200, ms: 900, ttft: 300, in: 100, out: 20, done: true,
|
||
group: { id: "mine", name: "Mine" },
|
||
}));
|
||
|
||
function serve(lang, web) {
|
||
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", fields: [] }], profiles: [], settings: { lang, theme: "light" } };
|
||
return async (r) => {
|
||
const url = new URL(r.request().url());
|
||
const json = (data) => r.fulfill({ json: data });
|
||
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:${web}};` });
|
||
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
||
if (url.pathname === "/api/state") return json(state);
|
||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||
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: routes.length, totals: { requests: routes.length, rerouted: 0, errors: 0 }, routes });
|
||
}
|
||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||
if (url.pathname === "/api/groups") return json({ models, pools: [], deciders: [], found: true, groups });
|
||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||
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 r.fulfill({ body: await fs.readFile(file), contentType });
|
||
};
|
||
}
|
||
|
||
// the page's boot under the whole suite's load (#3478)
|
||
const boot = 15000;
|
||
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
for (const lang of Object.keys(words)) {
|
||
for (const { width, web } of [{ width: 1280, web: false }, { width: 640, web: false }, { width: 420, web: true }]) {
|
||
const w = words[lang];
|
||
test(`${engine} ${lang} ${width}px${web ? " web" : " window"}: Routing groups is a page of its own`, async (t) => {
|
||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||
const page = await (await browser.newContext({ viewport: { width, height: 700 }, reducedMotion: "reduce" })).newPage();
|
||
t.after(async () => {
|
||
if (process.env.ARTIFACT_DIR) {
|
||
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
|
||
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${width}${web ? "-web" : ""}-routing-groups-page.png`) });
|
||
}
|
||
await browser.close();
|
||
});
|
||
page.setDefaultTimeout(5000);
|
||
page.setDefaultNavigationTimeout(60000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve(lang, web));
|
||
await page.goto("http://magpie.test/?view=routing");
|
||
await page.locator(".rt-reqs > *").first().waitFor({ state: "attached", timeout: boot });
|
||
await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "attached", timeout: boot });
|
||
|
||
// the Routing page: the stage and the requests, no groups, no jump
|
||
assert.equal(await page.locator("#view-routing .rt-gsec, #view-routing .rt-group").count(), 0, "no groups on the Routing page");
|
||
assert.equal(await page.locator("#rtGoGroups, #rtNewGroup").count(), 0, "its head has no way down to them");
|
||
assert.equal(await page.locator("#view-groups .rt-gsec").count(), 1, "the groups are on their own page");
|
||
|
||
// the sidebar (or the header's tabs) names the page, after Routing
|
||
const nav = page.locator('button[data-view="groups"]');
|
||
assert.equal(await nav.count(), 1);
|
||
assert.equal((await nav.textContent()).trim(), w.nav);
|
||
assert.equal(await page.evaluate(() => {
|
||
const r = document.querySelector('button[data-view="routing"]');
|
||
return r.nextElementSibling === document.querySelector('button[data-view="groups"]');
|
||
}), true, "right after Routing");
|
||
|
||
// the sidebar has the tab; the header's row has no room for it (at
|
||
// 860px it pushed the logo out), so there Routing's head opens the
|
||
// page and Routing's tab stands for both
|
||
const side = await page.evaluate(() => document.body.classList.contains("side-nav"));
|
||
const into = page.locator("#rtToGroups");
|
||
assert.equal(side, width >= 1024, "the sidebar from 1024 points");
|
||
assert.equal(await nav.isVisible(), side, "the tab where there is room");
|
||
assert.equal(await into.isVisible(), !side, "Routing's head opens them where there is no tab");
|
||
if (side) await nav.click();
|
||
else {
|
||
assert.equal((await into.textContent()).replace("›", "").trim(), w.nav);
|
||
await into.click();
|
||
}
|
||
const view = page.locator("#view-groups");
|
||
await view.waitFor();
|
||
const on = await page.evaluate(() => [...document.querySelectorAll("#nav button[data-view].on")].map((b) => b.dataset.view));
|
||
assert.deepEqual(on, [side ? "groups" : "routing"], "the tab shown as the page's");
|
||
assert.equal(await page.locator("#view-routing").isHidden(), true);
|
||
const rows = view.locator(".rt-group");
|
||
await rows.first().waitFor({ timeout: boot });
|
||
assert.equal(await rows.count(), 3);
|
||
|
||
// the toolbar: the filter, how many, then New group, the filled one
|
||
const head = view.locator(".rt-gsec > .row-head").first();
|
||
assert.equal(await head.locator(".rt-gfilter").count(), 1, "the filter");
|
||
assert.equal((await head.locator(".rt-gcount").textContent()).trim(), w.count);
|
||
const fresh = head.locator(".rt-gnew");
|
||
assert.equal((await fresh.textContent()).trim(), w.fresh);
|
||
assert.equal(await fresh.evaluate((e) => e.classList.contains("primary")), true, "New group is the filled button");
|
||
assert.equal(await head.locator(".rt-gimportbtn").count(), 1, "Import");
|
||
assert.equal(await head.locator(".rt-gselect").count(), 1, "Select");
|
||
assert.equal(await head.locator("select").count(), 0, "no native select");
|
||
const fb = await fresh.boundingBox();
|
||
assert(fb && fb.x >= 0 && fb.x + fb.width <= width && fb.y >= 0 && fb.y + fb.height <= 700, "New group in sight on arrival");
|
||
// the list right under the toolbar, Settings under the list
|
||
const order = await page.evaluate(() => {
|
||
const s = document.querySelector("#view-groups .rt-gsec"), kids = [...s.children];
|
||
const at = (q) => kids.findIndex((k) => k.matches(q));
|
||
return [at(".row-head"), at(".rt-groups"), at(".rt-gset-head"), at(".rt-gset")];
|
||
});
|
||
assert.deepEqual(order, [0, 1, 3, 4], "toolbar, list, (off), Settings, its card");
|
||
assert.equal((await view.locator(".rt-gset-head .label").textContent()).trim(), w.settings);
|
||
assert.equal(await view.locator(".rt-gset .rt-gfound").count(), 1, "found groups in Settings");
|
||
assert.equal(await view.locator(".rt-gset .rt-gnames").count(), 1, "the names in Settings");
|
||
const gb = await view.locator(".rt-groups").boundingBox(), hb = await head.boundingBox();
|
||
assert(gb.y >= hb.y + hb.height - 1 && gb.y - (hb.y + hb.height) < 24, "the list right below the toolbar");
|
||
const over = await page.evaluate(() => document.documentElement.scrollWidth - innerWidth);
|
||
assert(over <= 0, `no sideways scroll (${over}px)`);
|
||
const headOver = await head.evaluate((h) => h.scrollWidth - h.clientWidth);
|
||
assert(headOver <= 0, `nothing overflows the toolbar (${headOver}px)`);
|
||
const border = await fresh.evaluate((e) => { const c = getComputedStyle(e); return c.borderLeftWidth !== c.borderRightWidth || c.borderLeftColor !== c.borderRightColor; });
|
||
assert.equal(border, false, "no left-border accent");
|
||
|
||
// New group opens its editor at the list's top, on this page
|
||
await fresh.click();
|
||
await view.locator(".rt-gedit").first().waitFor();
|
||
assert.equal(await page.locator("#view-routing .rt-gedit").count(), 0);
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
}
|
||
}
|
||
|
||
// a request's group on the Routing page opens the groups page on its row
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
test(`${engine}: a request's group goes to its row on the groups page`, 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: 1280, height: 700 }, reducedMotion: "reduce" })).newPage();
|
||
page.setDefaultTimeout(5000);
|
||
page.setDefaultNavigationTimeout(60000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
await page.route("**/*", serve("en", false));
|
||
await page.goto("http://magpie.test/?view=routing");
|
||
await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "attached", timeout: boot });
|
||
const go = page.locator('#view-routing .rt-go[data-go="group:mine"]').first();
|
||
await go.waitFor({ timeout: boot });
|
||
await go.click();
|
||
await page.locator("#view-groups").waitFor();
|
||
assert.equal(await page.locator("#view-routing").isHidden(), true, "Routing is left");
|
||
const row = page.locator('#view-groups .rt-group[data-id="mine"]');
|
||
await row.waitFor();
|
||
const rb = await row.boundingBox();
|
||
assert(rb.y >= 0 && rb.y + rb.height <= 700, "its row in sight");
|
||
// the window opened on a new group of a model: the groups page
|
||
await page.goto("http://magpie.test/?view=groups&newgroup=a%2Fn");
|
||
await page.locator("#view-groups .rt-gedit").first().waitFor({ timeout: boot });
|
||
assert.equal(await page.locator("#view-groups").isVisible(), true);
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
|
||
// The groups page draws itself again each second when the accounts' quotas
|
||
// change, as the Routing page did under streaming requests (routing-steady
|
||
// and routing-pointer-pin, gone with the groups' move): the quota line
|
||
// comes in under a group by itself, and with a group open in its editor
|
||
// and a name being typed, the field keeps its focus and what was typed,
|
||
// and the list stays where it is.
|
||
const withProvider = { models, pools: [], deciders: [], found: true, groups: groups.map((g) => ({ ...g, memberInfo: g.memberInfo.map((i) => ({ ...i, provider: i.id.split("/")[0], name: i.id.split("/")[0].toUpperCase() })) })) };
|
||
// two accounts: the line is what they have left together
|
||
const card = (amount) => ["a1@example.com", "a2@example.com"].map((user) => ({ provider: "a", name: "A", kind: "subscription", icon: "generic", plan: "Pro", user, readAt: new Date().toISOString(),
|
||
windows: [{ name: "Credits", amount, limit: 500, unit: "credits", used: (100 * amount) / 500, resetsAt: new Date(Date.now() + 9 * 864e5).toISOString() }] }));
|
||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||
for (const width of [1280, 420]) {
|
||
test(`${engine} ${width}px: the groups page draws new quotas by itself, an open editor left alone`, 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, height: 500 }, reducedMotion: "reduce" })).newPage();
|
||
page.setDefaultTimeout(5000);
|
||
page.setDefaultNavigationTimeout(60000);
|
||
const errors = [];
|
||
page.on("pageerror", (e) => errors.push(e.message));
|
||
const base = serve("en", width < 600);
|
||
await page.route("**/*", (r) => {
|
||
const at = new URL(r.request().url()).pathname;
|
||
if (at === "/api/groups") return r.fulfill({ json: withProvider });
|
||
if (at === "/api/usage/quotas") return r.fulfill({ json: [] });
|
||
return base(r);
|
||
});
|
||
await page.goto("http://magpie.test/?view=groups");
|
||
const row = page.locator('#view-groups .rt-group[data-id="mine"]');
|
||
await row.waitFor({ timeout: boot });
|
||
await page.waitForFunction(() => Array.isArray(quotas), null, { timeout: boot });
|
||
// quotas come in: the line shows with no click and no reload
|
||
await page.evaluate((q) => { quotas = q; }, card(400));
|
||
await row.locator(".rt-gquota").waitFor({ timeout: 5000 });
|
||
|
||
await row.getByRole("button", { name: "Edit", exact: true }).click();
|
||
const name = page.locator("#view-groups .rt-gedit input").first();
|
||
await name.waitFor();
|
||
// focus, not a click: at a phone's height the editor's Save bar can
|
||
// sit over it, and what is asked here is the redraw, not the reach
|
||
await name.focus();
|
||
await page.keyboard.type("Opus and more");
|
||
const typed = await name.inputValue();
|
||
const top = async () => (await name.boundingBox()).y;
|
||
const before = await top(), scrolled = await page.locator("#view-groups").evaluate((v) => v.scrollTop);
|
||
// new quotas twice, each a tick's redraw were the editor not open
|
||
for (const amount of [300, 200]) {
|
||
await page.evaluate((q) => { quotas = q; }, card(amount));
|
||
await page.waitForTimeout(1300);
|
||
}
|
||
assert.equal(await name.evaluate((e) => e === document.activeElement), true, "the field kept its focus");
|
||
assert.equal(await name.inputValue(), typed);
|
||
assert.equal(await page.locator("#view-groups").evaluate((v) => v.scrollTop), scrolled, "the view didn't scroll");
|
||
assert(Math.abs((await top()) - before) < 1, "the field stayed where it was");
|
||
await page.keyboard.type("!");
|
||
assert.equal(await name.inputValue(), typed + "!");
|
||
assert.deepEqual(errors, []);
|
||
});
|
||
}
|
||
}
|