routing: with routing groups switched off, their sidebar tab goes

yyddbds (Discord) turned Routing groups off in Plugins > Built-in and
the sidebar still showed its tab. The tab was tagged with the routing
plugin only (data-feature="routing"), so only switching Routing off hid
it. It is now tagged "routing groups", like Routing's own "Routing
groups >" button and the two "Make a routing group" buttons.

The page also holds each provider's accounts and keys (pools), which
stay editable with groups off. So with groups off:
- ?view=groups, or a page open when groups are switched off, opens
  Routing (offView in app.js), not Agents;
- the groups' section moves under Routing's requests, with the "turn on
  routing groups" note and the pools; turning them on opens the groups
  page again and moves the section back.
Every other sidebar tab (sessions, library, routing, gateway, usage,
masking) was already tagged with its own plugin; only groups was wrong.

Run, on mote (macOS 27):
- routing-groups-off.test.cjs (rewritten: 1200, 900 and 420px, both
  engines, every language): 12 of 18 red on the old code, 18 of 18
  green on this one.
- routing-groups-off, builtins, sidebar at the rebased head 3930a3917:
  green in Chromium and WebKit.
- Whole GUI suite at the old base c9d253e4a: 22,447 of 22,724 pass, 277
  red in 46 files. Those 46 files rerun at the rebased head (on
  bceeabd93): 258 red, every one in an open issue filed before this
  change (#5475 umbrella; #5392 routing-intent-entry, #5332 i18n-keys,
  #5232 provider-fetch-again, #3952 mobile-web, #4541 page-width-steady,
  #4720/#4721 vertex-editor, #5262 zero-priced-free, #4388
  model-chip-steady, #4644 account-weight, #3799 routing-row-swap,
  #3954 routing-story-shrinks, #5586 routing-context-fold, #3479
  header-centre, #4787/#5425 nav-timeout, #5215 tray-cell-click, #3415
  usage-fold, #2448 s3-sync, #4624 omarchy, #5048 usage-ledger, #4320
  recovered-file). None is in a test of the nav or the groups page.
- go vet ./..., GOOS=linux/windows go vet ./internal/gui and gofmt -l
  at the old base: clean (no Go file changes).
- TestCoreScriptBudget, worked out by hand at the pushed head (on
  b8270850d): the core's scripts are 1,533,791 of 1,533,802. The 526
  bytes this adds to app.js would be 351 over, so the comments it adds
  are cut to one line. No raise. node --check app.js passes.

Not tried: the real app; the GUI files rerun after the last rebase
(b8270850d; the only change since is comments in app.js); the panel's new-group path with groups off;
the same 46 files on a clean bceeabd93 (queued behind the suite lock
for over an hour; the reds above all predate this change).

