Files
magpie/internal/gui/tests/group-found-off.test.cjs
T
yetone cec267f902 gui: a field's long explanation shows on asking, in the editor and Routing groups (yujezhang on X)
yujezhang on X (11-10): "现在界面好多描述都太繁琐了 ... 界面只保留完成
操作必需的信息". The longest always-visible lines left were in a
provider's editor (100 to 666 characters a field) and Routing groups'
settings (69 to 318). They now work like Settings' rows since 11-02:
with a mouse, the explanation rests out of sight and the row's hover
(450ms) or keyboard focus shows it in the shared .set-hint card. A touch
screen keeps every line. No layout moves, no new page, no info icon
(the owner chose hover on the row for Settings).

Removed or moved:
- Routing's empty caption ("Every request an agent sends to magpie
  shows up here, routed for real.") is gone from the empty state: the
  mode line above it says the same. The key stays, the panel uses it.
- A provider editor field's explanation (.fld > .hint.expl): Headers,
  Certificate, Compaction, the routing and rate-limit fields and the
  rest: in the card. A line with a link or control in it, a warning and
  an error stay in sight.
- Two fields keep one short line in sight for what turning them on
  costs: Certificate ("Turn it on only on a network you trust.") and
  Compaction ("A conversation compacted this way continues only on
  this provider and account."). New keys in zh, zh-TW, ja and de.
- The editor's own settings rows (.prov-prefs: warm-up, check-in,
  resets) hide their lines as Settings' do; a result line (.say) stays.
- Routing groups: Found, Names and the three defaults' small lines: in
  the card. The no-names line stays.
