gui: an agent's model picker lists magpie's models before the ones it asks for itself (abledo on Discord)

abledo: "为什么claudecode的magpie模型选不了?其他的agent可以选". Claude Code
pointed at a relay through its own ANTHROPIC_BASE_URL showed that relay's
Claude models first ("Claude Code · <host>", a dozen-plus rows), and with
the current model lifted to the top every magpie model sat below the fold.
The server always sent them; only the order hid them.

openPicker now orders: the picker's own choices (Automatic, Off), routing
groups, each provider's models, then the agent's own direct rows. This
covers every agent with direct rows (Claude Code, Codex, dsh), not only
Claude Code. The current model is still lifted to the top.

Run:
- new claude-picker-magpie-first.test.cjs: chromium + webkit, widths 1100
  and 420, en/zh/zh-TW/ja/de, wired false and true: 22/22. Fails on the
  old app.js (own group before Zhipu).
- claude-picker-fold.test.cjs updated for the new order (own group and
  its fold row last): 22/22.
- the 67 GUI tests that touch direct rows or #pop, with the change: green
  except claude-picker-fold before its update. searcher-pick chromium zh
  failed twice under load at its scrollIntoViewIfNeeded after reload
  (#1745); it passes alone 2/2 and in the later batch.
- go test -tags nogui ./internal/gui: ok.
Not tried: the real desktop app with a real relay-configured Claude Code.
This commit is contained in:
yetone
2026-10-14 20:21:25 +08:00
parent 07e95265af
commit f3ea4bd69e
3 changed files with 129 additions and 10 deletions
+7 -3
View File
@@ -4441,9 +4441,13 @@ function openPicker(agent, field, anchor, ev, only) {
if (again) return;
const cur = field.value;
let options = field.options.filter((o) => !only || only(o));
// routing groups come first, before the agent's own models and each
// provider's; only the picker's own choices (Automatic, Off) above them
options = [...options.filter((o) => o.reset), ...options.filter((o) => !o.reset && o.group === ROUTING_GROUPS), ...options.filter((o) => !o.reset && o.group !== ROUTING_GROUPS)];
// routing groups come first, then each provider's, then the models the
// agent asks for itself, not through magpie: Claude Code's own list of
// Claude models above them hid every magpie model below the fold (abledo
// on Discord: "claudecode的magpie模型选不了"). Only the picker's own
// choices (Automatic, Off) above them all
const rest = options.filter((o) => !o.reset && o.group !== ROUTING_GROUPS);
options = [...options.filter((o) => o.reset), ...options.filter((o) => !o.reset && o.group === ROUTING_GROUPS), ...rest.filter((o) => !o.direct), ...rest.filter((o) => o.direct)];
const effortPicker = !only && (field.key === "effort" || field.label === "effort" || field.label === "thinking" || field.label === SUB_EFFORT || roleLevel(field.label));
options = oneRowPerModel(options, cur);
// Current model first, then the rest in catalog order. Effort levels keep
@@ -7,8 +7,10 @@
// one, opened at a click without the page moving; an alias and its dated
// id are one row, the alias's, or the dated one's while that is the value
// set. In English and Chinese. No backend: the API is faked here.
// The fold row ends Claude Code's own rows, though the account comes after
// the providers the user added (where it was, Claude Code was headed twice);
// The fold row ends Claude Code's own rows, which come after magpie's
// (abledo on Discord: they hid every magpie model below the fold), though
// the account is listed among magpie's (where it was, Claude Code was
// headed twice);
// a click on it leaves the keys to the filter (focus went to the page, and
// Esc and the arrows did nothing); a query shows the rows it finds, so an id
// typed in full is picked with Enter (which only opened the fold); and a
@@ -118,10 +120,10 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.equal(fold[0].v, w.two);
assert.equal(fold[0].n, w.whose);
assert(names.includes("DeepSeek V4"), "another provider's stay unfolded");
// after Claude Code's own rows, before the providers the user added:
// Claude Code is headed once
assert.deepEqual(await page.locator("#list li.group").allTextContents(), ["Claude Code", "DeepSeek"]);
assert.equal(await page.locator("#list li.fold + li.group").textContent(), "DeepSeek");
// magpie's first, then Claude Code's own rows and the fold after
// them: Claude Code is headed once
assert.deepEqual(await page.locator("#list li.group").allTextContents(), ["DeepSeek", "Claude Code"]);
assert.equal(await page.locator("#list li:last-child.fold").count(), 1);
const foldRow = page.locator("#list li.fold");
assert.equal(await foldRow.getAttribute("aria-expanded"), "false");
@@ -199,7 +201,7 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert(names.includes("claude-opus-4-5-20251101") && !names.includes("claude-opus-4-5"), names.join(", "));
await page.locator('#pickerRail .rail-item[data-group="favorites"]').click();
await page.waitForFunction(() => document.querySelectorAll("#list li:not(.group)").length === 2);
assert.deepEqual((await rows(page)).map((r) => r.v), ["claude-opus-4-5-20251101", "Claude Opus 4.5"]);
assert.deepEqual((await rows(page)).map((r) => r.v), ["Claude Opus 4.5", "claude-opus-4-5-20251101"]);
await page.context().close();
});
}
@@ -0,0 +1,113 @@
// Run with Node's test runner and Playwright on the module path; see README.md.
// abledo on Discord: "为什么claudecode的magpie模型选不了?其他的agent可以选".
// Claude Code not yet connected, with a relay of the user's own as its
// ANTHROPIC_BASE_URL: its picker opened on a long list of Claude models it
// asks the relay for itself, under "Claude Code · <host>", and every magpie
// model sat below it, out of sight. magpie's models now come first and the
// agent's own direct ones after them, connected or not, the current model
// still at the top. In five languages, chromium and webkit, at 1100 and 420
// wide. No backend: the API is faked here.
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 host = "api.somerelay.example";
const own = (value, note) => ({ value, note, icon: "claude-color", group: "Claude Code · " + host, direct: host });
// in the backend's order: Claude Code's own, then magpie's
const options = [
own("claude-opus-5-5", "Claude Opus 5.5"),
own("claude-haiku-5-5", "Claude Haiku 5.5"),
own("claude-sonnet-5-5", "Claude Sonnet 5.5"),
own("claude-fable-5-1", "Claude Fable 5.1"),
own("claude-opus-5", "Claude Opus 5"),
own("claude-sonnet-5", "Claude Sonnet 5"),
own("claude-fable-5", "Claude Fable 5"),
own("claude-opus-4-8", "Claude Opus 4.8"),
own("claude-sonnet-4-8", "Claude Sonnet 4.8"),
own("claude-opus-4-5", "Claude Opus 4.5"),
own("claude-sonnet-4-5", "Claude Sonnet 4.5"),
own("claude-haiku-4-5", "Claude Haiku 4.5"),
{ value: "zhipu/glm-4.6", label: "GLM-4.6", note: "Zhipu · via magpie", icon: "zhipu-color", group: "Zhipu", ref: "zhipu/glm-4.6" },
{ value: "deepseek/deepseek-v4", label: "DeepSeek V4", note: "DeepSeek · via magpie", icon: "deepseek-color", group: "DeepSeek", ref: "deepseek/deepseek-v4" },
];
const state = (value, wired) => ({
agents: [{ id: "claude", name: "Claude Code", icon: "claudecode-color", path: "/test/settings.json", wired,
fields: [{ key: "model", label: "model", value, options }] }],
profiles: [],
});
function server(lang, value, wired, sets) {
let cur = state(value, wired);
return async (route) => {
const req = route.request(), url = new URL(req.url());
if (url.pathname === "/boot.js") return route.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
if (url.pathname === "/wails/runtime.js") return route.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
if (url.pathname === "/api/state") return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
if (url.pathname === "/api/set") {
const body = req.postDataJSON();
sets.push(body);
cur = state(body.value, true);
return route.fulfill({ json: { ...cur, settings: { lang, theme: "light" } } });
}
if (url.pathname === "/api/usage/quotas") return route.fulfill({ json: [] });
if (url.pathname === "/api/groups") return route.fulfill({ json: { groups: [] } });
if (url.pathname === "/api/agents/cli") return route.fulfill({ json: { agents: {}, pending: false } });
if (url.pathname === "/api/providers") return route.fulfill({ json: { providers: [], gateway: { running: true } } });
if (url.pathname.startsWith("/api/")) return route.fulfill({ 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 route.fulfill({ body: await fs.readFile(file), contentType });
};
}
const row = '.row.agent[data-id="claude"]';
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
test(engine + ": Claude Code's picker shows magpie's models first", async (t) => {
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
const errors = [];
t.after(async () => {
if (errors.length) console.log(errors);
await browser.close();
});
for (const width of [1100, 420]) {
for (const lang of ["en", "zh", "zh-TW", "ja", "de"]) {
await t.test(`${lang} at ${width}`, async () => {
for (const wired of [false, true]) {
const sets = [];
const context = await browser.newContext({ viewport: { width, height: 760 } });
const page = await context.newPage();
page.setDefaultTimeout(5000);
page.on("pageerror", (e) => errors.push(e.message));
await page.route("**/*", server(lang, "claude-opus-5-5", wired, sets));
await page.goto("http://magpie.test/");
await page.locator(row).waitFor();
await page.locator(`${row} .field[data-key="model"]`).first().click();
await page.locator("#pop:not([hidden]) #list li").first().waitFor();
await page.waitForTimeout(400); // the picker grows open
const groups = await page.locator("#list li.group").allTextContents();
const at = (g) => groups.findIndex((x) => x.toLowerCase() === g.toLowerCase());
assert(at("Zhipu") >= 0 && at("DeepSeek") > at("Zhipu"), `${wired}: ${groups.join(" | ")}`);
assert(at("Claude Code · " + host) > at("DeepSeek"), `${wired}: the agent's own come last: ${groups.join(" | ")}`);
// the current one still heads the list, and magpie's first one
// is in sight without a scroll
const names = await page.locator("#list li:not(.group) .v").allTextContents();
const cur = names.indexOf("claude-opus-5-5");
assert(cur >= 0 && cur < names.indexOf("GLM-4.6") && names.lastIndexOf("claude-opus-5-5") === cur, `${wired}: ${names.join(" | ")}`);
const glm = page.locator("#list li:not(.group)", { hasText: "GLM-4.6" });
const box = await glm.boundingBox(), list = await page.locator("#list").boundingBox();
assert(box && box.y + box.height <= list.y + list.height + 1, `${wired}: GLM-4.6 is below the fold at ${JSON.stringify(box)} in ${JSON.stringify(list)}`);
await glm.click();
await page.waitForFunction(() => document.querySelector("#pop").hidden);
assert.deepEqual(sets, [{ agent: "claude", field: "model", value: "zhipu/glm-4.6" }]);
await context.close();
}
});
}
}
assert.deepEqual(errors, []);
});
}