Reported-by: yyddbds (Discord)
This commit is contained in:
yetone
2026-11-09 18:11:53 +08:00
parent b8270850df
commit f5f68b4335
4 changed files with 68 additions and 23 deletions
+12 -5
View File
@@ -5640,7 +5640,7 @@ function keptNote(m) {
} else {
words.append(el("span", "", t("{provider} is used only through routing groups, and {model} is in none, so no agent can use it. Make a group of it, or untick “Only through routing groups” in {provider}'s models.", { provider: m.provider, model })));
act.textContent = t("Make a routing group of it");
act.dataset.feature = "routing"; // made on the Routing page
act.dataset.feature = "routing groups";
act.onclick = (ev) => {
ev.stopPropagation();
closePicker();
@@ -11509,7 +11509,7 @@ function renderModels(p) {
if (!p.unlisted) { lost.append(" " + t("Once saved, make a group of them in Routing groups.")); return; }
for (const id of none.slice(0, 4)) {
const b = el("button", "text action", t("Make a routing group of {model}", { model: id }));
b.dataset.feature = "routing"; // made on the Routing page
b.dataset.feature = "routing groups";
b.onclick = (ev) => { if (mode !== "window") api("window/main?view=groups&newgroup=" + encodeURIComponent(p.id + "/" + id), {}); else window.newGroupWith?.(p.id + "/" + id, "", ev); };
lost.append(b);
}
@@ -23144,8 +23144,8 @@ async function show(v) {
v = magpie.replacing?.(v) || v;
// a page gateway mode leaves out (a link to it, an address kept) opens Providers
if (gatewayMode && GATEWAY_HIDES.includes(v)) v = "providers";
// and one a built-in plugin switched off has, Agents
if (featureHides($(`#nav button[data-view="${v}"]`))) v = gatewayMode ? "providers" : "agents";
// and one a built-in plugin switched off has, offView
v = offView(v);
if (v !== view) {
if (v === "plugins" && pluginUpdates) window.pluginTabTo?.("installed");
if (view === "providers" && (editing !== null || importing || importingApps)) {
@@ -23234,6 +23234,12 @@ function setGatewayMode(on) {
else if (!sideNav()) slide($("#nav"), "nav");
navSubs();
}
// offView: v, or the page a plugin switched off sends it to (yyddbds)
function offView(v) {
if (!featureHides($(`#nav button[data-view="${v}"]`))) return v;
if (v === "groups" && !featureHides($('#nav button[data-view="routing"]'))) return "routing";
return gatewayMode ? "providers" : "agents";
}
// navHides leaves out the tabs of the pages gateway mode or a built-in
// plugin switched off leaves out
function navHides() {
@@ -23255,7 +23261,8 @@ function applyFeatures(list) {
if (mode === "panel" && panelTab !== "agents") setPanelTab(panelTab); // its tab may be gone
if (mode !== "window") return;
navHides();
if (featureHides($(`#nav button[data-view="${view}"]`))) show(gatewayMode ? "providers" : "agents");
window.routingGroupsHome?.();
if (offView(view) !== view) show(offView(view));
else if (!sideNav()) slide($("#nav"), "nav");
setSetTab(setTab);
navSubs();
+1 -1
View File
@@ -72,7 +72,7 @@
<span class="nav-gl" data-t>Models</span>
<button data-view="providers"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><circle cx="7" cy="10" r="3"/><path d="M10 10h7M14 10v3M16.5 10v2"/></g></svg><span data-t>Providers</span></button>
<button data-view="routing" data-feature="routing"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M3 10h5l4-5h5M8 10l4 5h5M14.5 3l2.5 2-2.5 2M14.5 13l2.5 2-2.5 2"/></g></svg><span data-t>Routing</span></button>
<button data-view="groups" data-feature="routing"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="5" height="5" rx="1.2"/><rect x="11.5" y="3.5" width="5" height="5" rx="1.2"/><rect x="3.5" y="11.5" width="5" height="5" rx="1.2"/><path d="M14 11.5v5M11.5 14h5"/></g></svg><span data-t>Routing groups</span></button>
<button data-view="groups" data-feature="routing groups"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3.5" y="3.5" width="5" height="5" rx="1.2"/><rect x="11.5" y="3.5" width="5" height="5" rx="1.2"/><rect x="3.5" y="11.5" width="5" height="5" rx="1.2"/><path d="M14 11.5v5M11.5 14h5"/></g></svg><span data-t>Routing groups</span></button>
<button data-view="gateway" data-feature="gateway"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="4" width="14" height="5" rx="1.5"/><rect x="3" y="11" width="14" height="5" rx="1.5"/><path d="M6 6.5h.01M6 13.5h.01"/></g></svg><span data-t>Gateway</span></button>
<span class="nav-gl" data-t>Insights</span>
<button data-view="usage" data-feature="usage"><svg class="nav-ic" viewBox="0 0 20 20" width="16" height="16" aria-hidden="true"><g fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round"><path d="M4 16V9M8 16V5M12 16v-5M16 16V7"/></g></svg><span data-t>Usage</span></button>
+22 -10
View File
@@ -21,7 +21,7 @@ magpie.plugin("routing", (ctx) => {
title: "Routing",
html: `
<div class="row-head"><span class="label" data-t>Routing</span><span class="rt-livedot" aria-hidden="true"></span><span class="note" data-t>live, as the gateway decides</span><span class="grow"></span>
<button class="text rt-togroups" type="button" id="rtToGroups"><span data-t>Routing groups</span> ›</button>
<button class="text rt-togroups" type="button" id="rtToGroups" data-feature="groups"><span data-t>Routing groups</span> ›</button>
<button class="text rt-mask" id="rtMask" aria-pressed="false" data-tt="Mask the accounts on every page — email addresses and account names — for a screenshot to share"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M9.9 4.2A10.4 10.4 0 0 1 12 4c6.5 0 10 8 10 8a17.6 17.6 0 0 1-2.2 3.2M6.6 6.6C3.9 8.4 2 12 2 12s3.5 8 10 8a9.7 9.7 0 0 0 5.4-1.6M9.9 9.9a3 3 0 0 0 4.2 4.2M2 2l20 20"/></svg><span data-t>Hide accounts</span></button></div>
<section class="rt" id="rt"></section>
<div class="rt-more" id="rtMore"></div>
@@ -2832,19 +2832,21 @@ function routingPage(part) {
async function goRouting(e, go) {
const i = go.indexOf(":"), kind = go.slice(0, i), id = CSS.escape(go.slice(i + 1));
const row = kind === "group" ? gList.querySelector(`.rt-group[data-id="${id}"]`) : pList.querySelector(`.rt-pool[data-provider="${id}"]`);
if (!row) return;
// they are on the Routing groups page: it opens, and the row comes
if (!row || featureHides(row)) return;
// they are on the Routing groups page (on Routing with the groups
// off: groupsHome): it opens, and the row comes
// into sight as the reader's click asked. A page just opened is at the
// row at once, and that is where the reader is in it (arrived): else
// the page put itself back where the reader last left it
const asked = window.scrollOnPurpose?.(e), opens = gView().hidden;
if (opens && !(await window.show("groups"))) return;
const home = gsec.closest("main") || gView();
const asked = window.scrollOnPurpose?.(e), opens = home.hidden;
if (opens && !(await window.show(home.id.slice("view-".length)))) return;
// from Routing: its toolbar leads back to the request (gBack)
if (opens && e.target.closest?.("#view-routing")) openedFrom(e.target.closest(".rt-go"));
if (opens && home === gView() && e.target.closest?.("#view-routing")) openedFrom(e.target.closest(".rt-go"));
if (asked) {
readerScrolls(1000);
row.scrollIntoView({ block: "center", behavior: opens || still() ? "auto" : "smooth" });
if (opens) window.arrived?.(gView());
if (opens) window.arrived?.(home);
}
row.classList.remove("rt-found");
void row.offsetWidth;
@@ -5816,6 +5818,8 @@ function routingPage(part) {
applyFeatures(next);
status(t("Routing groups are on"), "ok", 1500);
loadGroups();
// the note was on Routing (groupsHome): the groups are on their page
if (!$("#view-routing").hidden && document.body.classList.contains("window")) window.show("groups");
} catch (err) {
status(t(err.message), "err");
} finally {
@@ -5824,7 +5828,8 @@ function routingPage(part) {
};
const gOffBox = el("div", "list rt-goffbox");
gOffBox.append(el("div", "rt-goffwhy", t("Routing groups are off in Plugins › Built-in: the groups magpie finds, one model several providers serve, still route, but your own can't be made or changed here.")), gOn);
gOff.append(gOffBox);
// on Routing then (groupsHome), under its requests, named as before 11-06
gOff.append(el("div", "row-head", el("span", "label", t("Routing groups"))), gOffBox);
// the settings that hold for every group, under the list (11-06)
const sHead = el("div", "row-head rt-gset-head");
sHead.dataset.feature = "groups";
@@ -5834,9 +5839,16 @@ function routingPage(part) {
gSet.append(gFound, gNames, ...gDefs);
gsec.append(gHead, gList, gOff, sHead, gSet, pHead, pList);
// on the Routing groups page, a page of their own; Try again on it puts
// them back in its markup made anew
// them back in its markup made anew. With the groups off, that page's
// tab leaves the sidebar (yyddbds on Discord: it stayed), and what is
// left of it, the note that turns them on and the providers' own
// accounts, goes under Routing's requests, where it was before 11-06.
// app.js asks again when a built-in is switched (applyFeatures).
const gHome = () => $("#rtGroups");
window.routingGroupsHome = (main) => (main?.querySelector("#rtGroups") || gHome())?.append(gsec);
window.routingGroupsHome = (main) => {
const to = featuresOff.has("groups") ? more : main?.querySelector("#rtGroups") || gHome();
if (to && gsec.parentElement !== to) to.append(gsec);
};
window.routingGroupsHome();
if (gHome()) byWidth(gHome(), { max520: (w) => w <= 520 });
const ROUTE_OPTS = [["", "Smart"], ["order", "In order"], ["drain", "Until used up"], ["rotate", "In turn"], ["usage", "Least used"], ["pace", "Use before expiry"], ["free", "Free first"], ["fast", "Speed first"]];
+33 -7
View File
@@ -6,6 +6,11 @@
// after which the groups and New group are back and the note is gone. With
// them on, there is no note. English and Chinese, Chromium and WebKit, wide
// and narrow, and every language has the strings.
// yyddbds on Discord: with them off, the sidebar still had a Routing
// groups tab. Off, it is gone (and Routing's own "Routing groups ›"), an
// address kept for the page opens Routing, and what is left of the page,
// the note and the providers' own accounts, is under Routing's requests.
// Turned on, the tab is back and the groups' page opens.
const assert = require("node:assert/strict");
const fs = require("node:fs/promises");
const path = require("node:path");
@@ -17,6 +22,7 @@ const models = [
{ id: "a/m", name: "m", providerName: "A", icon: "generic" },
{ id: "b/m", name: "m", providerName: "B", icon: "generic" },
];
const pools = [{ provider: "a", name: "A", icon: "generic", kind: "key", who: ["k1", "k2"], routing: "", affinity: "" }];
const mine = { id: "mine", name: "Mine", members: ["a/m", "b/m"], ready: true, memberInfo: [{ id: "a/m", ready: true }, { id: "b/m", ready: true }] };
function serve(lang, start, posts) {
@@ -39,7 +45,7 @@ function serve(lang, start, posts) {
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({ models, pools: [], deciders: [], found: true, groups: [mine] });
if (url.pathname === "/api/groups") return json({ models, pools: [], deciders: [], found: true, groups: [mine], pools });
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);
@@ -58,6 +64,10 @@ const keys = [
"Routing groups are off in Plugins › Built-in: the groups magpie finds, one model several providers serve, still route, but your own can't be made or changed here.",
];
// the pages' tabs a reader sees, the sidebar's or the header's
const tabs = (page) => page.evaluate(() => [...document.querySelectorAll("#nav button[data-view]")].filter((b) => !b.hidden && b.offsetParent && getComputedStyle(b).display !== "none").map((b) => b.dataset.view));
const shown = (page) => page.evaluate(() => [...document.querySelectorAll("main.view")].filter((v) => !v.hidden).map((v) => v.id));
async function open(engine, width, t, name) {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
@@ -76,16 +86,26 @@ async function open(engine, width, t, name) {
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
const w = words[lang];
for (const width of [900, 420]) {
test(`${engine} ${lang} ${width}px: with routing groups off, the Routing page says so and turns them on`, async (t) => {
// the sidebar from 1024 points, the header's tabs under it, and narrow
for (const width of [1200, 900, 420]) {
test(`${engine} ${lang} ${width}px: with routing groups off, their tab is gone, and Routing says so and turns them on`, async (t) => {
const page = await open(engine, width, t, `${engine}-${lang}-${width}-routing-groups-off.png`);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, false, posts));
await page.goto("http://magpie.test/?view=groups");
const note = page.locator(".rt-gsec .rt-goff");
const note = page.locator("#view-routing .rt-gsec .rt-goff");
await note.waitFor();
assert.deepEqual(await shown(page), ["view-routing"], "an address kept for the groups' page opens Routing");
if (width >= 800) {
const ts = await tabs(page);
assert(ts.includes("routing"), ts.join());
assert(!ts.includes("groups"), `no Routing groups tab: ${ts.join()}`);
}
assert.equal(await page.locator("#rtToGroups").isVisible(), false, "nor Routing's way to the page");
// the providers' own accounts are still to be set, on Routing
await page.locator("#view-routing .rt-pool[data-provider=\"a\"]").waitFor({ state: "visible" });
const text = await note.innerText();
assert(text.includes(w.why), text);
const btn = note.locator("button", { hasText: w.on });
@@ -98,15 +118,19 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await btn.click();
await note.waitFor({ state: "hidden" });
assert.deepEqual(posts, [{ id: "groups", on: true }]);
await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "visible" });
await page.locator(".rt-gnew").waitFor({ state: "visible" });
// on, the groups' page opens, with them and New group, its tab back
await page.locator("#view-groups .rt-group", { hasText: "Mine" }).waitFor({ state: "visible" });
await page.locator("#view-groups .rt-gnew").waitFor({ state: "visible" });
assert.deepEqual(await shown(page), ["view-groups"]);
if (width >= 1024) assert((await tabs(page)).includes("groups"), "the tab is back");
await page.locator("#view-groups .rt-pool[data-provider=\"a\"]").waitFor({ state: "visible" });
await page.waitForFunction((m) => document.querySelector("#status").textContent.includes(m), w.done);
assert.deepEqual(errors, []);
});
}
test(`${engine} ${lang}: with routing groups on, there is no note`, async (t) => {
const page = await open(engine, 900, t, `${engine}-${lang}-routing-groups-on.png`);
const page = await open(engine, 1200, t, `${engine}-${lang}-routing-groups-on.png`);
const errors = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, true, []));
@@ -114,6 +138,8 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
await page.locator(".rt-group", { hasText: "Mine" }).waitFor({ state: "visible" });
assert.equal(await page.locator(".rt-goff").isVisible(), false);
assert(await page.locator(".rt-gnew").isVisible());
assert.deepEqual(await shown(page), ["view-groups"]);
assert((await tabs(page)).includes("groups"), "the tab is there");
assert.deepEqual(errors, []);
});
}