routing: a switched-off group's words stay readable, its logos go grey (jiabubu on Discord)

A group switched off had everything but its switch at opacity .5, and
one with no member ready either (.off, .6) was dimmed twice, to .3: its
name read at 1.92:1 (light) and 2.49:1 (dark). jiabubu found such
groups too faint to read.

Now a switched-off card is not dimmed. Its name is --fg-2 at weight 500
instead of --fg at 600, its handle's logos are grayscale at .6, and the
off switch and the "switched off" tag stay as they were. Its members
keep the same --muted as an on group's. .off does not dim it again. No
new colours, only existing tokens.

Measured contrast (both engines, en and zh):
- light: name 8.64:1 (on: 16.97), members 3.66 (on: 3.66), id 8.22
- dark: name 8.03:1 (on: 13.41), members 4.64 (on: 4.64), id 8.43

Tests:
- group-disabled-contrast.test.cjs (new). Composites each text's colour
  and every opacity above it over its backgrounds and checks:
  - the name and id are at least 4.5:1;
  - the members read no fainter than an on group's;
  - the name is quieter than an on group's;
  - the switch is off, the tag is there, and the logos are grey (an on
    group's are not).
  Runs in chromium and webkit, light and dark, en and zh.
- group-switch-add-many.test.cjs checked that every child but the switch
  was at .5. It now checks the new look: the handle is grey at .6 and
  the rest is not dimmed.

Run (on mote):
- At the pushed base 4c8e1cfdf: group-disabled-contrast,
  group-switch-add-many and group-select-copy, 16/16.
- At 09812e66b: the 49 group-*, routing-group*, panel-routing* and
  fallback-group* files, 521/526.
  - 4 reds were group-switch-add-many's old .5 check (updated above).
  - 1 red was group-found-skip "webkit de 390px" (#4617, red at base).
- go test -tags nogui -run 'Budget|Routing|Plugin.*Asset' ./internal/gui: ok.

Broken by hand: with routing.css reverted, group-disabled-contrast is
8/8 red ("the name reads at 1.92:1" / "2.49:1").

Looked at screenshots in chromium, light and dark.

Not tried: the real app's window, and WebKitGTK. Only CSS changed, with
no motion and no new API.

Reported-by: jiabubu (Discord)
This commit is contained in:
yetone
2026-11-06 15:51:04 +08:00
parent 4c8e1cfdfc
commit 152c3852ff
3 changed files with 128 additions and 5 deletions
@@ -556,8 +556,13 @@ button.rt-session { cursor: pointer; }
.rt-group { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 14px; cursor: pointer; transition: background .12s; }
.rt-group:hover { background: var(--card-2); }
.rt-group.off { opacity: .6; }
/* switched off as a whole: dimmed but for its switch, which brings it back */
.rt-group.disabled > :not(.rt-gon) { opacity: .5; }
/* switched off as a whole: its switch, its "switched off" tag and its
grey logos say so, and its words stay readable (jiabubu on Discord: at
half opacity they were too faint to read), the name a step quieter than
an on group's and not dimmed again by .off */
.rt-group.disabled { opacity: 1; }
.rt-group.disabled .nm b { color: var(--fg-2); font-weight: 500; }
.rt-group.disabled > .ics, .rt-group.disabled > .rt-ghandle { filter: grayscale(1); opacity: .6; }
.rt-group .rt-gon { flex: none; transform: scale(.85); }
.rt-group .ics { display: flex; gap: 3px; flex: none; min-width: 18px; }
.rt-group .ics .ic { width: 16px; height: 16px; }
@@ -0,0 +1,116 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// A routing group switched off stays readable (jiabubu on Discord: at half
// opacity its words were too faint to read). Its name and its members read
// at a contrast an on group's members have, and it still looks switched
// off: its switch is off, its tag says so, its name is quieter than an on
// group's and its logos are grey. In both engines and themes, in English
// and Chinese.
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 models = [
{ id: "or/a:free", name: "a:free", providerName: "OpenRouter", icon: "generic" },
{ id: "an/claude-opus-5-5", name: "claude-opus-5-5", providerName: "Anthropic", icon: "generic" },
];
const info = (ids) => ids.map((id) => ({ id, ready: true }));
const groups = () => ({
models, pools: [],
groups: [{ id: "on", name: "Lit", members: ["an/claude-opus-5-5"], match: [], matched: [], fast: [], off: [], routing: "order", ready: true, patterns: [], memberInfo: info(["an/claude-opus-5-5"]) },
// switched off, and with that no member ready either: dimmed once, not twice
{ id: "dark", name: "Quiet", members: ["or/a:free"], match: [], matched: [], fast: [], off: [], routing: "order", ready: false, disabled: true, patterns: [], memberInfo: info(["or/a:free"]) }],
});
function serve(lang, theme, posts) {
const state = { agents: [{ id: "codex", name: "Codex", path: "/test/codex", fields: [] }], profiles: [], settings: { lang, theme } };
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:"${theme}",web:true};` });
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.startsWith("/api/groups/")) {
posts.push({ path: url.pathname, body: JSON.parse(r.request().postData() || "{}") });
return json(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 });
};
}
// contrast gives the WCAG contrast of an element's text against what is
// drawn under it: its colour with every opacity above it, over the
// backgrounds of the boxes it sits in, composited from the page down
const contrast = (loc) => loc.evaluate((e) => {
const rgba = (c) => { const m = c.match(/[\d.]+/g).map(Number); return [m[0], m[1], m[2], m.length > 3 ? m[3] : 1]; };
const chain = [];
for (let n = e; n; n = n.parentElement) chain.unshift(n);
let bg = [255, 255, 255];
for (const n of chain) {
const [r, g, b, a] = rgba(getComputedStyle(n).backgroundColor);
bg = [r, g, b].map((v, i) => v * a + bg[i] * (1 - a));
}
let alpha = 1;
for (const n of chain) alpha *= Number(getComputedStyle(n).opacity);
const [r, g, b, a] = rgba(getComputedStyle(e).color);
const fg = [r, g, b].map((v, i) => v * a * alpha + bg[i] * (1 - a * alpha));
const lum = (c) => c.map((v) => { v /= 255; return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4; }).reduce((s, v, i) => s + v * [0.2126, 0.7152, 0.0722][i], 0);
const [hi, lo] = [lum(fg), lum(bg)].sort((x, y) => y - x);
return (hi + 0.05) / (lo + 0.05);
});
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
for (const theme of ["light", "dark"]) {
test(`${engine} ${lang} ${theme}: a switched-off group stays readable and looks off`, async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const page = await (await browser.newContext({ viewport: { width: 1100, height: 900 }, reducedMotion: "reduce", colorScheme: theme })).newPage();
t.after(() => browser.close());
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, theme, posts));
await page.goto("http://magpie.test/?view=routing");
const on = page.locator(".rt-group", { hasText: "Lit" });
const off = page.locator(".rt-group.disabled", { hasText: "Quiet" });
await off.waitFor();
await on.waitFor();
await page.evaluate(() => document.fonts.ready);
if (process.env.ARTIFACT_DIR) await page.locator(".rt-groups").screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-${theme}-group-disabled.png`) });
const nameOff = await contrast(off.locator(".nm b")), nameOn = await contrast(on.locator(".nm b"));
const memOff = await contrast(off.locator(".mem").first()), memOn = await contrast(on.locator(".mem").first());
const idOff = await contrast(off.locator(".nm code.mdl"));
t.diagnostic(`off: name ${nameOff.toFixed(2)}, members ${memOff.toFixed(2)}, id ${idOff.toFixed(2)}; on: name ${nameOn.toFixed(2)}, members ${memOn.toFixed(2)}`);
// readable: its name as body text is, its members and id as an on group's members are
assert.ok(nameOff >= 4.5, `the name reads at ${nameOff.toFixed(2)}:1`);
assert.ok(memOff >= Math.min(memOn, 3.4) - 0.01, `the members read at ${memOff.toFixed(2)}:1 (an on group's: ${memOn.toFixed(2)}:1)`);
assert.ok(idOff >= 4.5, `the id reads at ${idOff.toFixed(2)}:1`);
// and still visibly off
assert.ok(nameOff < nameOn - 0.5, `the name is quieter than an on group's (${nameOff.toFixed(2)} vs ${nameOn.toFixed(2)})`);
assert.equal(await off.locator(".rt-gon").getAttribute("aria-checked"), "false");
assert.equal(await off.locator(".tag.idle").count(), 1, "its tag says it is switched off");
assert.equal(await on.locator(".tag.idle").count(), 0);
const look = await off.locator(".rt-ghandle").evaluate((e) => ({ filter: getComputedStyle(e).filter, opacity: Number(getComputedStyle(e).opacity) }));
assert.match(look.filter, /grayscale\(1\)/, "its logos are grey");
assert.ok(look.opacity < 1);
assert.equal(await on.locator(".rt-ghandle").evaluate((e) => getComputedStyle(e).filter), "none", "an on group's logos keep their colours");
assert.deepEqual(posts, []);
assert.deepEqual(errors, []);
});
}
}
}
@@ -3,7 +3,7 @@
// and a group was made one model at a time, not seeing which groups a
// model was in already.
// - A group of the user's has a switch on its card: off, it posts
// groups/switch with on false, the card is dimmed but for the switch and
// groups/switch with on false, the card's logos go grey and it
// says "switched off", and the keyboard stays on the switch; on again
// posts on true. A group magpie found has no switch (it is removed).
// - justacati on X: a group switched off is listed after the ones on, and
@@ -110,8 +110,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(await down.first().evaluate((b) => b.disabled || b.getAttribute("aria-disabled") === "true" || b.classList.contains("off")), true, "Move down offered on the last group on");
await page.keyboard.press("Escape");
await sw().focus();
const dim = await card("g").evaluate((r) => [...r.children].map((c) => [c.classList.contains("rt-gon"), getComputedStyle(c).opacity]));
for (const [isSw, o] of dim) assert.equal(o, isSw ? "1" : "0.5");
// off, its logos are grey and its words stay readable, not dimmed
// (jiabubu on Discord; group-disabled-contrast measures them)
const dim = await card("g").evaluate((r) => [...r.children].map((c) => [c.classList.contains("rt-ghandle"), getComputedStyle(c).opacity, getComputedStyle(c).filter]));
for (const [isLogo, o, f] of dim) assert.deepEqual([o, f], isLogo ? ["0.6", "grayscale(1)"] : ["1", "none"]);
assert.equal(await page.locator(".rt-gedit").count(), 0, "the switch opened the editor");
await sw().click();
await page.waitForFunction(() => !document.querySelector('.rt-group[data-id="g"]')?.classList.contains("disabled"));