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.
230 lines
15 KiB
JavaScript
230 lines
15 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// The window's sidebar (app.js layoutNav): from 1024 points the pages are
|
|
// listed down the left in their groups, the open one's own tabs under it in
|
|
// place of the page's strip, Settings and the gateway's address at the foot
|
|
// and the header a breadcrumb; narrower, they go back into the header's row.
|
|
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");
|
|
|
|
function serve(lang, reads, gateway = { url: "http://127.0.0.1:3425", running: true, window: true }) {
|
|
const state = { agents: [], profiles: [], settings: { lang, theme: "light" } };
|
|
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:${JSON.stringify(lang)},theme:"light",web:false,sideGateway:{url:"http://127.0.0.1:3425",running:true,boot:true}};` });
|
|
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/providers") { reads.push(performance.now()); return json({ providers: [], presets: [], excluded: [], gateway }); }
|
|
if (url.pathname === "/api/groups") return json({ groups: [] });
|
|
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 });
|
|
};
|
|
}
|
|
|
|
// each language's group names, and Settings' Models tab
|
|
const words = {
|
|
en: { groups: ["Work", "Models", "Insights", "Extend"], settings: "Settings", models: "Models" },
|
|
zh: { groups: ["使用", "模型", "观测", "扩展"], settings: "设置", models: "模型" },
|
|
"zh-TW": { groups: ["使用", "模型", "觀測", "擴充"], settings: "設定", models: "模型" },
|
|
ja: { groups: ["利用", "モデル", "観測", "拡張"], settings: "設定", models: "モデル" },
|
|
de: { groups: ["Arbeit", "Modelle", "Einblick", "Zusätze"], settings: "Einstellungen", models: "Modelle" },
|
|
};
|
|
const frame = (page) => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
test(`${engine}: the window's sidebar`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
|
|
for (const [lang, w] of Object.entries(words)) await t.test(lang, async () => {
|
|
const reads = [];
|
|
const context = await browser.newContext({ viewport: { width: 1024, height: 760 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang, reads));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
|
|
// at 1024 points the pages are down the left, in their groups
|
|
assert.ok(await page.evaluate(() => document.body.classList.contains("side-nav")), "a sidebar from 1024 points");
|
|
assert.ok(await page.locator("#side .side-scroll #nav").isVisible(), "the pages are in the sidebar");
|
|
assert.equal(await page.locator(".top #nav").count(), 0, "and not in the header");
|
|
assert.deepEqual(await page.locator("#nav .nav-gl:visible").allTextContents(), w.groups);
|
|
assert.deepEqual(await page.locator("#nav button[data-view]").evaluateAll((bs) => bs.map((b) => b.dataset.view)),
|
|
["agents", "sessions", "library", "providers", "routing", "groups", "gateway", "usage", "masking", "plugins"]);
|
|
assert.ok(await page.locator("#side .side-foot #prefs").isVisible(), "Settings at the sidebar's foot");
|
|
assert.equal((await page.locator("#prefs .side-l").textContent()).trim(), w.settings);
|
|
// no page's name or group cut, and nothing scrolls sideways
|
|
const cut = await page.locator("#side :is(.nav-gl, button[data-view] > span, #prefs .side-l)").evaluateAll((es) => es.filter((e) => e.scrollWidth > e.clientWidth + 1).map((e) => e.textContent));
|
|
assert.deepEqual(cut, [], "names read whole");
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
|
|
|
|
// the open page in the graphite of the text, not an accent colour
|
|
const [ic, fg] = await page.evaluate(() => [getComputedStyle(document.querySelector("#nav button.on .nav-ic")).color, getComputedStyle(document.body).color]);
|
|
assert.equal(ic, fg, "the open page's icon is the text's colour");
|
|
|
|
// a row pressed darkens and keeps its size: no button's squeeze
|
|
for (const sel of ['#nav button[data-view="usage"]', "#prefs"]) {
|
|
const r = page.locator(sel);
|
|
const bg = await r.evaluate((b) => getComputedStyle(b).backgroundColor);
|
|
const box = await r.boundingBox();
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
await page.mouse.down();
|
|
await page.waitForTimeout(250);
|
|
const [tf, pressed] = await r.evaluate((b) => [getComputedStyle(b).transform, getComputedStyle(b).backgroundColor]);
|
|
await page.mouse.move(box.x + box.width + 400, box.y);
|
|
await page.mouse.up();
|
|
assert.equal(tf, "none", `${sel} pressed is not squeezed`);
|
|
// a page's row has the open page's shape come to it instead
|
|
// (sidebar-glide.test.cjs); Settings, at the foot, darkens
|
|
if (sel === "#prefs") assert.notEqual(pressed, bg, `${sel} pressed darkens`);
|
|
}
|
|
|
|
// the gateway's address at the foot, drawn from boot.js ahead of the
|
|
// read, not held back until the providers have come in
|
|
assert.ok(await page.locator("#sideGw").isVisible(), "the gateway's line from boot.js");
|
|
assert.match(await page.locator("#sideGw").textContent(), /127\.0\.0\.1:3425/);
|
|
assert.ok(await page.locator("#sideGw span").evaluate((s) => s.scrollWidth <= s.clientWidth), "the address is read whole");
|
|
assert.equal(reads.length, 1, "read once for the sidebar");
|
|
|
|
// Settings: its tabs listed under it, its own strip hidden, and picked there
|
|
await page.locator("#prefs").click();
|
|
const subs = page.locator("#side .nav-sub:not(.leaving) .nav-s");
|
|
await subs.first().waitFor();
|
|
assert.equal(await subs.count(), 8);
|
|
assert.equal(await page.locator("#setTabs").isVisible(), false, "the page's own strip is hidden");
|
|
assert.deepEqual(await subs.evaluateAll((ss) => ss.map((s) => s.dataset.of)),
|
|
["setTab-general", "setTab-usage", "setTab-network", "setTab-models", "setTab-privacy", "setTab-otel", "setTab-sync", "setTab-about"]);
|
|
assert.deepEqual(await subs.evaluateAll((ss) => ss.filter((s) => s.scrollWidth > s.clientWidth + 1).map((s) => s.textContent)), [], "tab names read whole");
|
|
// the selection sets off as the row is pressed, ahead of the page,
|
|
// and goes back when the press leaves the row
|
|
const hlTo = () => page.evaluate(() => { const h = document.querySelector(".nav-sub:not(.leaving) .nav-hl"); return h.style.transform; });
|
|
const rowAt = (of) => page.evaluate((of) => `translateY(${document.querySelector(`.nav-s[data-of=${of}]`).offsetTop}px)`, of);
|
|
const startAt = await hlTo();
|
|
const net = await page.locator(".nav-s[data-of=setTab-network]").boundingBox();
|
|
await page.mouse.move(net.x + net.width / 2, net.y + net.height / 2);
|
|
await page.mouse.down();
|
|
assert.equal(await hlTo(), await rowAt("setTab-network"), "pressed, the selection is going to it");
|
|
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "before the page has the tab");
|
|
// the selection is the one shape: the row pressed has no ground of its own
|
|
assert.equal(await page.locator(".nav-s[data-of=setTab-network]").evaluate((b) => getComputedStyle(b).backgroundColor), "rgba(0, 0, 0, 0)", "no block under the finger ahead of the selection");
|
|
await page.mouse.move(net.x + net.width / 2, net.y + 200);
|
|
assert.equal(await hlTo(), startAt, "the press left the row: back");
|
|
await page.mouse.up();
|
|
assert.equal(await page.locator("#setTab-network").evaluate((b) => b.classList.contains("on")), false, "nothing picked");
|
|
await page.locator(".nav-s[data-of=setTab-models]").click();
|
|
await page.waitForFunction(() => document.querySelector("#setTab-models").classList.contains("on"));
|
|
await frame(page);
|
|
assert.equal(await page.locator(".nav-s.cur").getAttribute("data-of"), "setTab-models");
|
|
assert.equal(await page.locator(".nav-s.cur").getAttribute("aria-selected"), "true");
|
|
const crumb = await page.locator("#crumb").evaluate((c) => [...c.querySelectorAll("span, b")].map((e) => e.textContent));
|
|
assert.deepEqual(crumb, [w.settings, w.models], "the header says where the reader is");
|
|
// the selection sits on the tab picked
|
|
const [hl, cur] = await page.evaluate(() => [document.querySelector(".nav-sub:not(.leaving) .nav-hl").getBoundingClientRect().top, document.querySelector(".nav-s.cur").getBoundingClientRect().top]);
|
|
assert.ok(Math.abs(hl - cur) < 1, `the selection is on the tab: ${hl} ${cur}`);
|
|
|
|
// another page without tabs of its own: the list folds away
|
|
await page.locator('#nav button[data-view="agents"]').click();
|
|
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
|
|
|
|
// a point narrower, the header's row has them again, and no sidebar
|
|
await page.setViewportSize({ width: 1023, height: 760 });
|
|
await page.waitForFunction(() => !document.body.classList.contains("side-nav"));
|
|
await frame(page);
|
|
assert.ok(await page.locator(".top #nav").isVisible(), "the pages are in the header");
|
|
assert.equal(await page.locator("#side").isVisible(), false);
|
|
assert.equal(await page.locator("#crumb").isVisible(), false);
|
|
assert.equal(await page.locator("#nav .nav-gl:visible").count(), 0, "no group names in the header's row");
|
|
assert.ok(await page.evaluate(() => document.documentElement.scrollWidth <= document.documentElement.clientWidth), "the window does not scroll sideways");
|
|
// Settings' tabs are its own strip again
|
|
await page.locator("#prefs").click();
|
|
await page.locator("#setTabs").waitFor();
|
|
assert.equal(await page.locator(".nav-sub").count(), 0);
|
|
|
|
assert.deepEqual(errors, []);
|
|
await context.close();
|
|
});
|
|
|
|
await t.test("narrow from the start: the gateway is not read again for a sidebar", async () => {
|
|
const reads = [];
|
|
const context = await browser.newContext({ viewport: { width: 900, height: 700 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
await page.route("**/*", serve("en", reads));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
await page.waitForTimeout(2000);
|
|
// the providers list is read once after the start, for the
|
|
// Providers page to open on it (#1519), and nothing more with no
|
|
// sidebar to show its gateway
|
|
assert.equal(reads.length, 1, "read once, for the Providers page");
|
|
// made wide, the sidebar shows the gateway from that read
|
|
await page.setViewportSize({ width: 1200, height: 700 });
|
|
await page.locator("#sideGw").waitFor();
|
|
await page.waitForTimeout(500);
|
|
assert.equal(reads.length, 1, "the sidebar reads nothing more");
|
|
await context.close();
|
|
});
|
|
|
|
await t.test("the line boot.js drew is read again: a gateway gone since says so", async () => {
|
|
// boot.js is written once this process holds the gateway, before its
|
|
// listen is known to have worked; the read after the start has the
|
|
// last word on the line it drew (#3429)
|
|
const reads = [];
|
|
const context = await browser.newContext({ viewport: { width: 1200, height: 700 }, reducedMotion: "reduce" });
|
|
const page = await context.newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
await page.route("**/*", serve("en", reads, { url: "http://127.0.0.1:3490", running: false }));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
assert.match(await page.locator("#sideGw").textContent(), /127\.0\.0\.1:3425/, "boot.js's line first");
|
|
await page.waitForFunction(() => document.querySelector("#sideGw span")?.textContent === "Gateway stopped");
|
|
assert.ok(await page.locator("#sideGw").evaluate((b) => b.classList.contains("off")));
|
|
assert.match(await page.locator("#sideGw").getAttribute("title"), /3490/);
|
|
assert.equal(reads.length, 1, "the read the Providers page is made ready with, no other");
|
|
await context.close();
|
|
});
|
|
|
|
await t.test("the list opens and folds as it plays", async () => {
|
|
const context = await browser.newContext({ viewport: { width: 1200, height: 760 } });
|
|
const page = await context.newPage();
|
|
await page.route("**/*", serve("en", []));
|
|
await page.goto("http://magpie.test/");
|
|
await page.waitForSelector("#nav button.on");
|
|
// the unroll is counted as its animations are made, ahead of the
|
|
// click (#2950): on a busy machine the whole play is over before
|
|
// the one sample after the click lands, and a finished animation
|
|
// is out of getAnimations(); an animation made is a fact that
|
|
// stays put, so the assert reads that, not the moment sampled
|
|
await page.evaluate(() => {
|
|
window.navAnims = [];
|
|
const animate = Element.prototype.animate;
|
|
Element.prototype.animate = function (frames, options) {
|
|
window.navAnims.push(this);
|
|
return animate.call(this, frames, options);
|
|
};
|
|
});
|
|
await page.locator("#prefs").click();
|
|
const box = page.locator("#side .nav-sub").first();
|
|
await box.waitFor();
|
|
assert.ok(await box.evaluate((b) => window.navAnims.includes(b)), "the list unrolls");
|
|
await page.locator('#nav button[data-view="agents"]').click();
|
|
// folding: out of reach at once, gone once it has played
|
|
assert.equal(await page.locator(".nav-sub:not(.leaving)").count(), 0);
|
|
assert.equal(await page.locator(".nav-s").count(), 0, "its rows are no tabs while they fold");
|
|
await page.waitForFunction(() => !document.querySelector(".nav-sub"));
|
|
await context.close();
|
|
});
|
|
});
|
|
}
|