- settingshints.js listens on document, so the editor (in #modal) and
  Routing get the card; the card grows from its row in 150ms, strong
  ease-out, a fade alone under reduced motion.

A line held out of sight is position: absolute in its field's box
(.fld and .hint-row > .txt are position: relative): placed against the
page, deep in the editor's scroll, it grew the page a scrollbar and
made the editor 10px narrower, and account-weight's de 390 in WebKit
ran an account line 3px past its row. Its sr-only -1px margin is
dropped, so it no longer sits 1px left of its row (warm-at-times,
warm-now and checkin-now-account check every .sub is inside its row).

Tests:
- New editor-hints.test.cjs (chromium + webkit, en/zh/zh-TW/ja/de,
  1100 and 420): at rest the explanation is out of sight and still
  described; Certificate's lead is in sight on one line; a hover shows
  the card with the text, inside the window, not over the name, nothing
  moving, taking no pointer; leaving hides it; Tab onto a field shows
  it; every out-of-sight line is placed in its own field; Routing
  groups' lines the same. 42/42 with account-weight on the Linux box.
- Broken by hand: the hide rule replaced and ROWS without the editor
  and groups: 0/20 red. The position: relative rule removed: 20/20 red
  (the placement check), then restored.
- vertex-editor: a hint resting out of sight isn't "cut".
  group-found-off: rows carry hint-row.
- 271 GUI files (every editor/edit= test, hints, visibility, prov-prefs,
  rt-gset/rt-cap, i18n-keys, old-webkit) in both engines on the WSL box
  (magpie-desktop), mine against a copy of 5d9e29814: 5589 pass / 241
  fail mine, 5528 / 262 base. Every file red in mine is red on base too
  except group-morph, provider-image-files and restart-app (one subtest
  each at concurrency 8); alone those three pass 114/114.
- settings-hints ja/de 420 and settings-lines-wrap de 440 fail the same
  on base (#5872).

Not tried: the whole 1343-file GUI suite (mote's suite.lock queue was
hours long); a touch screen; the real Linux app (WebKitGTK); macOS
Playwright.
2026-11-10 16:09:34 +08:00

135 lines
8.6 KiB
JavaScript

// Run with Node's test runner and Playwright on the module path; see README.md.
// The groups magpie finds on its own (auto-<model>) can be turned off all
// at once (蓝猫 on Discord: "路由分组会自动创建,可以关闭掉吗"), not only
// removed one by one. A switch by the routing groups' list, with what it
// does in words, says whether they are found; clicked off, it posts
// groups/found {on:false}, the found groups leave the list and the user's
// stay, and the page says which agent was moved off a found group to its
// model from one provider. Clicked on again, they are back. Neither click
// moves the page, and the switch has no left-border accent. In English and
// Chinese, Chromium and WebKit.
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: "a/m", name: "m", providerName: "A", icon: "generic" },
{ id: "b/m", name: "m", providerName: "B", icon: "generic" },
{ id: "a/x", name: "x", providerName: "A", icon: "generic" },
];
const info = (ids) => ids.map((id) => ({ id, ready: true }));
const found = { id: "auto-m", name: "Model M", members: ["a/m", "b/m"], auto: true, ready: true, memberInfo: info(["a/m", "b/m"]) };
const mine = { id: "mine", name: "Mine", members: ["a/x", "b/m"], ready: true, memberInfo: info(["a/x", "b/m"]) };
const groups = (on, moved) => ({ models, pools: [], deciders: [], found: on, groups: on ? [mine, found] : [mine], ...(moved ? { moved } : {}) });
const words = {
en: { label: "Find groups on their own", onHint: "becomes a group of them", offHint: "only the groups you made or changed",
moved: "Claude Code moved to a/m", back: "Found groups are on" },
zh: { label: "自动创建路由组", onHint: "会自动成组", offHint: "只列出和提供你新建或改过的组",
moved: "Claude Code 已改用 a/m", back: "已开启自动创建路由组" },
};
function serve(lang, posts) {
let on = true;
const state = { agents: [{ id: "claude", name: "Claude Code", path: "/test/claude", 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: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(on));
if (url.pathname === "/api/groups/found") {
const body = JSON.parse(r.request().postData() || "{}");
posts.push(body);
on = body.on;
return json(groups(on, on ? null : [{ agent: "Claude Code", field: "model", from: "group/auto-m", to: "a/m" }]));
}
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 });
};
}
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
for (const lang of ["en", "zh"]) {
const w = words[lang];
test(`${engine} ${lang}: found groups turned off and on`, 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" })).newPage();
t.after(async () => {
if (process.env.ARTIFACT_DIR) {
await fs.mkdir(process.env.ARTIFACT_DIR, { recursive: true });
await page.screenshot({ path: path.join(process.env.ARTIFACT_DIR, `${engine}-${lang}-group-found-off.png`) });
}
await browser.close();
});
page.setDefaultTimeout(5000);
page.setDefaultNavigationTimeout(60000);
const errors = [], posts = [];
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", serve(lang, posts));
await page.goto("http://magpie.test/?view=groups");
const card = (name) => page.locator(".rt-group", { hasText: name });
await card("Model M").waitFor();
const box = page.locator(".rt-gsec .rt-gfound");
const sw = box.locator("button[role=switch]");
assert.equal(await sw.getAttribute("aria-label"), w.label);
assert.equal(await sw.getAttribute("aria-checked"), "true");
assert((await box.textContent()).includes(w.label));
assert((await box.textContent()).includes(w.onHint), "it says what found groups are");
// under the list, in the page's Settings, the names in agents' lists
// (for every group) after it
const order = await page.evaluate(() => {
const s = document.querySelector(".rt-gsec");
return [...s.children].map((c) => c.className).filter((c) => c !== "rt-goff");
});
assert.deepEqual(order.slice(0, 4), ["row-head", "list rt-groups", "row-head rt-gset-head", "list rt-gset"]);
assert.deepEqual(await page.evaluate(() => [...document.querySelector(".rt-gset").children].map((c) => c.className)), ["rt-gfound hint-row", "rt-gnames hint-row", "rt-gdef rt-gdef-sink hint-row", "rt-gdef rt-gdef-first hint-row", "rt-gdef rt-gdef-patience hint-row"]);
const border = await sw.evaluate((e) => { const c = getComputedStyle(e); return c.borderLeftWidth !== c.borderRightWidth || c.borderLeftColor !== c.borderRightColor; });
assert.equal(border, false, "no left-border accent");
await box.evaluate((x) => x.scrollIntoView({ block: "center" })); // by the test, as the reader would
await page.waitForTimeout(200);
const at = () => page.evaluate(() => [...document.querySelectorAll("*")].filter((e) => e.scrollTop).map((e) => [e.id || e.className, e.scrollTop]).join(";"));
const before = await at();
await sw.click();
await page.waitForFunction(() => document.querySelector(".rt-gfound button[role=switch]")?.getAttribute("aria-checked") === "false");
assert.deepEqual(posts, [{ on: false }]);
await card("Model M").waitFor({ state: "detached" }); // the found group left the list
assert.equal(await card("Mine").count(), 1, "the user's group stays");
assert((await box.textContent()).includes(w.offHint), "it says what is listed now");
await page.waitForFunction((m) => document.querySelector("#status").textContent.includes(m), w.moved);
assert.equal(await at(), before, "the click moved nothing");
await box.locator("button[role=switch]").click();
await card("Model M").waitFor();
assert.deepEqual(posts, [{ on: false }, { on: true }]);
assert.equal(await box.locator("button[role=switch]").getAttribute("aria-checked"), "true");
await page.waitForFunction((m) => document.querySelector("#status").textContent.includes(m), w.back);
assert.equal(await at(), before, "nor did the second");
const missing = await page.evaluate(() => [
"Find groups on their own", "Found groups are on", "Found groups are off: only yours are listed and served",
"A model two or more of your providers serve becomes a group of them (auto/…). Switch it off to list and serve only the groups you made or changed.",
"Off: only the groups you made or changed are listed and served. An agent set to a found group is moved to its model from one provider, and a request still naming one goes there too.",
"No group yet. New group makes one of any models you like.",
].filter((k) => !I18N.zh[k]));
assert.deepEqual(missing, [], "every string has its Chinese");
assert.deepEqual(errors, []);
});
}
}