routing: long routing groups no longer widen the page (noahhrreion)
noahhrreion (Discord #general): on Routing the groups at the foot made the page wider than the window, a scrollbar under it and each row's routing, Edit and switch far off to the right. Cause:173b7e274let the editor's Save bar stick by having the groups' list clip its overflow (overflow: clip) instead of hiding it. A box that hides its overflow is a scroll container, whose least width as a grid item is 0; one that clips is not, so the .rt-gsec grid, with no columns of its own, sized its one auto column to the longest member line, which never wraps. With twelve long members that was 7,100 to 8,200px, and #view-routing scrolled sideways. The column is now held to the section (grid-template-columns: minmax(0, 1fr)); the list keeps clip, so the Save bar still sticks. Member lines are cut with an ellipsis in their row again (wrapped on a phone's web page, as before). routing-groups-wide.test.cjs (new): three groups of twelve long members; #view-routing and the document no wider than the window, every row and its members, routing, Edit and switch inside the list, the long line cut or wrapped. Chromium and WebKit, the desktop window 1440 to 560px (windowMinW) and the web page 1440 to 360px, en/zh/zh-TW/ja/de. view-no-sideways serves no groups, so it missed this. Broken by hand: with origin/main's routing.css the new test is red in both engines (desktop en 1440px: scrollWidth 7120 > 1228). Run on mote: - At this tree on origin/main6a6e4fefa(routing.css is the same there as atc86fa2a34, where the rest was run): routing-groups-wide and routing-affinity-order 22 of 22 ok; routing-affinity-order alone with origin/main's routing.css 20 of 20. - Atc86fa2a34with this change: go test -run 'Budget|CSS|Asset' ./internal/gui ok. The routing-*, group-*, view-no-sideways, click-scroll and old-webkit files (both engines, concurrency 4) were cut short when mote rebooted at load ~94: 416 ok, 3 red, all a 5s wait timing out in WebKit (routing-affinity-cache-write, #3772; routing-affinity-order, #4976, filed now). Both pass alone. The rest of that run was not run again. Not tried: the real app window, WebKitGTK on Linux, a real account's groups. Not changed: in German at 420px the page head's Hide accounts and New group run ~50px over, with or without groups; the desktop window can't be that narrow (560px least).
This commit is contained in:
@@ -464,7 +464,7 @@ button.rt-session { cursor: pointer; }
|
||||
.rt-livedot.on { animation: rtlive 1.8s infinite; }
|
||||
@media (prefers-reduced-motion: reduce) { .rt-livedot.on { animation: none; } }
|
||||
/* routing groups, and the providers routing over several of their own */
|
||||
.rt-gsec { display: grid; gap: 6px; margin-top: 16px; }
|
||||
.rt-gsec { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin-top: 16px; }
|
||||
.rt-gsec .row-head .note { margin-right: 6px; }
|
||||
/* the groups filtered by name and model, beside Select and New group */
|
||||
.rt-gsec .rt-gfilter { width: 190px; min-width: 0; flex: 0 1 190px; height: 24px; margin: 0 6px 0 4px; }
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
// Run with Node's test runner and Playwright on the module path; see README.md.
|
||||
// Routing groups with long names and many members (noahhrreion on Discord):
|
||||
// the Routing page went wider than the window, with a scrollbar under it and
|
||||
// each row's routing, Edit and switch far off to the right. The groups' list
|
||||
// clips its overflow (overflow: clip, so the editor's Save bar can stick), and
|
||||
// a box that clips is not a scroll container, so the section's grid gave its
|
||||
// one column the whole width of the longest member line. The column is held
|
||||
// to the section's width: the member lines are cut with an ellipsis inside
|
||||
// their row (wrapped, on a phone) and nothing on the page is wider than the window. Chromium and
|
||||
// WebKit, the desktop window down to its least width (560px, windowMinW)
|
||||
// and the browser page down to 360px, en/zh/zh-TW/ja/de. view-no-sideways
|
||||
// checks every page with no groups at all, so it never saw this.
|
||||
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(path.join(__dirname, "../assets"));
|
||||
const long = "a-really-long-model-name-that-keeps-on-going-flash-preview-2026";
|
||||
const models = Array.from({ length: 12 }, (_, i) => ({ id: `p${i}/${long}-${i}`, name: `${long}-${i}`, providerName: "Provider With A Long Name " + i, icon: "generic" }));
|
||||
const info = models.map((m) => ({ id: m.id, ready: true }));
|
||||
const base = { members: models.map((m) => m.id), ready: true, memberInfo: info, offers: [], shared: [] };
|
||||
const groups = { models, pools: [], groups: [
|
||||
{ ...base, id: "g1", name: "A group with a rather long name that goes on " + long, routing: "smart" },
|
||||
{ ...base, id: "g2", name: "weights", routing: "weight", weights: Object.fromEntries(models.map((m, i) => [m.id, i + 1])) },
|
||||
{ ...base, id: "g3", name: "turns", routing: "turn", rules: [{ use: models[0].id, tokens: 100000 }] },
|
||||
] };
|
||||
|
||||
function serve(lang, web) {
|
||||
const state = { agents: [{ id: "codex", name: "Codex", path: "/t", 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: 1, totals: { requests: 0, rerouted: 0, errors: 0 }, routes: [] });
|
||||
}
|
||||
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: [], 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", ".png": "image/png" }[path.extname(file)];
|
||||
await r.fulfill({ body: await fs.readFile(file).catch(() => ""), contentType });
|
||||
};
|
||||
}
|
||||
|
||||
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
||||
test(`${engine}: long routing groups leave the Routing page the window's width`, async (t) => {
|
||||
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
||||
t.after(() => browser.close());
|
||||
for (const web of [false, true]) {
|
||||
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
|
||||
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
|
||||
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-group").nth(2).waitFor();
|
||||
const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 100)))));
|
||||
for (const width of web ? [1440, 1100, 700, 440, 360] : [1440, 1100, 900, 700, 560]) {
|
||||
const at = `${web ? "web" : "desktop"} ${lang} ${width}px`;
|
||||
await page.setViewportSize({ width, height: 900 });
|
||||
await settle();
|
||||
const m = await page.evaluate(() => {
|
||||
const v = document.querySelector("#view-routing"), de = document.documentElement;
|
||||
const rows = [...document.querySelectorAll(".rt-groups > .rt-group")].map((g) => {
|
||||
const b = g.getBoundingClientRect(), list = g.parentElement.getBoundingClientRect();
|
||||
const kids = [...g.querySelectorAll(".mem, .tags, .switch, button")].map((e) => e.getBoundingClientRect()).filter((k) => k.width > 0);
|
||||
return { right: b.right, listRight: list.right, out: kids.filter((k) => k.right > b.right + 1).length };
|
||||
});
|
||||
const mem = document.querySelector(".rt-group .mem");
|
||||
// cut with an ellipsis, or (the browser page on a phone) wrapped onto more lines
|
||||
const cs = mem && getComputedStyle(mem), lines = mem && mem.getBoundingClientRect().height / (parseFloat(cs.lineHeight) || parseFloat(cs.fontSize) * 1.3);
|
||||
return { view: [v.scrollWidth, v.clientWidth], doc: [de.scrollWidth, de.clientWidth], rows, cut: mem && (mem.scrollWidth > mem.clientWidth || lines > 1.5) };
|
||||
});
|
||||
assert(m.view[0] <= m.view[1] + 1, `${at}: the Routing view is no wider than the window: scrollWidth ${m.view[0]} > ${m.view[1]}`);
|
||||
assert(m.doc[0] <= m.doc[1] + 1, `${at}: the document is no wider than the window: ${m.doc}`);
|
||||
assert.equal(m.rows.length, 3, `${at}: every group drawn`);
|
||||
for (const r of m.rows) {
|
||||
assert(r.right <= r.listRight + 1 && r.right <= width + 1, `${at}: a group row inside its list and the window: ${JSON.stringify(r)}`);
|
||||
assert.equal(r.out, 0, `${at}: the row's members, routing, Edit and switch inside it`);
|
||||
}
|
||||
assert(m.cut, `${at}: the long member line is cut or wrapped inside its row`);
|
||||
}
|
||||
assert.deepEqual(errors, [], `${web ? "web" : "desktop"} ${lang}: no page error`);
|
||||
await page.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user