diff --git a/internal/gui/assets/plugins/routing/routing.css b/internal/gui/assets/plugins/routing/routing.css index 7d5b36fa6..c31f1807b 100644 --- a/internal/gui/assets/plugins/routing/routing.css +++ b/internal/gui/assets/plugins/routing/routing.css @@ -59,7 +59,11 @@ .rt-hub i { font-style: normal; font-size: 10.5px; font-weight: 560; margin-top: 5px; padding: 1px 8px; border-radius: 999px; background: var(--fg); color: var(--card); } .rt-hub.tick, .rt-src.tick { animation: rttick .4s ease-out; } @keyframes rttick { 40% { transform: scale(1.04); } } -.rt-accts { position: relative; z-index: 1; list-style: none; margin: 0; padding: 0; display: grid; gap: 7px; min-width: 0; } +/* one column as wide as the list: a row out of sight is as wide as WebKit + last drew it (content-visibility), and in a column as wide as its rows + "No request yet" held the page as wide as a wider window had it, a + scrollbar under it (young02036 on Discord) */ +.rt-accts { position: relative; z-index: 1; list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 7px; min-width: 0; } .rt-accts li { position: relative; display: grid; grid-template-columns: 10px minmax(0, 1fr) fit-content(60%); align-items: center; column-gap: 10px; row-gap: 6px; padding: 9px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; font-size: 13px; transition: opacity .3s, border-color .3s, transform .5s cubic-bezier(.2, .8, .2, 1); } .rt-accts li { margin-left: calc(var(--depth, 0) * 18px); } /* a key off screen is not laid out or painted (#3164): with hundreds of @@ -520,8 +524,10 @@ button.rt-session { cursor: pointer; } .rt-patadd { display: flex; gap: 6px; align-items: center; } .rt-pats .fbl:not(:empty) + .rt-patadd { margin-top: 4px; } .rt-patadd input { flex: 1; min-width: 0; } -.rt-group .tags { display: flex; gap: 4px; flex: none; } -.rt-group .tag { font-size: 11px; line-height: 18px; padding: 0 8px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); white-space: nowrap; } +/* the tags take up to half the row, onto more lines rather than pushing + Edit and the switch out of it (young02036 on Discord) */ +.rt-group .tags { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; flex: 0 1 auto; min-width: 0; max-width: 50%; } +.rt-group .tag { max-width: 100%; overflow: hidden; text-overflow: ellipsis; font-size: 11px; line-height: 18px; padding: 0 8px; border-radius: 999px; box-shadow: inset 0 0 0 1px var(--line); color: var(--muted); white-space: nowrap; } .rt-group .tag.bad { color: var(--red); } .rt-group .tag.idle { opacity: .55; } /* the routing tag is a pop-up button for the group's routings (#3450) */ @@ -601,7 +607,8 @@ button.rt-session { cursor: pointer; } .rt-pool .nm span:last-child { font-size: 12px; color: var(--muted); } /* a label column and a control column, so Routing's and Stays' segments start at one edge whatever their labels' widths */ -.rt-pool .ctl { display: grid; grid-template-columns: auto auto; align-items: center; justify-items: start; gap: 6px 8px; } +.rt-pool .ctl { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; justify-items: start; gap: 6px 8px; min-width: 0; max-width: 100%; } +.rt-pool .segs { max-width: 100%; flex-wrap: wrap; } .rt-pool .lab { display: contents; } .rt-pool .lab small { font-size: 11px; color: var(--muted); } /* narrow, a row keeps only its routing, which switches from here */ @@ -611,7 +618,7 @@ button.rt-session { cursor: pointer; } display: grid; grid-template-columns: auto minmax(0, 1fr) auto; /* the logos as wide as they are */ gap: 6px 8px; padding: 12px 12px 12px 14px; /* the grip's room, as wide */ } - body.web .rt-group .tags { display: flex; flex-wrap: wrap; grid-column: 2 / -1; grid-row: 2; } + body.web .rt-group .tags { justify-content: flex-start; max-width: none; grid-column: 2 / -1; grid-row: 2; } body.web .rt-group > .text { grid-column: 3; grid-row: 1; } body.web .rt-group .nm { flex-wrap: wrap; } body.web .rt-group .mem { white-space: normal; overflow-wrap: anywhere; } @@ -628,7 +635,6 @@ button.rt-session { cursor: pointer; } body.web .rt-gadd { min-height: 44px; } body.web .rt-pool .ctl { grid-template-columns: minmax(0, 1fr); } body.web .rt-pool .lab small { padding-top: 6px; } - body.web .rt-pool .segs { flex-wrap: wrap; } body.web .rt-stats { flex-wrap: wrap; gap: 10px 16px; } /* the upstream a request went to takes a line of its own on a phone, so the reasoning beside the provider isn't cut to two letters */ diff --git a/internal/gui/tests/routing-rows-fit.test.cjs b/internal/gui/tests/routing-rows-fit.test.cjs new file mode 100644 index 000000000..7e5b59909 --- /dev/null +++ b/internal/gui/tests/routing-rows-fit.test.cjs @@ -0,0 +1,122 @@ +// Run with Node's test runner and Playwright on the module path; see README.md. +// Every row on the Routing page fits the window (young02036 on Discord: a +// group's long line pushed the page wider than the window, with a scrollbar +// under it). routing-groups-wide holds the member lines; this holds the rest +// of each row as the window is made narrower and wider again, a group's +// editor open and shut between: +// - a group of many tags (German's long ones, or any at 700px) had pushed its +// Edit and switch out past the row's edge, where the list cut them off; +// - a provider's Routing and Stays segments (Several accounts or keys) ran +// out past their row in the desktop window; +// - in WebKit the live stage's "No request yet" kept the width it had in a +// wider window once it was out of sight (content-visibility remembered +// it), and held the whole page that wide, a scrollbar under it. +// Members are "WorkBuddy AI · Hy3 · 免费", as the reporter's were. Chromium and +// WebKit, the desktop window down to 560px and the browser page to 360px, +// en/zh/zh-TW/ja/de. +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 long = "a-really-long-model-name-that-keeps-on-going-flash-preview-2026"; +const models = Array.from({ length: 6 }, (_, i) => ({ id: `p${i}/${long}-${i}`, name: `${long}-${i}`, providerName: "Provider With A Long Name " + i, icon: "generic" })); +const ids = models.map((m) => m.id); +// members no model of the list names: their line is the group's own words +const hy = ["workbuddy-ai/hy3", "workbuddy-ai/hy3-turbo"]; +const info = [...ids.map((id) => ({ id, ready: true })), ...hy.map((id) => ({ id, ready: true, name: "WorkBuddy AI", model: "Hy3", provider: "workbuddy-ai", free: true }))]; +const base = { members: [...hy, ...ids], ready: true, memberInfo: info, offers: [], shared: [] }; +const groups = { + models, + pools: [{ provider: "workbuddy-ai", name: "WorkBuddy AI", icon: "generic", kind: "account", who: ["a", "b", "c"], routing: "order" }], + groups: [ + { ...base, id: "g1", name: "smart", routing: "smart" }, + { ...base, id: "g2", name: "manual", routing: "manual", pick: hy[0] }, + // every tag a row can carry + { ...base, id: "g3", name: "order", routing: "order", affinity: "session", sink: true, unlists: true, firstToken: 30, rules: [{ use: ids[0], tokens: 100000 }, { use: ids[1], tokens: 5 }], off: [ids[2]] }, + ], +}; + +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 }); + }; +} + +// what sticks out: the page past the window, and a row's controls past the row +const measure = (page) => page.evaluate(() => { + const v = document.querySelector("#view-routing"), de = document.documentElement; + const out = []; + for (const row of document.querySelectorAll(".rt-groups > *, .rt-pools > *")) { + const rb = row.getBoundingClientRect(); + for (const k of row.querySelectorAll(".tags, .tag, button, .segs, .ctl")) { + const b = k.getBoundingClientRect(); + if (b.width && b.right > rb.right + 1) out.push(`${row.className} > ${k.className || k.tagName} "${k.textContent.slice(0, 24)}" ${Math.round(b.right - rb.right)}px past`); + } + } + // what holds the page wide, for the message + const wide = [...v.querySelectorAll("*")].filter((e) => e.getBoundingClientRect().right > innerWidth + 1 && ![...e.children].some((c) => c.getBoundingClientRect().right > innerWidth + 1)).slice(0, 4).map((e) => `${e.tagName}.${e.className} ${Math.round(e.getBoundingClientRect().width)}px`); + return { view: [v.scrollWidth, v.clientWidth], doc: [de.scrollWidth, de.clientWidth], out, wide }; +}); + +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}: every Routing row fits the window, an editor open or not`, async (t) => { + const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" })); + t.after(() => browser.close()); + for (const web of [false, true]) { + const widths = web ? [1100, 700, 440, 360] : [1100, 900, 700, 560]; + 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 memLine = await page.locator(".rt-group[data-id=g1] .mem").first().textContent(); + assert(memLine.includes("WorkBuddy AI · Hy3"), `the reporter's member line: ${memLine}`); + const settle = () => page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(() => setTimeout(r, 150))))); + // the list, then each group's editor in turn, on one page: the + // window narrowed and widened again under each + for (const open of [null, "g1", "g2", "g3"]) { + if (open) { + await page.keyboard.press("Escape"); + await page.locator(`.rt-group[data-id=${open}] .main`).click({ position: { x: 4, y: 4 } }); + await page.locator(".rt-gedit").waitFor(); + } + for (const width of [...widths, 1440]) { + const at = `${web ? "web" : "desktop"} ${open ? open + "'s editor" : "list"} ${width}px`; + await page.setViewportSize({ width, height: 900 }); + await settle(); + const m = await measure(page); + assert(m.view[0] <= m.view[1] + 1, `${at}: the Routing view no wider than the window: ${m.view} ${m.wide.join(", ")}`); + assert(m.doc[0] <= m.doc[1] + 1, `${at}: the document no wider than the window: ${m.doc} ${m.wide.join(", ")}`); + assert.deepEqual(m.out, [], `${at}: each row's tags, Edit, switch and segments inside it`); + } + } + assert.deepEqual(errors, [], `${web ? "web" : "desktop"}: no page error`); + await page.close(); + } + }); + } +}